@elliemae/ssf-guest 2.24.0 → 2.25.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/guest.js +11 -5
- package/dist/cjs/tests/utils.js +6 -2
- package/dist/esm/guest.js +13 -6
- package/dist/esm/tests/utils.js +6 -2
- package/dist/public/callchain-grandchild.html +1 -1
- package/dist/public/creditService.html +1 -1
- package/dist/public/e2e-guest.html +1 -1
- package/dist/public/index.html +1 -1
- package/dist/public/js/emuiSsfGuest.42c1a5949e7eb13de9e0.js +3 -0
- package/dist/public/js/emuiSsfGuest.42c1a5949e7eb13de9e0.js.br +0 -0
- package/dist/public/js/emuiSsfGuest.42c1a5949e7eb13de9e0.js.gz +0 -0
- package/dist/public/js/emuiSsfGuest.42c1a5949e7eb13de9e0.js.map +1 -0
- package/dist/public/loanValidation.html +1 -1
- package/dist/public/pricingService.html +1 -1
- package/dist/public/titleService.html +1 -1
- package/dist/public/util.js +1 -1
- package/dist/public/util.js.br +0 -0
- package/dist/public/util.js.gz +0 -0
- package/dist/public/util.js.map +1 -1
- package/dist/public/v2-guest.html +1 -1
- package/dist/types/lib/guest.d.ts +16 -0
- package/dist/types/lib/tests/utils.d.ts +3 -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/dist/umd/util.js +1 -1
- package/dist/umd/util.js.br +0 -0
- package/dist/umd/util.js.gz +0 -0
- package/dist/umd/util.js.map +1 -1
- package/package.json +2 -2
- package/dist/public/js/emuiSsfGuest.bb7f9a5114e5717cda3d.js +0 -3
- package/dist/public/js/emuiSsfGuest.bb7f9a5114e5717cda3d.js.br +0 -0
- package/dist/public/js/emuiSsfGuest.bb7f9a5114e5717cda3d.js.gz +0 -0
- package/dist/public/js/emuiSsfGuest.bb7f9a5114e5717cda3d.js.map +0 -1
package/dist/umd/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(q,R){typeof exports=="object"&&typeof module=="object"?module.exports=R(require("emuiDiagnostics")):typeof define=="function"&&define.amd?define(["emuiDiagnostics"],R):typeof exports=="object"?exports.ice=R(require("emuiDiagnostics")):(q.ice=q.ice||{},q.ice.guest=R(q.emuiDiagnostics))})(globalThis,Z=>(()=>{var q={572(a,l,c){var g=c(736),h=g.Symbol;a.exports=h},561(a,l,c){var g=c(572),h=c(504),w=c(567),u="[object Null]",p="[object Undefined]",I=g?g.toStringTag:void 0;function v(y){return y==null?y===void 0?p:u:I&&I in Object(y)?h(y):w(y)}a.exports=v},605(a,l,c){var g=c(327),h=/^\s+/;function w(u){return u&&u.slice(0,g(u)+1).replace(h,"")}a.exports=w},433(a){var l=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis;a.exports=l},504(a,l,c){var g=c(572),h=Object.prototype,w=h.hasOwnProperty,u=h.toString,p=g?g.toStringTag:void 0;function I(v){var y=w.call(v,p),f=v[p];try{v[p]=void 0;var m=!0}catch{}var x=u.call(v);return m&&(y?v[p]=f:delete v[p]),x}a.exports=I},567(a){var l=Object.prototype,c=l.toString;function g(h){return c.call(h)}a.exports=g},736(a,l,c){var g=c(433),h=typeof self=="object"&&self&&self.Object===Object&&self,w=g||h||Function("return this")();a.exports=w},327(a){var l=/\s/;function c(g){for(var h=g.length;h--&&l.test(g.charAt(h)););return h}a.exports=c},702(a,l,c){var g=c(230),h=c(381),w=c(569),u="Expected a function",p=Math.max,I=Math.min;function v(y,f,m){var x,k,U,C,E,_,A=0,S=!1,W=!1,N=!0;if(typeof y!="function")throw new TypeError(u);f=w(f)||0,g(m)&&(S=!!m.leading,W="maxWait"in m,U=W?p(w(m.maxWait)||0,f):U,N="trailing"in m?!!m.trailing:N);function F(b){var P=x,G=k;return x=k=void 0,A=b,C=y.apply(G,P),C}function X(b){return A=b,E=setTimeout($,f),S?F(b):C}function J(b){var P=b-_,G=b-A,K=f-P;return W?I(K,U-G):K}function V(b){var P=b-_,G=b-A;return _===void 0||P>=f||P<0||W&&G>=U}function $(){var b=h();if(V(b))return H(b);E=setTimeout($,J(b))}function H(b){return E=void 0,N&&x?F(b):(x=k=void 0,C)}function z(){E!==void 0&&clearTimeout(E),A=0,x=_=k=E=void 0}function B(){return E===void 0?C:H(h())}function D(){var b=h(),P=V(b);if(x=arguments,k=this,_=b,P){if(E===void 0)return X(_);if(W)return clearTimeout(E),E=setTimeout($,f),F(_)}return E===void 0&&(E=setTimeout($,f)),C}return D.cancel=z,D.flush=B,D}a.exports=v},230(a){function l(c){var g=typeof c;return c!=null&&(g=="object"||g=="function")}a.exports=l},470(a){function l(c){return c!=null&&typeof c=="object"}a.exports=l},89(a,l,c){var g=c(561),h=c(470),w="[object Symbol]";function u(p){return typeof p=="symbol"||h(p)&&g(p)==w}a.exports=u},381(a,l,c){var g=c(736),h=function(){return g.Date.now()};a.exports=h},345(a,l,c){var g=c(702),h=c(230),w="Expected a function";function u(p,I,v){var y=!0,f=!0;if(typeof p!="function")throw new TypeError(w);return h(v)&&(y="leading"in v?!!v.leading:y,f="trailing"in v?!!v.trailing:f),g(p,I,{leading:y,maxWait:I,trailing:f})}a.exports=u},569(a,l,c){var g=c(605),h=c(230),w=c(89),u=NaN,p=/^[-+]0x[0-9a-f]+$/i,I=/^0b[01]+$/i,v=/^0o[0-7]+$/i,y=parseInt;function f(m){if(typeof m=="number")return m;if(w(m))return u;if(h(m)){var x=typeof m.valueOf=="function"?m.valueOf():m;m=h(x)?x+"":x}if(typeof m!="string")return m===0?m:+m;m=g(m);var k=I.test(m);return k||v.test(m)?y(m.slice(2),k?2:8):p.test(m)?u:+m}a.exports=f},388(a){"use strict";a.exports=Z}},R={};function T(a){var l=R[a];if(l!==void 0)return l.exports;var c=R[a]={exports:{}};return q[a](c,c.exports,T),c.exports}T.n=a=>{var l=a&&a.__esModule?()=>a.default:()=>a;return T.d(l,{a:l}),l},T.d=(a,l)=>{for(var c in l)T.o(l,c)&&!T.o(a,c)&&Object.defineProperty(a,c,{enumerable:!0,get:l[c]})},T.o=(a,l)=>Object.prototype.hasOwnProperty.call(a,l),T.r=a=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(a,"__esModule",{value:!0})};var Y={};return(()=>{"use strict";T.r(Y),T.d(Y,{SSFGuest:()=>ue});const l={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let c;const g=new Uint8Array(16);function h(){if(!c&&(c=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!c))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return c(g)}var w;const u=[];for(let n=0;n<256;++n)u.push((n+256).toString(16).slice(1));function p(n,e=0){return u[n[e+0]]+u[n[e+1]]+u[n[e+2]]+u[n[e+3]]+"-"+u[n[e+4]]+u[n[e+5]]+"-"+u[n[e+6]]+u[n[e+7]]+"-"+u[n[e+8]]+u[n[e+9]]+"-"+u[n[e+10]]+u[n[e+11]]+u[n[e+12]]+u[n[e+13]]+u[n[e+14]]+u[n[e+15]]}function I(n,e=0){const t=p(n,e);if(!w(t))throw TypeError("Stringified UUID is invalid");return t}const v=null;function y(n,e,t){if(l.randomUUID&&!e&&!n)return l.randomUUID();n=n||{};const s=n.random||(n.rng||h)();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 p(s)}const f=y;var m=T(345),x=T.n(m);const k="elli:remoting",U="elli:remoting:response",C="elli:remoting:exception",E=({messageType:n,messageBody:e,requestId:t,onewayMsg:s=!1})=>({requestId:t??(s?null:f()),source:k,type:n,body:e}),_=n=>{const{targetWin:e,targetOrigin:t,messageType:s,messageBody:i}=n,r=E({messageType:s,messageBody:i});e.postMessage(r,t)};class A{#i;#e;#t=new Map;#a=new Map;#n=null;#s=null;#c=new Map;constructor(e,t){if(!e)throw new Error("logger is required");if(!t)throw new Error("correlationId is required");this.#i=t,this.#e=e}#p=()=>{this.#n=null;const e=Date.now(),t=[];let s=null;if(this.#a.forEach((i,r)=>{const{requestId:o,cancelTime:d}=i;d&&d<=e?(this.#e.debug(`Detected response timeout for requestId: ${o}...`),t.push(r),i.resolve(void 0)):d&&(s=s===null?d:Math.min(s,d))}),t.forEach(i=>{this.#a.delete(i)}),s!==null){const i=Math.max(s-Date.now(),0);this.#g(i)}};#g=e=>{this.#n===null&&(this.#n=window.setTimeout(this.#p,e))};#f=()=>{this.#n!==null&&(window.clearTimeout(this.#n),this.#n=null)};#r=e=>{const t=this.#a.get(e);return this.#e.debug(`serving requestId: ${e}`),this.#a.delete(e),t};#o=e=>{const{requestId:t}=e;this.#e.debug(`Response received for invocation requestId: ${t}`);const s=this.#r(t);return s?(s.resolve(e.body),!0):(this.#e.debug(`Received response to stale/invalid request with requestId: ${t}`),!1)};#h=e=>{this.#e.debug(`Exception received for invocation (requestId = ${e.requestId})`);const t=this.#r(e.requestId);return t?(t.reject(new Error(e.body)),!0):(this.#e.warn(`Received exception for stale/invalid request (requestId = ${e.requestId})`),!1)};#v=({sourceWin:e,sourceOrigin:t,message:s})=>{this.#e.debug(`Received message of type "${s.type}"`);const i=this.#t.get(s.type);return i?(i.forEach(r=>{this.#e.debug(`Invoking message handler ${r.name}`),r({sourceWin:e,sourceOrigin:t,requestId:s.requestId,type:s.type,body:s.body})}),!0):!1};#l=e=>{if(this.#c.size===0||!e.source)return!1;const t=this.#c.get(e.source);return!t||e?.data?.source!==k?!1:(this.#e.debug(`Remoting: Received message of type "${e.data.type}"`),e.data.type===U?this.#o(e.data):e.data.type===C?this.#h(e.data):this.#v({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.#c.set(s,t)};initialize=e=>{this.#s&&this.#s.removeEventListener("message",this.#l),e.addEventListener("message",this.#l),this.#s=e,this.#e.debug(`initialized remoting id: ${this.#i}`)};close=()=>{this.#s&&(this.#s.removeEventListener("message",this.#l),this.#s=null),this.#f(),this.#e.debug(`closed remoting id: ${this.#i}`)};invoke=e=>{const{targetWin:t,targetOrigin:s,messageType:i,messageBody:r,responseTimeoutMs:o}=e;return new Promise((d,O)=>{const j=E({messageType:i,messageBody:r});this.#a.set(j.requestId,{requestId:j.requestId,resolve:d,reject:O,cancelTime:o?Date.now()+o:null}),t.postMessage(j,s);const{requestId:L}=j;this.#e.debug(`Posted invocation message of type ${i} requestId: ${L||""}`),o&&(this.#e.debug(`scheduling timeout check for requestId: ${L||""} in ${o} ms`),this.#g(o))})};listen=e=>{const{messageType:t,callback:s}=e,i=this.#t.get(t)||[];i.push(s),this.#t.set(t,i)};unlisten=e=>{const{messageType:t,callback:s}=e,i=this.#t.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=E({messageType:i,messageBody:r,onewayMsg:!0});t.postMessage(o,s),this.#e.debug(`Posted one-way message of type "${i}"`)};removeSender=e=>{const{window:t}=e;t&&this.#c.delete(t)};respond=e=>{const{targetWin:t,targetOrigin:s,requestId:i,response:r}=e,o=E({messageType:U,messageBody:r,requestId:i});t.postMessage(o,s),this.#e.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,d=E({messageType:C,messageBody:o,requestId:i});t.postMessage(d,s),this.#e.debug(`Exception sent to caller for invocation. requestId: ${i}`)}}var S=(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))(S||{});class W{__TYPE__="Proxy";id;objectType;constructor(e,t){this.id=e,this.objectType=t}}const N=n=>n?.constructor?.name==="Proxy"||n?.constructor?.name==="ScriptingObjectProxy"||n?.__TYPE__==="Proxy";class F{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 X{static[Symbol.hasInstance](e){return typeof e=="object"&&e!==null&&"getType"in e&&typeof e.getType=="function"&&e.getType()==="ProxyEvent"}#i;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.#i=i,this.id=`${this.objectId}.${this.name}`.toLowerCase()}subscribe=e=>this.#i.subscribe({eventId:this.id,callback:e});unsubscribe=e=>{this.#i.unsubscribe({eventId:this.id,token:e})}}const J=n=>n instanceof F,V=(n,e)=>`${n.toLowerCase()}.${e.toLowerCase()}`;var $=T(388);const H=()=>{const{parent:n}=window;try{return n?.location?.href}catch{return null}},z=n=>{if(!n||n==="about:blank")return"*";try{const{origin:e}=new URL(n);return e==="null"||!e?"*":e}catch{try{const{origin:e}=new URL(n,document.baseURI);return e==="null"||!e?"*":e}catch{return"*"}}},B=()=>window.self!==window.parent,D=(n,e)=>{const t=e||document.body,s=document.defaultView?.getComputedStyle?.(t,null),i=s?s[n]:"0";return parseInt(i,10)},b=/^https?:\/\/([a-z0-9-]+\.)*(?:elliemae\.io|ellielabs\.com|ellieservices\.com|encompassloconnect\.com|ice\.com|localhost:[0-9]+)$/i,P="elli:remoting",G=3e4,K=()=>new Promise((n,e)=>{if(B())n({origin:z(document.referrer||H()),window:window.parent});else{const t=window;let s;const i=r=>{if(b.test(r.origin)){const{source:o,type:d}=r.data||{};if(o===P&&d===S.HandShake){const{origin:O}=r,j=r.source;clearTimeout(s),_({targetWin:j,targetOrigin:O,messageType:S.HandShakeAck,messageBody:{}}),t.removeEventListener("message",i),n({origin:O,window:j})}}};s=setTimeout(()=>{t.removeEventListener("message",i),e(new Error(`Host handshake timed out after ${G}ms`))},G),t.addEventListener("message",i)}});let M=!1;const re=n=>{M=n},ee=(n=null)=>{let e=n;const t=()=>{if(!e&&(e=window.ice?.guest?.SSFGuest?new window.ice.guest.SSFGuest:null,!e))throw new Error("Guest definition not found");return e};window.elli=window.elli??{},window.elli.script={guest:{create:(s,i)=>t().addScript(s,i)},connect:s=>t().connect(s),getObject:s=>t().getObject(s),setLogLevel:s=>t().setLogLevel(s),subscribe:(s,i,r,o)=>t().subscribe({eventId:`${s}.${i}`,callback:d=>r(d?.obj,d?.eventParams,d?.eventOptions),criteria:o?.criteria}),unsubscribe:(s,i,r)=>t().unsubscribe({eventId:`${s}.${i}`,token:r})}};try{ee()}catch{}var oe=(n=>(n.OBJECT="object",n.VALUE="value",n))(oe||{});const te=12e4,ce=2e3,ae={eventFeedback:!0},se=()=>{const{document:n}=window,e=n.body,t=n.documentElement,i={height:e.offsetHeight+D("marginTop")+D("marginBottom"),width:Math.max(e.scrollWidth,t.scrollWidth)};_({targetWin:window.parent,targetOrigin:z(n.referrer||H()),messageType:S.GuestResize,messageBody:i}),window.removeEventListener("load",se)};B()&&window.addEventListener("load",se);const ie={"cdn.ice.com":"https://api.elliemae.com/diagnostics/v2/logging","cdn.np.ice.com":"https://stg.api.elliemae.com/diagnostics/v2/logging","cdn.uat.ice.com":"https://concept.api.elliemae.com/diagnostics/v2/logging","cdn.pt1.ice.com":"https://pel1.api.ellielabs.com/diagnostics/v2/logging","cdn.qa1.ice.com":"https://int.api.ellielabs.com/diagnostics/v2/logging","cdn.dev1.ice.com":"https://int.api.ellielabs.com/diagnostics/v2/logging","cdn.mortgagetech.ice.com":"https://api.elliemae.com/diagnostics/v2/logging","cdn.mortgagetech.s1.ice.com":"https://stg.api.elliemae.com/diagnostics/v2/logging","cdn.mortgagetech.uat1.ice.com":"https://concept.api.elliemae.com/diagnostics/v2/logging","cdn.mortgagetech.pl1.ice.com":"https://pel1.api.ellielabs.com/diagnostics/v2/logging","cdn.mortgagetech.q1.ice.com":"https://int.api.ellielabs.com/diagnostics/v2/logging","cdn.mortgagetech.d1.ice.com":"https://int.api.ellielabs.com/diagnostics/v2/logging",localhost:"https://int.api.ellielabs.com/diagnostics/v2/logging"},ne=["click","scroll","keypress","touchstart"],le=()=>{const n=document.currentScript?.src||"file:///opt/jenkins/workspace/UIPlatform_pui-microfe_master/253/libs/ssf-guest/lib/guest.ts",e=n?new URL(n).hostname:"localhost";return ie[e]||ie["cdn.mortgagetech.q1.ice.com"]};class ue{#i;#e;#t;#a=!1;#n=null;#s=!1;#c=new Map;#p=null;#g=null;#f=null;#r=null;#o=null;#h=null;#v=new Map;#l(){if(!this.#o||!this.#r)throw new Error("Guest is not connected to a host. Call connect() first.");return{hostWindow:this.#o,hostOrigin:this.#r}}#E=!1;#u=null;#m=null;#b=null;#S=!0;#j=te;#O;#w=null;constructor(e){const{console:t=!1,url:s=window.__ICE__?.diagnosticsUrl||le(),index:i="ssf-guest-v2",team:r="ICE",appName:o="SSF Guest V2 Application"}=e?.logger??{};this.#O=e?.logger,this.#E=e?.usesDevConnectAPI??!1,this.#S=e?.keepAlive??!0,this.#j=e?.keepAliveInterval??te;const d=t?(0,$.Console)():(0,$.http)(s);this.#e=e?.appLogger??(0,$.logger)({transport:d,index:i,team:r,appName:o}),(0,$.webvitals)(this.#e),(0,$.logUnhandledErrors)(this.#e),this.#i=f(),this.#t=new A(this.#e,this.#i),ee(this),this.#e.audit({message:"Guest created",guestUrl:window.location.href,correlationId:this.#i})}#d=()=>({guestId:this.#p,guestTitle:this.#g,guestUrl:this.#f});#y=e=>{if(!e||!e.objectId)throw this.#e.error("Deserialization of scripting object failed. Object does not have an Object ID."),new Error("Cannot deserialize object JSON into proxy.");const t=new W(e.objectId,e.objectType);return e.functions&&e.functions.forEach(s=>{Object.defineProperty(t,s,{value:async(...i)=>{const o=t[s]?.callContext?.callChain;return this.#x({objectId:t.id,functionName:s,functionParams:[...i],callerChain:o})},enumerable:!0})}),e.events&&e.events.forEach(s=>{Object.defineProperty(t,s,{value:new X({objectId:t.id,name:s,eventSrc:this}),enumerable:!0})}),this.#e.debug(`Created guest proxy for scripting object (id = "${t.id}")`),t};#x=async({objectId:e,functionName:t,functionParams:s,callerChain:i})=>{this.#e.debug(`Invoking scripting object method ${e}.${t}()...`);const r=[];if(s)for(let L=0;L<s.length;L+=1){const Q=s[L];Q instanceof Promise&&r.push(Q.then(de=>{s[L]=de}))}await Promise.all(r);const{hostWindow:o,hostOrigin:d}=this.#l(),O=await this.#t.invoke({targetWin:o,targetOrigin:d,messageType:S.ObjectInvoke,messageBody:{objectId:e,functionName:t,functionParams:s,...i?.length?{callerChain:i}:{}}}),j=this.#I(O);return this.#e.audit({message:"Guest proxy invoked Scripting Object method",scriptingObject:e,scriptingMethod:t,...this.#d()}),j};#T(e,t){return Object.entries(t).every(([s,i])=>{const r=e[s];if("eq"in i)return r===i.eq;if("in"in i)return Array.isArray(i.in)&&i.in.includes(r);if("includes"in i)return Array.isArray(r)&&r.includes(i.includes);if("gt"in i){const o=typeof r=="number"?r:Number(r);return!Number.isNaN(o)&&o>i.gt}if("lt"in i){const o=typeof r=="number"?r:Number(r);return!Number.isNaN(o)&&o<i.lt}if("regex"in i)try{let o=this.#v.get(i.regex);return o||(o=new RegExp(i.regex),this.#v.set(i.regex,o)),typeof r=="string"&&o.test(r)}catch{return!1}return!1})}#I=e=>e?.type==="object"&&"object"in e?this.#y(e.object):e?.type==="value"?e.value:e;#k=({body:e})=>{e?.logLevel&&(this.#e.setLogLevel(e.logLevel),this.#e.debug(`Log level changed by host to ${e.logLevel}`)),this.#p=e?.guestId??null,this.#g=e?.guestTitle??null,this.#f=e?.guestUrl??null,this.#e.audit({message:"Received configuration from Host",...this.#d()})};#L=()=>{window.focus()};#_=async()=>{await this.close(),window.close()};#$=()=>{B()||(this.#h=setInterval(()=>{this.#o?.closed&&this.close().then(()=>{window.close()}).catch(()=>{})},1e3))};#P=async({sourceWin:e,sourceOrigin:t,requestId:s,body:i})=>{const r=this.#y(i.object);if(r){const o=V(r.id,i.eventName);this.#e.debug(`Received event "${o}" from host`);let d;i.eventHandler?d=[{callback:window[i.eventHandler],token:f()}]:d=this.#c.get(o)||[];const O=[];if(d.forEach(j=>{if(j?.callback){if(j.criteria&&!(i.eventParams?this.#T(i.eventParams,j.criteria):!1)){this.#e.debug(`Event ${o} did not match criteria for subscriber ${j.callback.name}`);return}this.#e.debug(`Invoking event subscriber ${j.callback.name} for event ${o}`);const L=j.callback({obj:r,eventName:i.eventName,eventParams:i.eventParams,eventOptions:i.eventOptions});L instanceof Promise?O.push(L):typeof L<"u"&&O.push(Promise.resolve(L))}}),s){const j=await Promise.all(O);this.#t.respond({targetWin:e,targetOrigin:t,requestId:s,response:j}),this.#e.audit({message:"Guest proxy processed event from host and responded",scriptingEventId:o,scriptingObject:r.id,...this.#d()})}else this.#e.audit({message:"Guest proxy processed event from host",scriptingEventId:o,scriptingObject:r.id,...this.#d()})}};#C=async()=>{if(!(!this.#u||!this.#m||!this.#b))try{await fetch(`${this.#b}/oauth2/v1/token/introspection?${new URLSearchParams({token:this.#u,client_id:this.#m}).toString()}`,{headers:{"content-type":"application/x-www-form-urlencoded;charset=UTF-8"},method:"POST"})}catch(e){this.#e.warn(`Failed to extend token lifetime: ${e.message}`)}};#G=async()=>{if(this.#u&&this.#m&&this.#b)try{await fetch(`${this.#b}/oauth2/v1/token/revocation?${new URLSearchParams({token:this.#u,client_id:this.#m}).toString()}`,{method:"POST"})}catch(e){this.#e.error(`Error revoking token. ${e.message}`)}finally{this.#u=null,this.#m=null}};#R=async()=>{if(this.#S)try{const e=await Promise.race([this.getObject("application"),new Promise(t=>{setTimeout(()=>t(null),ce)})]);e?(this.#w=x()(async()=>{try{await e.keepSessionAlive(),await this.#C()}catch(t){this.#e.error(`Error keeping session alive. ${t.message}`)}},this.#j,{leading:!1}),ne.forEach(t=>{document.addEventListener(t,this.#w)})):this.#e.warn("Application object not available to send keep alive")}catch(e){this.#e.error(`Error getting application object. ${e.message}`)}};addScript=async(e,t)=>{if(!this.#a&&e){await this.connect();const s=document.createElement("script");s.setAttribute("src",e),s.setAttribute("type","module"),await new Promise((i,r)=>{let o,d;const O=()=>{s.removeEventListener("load",o),s.removeEventListener("error",d)};o=()=>{O(),this.#a=!0,re(!0),i()},d=()=>{O(),r(new Error(`Failed to load script: ${e}`))},s.addEventListener("load",o),s.addEventListener("error",d),this.#n=t.appendChild(s)})}};close=async()=>{this.#s&&(this.#o&&this.#r&&(this.#t.send({targetWin:this.#o,targetOrigin:this.#r,messageType:S.GuestClose,messageBody:{}}),this.#t.removeSender({origin:this.#r,window:this.#o})),this.#t.close(),this.#h&&(clearInterval(this.#h),this.#h=null),this.#w&&ne.forEach(e=>{document.removeEventListener(e,this.#w)}),await this.#G(),window.removeEventListener("beforeunload",this.close),this.#s=!1,this.#e.audit({message:"Guest disconnected from host",...this.#d()}),this.#p=null,this.#f=null,this.#g=null)};connect=async e=>{if(!this.#s){let t=window,s={...ae};if(e){const{window:r,...o}=e;r&&(t=r),s={...s,...o}}const i=await K();this.#r=i.origin,this.#o=i.window,this.#t.initialize(t),this.#t.addSender({origin:this.#r,window:this.#o}),this.#t.listen({messageType:S.ObjectEvent,callback:this.#P.bind(this)}),this.#t.listen({messageType:S.HostConfig,callback:this.#k.bind(this)}),this.#t.listen({messageType:S.GuestFocus,callback:this.#L.bind(this)}),this.#t.listen({messageType:S.HostClose,callback:this.#_.bind(this)}),this.#t.send({targetWin:this.#o,targetOrigin:this.#r,messageType:S.GuestReady,messageBody:s}),this.#s=!0,this.#$(),this.#E&&await this.getAuthToken(),await this.#R(),window.addEventListener("beforeunload",this.close),this.#e.audit({message:"Guest connected to host",guestUrl:window.location.href})}};getAuthToken=async()=>{if(!this.#u&&this.#s)try{const e=await this.getObject("auth");if(e){const t=await e.getAccessToken();this.#u=t?.access_token,this.#b=t?.host_name,this.#m=t?.client_id}else this.#e.warn("Auth object not available to get access token from host")}catch(e){this.#e.error(`Error getting access token from auth object. ${e.message}`)}return this.#u};getObject=async e=>{if(this.#e.debug(`Retrieving scripting object "${e}" from host...`),!this.#s)throw new Error("Not connected to host");const{hostWindow:t,hostOrigin:s}=this.#l(),i=await this.#t.invoke({targetWin:t,targetOrigin:s,messageType:S.ObjectGet,messageBody:{objectId:e}}),r=this.#y(i.object);return this.#e.audit({message:"Received scripting object from host",scriptingObject:e,...this.#d()}),r};listObjects=async()=>{if(this.#e.debug("Retrieving names of scripting objects exposed by host..."),!this.#s)throw new Error("Not connected to host");const{hostWindow:e,hostOrigin:t}=this.#l(),s=await this.#t.invoke({targetWin:e,targetOrigin:t,messageType:S.ListObjects,messageBody:{}});return this.#e.audit({message:"Received names of all scripting objects exposed by host",objects:s,...this.#d()}),s};removeScript=()=>{if(this.#a&&this.#n){const{parentNode:e}=this.#n;e?.removeChild?.(this.#n)}};setLogLevel=e=>{this.#e.setLogLevel(e),this.#e.debug(`Log level changed by guest to ${e}`)};subscribe=e=>{const{eventId:t,criteria:s,callback:i}=e;this.#e.debug(`Registering subscription for event ${t}`);const r=this.#c.get(t.toLowerCase())||[],o=f();r.push({callback:i,token:o,criteria:s}),this.#c.set(t.toLowerCase(),r);const{hostWindow:d,hostOrigin:O}=this.#l();return this.#t.send({targetWin:d,targetOrigin:O,messageType:S.GuestEventSubscribe,messageBody:{eventId:t,criteria:s,token:o}}),this.#e.debug(`Subscribed to event ${t} with token ${o}`),o};unsubscribe=e=>{const{eventId:t,token:s}=e,i=this.#c.get(t.toLowerCase());if(i){const r=i.length,o=i.filter(d=>d.token!==s);if(o.length<r){this.#c.set(t.toLowerCase(),o);const{hostWindow:d,hostOrigin:O}=this.#l();this.#t.send({targetWin:d,targetOrigin:O,messageType:S.GuestEventUnsubscribe,messageBody:{eventId:t,token:s}}),this.#e.debug(`Unsubscribed from event ${t}`)}}}}})(),Y})());
|
|
1
|
+
(function(q,R){typeof exports=="object"&&typeof module=="object"?module.exports=R(require("emuiDiagnostics")):typeof define=="function"&&define.amd?define(["emuiDiagnostics"],R):typeof exports=="object"?exports.ice=R(require("emuiDiagnostics")):(q.ice=q.ice||{},q.ice.guest=R(q.emuiDiagnostics))})(globalThis,J=>(()=>{var q={572(a,l,c){var g=c(736),h=g.Symbol;a.exports=h},561(a,l,c){var g=c(572),h=c(504),w=c(567),u="[object Null]",f="[object Undefined]",I=g?g.toStringTag:void 0;function v(y){return y==null?y===void 0?f:u:I&&I in Object(y)?h(y):w(y)}a.exports=v},605(a,l,c){var g=c(327),h=/^\s+/;function w(u){return u&&u.slice(0,g(u)+1).replace(h,"")}a.exports=w},433(a){var l=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis;a.exports=l},504(a,l,c){var g=c(572),h=Object.prototype,w=h.hasOwnProperty,u=h.toString,f=g?g.toStringTag:void 0;function I(v){var y=w.call(v,f),b=v[f];try{v[f]=void 0;var m=!0}catch{}var T=u.call(v);return m&&(y?v[f]=b:delete v[f]),T}a.exports=I},567(a){var l=Object.prototype,c=l.toString;function g(h){return c.call(h)}a.exports=g},736(a,l,c){var g=c(433),h=typeof self=="object"&&self&&self.Object===Object&&self,w=g||h||Function("return this")();a.exports=w},327(a){var l=/\s/;function c(g){for(var h=g.length;h--&&l.test(g.charAt(h)););return h}a.exports=c},702(a,l,c){var g=c(230),h=c(381),w=c(569),u="Expected a function",f=Math.max,I=Math.min;function v(y,b,m){var T,k,U,P,E,_,A=0,S=!1,C=!1,H=!0;if(typeof y!="function")throw new TypeError(u);b=w(b)||0,g(m)&&(S=!!m.leading,C="maxWait"in m,U=C?f(w(m.maxWait)||0,b):U,H="trailing"in m?!!m.trailing:H);function N(p){var $=T,M=k;return T=k=void 0,A=p,P=y.apply(M,$),P}function Y(p){return A=p,E=setTimeout(D,b),S?N(p):P}function X(p){var $=p-_,M=p-A,B=b-$;return C?I(B,U-M):B}function Q(p){var $=p-_,M=p-A;return _===void 0||$>=b||$<0||C&&M>=U}function D(){var p=h();if(Q(p))return G(p);E=setTimeout(D,X(p))}function G(p){return E=void 0,H&&T?N(p):(T=k=void 0,P)}function V(){E!==void 0&&clearTimeout(E),A=0,T=_=k=E=void 0}function z(){return E===void 0?P:G(h())}function W(){var p=h(),$=Q(p);if(T=arguments,k=this,_=p,$){if(E===void 0)return Y(_);if(C)return clearTimeout(E),E=setTimeout(D,b),N(_)}return E===void 0&&(E=setTimeout(D,b)),P}return W.cancel=V,W.flush=z,W}a.exports=v},230(a){function l(c){var g=typeof c;return c!=null&&(g=="object"||g=="function")}a.exports=l},470(a){function l(c){return c!=null&&typeof c=="object"}a.exports=l},89(a,l,c){var g=c(561),h=c(470),w="[object Symbol]";function u(f){return typeof f=="symbol"||h(f)&&g(f)==w}a.exports=u},381(a,l,c){var g=c(736),h=function(){return g.Date.now()};a.exports=h},345(a,l,c){var g=c(702),h=c(230),w="Expected a function";function u(f,I,v){var y=!0,b=!0;if(typeof f!="function")throw new TypeError(w);return h(v)&&(y="leading"in v?!!v.leading:y,b="trailing"in v?!!v.trailing:b),g(f,I,{leading:y,maxWait:I,trailing:b})}a.exports=u},569(a,l,c){var g=c(605),h=c(230),w=c(89),u=NaN,f=/^[-+]0x[0-9a-f]+$/i,I=/^0b[01]+$/i,v=/^0o[0-7]+$/i,y=parseInt;function b(m){if(typeof m=="number")return m;if(w(m))return u;if(h(m)){var T=typeof m.valueOf=="function"?m.valueOf():m;m=h(T)?T+"":T}if(typeof m!="string")return m===0?m:+m;m=g(m);var k=I.test(m);return k||v.test(m)?y(m.slice(2),k?2:8):f.test(m)?u:+m}a.exports=b},388(a){"use strict";a.exports=J}},R={};function x(a){var l=R[a];if(l!==void 0)return l.exports;var c=R[a]={exports:{}};return q[a](c,c.exports,x),c.exports}x.n=a=>{var l=a&&a.__esModule?()=>a.default:()=>a;return x.d(l,{a:l}),l},x.d=(a,l)=>{for(var c in l)x.o(l,c)&&!x.o(a,c)&&Object.defineProperty(a,c,{enumerable:!0,get:l[c]})},x.o=(a,l)=>Object.prototype.hasOwnProperty.call(a,l),x.r=a=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(a,"__esModule",{value:!0})};var K={};return(()=>{"use strict";x.r(K),x.d(K,{SSFGuest:()=>de});const l={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let c;const g=new Uint8Array(16);function h(){if(!c&&(c=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!c))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return c(g)}var w;const u=[];for(let n=0;n<256;++n)u.push((n+256).toString(16).slice(1));function f(n,e=0){return u[n[e+0]]+u[n[e+1]]+u[n[e+2]]+u[n[e+3]]+"-"+u[n[e+4]]+u[n[e+5]]+"-"+u[n[e+6]]+u[n[e+7]]+"-"+u[n[e+8]]+u[n[e+9]]+"-"+u[n[e+10]]+u[n[e+11]]+u[n[e+12]]+u[n[e+13]]+u[n[e+14]]+u[n[e+15]]}function I(n,e=0){const t=f(n,e);if(!w(t))throw TypeError("Stringified UUID is invalid");return t}const v=null;function y(n,e,t){if(l.randomUUID&&!e&&!n)return l.randomUUID();n=n||{};const s=n.random||(n.rng||h)();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 f(s)}const b=y;var m=x(345),T=x.n(m);const k="elli:remoting",U="elli:remoting:response",P="elli:remoting:exception",E=({messageType:n,messageBody:e,requestId:t,onewayMsg:s=!1})=>({requestId:t??(s?null:b()),source:k,type:n,body:e}),_=n=>{const{targetWin:e,targetOrigin:t,messageType:s,messageBody:i}=n,r=E({messageType:s,messageBody:i});e.postMessage(r,t)};class A{#s;#e;#t=new Map;#n=new Map;#r=null;#i=null;#a=new Map;constructor(e,t){if(!e)throw new Error("logger is required");if(!t)throw new Error("correlationId is required");this.#s=t,this.#e=e}#f=()=>{this.#r=null;const e=Date.now(),t=[];let s=null;if(this.#n.forEach((i,r)=>{const{requestId:o,cancelTime:d}=i;d&&d<=e?(this.#e.debug(`Detected response timeout for requestId: ${o}...`),t.push(r),i.resolve(void 0)):d&&(s=s===null?d:Math.min(s,d))}),t.forEach(i=>{this.#n.delete(i)}),s!==null){const i=Math.max(s-Date.now(),0);this.#g(i)}};#g=e=>{this.#r===null&&(this.#r=window.setTimeout(this.#f,e))};#b=()=>{this.#r!==null&&(window.clearTimeout(this.#r),this.#r=null)};#o=e=>{const t=this.#n.get(e);return this.#e.debug(`serving requestId: ${e}`),this.#n.delete(e),t};#c=e=>{const{requestId:t}=e;this.#e.debug(`Response received for invocation requestId: ${t}`);const s=this.#o(t);return s?(s.resolve(e.body),!0):(this.#e.debug(`Received response to stale/invalid request with requestId: ${t}`),!1)};#h=e=>{this.#e.debug(`Exception received for invocation (requestId = ${e.requestId})`);const t=this.#o(e.requestId);return t?(t.reject(new Error(e.body)),!0):(this.#e.warn(`Received exception for stale/invalid request (requestId = ${e.requestId})`),!1)};#w=({sourceWin:e,sourceOrigin:t,message:s})=>{this.#e.debug(`Received message of type "${s.type}"`);const i=this.#t.get(s.type);return i?(i.forEach(r=>{this.#e.debug(`Invoking message handler ${r.name}`),r({sourceWin:e,sourceOrigin:t,requestId:s.requestId,type:s.type,body:s.body})}),!0):!1};#l=e=>{if(this.#a.size===0||!e.source)return!1;const t=this.#a.get(e.source);return!t||e?.data?.source!==k?!1:(this.#e.debug(`Remoting: Received message of type "${e.data.type}"`),e.data.type===U?this.#c(e.data):e.data.type===P?this.#h(e.data):this.#w({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.#a.set(s,t)};initialize=e=>{this.#i&&this.#i.removeEventListener("message",this.#l),e.addEventListener("message",this.#l),this.#i=e,this.#e.debug(`initialized remoting id: ${this.#s}`)};close=()=>{this.#i&&(this.#i.removeEventListener("message",this.#l),this.#i=null),this.#b(),this.#e.debug(`closed remoting id: ${this.#s}`)};invoke=e=>{const{targetWin:t,targetOrigin:s,messageType:i,messageBody:r,responseTimeoutMs:o}=e;return new Promise((d,O)=>{const j=E({messageType:i,messageBody:r});this.#n.set(j.requestId,{requestId:j.requestId,resolve:d,reject:O,cancelTime:o?Date.now()+o:null}),t.postMessage(j,s);const{requestId:L}=j;this.#e.debug(`Posted invocation message of type ${i} requestId: ${L||""}`),o&&(this.#e.debug(`scheduling timeout check for requestId: ${L||""} in ${o} ms`),this.#g(o))})};listen=e=>{const{messageType:t,callback:s}=e,i=this.#t.get(t)||[];i.push(s),this.#t.set(t,i)};unlisten=e=>{const{messageType:t,callback:s}=e,i=this.#t.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=E({messageType:i,messageBody:r,onewayMsg:!0});t.postMessage(o,s),this.#e.debug(`Posted one-way message of type "${i}"`)};removeSender=e=>{const{window:t}=e;t&&this.#a.delete(t)};respond=e=>{const{targetWin:t,targetOrigin:s,requestId:i,response:r}=e,o=E({messageType:U,messageBody:r,requestId:i});t.postMessage(o,s),this.#e.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,d=E({messageType:P,messageBody:o,requestId:i});t.postMessage(d,s),this.#e.debug(`Exception sent to caller for invocation. requestId: ${i}`)}}var S=(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))(S||{});class C{#s;#e;#t;#n=new Map;static DEFAULT_THROTTLE_MS=1e4;constructor(e){this.#s=e.logger,this.#e=e.enabled??!0,this.#t=e.throttleMs??C.DEFAULT_THROTTLE_MS}get enabled(){return this.#e}log(e,t){if(!this.#e){this.#s.debug(t);return}if(this.#t>0){const s=performance.now(),i=this.#n.get(e);if(i!==void 0&&s-i<this.#t){this.#s.debug(t);return}this.#n.set(e,s)}this.#s.audit(t)}}class H{__TYPE__="Proxy";id;objectType;constructor(e,t){this.id=e,this.objectType=t}}const N=n=>n?.constructor?.name==="Proxy"||n?.constructor?.name==="ScriptingObjectProxy"||n?.__TYPE__==="Proxy";class Y{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 X{static[Symbol.hasInstance](e){return typeof e=="object"&&e!==null&&"getType"in e&&typeof e.getType=="function"&&e.getType()==="ProxyEvent"}#s;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.#s=i,this.id=`${this.objectId}.${this.name}`.toLowerCase()}subscribe=e=>this.#s.subscribe({eventId:this.id,callback:e});unsubscribe=e=>{this.#s.unsubscribe({eventId:this.id,token:e})}}const Q=n=>n instanceof Y,D=(n,e)=>`${n.toLowerCase()}.${e.toLowerCase()}`;var G=x(388);const V=()=>{const{parent:n}=window;try{return n?.location?.href}catch{return null}},z=n=>{if(!n||n==="about:blank")return"*";try{const{origin:e}=new URL(n);return e==="null"||!e?"*":e}catch{try{const{origin:e}=new URL(n,document.baseURI);return e==="null"||!e?"*":e}catch{return"*"}}},W=()=>window.self!==window.parent,p=(n,e)=>{const t=e||document.body,s=document.defaultView?.getComputedStyle?.(t,null),i=s?s[n]:"0";return parseInt(i,10)},$=/^https?:\/\/([a-z0-9-]+\.)*(?:elliemae\.io|ellielabs\.com|ellieservices\.com|encompassloconnect\.com|ice\.com|localhost:[0-9]+)$/i,M="elli:remoting",B=3e4,re=()=>new Promise((n,e)=>{if(W())n({origin:z(document.referrer||V()),window:window.parent});else{const t=window;let s;const i=r=>{if($.test(r.origin)){const{source:o,type:d}=r.data||{};if(o===M&&d===S.HandShake){const{origin:O}=r,j=r.source;clearTimeout(s),_({targetWin:j,targetOrigin:O,messageType:S.HandShakeAck,messageBody:{}}),t.removeEventListener("message",i),n({origin:O,window:j})}}};s=setTimeout(()=>{t.removeEventListener("message",i),e(new Error(`Host handshake timed out after ${B}ms`))},B),t.addEventListener("message",i)}});let F=!1;const oe=n=>{F=n},ee=(n=null)=>{let e=n;const t=()=>{if(!e&&(e=window.ice?.guest?.SSFGuest?new window.ice.guest.SSFGuest:null,!e))throw new Error("Guest definition not found");return e};window.elli=window.elli??{},window.elli.script={guest:{create:(s,i)=>t().addScript(s,i)},connect:s=>t().connect(s),getObject:s=>t().getObject(s),setLogLevel:s=>t().setLogLevel(s),subscribe:(s,i,r,o)=>t().subscribe({eventId:`${s}.${i}`,callback:d=>r(d?.obj,d?.eventParams,d?.eventOptions),criteria:o?.criteria}),unsubscribe:(s,i,r)=>t().unsubscribe({eventId:`${s}.${i}`,token:r})}};try{ee()}catch{}var ce=(n=>(n.OBJECT="object",n.VALUE="value",n))(ce||{});const te=12e4,ae=2e3,le={eventFeedback:!0},se=()=>{const{document:n}=window,e=n.body,t=n.documentElement,i={height:e.offsetHeight+p("marginTop")+p("marginBottom"),width:Math.max(e.scrollWidth,t.scrollWidth)};_({targetWin:window.parent,targetOrigin:z(n.referrer||V()),messageType:S.GuestResize,messageBody:i}),window.removeEventListener("load",se)};W()&&window.addEventListener("load",se);const ie={"cdn.ice.com":"https://api.elliemae.com/diagnostics/v2/logging","cdn.np.ice.com":"https://stg.api.elliemae.com/diagnostics/v2/logging","cdn.uat.ice.com":"https://concept.api.elliemae.com/diagnostics/v2/logging","cdn.pt1.ice.com":"https://pel1.api.ellielabs.com/diagnostics/v2/logging","cdn.qa1.ice.com":"https://int.api.ellielabs.com/diagnostics/v2/logging","cdn.dev1.ice.com":"https://int.api.ellielabs.com/diagnostics/v2/logging","cdn.mortgagetech.ice.com":"https://api.elliemae.com/diagnostics/v2/logging","cdn.mortgagetech.s1.ice.com":"https://stg.api.elliemae.com/diagnostics/v2/logging","cdn.mortgagetech.uat1.ice.com":"https://concept.api.elliemae.com/diagnostics/v2/logging","cdn.mortgagetech.pl1.ice.com":"https://pel1.api.ellielabs.com/diagnostics/v2/logging","cdn.mortgagetech.q1.ice.com":"https://int.api.ellielabs.com/diagnostics/v2/logging","cdn.mortgagetech.d1.ice.com":"https://int.api.ellielabs.com/diagnostics/v2/logging",localhost:"https://int.api.ellielabs.com/diagnostics/v2/logging"},ne=["click","scroll","keypress","touchstart"],ue=()=>{const n=document.currentScript?.src||"file:///opt/jenkins/workspace/UIPlatform_pui-microfe_master/256/libs/ssf-guest/lib/guest.ts",e=n?new URL(n).hostname:"localhost";return ie[e]||ie["cdn.mortgagetech.q1.ice.com"]};class de{#s;#e;#t;#n=!1;#r=null;#i=!1;#a=new Map;#f=null;#g=null;#b=null;#o=null;#c=null;#h=null;#w=new Map;#l(){if(!this.#c||!this.#o)throw new Error("Guest is not connected to a host. Call connect() first.");return{hostWindow:this.#c,hostOrigin:this.#o}}#S=!1;#u=null;#m=null;#v=null;#j=!0;#O=te;#T;#y=null;#p;constructor(e){const{console:t=!1,url:s=window.__ICE__?.diagnosticsUrl||ue(),index:i="ssf-guest-v2",team:r="ICE",appName:o="SSF Guest V2 Application"}=e?.logger??{};this.#T=e?.logger,this.#S=e?.usesDevConnectAPI??!1,this.#j=e?.keepAlive??!0,this.#O=e?.keepAliveInterval??te;const d=t?(0,G.Console)():(0,G.http)(s);this.#e=e?.appLogger??(0,G.logger)({transport:d,index:i,team:r,appName:o}),this.#p=new C({logger:this.#e,enabled:e?.auditOperations,throttleMs:e?.auditThrottleMs}),(0,G.webvitals)(this.#e),(0,G.logUnhandledErrors)(this.#e),this.#s=b(),this.#t=new A(this.#e,this.#s),ee(this),this.#e.audit({message:"Guest created",guestUrl:window.location.href,correlationId:this.#s})}#d=()=>({guestId:this.#f,guestTitle:this.#g,guestUrl:this.#b});#E=e=>{if(!e||!e.objectId)throw this.#e.error("Deserialization of scripting object failed. Object does not have an Object ID."),new Error("Cannot deserialize object JSON into proxy.");const t=new H(e.objectId,e.objectType);return e.functions&&e.functions.forEach(s=>{Object.defineProperty(t,s,{value:async(...i)=>{const o=t[s]?.callContext?.callChain;return this.#x({objectId:t.id,functionName:s,functionParams:[...i],callerChain:o})},enumerable:!0})}),e.events&&e.events.forEach(s=>{Object.defineProperty(t,s,{value:new X({objectId:t.id,name:s,eventSrc:this}),enumerable:!0})}),this.#e.debug(`Created guest proxy for scripting object (id = "${t.id}")`),t};#x=async({objectId:e,functionName:t,functionParams:s,callerChain:i})=>{this.#e.debug(`Invoking scripting object method ${e}.${t}()...`);const r=[];if(s)for(let L=0;L<s.length;L+=1){const Z=s[L];Z instanceof Promise&&r.push(Z.then(ge=>{s[L]=ge}))}await Promise.all(r);const{hostWindow:o,hostOrigin:d}=this.#l(),O=await this.#t.invoke({targetWin:o,targetOrigin:d,messageType:S.ObjectInvoke,messageBody:{objectId:e,functionName:t,functionParams:s,...i?.length?{callerChain:i}:{}}}),j=this.#k(O);return this.#p.log(`invoke:${e}.${t}`,{message:"Guest proxy invoked Scripting Object method",scriptingObject:e,scriptingMethod:t,...this.#d()}),j};#I(e,t){return Object.entries(t).every(([s,i])=>{const r=e[s];if("eq"in i)return r===i.eq;if("in"in i)return Array.isArray(i.in)&&i.in.includes(r);if("includes"in i)return Array.isArray(r)&&r.includes(i.includes);if("gt"in i){const o=typeof r=="number"?r:Number(r);return!Number.isNaN(o)&&o>i.gt}if("lt"in i){const o=typeof r=="number"?r:Number(r);return!Number.isNaN(o)&&o<i.lt}if("regex"in i)try{let o=this.#w.get(i.regex);return o||(o=new RegExp(i.regex),this.#w.set(i.regex,o)),typeof r=="string"&&o.test(r)}catch{return!1}return!1})}#k=e=>e?.type==="object"&&"object"in e?this.#E(e.object):e?.type==="value"?e.value:e;#L=({body:e})=>{e?.logLevel&&(this.#e.setLogLevel(e.logLevel),this.#e.debug(`Log level changed by host to ${e.logLevel}`)),this.#f=e?.guestId??null,this.#g=e?.guestTitle??null,this.#b=e?.guestUrl??null,this.#e.audit({message:"Received configuration from Host",...this.#d()})};#_=()=>{window.focus()};#$=async()=>{await this.close(),window.close()};#P=()=>{W()||(this.#h=setInterval(()=>{this.#c?.closed&&this.close().then(()=>{window.close()}).catch(()=>{})},1e3))};#C=async({sourceWin:e,sourceOrigin:t,requestId:s,body:i})=>{const r=this.#E(i.object);if(r){const o=D(r.id,i.eventName);this.#e.debug(`Received event "${o}" from host`);let d;i.eventHandler?d=[{callback:window[i.eventHandler],token:b()}]:d=this.#a.get(o)||[];const O=[];if(d.forEach(j=>{if(j?.callback){if(j.criteria&&!(i.eventParams?this.#I(i.eventParams,j.criteria):!1)){this.#e.debug(`Event ${o} did not match criteria for subscriber ${j.callback.name}`);return}this.#e.debug(`Invoking event subscriber ${j.callback.name} for event ${o}`);const L=j.callback({obj:r,eventName:i.eventName,eventParams:i.eventParams,eventOptions:i.eventOptions});L instanceof Promise?O.push(L):typeof L<"u"&&O.push(Promise.resolve(L))}}),s){const j=await Promise.all(O);this.#t.respond({targetWin:e,targetOrigin:t,requestId:s,response:j}),this.#p.log(`event:${o}`,{message:"Guest proxy processed event from host and responded",scriptingEventId:o,scriptingObject:r.id,...this.#d()})}else this.#p.log(`event:${o}`,{message:"Guest proxy processed event from host",scriptingEventId:o,scriptingObject:r.id,...this.#d()})}};#G=async()=>{if(!(!this.#u||!this.#m||!this.#v))try{await fetch(`${this.#v}/oauth2/v1/token/introspection?${new URLSearchParams({token:this.#u,client_id:this.#m}).toString()}`,{headers:{"content-type":"application/x-www-form-urlencoded;charset=UTF-8"},method:"POST"})}catch(e){this.#e.warn(`Failed to extend token lifetime: ${e.message}`)}};#R=async()=>{if(this.#u&&this.#m&&this.#v)try{await fetch(`${this.#v}/oauth2/v1/token/revocation?${new URLSearchParams({token:this.#u,client_id:this.#m}).toString()}`,{method:"POST"})}catch(e){this.#e.error(`Error revoking token. ${e.message}`)}finally{this.#u=null,this.#m=null}};#U=async()=>{if(this.#j)try{const e=await Promise.race([this.getObject("application"),new Promise(t=>{setTimeout(()=>t(null),ae)})]);e?(this.#y=T()(async()=>{try{await e.keepSessionAlive(),await this.#G()}catch(t){this.#e.error(`Error keeping session alive. ${t.message}`)}},this.#O,{leading:!1}),ne.forEach(t=>{document.addEventListener(t,this.#y)})):this.#e.warn("Application object not available to send keep alive")}catch(e){this.#e.error(`Error getting application object. ${e.message}`)}};addScript=async(e,t)=>{if(!this.#n&&e){await this.connect();const s=document.createElement("script");s.setAttribute("src",e),s.setAttribute("type","module"),await new Promise((i,r)=>{let o,d;const O=()=>{s.removeEventListener("load",o),s.removeEventListener("error",d)};o=()=>{O(),this.#n=!0,oe(!0),i()},d=()=>{O(),r(new Error(`Failed to load script: ${e}`))},s.addEventListener("load",o),s.addEventListener("error",d),this.#r=t.appendChild(s)})}};close=async()=>{this.#i&&(this.#c&&this.#o&&(this.#t.send({targetWin:this.#c,targetOrigin:this.#o,messageType:S.GuestClose,messageBody:{}}),this.#t.removeSender({origin:this.#o,window:this.#c})),this.#t.close(),this.#h&&(clearInterval(this.#h),this.#h=null),this.#y&&ne.forEach(e=>{document.removeEventListener(e,this.#y)}),await this.#R(),window.removeEventListener("beforeunload",this.close),this.#i=!1,this.#e.audit({message:"Guest disconnected from host",...this.#d()}),this.#f=null,this.#b=null,this.#g=null)};connect=async e=>{if(!this.#i){let t=window,s={...le};if(e){const{window:r,...o}=e;r&&(t=r),s={...s,...o}}const i=await re();this.#o=i.origin,this.#c=i.window,this.#t.initialize(t),this.#t.addSender({origin:this.#o,window:this.#c}),this.#t.listen({messageType:S.ObjectEvent,callback:this.#C.bind(this)}),this.#t.listen({messageType:S.HostConfig,callback:this.#L.bind(this)}),this.#t.listen({messageType:S.GuestFocus,callback:this.#_.bind(this)}),this.#t.listen({messageType:S.HostClose,callback:this.#$.bind(this)}),this.#t.send({targetWin:this.#c,targetOrigin:this.#o,messageType:S.GuestReady,messageBody:s}),this.#i=!0,this.#P(),this.#S&&await this.getAuthToken(),await this.#U(),window.addEventListener("beforeunload",this.close),this.#e.audit({message:"Guest connected to host",guestUrl:window.location.href})}};getAuthToken=async()=>{if(!this.#u&&this.#i)try{const e=await this.getObject("auth");if(e){const t=await e.getAccessToken();this.#u=t?.access_token,this.#v=t?.host_name,this.#m=t?.client_id}else this.#e.warn("Auth object not available to get access token from host")}catch(e){this.#e.error(`Error getting access token from auth object. ${e.message}`)}return this.#u};getObject=async e=>{if(this.#e.debug(`Retrieving scripting object "${e}" from host...`),!this.#i)throw new Error("Not connected to host");const{hostWindow:t,hostOrigin:s}=this.#l(),i=await this.#t.invoke({targetWin:t,targetOrigin:s,messageType:S.ObjectGet,messageBody:{objectId:e}}),r=this.#E(i.object);return this.#p.log(`getObject:${e}`,{message:"Received scripting object from host",scriptingObject:e,...this.#d()}),r};listObjects=async()=>{if(this.#e.debug("Retrieving names of scripting objects exposed by host..."),!this.#i)throw new Error("Not connected to host");const{hostWindow:e,hostOrigin:t}=this.#l(),s=await this.#t.invoke({targetWin:e,targetOrigin:t,messageType:S.ListObjects,messageBody:{}});return this.#p.log("listObjects",{message:"Received names of all scripting objects exposed by host",objects:s,...this.#d()}),s};removeScript=()=>{if(this.#n&&this.#r){const{parentNode:e}=this.#r;e?.removeChild?.(this.#r)}};setLogLevel=e=>{this.#e.setLogLevel(e),this.#e.debug(`Log level changed by guest to ${e}`)};subscribe=e=>{const{eventId:t,criteria:s,callback:i}=e;this.#e.debug(`Registering subscription for event ${t}`);const r=this.#a.get(t.toLowerCase())||[],o=b();r.push({callback:i,token:o,criteria:s}),this.#a.set(t.toLowerCase(),r);const{hostWindow:d,hostOrigin:O}=this.#l();return this.#t.send({targetWin:d,targetOrigin:O,messageType:S.GuestEventSubscribe,messageBody:{eventId:t,criteria:s,token:o}}),this.#e.debug(`Subscribed to event ${t} with token ${o}`),o};unsubscribe=e=>{const{eventId:t,token:s}=e,i=this.#a.get(t.toLowerCase());if(i){const r=i.length,o=i.filter(d=>d.token!==s);if(o.length<r){this.#a.set(t.toLowerCase(),o);const{hostWindow:d,hostOrigin:O}=this.#l();this.#t.send({targetWin:d,targetOrigin:O,messageType:S.GuestEventUnsubscribe,messageBody:{eventId:t,token:s}}),this.#e.debug(`Unsubscribed from event ${t}`)}}}}})(),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
|