@soyio/soyio-widget 0.0.20 → 0.0.21
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/index.js +1 -1
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
package/dist/index.umd.cjs
CHANGED
|
@@ -14,4 +14,4 @@
|
|
|
14
14
|
|
|
15
15
|
`+cn(u))}}),S.try(function(){if(!a)throw new Error("No handler found for post message: "+t.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);return a.handler({source:n,origin:e,data:t.data})}).then(function(u){return c("success",u)},function(u){return c("error",null,u)})]).then(k).catch(function(u){if(a&&a.handleError)return a.handleError(u);throw u})}function kt(n,e,t){if(!vt(t.hash)){var r=ht(t.hash);if(!r)throw new Error("No handler found for post message ack for message: "+t.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);try{if(!_(r.domain,e))throw new Error("Ack origin "+e+" does not match domain "+r.domain.toString());if(n!==r.win)throw new Error("Ack source does not match registered window")}catch(o){r.promise.reject(o)}r.ack=!0}}function Qt(n,e,t){if(!vt(t.hash)){var r=ht(t.hash);if(!r)throw new Error("No handler found for post message response for message: "+t.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!_(r.domain,e))throw new Error("Response origin "+e+" does not match domain "+(o=r.domain,Array.isArray(o)?"("+o.join(" | ")+")":v(o)?"RegExp("+o.toString()+")":o.toString()));var o;if(n!==r.win)throw new Error("Response source does not match registered window");lt(t.hash),t.ack==="error"?r.promise.reject(t.error):t.ack==="success"&&r.promise.resolve({source:n,origin:e,data:t.data})}}function mt(n,e){var t=e.on,r=e.send,o=z("receivedMessages");try{if(!window||window.closed||!n.source)return}catch{return}var i=n.source,a=n.origin,s=function(h,f,d,l){var p=l.on,w=l.send,m;try{m=dt(f,d,h,{on:p,send:w})}catch{return}if(m&&typeof m=="object"&&m!==null){var I=m.__post_robot_10_0_46__;if(Array.isArray(I))return I}}(n.data,i,a,{on:t,send:r});if(s){it(i);for(var c=0;c<s.length;c++){var u=s[c];if(o.has(u.id)||(o.set(u.id,!0),G(i)&&!u.fireAndForget))return;u.origin.indexOf("file:")===0&&(a="file://");try{u.type==="postrobot_message_request"?Kt(i,a,u,{on:t,send:r}):u.type==="postrobot_message_response"?Qt(i,a,u):u.type==="postrobot_message_ack"&&kt(i,a,u)}catch(h){setTimeout(function(){throw h},0)}}}}function V(n,e,t){if(!n)throw new Error("Expected name");if(typeof(e=e||{})=="function"&&(t=e,e={}),!t)throw new Error("Expected handler");var r=function o(i,a){var s=i.name,c=i.win,u=i.domain,h=M("requestListeners");if(!s||typeof s!="string")throw new Error("Name required to add request listener");if(c&&c!=="*"&&U.isProxyWindow(c)){var f=c.awaitWindow().then(function(N){return o({name:s,win:N,domain:u},a)});return{cancel:function(){f.then(function(N){return N.cancel()},k)}}}var d=c;if(Array.isArray(d)){for(var l=[],p=0,w=d;p<w.length;p++)l.push(o({name:s,domain:u,win:w[p]},a));return{cancel:function(){for(var N=0;N<l.length;N++)l[N].cancel()}}}if(Array.isArray(u)){for(var m=[],I=0,T=u;I<T.length;I++)m.push(o({name:s,win:d,domain:T[I]},a));return{cancel:function(){for(var N=0;N<m.length;N++)m[N].cancel()}}}var O=wt({name:s,win:d,domain:u});d&&d!=="*"||(d=Sn());var b=(u=u||"*").toString();if(O)throw d&&u?new Error("Request listener already exists for "+s+" on domain "+u.toString()+" for "+(d===Sn()?"wildcard":"specified")+" window"):d?new Error("Request listener already exists for "+s+" for "+(d===Sn()?"wildcard":"specified")+" window"):u?new Error("Request listener already exists for "+s+" on domain "+u.toString()):new Error("Request listener already exists for "+s);var j=h.getOrSet(d,function(){return{}}),E=sn(j,s,function(){return{}}),A,J;return On(u)?(A=sn(E,"__domain_regex__",function(){return[]})).push(J={regex:u,listener:a}):E[b]=a,{cancel:function(){delete E[b],J&&(A.splice(A.indexOf(J,1)),A.length||delete E.__domain_regex__),Object.keys(E).length||delete j[s],d&&!Object.keys(j).length&&h.del(d)}}}({name:n,win:e.window,domain:e.domain||"*"},{handler:t||e.handler,handleError:e.errorHandler||function(o){throw o}});return{cancel:function(){r.cancel()}}}function _t(n,e,t){typeof(e=e||{})=="function"&&(t=e,e={});var r=new S,o;return e.errorHandler=function(i){o.cancel(),r.reject(i)},o=V(n,e,function(i){if(o.cancel(),r.resolve(i),t)return t(i)}),r.cancel=o.cancel,r}var Y=function n(e,t,r,o){var i=(o=o||{}).domain||"*",a=o.timeout||-1,s=o.timeout||5e3,c=o.fireAndForget||!1;return U.toProxyWindow(e,{send:n}).awaitWindow().then(function(u){return S.try(function(){if(function(h,f,d){if(!h)throw new Error("Expected name");if(d&&typeof d!="string"&&!Array.isArray(d)&&!On(d))throw new TypeError("Can not send "+h+". Expected domain "+JSON.stringify(d)+" to be a string, array, or regex");if(G(f))throw new Error("Can not send "+h+". Target window is closed")}(t,u,i),function(h,f){var d=Jn(f);if(d)return d===h;if(f===h||function(w){w===void 0&&(w=window);try{if(w.top)return w.top}catch{}if($(w)===w)return w;try{if(Hn(window,w)&&window.top)return window.top}catch{}try{if(Hn(w,window)&&window.top)return window.top}catch{}for(var m=0,I=function O(b){for(var j=[],E=0,A=Gn(b);E<A.length;E++){var J=A[E];j.push(J);for(var N=0,dn=O(J);N<dn.length;N++)j.push(dn[N])}return j}(w);m<I.length;m++){var T=I[m];try{if(T.top)return T.top}catch{}if($(T)===T)return T}}(f)===f)return!1;for(var l=0,p=Gn(h);l<p.length;l++)if(p[l]===f)return!0;return!1}(window,u))return function(h,f,d){f===void 0&&(f=5e3),d===void 0&&(d="Window");var l=function(p){return M("helloPromises").getOrSet(p,function(){return new S})}(h);return f!==-1&&(l=l.timeout(f,new Error(d+" did not load after "+f+"ms"))),l}(u,s)}).then(function(h){return function(f,d,l,p){var w=p.send;return S.try(function(){return typeof d=="string"?d:S.try(function(){return l||An(f,{send:w}).then(function(m){return m.domain})}).then(function(m){if(!_(d,d))throw new Error("Domain "+kn(d)+" does not match "+kn(d));return m})})}(u,i,(h===void 0?{}:h).domain,{send:n})}).then(function(h){var f=h,d=t==="postrobot_method"&&r&&typeof r.name=="string"?r.name+"()":t,l=new S,p=t+"_"+q();if(!c){var w={name:t,win:u,domain:f,promise:l};(function(E,A){z("responseListeners").set(E,A)})(p,w);var m=M("requestPromises").getOrSet(u,function(){return[]});m.push(l),l.catch(function(){(function(E){z("erroredResponseListeners").set(E,!0)})(p),lt(p)});var I=function(E){return M("knownWindows").get(E,!1)}(u)?1e4:2e3,T=a,O=I,b=T,j=function(E,A){var J;return function N(){J=setTimeout(function(){(function(){if(G(u))return l.reject(new Error("Window closed for "+t+" before "+(w.ack?"response":"ack")));if(w.cancelled)return l.reject(new Error("Response listener was cancelled for "+t));O=Math.max(O-500,0),b!==-1&&(b=Math.max(b-500,0)),w.ack||O!==0?b===0&&l.reject(new Error("No response for postMessage "+d+" in "+C()+" in "+T+"ms")):l.reject(new Error("No ack for postMessage "+d+" in "+C()+" in "+I+"ms"))})(),N()},500)}(),{cancel:function(){clearTimeout(J)}}}();l.finally(function(){j.cancel(),m.splice(m.indexOf(l,1))}).catch(k)}return zn(u,f,{id:q(),origin:C(window),type:"postrobot_message_request",hash:p,name:t,data:r,fireAndForget:c},{on:V,send:n}).then(function(){return c?l.resolve():l},function(E){throw new Error("Send request message failed for "+d+" in "+C()+`
|
|
16
16
|
|
|
17
|
-
`+cn(E))})})})};function ne(n,e,t){return ft(n,e,t,{on:V,send:Y})}function te(n,e,t){return dt(n,e,t,{on:V,send:Y})}function ee(n){return new U({send:Y,win:n})}function re(n){return U.toProxyWindow(n,{send:Y})}function pt(){fn().initialized||(fn().initialized=!0,e=(n={on:V,send:Y}).on,t=n.send,(r=fn()).receiveMessage=r.receiveMessage||function(o){return mt(o,{on:e,send:t})},function(o){var i=o.on,a=o.send;z().getOrSet("postMessageListener",function(){return function(s,c,u){return s.addEventListener("message",u),{cancel:function(){s.removeEventListener("message",u)}}}(window,0,function(s){(function(c,u){var h=u.on,f=u.send;S.try(function(){var d=c.source||c.sourceElement,l=c.origin||c.originalEvent&&c.originalEvent.origin,p=c.data;if(l==="null"&&(l="file://"),d){if(!l)throw new Error("Post message did not have origin domain");mt({source:d,origin:l,data:p},{on:h,send:f})}})})(s,{on:i,send:a})})})}({on:V,send:Y}),function(o){var i=o.on,a=o.send;z("builtinListeners").getOrSet("helloListener",function(){var s=i("postrobot_hello",{domain:"*"},function(u){return rt(u.source,{domain:u.origin}),{instanceID:et()}}),c=Jn();return c&&An(c,{send:a}).catch(function(u){}),s})}({on:V,send:Y}));var n,e,t,r}function oe(){(function(){for(var e=z("responseListeners"),t=0,r=e.keys();t<r.length;t++){var o=r[t],i=e.get(o);i&&(i.cancelled=!0),e.del(o)}})(),(n=z().get("postMessageListener"))&&n.cancel();var n;delete window.__post_robot_10_0_46__}var ie=!0;function ae(n){for(var e=0,t=M("requestPromises").get(n,[]);e<t.length;e++)t[e].reject(new Error("Window "+(G(n)?"closed":"cleaned up")+" before response")).catch(k)}pt()}])})})(Bn);var Dt=Bn.exports;(function(W){W.exports=Dt,W.exports.default=W.exports})(Fn);var Nt=Fn.exports;const hn=At(Nt),Rt="WIDGET_MOUNTED",Tt="WIDGET_EVENT";function zt(W){const{configure:D,onEvent:H}=W;hn.on(Rt,()=>{D()}),hn.on(Tt,y=>{H(y.data),Wt.includes(y.data.
|
|
17
|
+
`+cn(E))})})})};function ne(n,e,t){return ft(n,e,t,{on:V,send:Y})}function te(n,e,t){return dt(n,e,t,{on:V,send:Y})}function ee(n){return new U({send:Y,win:n})}function re(n){return U.toProxyWindow(n,{send:Y})}function pt(){fn().initialized||(fn().initialized=!0,e=(n={on:V,send:Y}).on,t=n.send,(r=fn()).receiveMessage=r.receiveMessage||function(o){return mt(o,{on:e,send:t})},function(o){var i=o.on,a=o.send;z().getOrSet("postMessageListener",function(){return function(s,c,u){return s.addEventListener("message",u),{cancel:function(){s.removeEventListener("message",u)}}}(window,0,function(s){(function(c,u){var h=u.on,f=u.send;S.try(function(){var d=c.source||c.sourceElement,l=c.origin||c.originalEvent&&c.originalEvent.origin,p=c.data;if(l==="null"&&(l="file://"),d){if(!l)throw new Error("Post message did not have origin domain");mt({source:d,origin:l,data:p},{on:h,send:f})}})})(s,{on:i,send:a})})})}({on:V,send:Y}),function(o){var i=o.on,a=o.send;z("builtinListeners").getOrSet("helloListener",function(){var s=i("postrobot_hello",{domain:"*"},function(u){return rt(u.source,{domain:u.origin}),{instanceID:et()}}),c=Jn();return c&&An(c,{send:a}).catch(function(u){}),s})}({on:V,send:Y}));var n,e,t,r}function oe(){(function(){for(var e=z("responseListeners"),t=0,r=e.keys();t<r.length;t++){var o=r[t],i=e.get(o);i&&(i.cancelled=!0),e.del(o)}})(),(n=z().get("postMessageListener"))&&n.cancel();var n;delete window.__post_robot_10_0_46__}var ie=!0;function ae(n){for(var e=0,t=M("requestPromises").get(n,[]);e<t.length;e++)t[e].reject(new Error("Window "+(G(n)?"closed":"cleaned up")+" before response")).catch(k)}pt()}])})})(Bn);var Dt=Bn.exports;(function(W){W.exports=Dt,W.exports.default=W.exports})(Fn);var Nt=Fn.exports;const hn=At(Nt),Rt="WIDGET_MOUNTED",Tt="WIDGET_EVENT";function zt(W){const{configure:D,onEvent:H}=W;hn.on(Rt,()=>{D()}),hn.on(Tt,y=>{H(y.data),Wt.includes(y.data.eventName)&&Ln()})}function jt(W){zt(W)}function Ct(W){hn.send(W.contentWindow,"ready")}function Mt(W,D){hn.send(W.contentWindow,"config",D)}class Lt{constructor(D){Cn(this,ln);Cn(this,vn);nn(this,"iframe");nn(this,"flow");nn(this,"configProps");nn(this,"onEvent");nn(this,"isSandbox");this.flow=D.flow,this.configProps=D.configProps,this.onEvent=D.onEvent,this.isSandbox=D.isSandbox??!1,this.validateProps(),this.iframe=Pt(this.flow,this.configProps,this.isSandbox,D.developmentUrl),jt({configure:Mn(this,ln,gt).bind(this),onEvent:Mn(this,vn,yt).bind(this)})}validateProps(){if(this.flow==="authenticate"){if(!this.configProps.identityId)throw new Error("identityId is required");if(!this.configProps.companyId)throw new Error("companyId is required")}else if(this.flow==="register"){if(!this.configProps.flowTemplateId)throw new Error("flowTemplateId is required");if(!this.configProps.companyId)throw new Error("companyId is required")}}close(){Ln()}}return ln=new WeakSet,gt=function(){Ct(this.iframe),Mt(this.iframe,this.configProps)},vn=new WeakSet,yt=function(D){this.onEvent(D)},Lt});
|