@machinemetrics/mm-react-embeddable 2.0.2-0 → 2.0.3-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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),Ce=require("prop-types"),we=require("styled-components"),ne=r=>r&&r.__esModule?r:{default:r},F=ne(t),g=ne(Ce),ce=ne(we),J=t.createContext(null),Q=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),ae="access_token",te=r=>r?r.kind?r:r.accessToken?{kind:ae,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,Te=60,_e=120,Ie=3e4,Me=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),V=r=>{try{return new URL(r).origin}catch{return null}},ue=(r,u)=>{const a=u==null?void 0:u.origin;return!a||V(r==null?void 0:r.authUrl)!==a?null:a},oe=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const u=r.split(".");return u.length<=2?r:u.slice(-2).join(".")},re=(r,u)=>{try{const a=new URL(r),p=new URL(u);return a.protocol!==p.protocol?!0:oe(a.hostname)!==oe(p.hostname)}catch{return!0}},le=(r,{onBlocked:u,onClosed:a})=>{const p=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!p)return u(),()=>{};const h=setInterval(()=>{p.closed&&(clearInterval(h),a())},1e3);return()=>clearInterval(h)},de=({children:r,launcher:u,broker:a,ready:p})=>{const h=t.useContext(J),[R,T]=t.useState({}),[q,Y]=t.useState({}),[W,k]=t.useState({}),[b,I]=t.useState({}),z=t.useRef(W);z.current=W;const _=t.useRef(R);_.current=R;const x=t.useRef(null),C=t.useRef({}),B=t.useRef({}),Z=t.useRef(a);Z.current=a;const L=t.useRef({}),O=t.useRef({}),v=t.useCallback((e,s,n)=>{!e||!s||(L.current[e]||(L.current[e]=new Set),n?L.current[e].add(s):L.current[e].delete(s))},[]),U=t.useCallback(e=>{const s=C.current[e];if(!s)return;const n=c=>!c[e]||c[e].clientId?c:{...c,[e]:{...c[e],clientId:s}};T(n),I(n)},[]),i=t.useCallback((e,s)=>{e&&(I(n=>n[e]?n:{...n,[e]:{origin:e,reason:s,clientId:C.current[e]||null}}),U(e))},[U]),l=t.useCallback((e,{v2:s=!1,origin:n=null}={})=>{var c;if(n){if(s&&z.current[n]){if(!((c=L.current[n])!=null&&c.has(e.instanceId)))return;const m=Date.now();if(m-(O.current[n]||0)<Ie)return;O.current[n]=m,L.current[n].clear();const D={...z.current};delete D[n],z.current=D,k(D)}T(m=>m[n]?m:{...m,[n]:{origin:n,authUrl:e.authUrl,status:s&&Z.current?"broker":"interactive",v2:s,scope:e.scope||null,acceptsCredentials:B.current[n]||null,consent:null,error:null,clientId:e.clientId||C.current[n]||null,popupBlocked:!1}}),U(n)}},[U]),o=t.useRef({}),f=t.useCallback(e=>{o.current[e]&&(clearTimeout(o.current[e]),delete o.current[e])},[]),d=t.useCallback(e=>{f(e),T(s=>{if(!s[e])return s;const n={...s};return delete n[e],n})},[f]),E=t.useCallback(e=>{e&&(d(e),Y(s=>({...s,[e]:(s[e]||0)+1})))},[d]),$=t.useCallback(e=>{d(e.origin)},[d]),w=t.useCallback((e,s)=>{const n=ue(e,s);if(n){if(re(n,window.location.origin)){i(n,"cross-site-legacy");return}l(e,{origin:n})}},[l,i]);t.useEffect(()=>{if(!h)return;const e=[h.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(C.current[n.origin]=s.clientId,U(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?B.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&re(n.origin,window.location.origin)&&i(n.origin,"cross-site-legacy")}),h.addListener("*","authorize",w),h.addListener("*","login",w),h.addListener("*","credential-request",(s,n)=>l(s,{v2:!0,origin:ue(s,n)}))];return()=>e.forEach(s=>s())},[h,w,l,U,i]),t.useEffect(()=>{const e=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const c=V(n.authUrl);if(!c||s.origin!==c)return;const m=_.current[c];if(!(!m||m.status!=="interactive")){if(n.accessToken){k(D=>({...D,[c]:te({accessToken:n.accessToken})})),d(c);return}E(c)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[d,E]);const M=t.useCallback((e,s)=>{const n=e==null?void 0:e.origin,c=te(s);!n||!c||(k(m=>({...m,[n]:c})),d(n))},[d]),A=t.useCallback((e,s)=>{T(n=>n[e]?{...n,[e]:{...n[e],...s}}:n)},[]),S=t.useRef({}),y=t.useCallback(async(e,{approve:s}={})=>{const n=Z.current,{origin:c}=e;let m;try{m=await n({origin:c,clientId:e.clientId,scope:e.scope,authUrl:e.authUrl},{approve:s})}catch{s?A(c,{error:{reason:"broker_unavailable"}}):A(c,{status:"interactive"});return}const D=m==null?void 0:m.status,H=(m==null?void 0:m.body)||{};if(D===200&&H.credential){M(e,H.credential);return}if(D===409&&H.consentRequired){A(c,{status:"interactive",consent:{client:H.client||null,stepUp:!!H.stepUp,scope:H.scope||e.scope},error:null});return}const X=H.error||"broker_error";if(!s&&Me.has(X)){A(c,{status:"interactive"});return}if(s&&X==="consent_denied"){A(c,{error:null});return}if(X==="rate_limited"&&!e.rateLimitRetried){const ee=Math.min(Number(H.retryAfter)>0?Number(H.retryAfter):Te,_e),ke={...e,rateLimitRetried:!0};f(c),o.current[c]=setTimeout(()=>{delete o.current[c],S.current[c]=!0,j.current(ke,{approve:s}).finally(()=>{delete S.current[c]})},ee*1e3),A(c,{rateLimitRetried:!0});return}d(c),I(ee=>({...ee,[c]:{origin:c,reason:`broker:${X}`,detail:{status:D!=null?D:null,reason:X},clientId:e.clientId||C.current[c]||null}}))},[M,A,d,f]),j=t.useRef(y);j.current=y,t.useEffect(()=>{Object.values(R).forEach(e=>{e.status!=="broker"||S.current[e.origin]||o.current[e.origin]||(S.current[e.origin]=!0,y(e).finally(()=>{delete S.current[e.origin]}))})},[R,y]);const G=t.useCallback(e=>!Z.current||!(e!=null&&e.consent)||S.current[e.origin]?Promise.resolve():(S.current[e.origin]=!0,y(e,{approve:!0}).finally(()=>{delete S.current[e.origin]})),[y]);t.useEffect(()=>()=>{x.current&&x.current(),Object.values(o.current).forEach(clearTimeout)},[]),t.useEffect(()=>{p===!1&&(Object.values(o.current).forEach(clearTimeout),o.current={},S.current={},C.current={},B.current={},L.current={},O.current={},z.current={},k({}),T({}),I({}))},[p]);const K=t.useCallback(e=>{x.current&&(x.current(),x.current=null);const s=u||le;x.current=s(e,{onBlocked:()=>{T(n=>n[e.origin]?{...n,[e.origin]:{...n[e.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=_.current[e.origin];!n||n.v2||E(e.origin)}})},[u,E]),P={pending:Object.values(R).filter(e=>e.status==="interactive"),authorize:K,approve:G,complete:M,dismiss:$,originEpochs:q,credentials:W,unsupported:b,setDelivered:v};return F.default.createElement(Q.Provider,{value:P},r)};de.propTypes={children:g.default.node,launcher:g.default.func,ready:g.default.bool,broker:g.default.func};const fe=()=>t.useContext(Q),pe=r=>{const{originEpochs:u}=t.useContext(Q),a=V(r);return a&&u[a]||0},be=r=>{const{credentials:u}=t.useContext(Q),a=V(r);return a&&u[a]||null},he=r=>{const{unsupported:u}=t.useContext(Q),a=V(r);return a&&u[a]||null},ie="MMEmbeddableZoneProvider requires a boolean `ready` prop (true once the host holds the bearer its credentialBroker needs). Embedded apps will not load until it is provided.",Ee=({children:r,authorizationLauncher:u,credentialBroker:a,ready:p})=>{const h=p===!0,R=t.useRef(!1);t.useEffect(()=>{p!==void 0||R.current||(R.current=!0,console.error(ie),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ie))},[p]);const[T,q]=t.useState({}),[Y,W]=t.useState({}),k=t.useRef({}),b=t.useRef({}),I=t.useRef({}),z=t.useCallback((i,l)=>{var o;return!!((o=I.current[i])!=null&&o.has(l))},[]),_=t.useCallback((i,l,o)=>{q(f=>({...f,[i]:{origin:l,frameRef:o}}))},[]),x=t.useCallback(i=>{q(l=>{const o={...l};return delete o[i],o}),W(l=>{const o={...l};return delete o[i],o}),delete I.current[i],Object.keys(b.current).forEach(l=>{b.current[l].instanceId===i&&delete b.current[l]})},[]);t.useEffect(()=>()=>{b.current={}},[]),t.useEffect(()=>{const i=(o=[],f,d)=>{o.forEach(E=>E(f,d))},l=o=>{var A,S,y,j,G,K,P;if(!((A=o==null?void 0:o.data)!=null&&A.instanceId))return;const{instanceId:f,type:d}=o.data,E=T[f],$=(y=(S=E==null?void 0:E.frameRef)==null?void 0:S.current)==null?void 0:y.contentWindow;if(!$||o.source!==$||o.origin!==E.origin)return;const w={origin:o.origin},M=k.current;if(d==="response"){const{callbackId:e,response:s,error:n}=o.data,c=b.current[e];c&&c.instanceId===f&&(c.callback(s,n),delete b.current[e]);return}if(d==="mark-registered"){const{requestType:e}=o.data;I.current[f]||(I.current[f]=new Set),I.current[f].add(e);return}d==="ready"&&W(e=>({...e,[f]:!0})),i((j=M[f])==null?void 0:j[d],o.data,w),i((G=M["*"])==null?void 0:G[d],o.data,w),i((K=M[f])==null?void 0:K["*"],o.data,w),i((P=M["*"])==null?void 0:P["*"],o.data,w)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[T]);const C=t.useCallback((i,l,o,f)=>{var E,$;const d=T[i];if(!d){console.warn(`Origin not set for id: ${i}. Unable to send message.`);return}($=(E=d==null?void 0:d.frameRef)==null?void 0:E.current)!=null&&$.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:l,...o,instanceId:i},f||d.origin)},[T]),B=t.useRef(0),Z=t.useCallback(()=>`${Date.now()}-${++B.current}`,[]),L=t.useCallback(async(i,l,o={})=>new Promise((f,d)=>{const E=Z(),$=(w,M)=>{delete b.current[E],M?d(M):f(w)};b.current[E]={instanceId:i,callback:$},C(i,"request",{callbackId:E,requestType:l,data:o})}),[C]),O=t.useCallback((i,l)=>{C(i,"load-options",l)},[C]),v=t.useCallback((i,l)=>{C(i,"validate",l)},[C]),U=t.useMemo(()=>({registerFrame:_,unregisterFrame:x,sendMessage:C,sendRequest:L,loadOptions:O,validate:v,hasHandler:z,readyFrames:Y,ready:h,addListener:(i,l,o)=>(k.current[i]||(k.current[i]={}),k.current[i][l]||(k.current[i][l]=[]),k.current[i][l].push(o),()=>{k.current[i][l]=k.current[i][l].filter(f=>f!==o)})}),[_,x,C,L,O,v,z,Y,h]);return F.default.createElement(J.Provider,{value:U},F.default.createElement(de,{launcher:u,broker:a,ready:h},r))},N=(r,u,a)=>{const p=t.useContext(J);if(p===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const h=t.useRef(a);t.useEffect(()=>{h.current=a},[a]),t.useEffect(()=>{if(!(!r||!u)){if(u.startsWith("key:")){const R=u.substring(4);return p.readyFrames[r]&&p.sendMessage(r,"subscribe-key",{keyChord:R}),p.addListener(r,`key-pressed:${R}`,(...q)=>h.current(...q))}return p.addListener(r,u,(...R)=>h.current(...R))}},[p,r,u])};Ee.propTypes={children:g.default.node.isRequired,ready:g.default.bool.isRequired,authorizationLauncher:g.default.func,credentialBroker:g.default.func};const se=ce.default.default||ce.default,Ae=1e4,Se="credentials",ye=(r,u)=>`${r}/mm-embedded-interop?id=${encodeURIComponent(u)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Se}`,Le=se.iframe`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),Ce=require("prop-types"),we=require("styled-components"),ne=r=>r&&r.__esModule?r:{default:r},D=ne(t),g=ne(Ce),ue=ne(we),J=t.createContext(null),Q=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),ae="access_token",te=r=>r?r.kind?r:r.accessToken?{kind:ae,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,Te=60,_e=120,Ie=3e4,Me=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),V=r=>{try{return new URL(r).origin}catch{return null}},ce=(r,u)=>{const a=u==null?void 0:u.origin;return!a||V(r==null?void 0:r.authUrl)!==a?null:a},oe=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const u=r.split(".");return u.length<=2?r:u.slice(-2).join(".")},re=(r,u)=>{try{const a=new URL(r),b=new URL(u);return a.protocol!==b.protocol?!0:oe(a.hostname)!==oe(b.hostname)}catch{return!0}},le=(r,{onBlocked:u,onClosed:a})=>{const b=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!b)return u(),()=>{};const m=setInterval(()=>{b.closed&&(clearInterval(m),a())},1e3);return()=>clearInterval(m)},de=({children:r,launcher:u,broker:a,ready:b})=>{const m=t.useContext(J),[R,_]=t.useState({}),[q,G]=t.useState({}),[W,k]=t.useState({}),[h,M]=t.useState({}),O=t.useRef(W);O.current=W;const I=t.useRef(R);I.current=R;const L=t.useRef(null),w=t.useRef({}),B=t.useRef({}),Z=t.useRef(a);Z.current=a;const y=t.useRef({}),v=t.useRef({}),$=t.useCallback((e,s,n)=>{!e||!s||(y.current[e]||(y.current[e]=new Set),n?y.current[e].add(s):y.current[e].delete(s))},[]),x=t.useCallback(e=>{const s=w.current[e];if(!s)return;const n=i=>!i[e]||i[e].clientId?i:{...i,[e]:{...i[e],clientId:s}};_(n),M(n)},[]),o=t.useCallback((e,s)=>{e&&(M(n=>n[e]?n:{...n,[e]:{origin:e,reason:s,clientId:w.current[e]||null}}),x(e))},[x]),l=t.useCallback((e,{v2:s=!1,origin:n=null}={})=>{var i;if(n){if(s&&O.current[n]){if(!((i=y.current[n])!=null&&i.has(e.instanceId)))return;const d=Date.now();if(d-(v.current[n]||0)<Ie)return;v.current[n]=d,y.current[n].clear();const S={...O.current};delete S[n],O.current=S,k(S)}_(d=>d[n]?d:{...d,[n]:{origin:n,authUrl:e.authUrl,status:s&&Z.current?"broker":"interactive",v2:s,scope:e.scope||null,acceptsCredentials:B.current[n]||null,consent:null,error:null,clientId:e.clientId||w.current[n]||null,popupBlocked:!1}}),x(n)}},[x]),c=t.useRef({}),p=t.useCallback(e=>{c.current[e]&&(clearTimeout(c.current[e]),delete c.current[e])},[]),f=t.useCallback(e=>{p(e),_(s=>{if(!s[e])return s;const n={...s};return delete n[e],n})},[p]),E=t.useCallback(e=>{e&&(f(e),G(s=>({...s,[e]:(s[e]||0)+1})))},[f]),U=t.useCallback(e=>{f(e.origin)},[f]),z=t.useCallback((e,s)=>{const n=ce(e,s);if(n){if(re(n,window.location.origin)){o(n,"cross-site-legacy");return}l(e,{origin:n})}},[l,o]);t.useEffect(()=>{if(!m)return;const e=[m.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(w.current[n.origin]=s.clientId,x(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?B.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&re(n.origin,window.location.origin)&&o(n.origin,"cross-site-legacy")}),m.addListener("*","authorize",z),m.addListener("*","login",z),m.addListener("*","credential-request",(s,n)=>l(s,{v2:!0,origin:ce(s,n)}))];return()=>e.forEach(s=>s())},[m,z,l,x,o]),t.useEffect(()=>{const e=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const i=V(n.authUrl);if(!i||s.origin!==i)return;const d=I.current[i];if(!(!d||d.status!=="interactive")){if(n.accessToken){k(S=>({...S,[i]:te({accessToken:n.accessToken})})),f(i);return}E(i)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[f,E]);const C=t.useCallback((e,s)=>{const n=e==null?void 0:e.origin,i=te(s);!n||!i||(k(d=>({...d,[n]:i})),f(n))},[f]),A=t.useCallback((e,s)=>{_(n=>n[e]?{...n,[e]:{...n[e],...s}}:n)},[]),T=t.useRef({}),P=t.useCallback(async(e,{approve:s}={})=>{const n=Z.current,{origin:i}=e;let d;try{d=await n({origin:i,clientId:e.clientId,scope:e.scope,authUrl:e.authUrl},{approve:s})}catch{s?A(i,{error:{reason:"broker_unavailable"}}):A(i,{status:"interactive"});return}const S=d==null?void 0:d.status,j=(d==null?void 0:d.body)||{};if(S===200&&j.credential){C(e,j.credential);return}if(S===409&&j.consentRequired){A(i,{status:"interactive",consent:{client:j.client||null,stepUp:!!j.stepUp,scope:j.scope||e.scope},error:null});return}const X=j.error||"broker_error";if(!s&&Me.has(X)){A(i,{status:"interactive"});return}if(s&&X==="consent_denied"){A(i,{error:null});return}if(X==="rate_limited"&&!e.rateLimitRetried){const ee=Math.min(Number(j.retryAfter)>0?Number(j.retryAfter):Te,_e),ke={...e,rateLimitRetried:!0};p(i),c.current[i]=setTimeout(()=>{delete c.current[i],T.current[i]=!0,F.current(ke,{approve:s}).finally(()=>{delete T.current[i]})},ee*1e3),A(i,{rateLimitRetried:!0});return}f(i),M(ee=>({...ee,[i]:{origin:i,reason:`broker:${X}`,detail:{status:S!=null?S:null,reason:X},clientId:e.clientId||w.current[i]||null}}))},[C,A,f,p]),F=t.useRef(P);F.current=P,t.useEffect(()=>{Object.values(R).forEach(e=>{e.status!=="broker"||T.current[e.origin]||c.current[e.origin]||(T.current[e.origin]=!0,P(e).finally(()=>{delete T.current[e.origin]}))})},[R,P]);const H=t.useCallback(e=>!Z.current||!(e!=null&&e.consent)||T.current[e.origin]?Promise.resolve():(T.current[e.origin]=!0,P(e,{approve:!0}).finally(()=>{delete T.current[e.origin]})),[P]);t.useEffect(()=>()=>{L.current&&L.current(),Object.values(c.current).forEach(clearTimeout)},[]),t.useEffect(()=>{b===!1&&(Object.values(c.current).forEach(clearTimeout),c.current={},T.current={},w.current={},B.current={},y.current={},v.current={},O.current={},k({}),_({}),M({}))},[b]);const Y=t.useCallback(e=>{L.current&&(L.current(),L.current=null);const s=u||le;L.current=s(e,{onBlocked:()=>{_(n=>n[e.origin]?{...n,[e.origin]:{...n[e.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=I.current[e.origin];!n||n.v2||E(e.origin)}})},[u,E]),K={pending:Object.values(R).filter(e=>e.status==="interactive"),authorize:Y,approve:H,complete:C,dismiss:U,originEpochs:q,credentials:W,unsupported:h,setDelivered:$};return D.default.createElement(Q.Provider,{value:K},r)};de.propTypes={children:g.default.node,launcher:g.default.func,ready:g.default.bool,broker:g.default.func};const fe=()=>t.useContext(Q),pe=r=>{const{originEpochs:u}=t.useContext(Q),a=V(r);return a&&u[a]||0},be=r=>{const{credentials:u}=t.useContext(Q),a=V(r);return a&&u[a]||null},he=r=>{const{unsupported:u}=t.useContext(Q),a=V(r);return a&&u[a]||null},ie="MMEmbeddableZoneProvider requires a boolean `ready` prop (true once the host holds the bearer its credentialBroker needs). Embedded apps will not load until it is provided.",Ee=({children:r,authorizationLauncher:u,credentialBroker:a,ready:b})=>{const m=b===!0,R=t.useRef(!1);t.useEffect(()=>{b!==void 0||R.current||(R.current=!0,console.error(ie),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ie))},[b]);const[_,q]=t.useState({}),[G,W]=t.useState({}),k=t.useRef({}),h=t.useRef({}),M=t.useRef({}),O=t.useCallback((o,l)=>{var c;return!!((c=M.current[o])!=null&&c.has(l))},[]),I=t.useCallback((o,l,c)=>{q(p=>({...p,[o]:{origin:l,frameRef:c}}))},[]),L=t.useCallback(o=>{q(l=>{const c={...l};return delete c[o],c}),W(l=>{const c={...l};return delete c[o],c}),delete M.current[o],Object.keys(h.current).forEach(l=>{h.current[l].instanceId===o&&delete h.current[l]})},[]);t.useEffect(()=>()=>{h.current={}},[]),t.useEffect(()=>{const o=(c=[],p,f)=>{c.forEach(E=>E(p,f))},l=c=>{var A,T,P,F,H,Y,K;if(!((A=c==null?void 0:c.data)!=null&&A.instanceId))return;const{instanceId:p,type:f}=c.data,E=_[p],U=(P=(T=E==null?void 0:E.frameRef)==null?void 0:T.current)==null?void 0:P.contentWindow;if(!U||c.source!==U||c.origin!==E.origin)return;const z={origin:c.origin},C=k.current;if(f==="response"){const{callbackId:e,response:s,error:n}=c.data,i=h.current[e];i&&i.instanceId===p&&(i.callback(s,n),delete h.current[e]);return}if(f==="mark-registered"){const{requestType:e}=c.data;M.current[p]||(M.current[p]=new Set),M.current[p].add(e);return}f==="ready"&&W(e=>({...e,[p]:!0})),o((F=C[p])==null?void 0:F[f],c.data,z),o((H=C["*"])==null?void 0:H[f],c.data,z),o((Y=C[p])==null?void 0:Y["*"],c.data,z),o((K=C["*"])==null?void 0:K["*"],c.data,z)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[_]);const w=t.useCallback((o,l,c,p)=>{var E,U;const f=_[o];if(!f){console.warn(`Origin not set for id: ${o}. Unable to send message.`);return}(U=(E=f==null?void 0:f.frameRef)==null?void 0:E.current)!=null&&U.contentWindow&&f.frameRef.current.contentWindow.postMessage({type:l,...c,instanceId:o},p||f.origin)},[_]),B=t.useRef(0),Z=t.useCallback(()=>`${Date.now()}-${++B.current}`,[]),y=t.useCallback(async(o,l,c={})=>new Promise((p,f)=>{const E=Z(),U=(z,C)=>{delete h.current[E],C?f(C):p(z)};h.current[E]={instanceId:o,callback:U},w(o,"request",{callbackId:E,requestType:l,data:c})}),[w]),v=t.useCallback((o,l)=>{w(o,"load-options",l)},[w]),$=t.useCallback((o,l)=>{w(o,"validate",l)},[w]),x=t.useMemo(()=>({registerFrame:I,unregisterFrame:L,sendMessage:w,sendRequest:y,loadOptions:v,validate:$,hasHandler:O,readyFrames:G,ready:m,addListener:(o,l,c)=>(k.current[o]||(k.current[o]={}),k.current[o][l]||(k.current[o][l]=[]),k.current[o][l].push(c),()=>{k.current[o][l]=k.current[o][l].filter(p=>p!==c)})}),[I,L,w,y,v,$,O,G,m]);return D.default.createElement(J.Provider,{value:x},D.default.createElement(de,{launcher:u,broker:a,ready:m},r))},N=(r,u,a)=>{const b=t.useContext(J);if(b===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const m=t.useRef(a);t.useEffect(()=>{m.current=a},[a]),t.useEffect(()=>{if(!(!r||!u)){if(u.startsWith("key:")){const R=u.substring(4);return b.readyFrames[r]&&b.sendMessage(r,"subscribe-key",{keyChord:R}),b.addListener(r,`key-pressed:${R}`,(...q)=>m.current(...q))}return b.addListener(r,u,(...R)=>m.current(...R))}},[b,r,u])};Ee.propTypes={children:g.default.node.isRequired,ready:g.default.bool.isRequired,authorizationLauncher:g.default.func,credentialBroker:g.default.func};const se=ue.default.default||ue.default,ye=1e4,Ae="credentials",Se=(r,u)=>`${r}/mm-embedded-interop?id=${encodeURIComponent(u)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Ae}`,Le=se.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
@@ -16,10 +16,10 @@
16
16
  text-align: center;
17
17
  color: #555;
18
18
  font-size: 14px;
19
- `,me=r=>{const u=r&&r.origin||"This app",a=r&&r.reason||"";switch(a){case"broker:scope_above_ceiling":return{title:`${u} can’t be authorized here`,detail:"It asks for permissions your role doesn’t have."};case"broker:origin_mismatch":case"broker:unknown_client":return{title:`${u} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${u} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return a.startsWith("broker:")?{title:`${u} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${u} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},ge=({entry:r})=>{const u=me(r);return F.default.createElement(xe,{"data-reason":r&&r.reason||void 0},F.default.createElement("div",{style:{fontWeight:600}},u.title),F.default.createElement("div",{style:{fontSize:12,color:"#888"}},u.detail))};ge.propTypes={entry:g.default.shape({origin:g.default.string,name:g.default.string,reason:g.default.string,detail:g.default.object})};const Ue=se.div`
19
+ `,me=r=>{const u=r&&r.origin||"This app",a=r&&r.reason||"";switch(a){case"broker:scope_above_ceiling":return{title:`${u} can’t be authorized here`,detail:"It asks for permissions your role doesn’t have."};case"broker:origin_mismatch":case"broker:unknown_client":return{title:`${u} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${u} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return a.startsWith("broker:")?{title:`${u} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${u} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},ge=({entry:r})=>{const u=me(r);return D.default.createElement(xe,{"data-reason":r&&r.reason||void 0},D.default.createElement("div",{style:{fontWeight:600}},u.title),D.default.createElement("div",{style:{fontSize:12,color:"#888"}},u.detail))};ge.propTypes={entry:g.default.shape({origin:g.default.string,name:g.default.string,reason:g.default.string,detail:g.default.object})};const Ue=se.div`
20
20
  height: 100%;
21
21
  display: flex;
22
22
  flex: 1;
23
23
  align-items: center;
24
24
  justify-content: center;
25
- `,ze=()=>F.default.createElement(Ue,null,F.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),Re=({id:r,src:u,path:a,onInit:p=()=>{},onTimeout:h,context:R={},params:T={},renderUnsupported:q,renderTimeout:Y,...W})=>{if("isConfiguring"in W)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in R)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in R)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const k=t.useRef(),b=V(u),[I,z]=t.useState(),[_,x]=t.useState(0),[C,B]=t.useState(!1),[Z,L]=t.useState(!1),O=pe(u),v=be(u),U=he(u),{setDelivered:i}=fe(),[l,o]=t.useState(0),[f,d]=t.useState(null),{registerFrame:E,unregisterFrame:$,sendMessage:w,ready:M}=t.useContext(J),[A,S]=t.useState(),y=t.useRef(),j=t.useRef(h),G=t.useRef(p),K=t.useRef(!1),P=t.useRef(),e=t.useCallback(()=>{K.current=!1,clearTimeout(y.current),clearTimeout(P.current),x(0),B(!1),L(!1),d(null),i(b,r,!1)},[i,b,r]);t.useEffect(()=>{(O>0||l>0)&&e()},[O,l,e]),t.useEffect(()=>{j.current=h},[h]),t.useEffect(()=>{G.current=p},[p]),t.useEffect(()=>{_&&w(r,"set-context",{context:{...R}},b)},[R,r,_,b]),t.useEffect(()=>{_&&w(r,"set-params",{params:T},b)},[T,r,_,b]),t.useEffect(()=>{a!==void 0&&S((a==null?void 0:a.indexOf("/"))===0?a:`/${a}`)},[a]),t.useEffect(()=>{A===void 0||!_||w(r,"navigate",{path:A},b)},[A,_,r,w,b]),t.useEffect(()=>{if(!u||!r||!k)return;if(!M){e(),z(void 0);return}e();const c=new URL(u);return E(r,c.origin,k),G.current(),z(ye(c.origin,r)),()=>{$(r)}},[u,r,M,E,k,e]),t.useEffect(()=>{if(!(!I||K.current))return y.current=setTimeout(()=>{B(!0),j.current&&j.current()},Ae),()=>clearTimeout(y.current)},[I,u,O,l]);const s=t.useCallback(()=>{K.current=!0,clearTimeout(y.current),B(!1)},[]);if(N(r,"init",c=>{s(),Array.isArray(c==null?void 0:c.acceptsCredentials)&&d(c.acceptsCredentials)}),N(r,"authorize",s),N(r,"login",s),N(r,"credential-request",()=>{s(),L(!0)}),t.useEffect(()=>{if(!Z||!v)return;const c=f;if(Array.isArray(c)&&!c.includes(v.kind))return;const m=v.kind==="access_token"?{accessToken:v.accessToken}:{};w(r,"credential",{...m,credential:v},b),i(b,r,!0)},[Z,v,f,r,w,b,i]),N(r,"ready",()=>{s(),x(c=>c+1)}),N(r,"heartbeat",()=>{P.current&&clearTimeout(P.current),P.current=setTimeout(()=>{o(c=>c+1)},6e3)}),t.useEffect(()=>()=>{P.current&&clearTimeout(P.current)},[]),U)return q?q(U):F.default.createElement(ge,{entry:U});if(C&&!_)return Y?Y():F.default.createElement(ze,null);const n={...W};return delete n.skipManifestCheck,F.default.createElement(Le,{key:`auth-epoch-${O}-frame-${l}`,$isReady:_,ref:k,src:I,...n})};Re.propTypes={id:g.default.string,src:g.default.string.isRequired,path:g.default.string,onInit:g.default.func,onTimeout:g.default.func,renderUnsupported:g.default.func,renderTimeout:g.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=ae;exports.EmbeddedAuthorizationContext=Q;exports.MMEmbeddableZone=Re;exports.MMEmbeddableZoneContext=J;exports.MMEmbeddableZoneProvider=Ee;exports.isCrossSite=re;exports.normalizeCredential=te;exports.popupAuthorizationLauncher=le;exports.unsupportedCopy=me;exports.useEmbeddedAuthorizations=fe;exports.useEmbeddedCredential=be;exports.useEmbeddedEffect=N;exports.useEmbeddedOriginEpoch=pe;exports.useEmbeddedUnsupported=he;
25
+ `,ze=()=>D.default.createElement(Ue,null,D.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),Re=({id:r,src:u,path:a,onInit:b=()=>{},onTimeout:m,context:R={},params:_={},renderUnsupported:q,renderTimeout:G,...W})=>{if("isConfiguring"in W)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in R)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in R)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const k=t.useRef(),h=V(u),[M,O]=t.useState(),[I,L]=t.useState(0),[w,B]=t.useState(!1),[Z,y]=t.useState(!1),v=pe(u),$=be(u),x=he(u),{setDelivered:o}=fe(),[l,c]=t.useState(0),[p,f]=t.useState(null),E=t.useRef(!0),{registerFrame:U,unregisterFrame:z,sendMessage:C,ready:A}=t.useContext(J),[T,P]=t.useState(),F=t.useRef(),H=t.useRef(m),Y=t.useRef(b),K=t.useRef(!1),e=t.useRef(),s=t.useCallback(()=>{K.current=!1,clearTimeout(F.current),clearTimeout(e.current),L(0),B(!1),y(!1),f(null),E.current=!0,o(h,r,!1)},[o,h,r]);t.useEffect(()=>{(v>0||l>0)&&s()},[v,l,s]),t.useEffect(()=>{H.current=m},[m]),t.useEffect(()=>{Y.current=b},[b]),t.useEffect(()=>{I&&C(r,"set-context",{context:{...R}},h)},[R,r,I,h]),t.useEffect(()=>{I&&C(r,"set-params",{params:_},h)},[_,r,I,h]),t.useEffect(()=>{a!==void 0&&P((a==null?void 0:a.indexOf("/"))===0?a:`/${a}`)},[a]),t.useEffect(()=>{T===void 0||!I||C(r,"navigate",{path:T},h)},[T,I,r,C,h]),t.useEffect(()=>{if(!u||!r||!k)return;if(!A){s(),O(void 0);return}s();const d=new URL(u);return U(r,d.origin,k),Y.current(),O(Se(d.origin,r)),()=>{z(r)}},[u,r,A,U,k,s]),t.useEffect(()=>{if(!(!M||K.current))return F.current=setTimeout(()=>{B(!0),H.current&&H.current()},ye),()=>clearTimeout(F.current)},[M,u,v,l]);const n=t.useCallback(()=>{K.current=!0,clearTimeout(F.current),B(!1)},[]);if(N(r,"init",d=>{n(),Array.isArray(d==null?void 0:d.acceptsCredentials)&&(f(d.acceptsCredentials),E.current=!1,clearTimeout(e.current),e.current=void 0)}),N(r,"authorize",n),N(r,"login",n),N(r,"credential-request",()=>{n(),y(!0)}),t.useEffect(()=>{if(!Z||!$)return;const d=p;if(Array.isArray(d)&&!d.includes($.kind))return;const S=$.kind==="access_token"?{accessToken:$.accessToken}:{};C(r,"credential",{...S,credential:$},h),o(h,r,!0)},[Z,$,p,r,C,h,o]),N(r,"ready",()=>{n(),L(d=>d+1)}),N(r,"heartbeat",()=>{E.current&&(e.current&&clearTimeout(e.current),e.current=setTimeout(()=>{c(d=>d+1)},6e3))}),t.useEffect(()=>()=>{e.current&&clearTimeout(e.current)},[]),x)return q?q(x):D.default.createElement(ge,{entry:x});if(w&&!I)return G?G():D.default.createElement(ze,null);const i={...W};return delete i.skipManifestCheck,D.default.createElement(Le,{key:`auth-epoch-${v}-frame-${l}`,$isReady:I,ref:k,src:M,...i})};Re.propTypes={id:g.default.string,src:g.default.string.isRequired,path:g.default.string,onInit:g.default.func,onTimeout:g.default.func,renderUnsupported:g.default.func,renderTimeout:g.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=ae;exports.EmbeddedAuthorizationContext=Q;exports.MMEmbeddableZone=Re;exports.MMEmbeddableZoneContext=J;exports.MMEmbeddableZoneProvider=Ee;exports.isCrossSite=re;exports.normalizeCredential=te;exports.popupAuthorizationLauncher=le;exports.unsupportedCopy=me;exports.useEmbeddedAuthorizations=fe;exports.useEmbeddedCredential=be;exports.useEmbeddedEffect=N;exports.useEmbeddedOriginEpoch=pe;exports.useEmbeddedUnsupported=he;
@@ -1,4 +1,4 @@
1
- import B, { createContext as fe, useContext as J, useState as z, useRef as h, useCallback as f, useEffect as R, useMemo as be } from "react";
1
+ import W, { createContext as fe, useContext as J, useState as O, useRef as h, useCallback as p, useEffect as R, useMemo as be } from "react";
2
2
  import w from "prop-types";
3
3
  import ce from "styled-components";
4
4
  const se = fe(null), te = fe({
@@ -16,200 +16,200 @@ const se = fe(null), te = fe({
16
16
  unsupported: {},
17
17
  setDelivered: () => {
18
18
  }
19
- }), ge = "access_token", ie = (r) => r ? r.kind ? r : r.accessToken ? {
19
+ }), ge = "access_token", ie = (t) => t ? t.kind ? t : t.accessToken ? {
20
20
  kind: ge,
21
- accessToken: r.accessToken,
22
- expiresAt: r.expiresAt || null
21
+ accessToken: t.accessToken,
22
+ expiresAt: t.expiresAt || null
23
23
  } : null : null, Ee = 60, Re = 120, we = 3e4, ke = /* @__PURE__ */ new Set([
24
24
  "host_not_allowed",
25
25
  "unbound_host_bound_guest",
26
26
  "invalid_token",
27
27
  "provider_unavailable"
28
- ]), ee = (r) => {
28
+ ]), ee = (t) => {
29
29
  try {
30
- return new URL(r).origin;
30
+ return new URL(t).origin;
31
31
  } catch {
32
32
  return null;
33
33
  }
34
- }, ue = (r, o) => {
35
- const u = o == null ? void 0 : o.origin;
36
- return !u || ee(r == null ? void 0 : r.authUrl) !== u ? null : u;
37
- }, ae = (r) => {
38
- if (!r || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(r) || r.includes(":"))
39
- return r;
40
- const o = r.split(".");
41
- return o.length <= 2 ? r : o.slice(-2).join(".");
42
- }, le = (r, o) => {
34
+ }, ue = (t, s) => {
35
+ const u = s == null ? void 0 : s.origin;
36
+ return !u || ee(t == null ? void 0 : t.authUrl) !== u ? null : u;
37
+ }, ae = (t) => {
38
+ if (!t || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(t) || t.includes(":"))
39
+ return t;
40
+ const s = t.split(".");
41
+ return s.length <= 2 ? t : s.slice(-2).join(".");
42
+ }, le = (t, s) => {
43
43
  try {
44
- const u = new URL(r), p = new URL(o);
45
- return u.protocol !== p.protocol ? !0 : ae(u.hostname) !== ae(p.hostname);
44
+ const u = new URL(t), m = new URL(s);
45
+ return u.protocol !== m.protocol ? !0 : ae(u.hostname) !== ae(m.hostname);
46
46
  } catch {
47
47
  return !0;
48
48
  }
49
- }, Te = (r, { onBlocked: o, onClosed: u }) => {
50
- const p = window.open(
51
- r.authUrl,
49
+ }, Te = (t, { onBlocked: s, onClosed: u }) => {
50
+ const m = window.open(
51
+ t.authUrl,
52
52
  "mm-embed-auth",
53
53
  "popup,width=600,height=700"
54
54
  );
55
- if (!p)
56
- return o(), () => {
55
+ if (!m)
56
+ return s(), () => {
57
57
  };
58
- const b = setInterval(() => {
59
- p.closed && (clearInterval(b), u());
58
+ const E = setInterval(() => {
59
+ m.closed && (clearInterval(E), u());
60
60
  }, 1e3);
61
- return () => clearInterval(b);
62
- }, pe = ({ children: r, launcher: o, broker: u, ready: p }) => {
63
- const b = J(se), [k, M] = z({}), [j, V] = z({}), [Z, T] = z({}), [m, A] = z({}), S = h(Z);
64
- S.current = Z;
65
- const C = h(k);
66
- C.current = k;
67
- const $ = h(null), I = h({}), H = h({}), K = h(u);
61
+ return () => clearInterval(E);
62
+ }, pe = ({ children: t, launcher: s, broker: u, ready: m }) => {
63
+ const E = J(se), [k, C] = O({}), [j, V] = O({}), [Z, T] = O({}), [b, A] = O({}), F = h(Z);
64
+ F.current = Z;
65
+ const y = h(k);
66
+ y.current = k;
67
+ const z = h(null), _ = h({}), H = h({}), K = h(u);
68
68
  K.current = u;
69
- const O = h({}), F = h({}), P = f((e, n, t) => {
70
- !e || !n || (O.current[e] || (O.current[e] = /* @__PURE__ */ new Set()), t ? O.current[e].add(n) : O.current[e].delete(n));
71
- }, []), v = f((e) => {
72
- const n = I.current[e];
69
+ const L = h({}), P = h({}), D = p((e, n, r) => {
70
+ !e || !n || (L.current[e] || (L.current[e] = /* @__PURE__ */ new Set()), r ? L.current[e].add(n) : L.current[e].delete(n));
71
+ }, []), v = p((e) => {
72
+ const n = _.current[e];
73
73
  if (!n)
74
74
  return;
75
- const t = (s) => !s[e] || s[e].clientId ? s : { ...s, [e]: { ...s[e], clientId: n } };
76
- M(t), A(t);
77
- }, []), i = f(
75
+ const r = (i) => !i[e] || i[e].clientId ? i : { ...i, [e]: { ...i[e], clientId: n } };
76
+ C(r), A(r);
77
+ }, []), c = p(
78
78
  (e, n) => {
79
- e && (A((t) => t[e] ? t : {
80
- ...t,
79
+ e && (A((r) => r[e] ? r : {
80
+ ...r,
81
81
  [e]: {
82
82
  origin: e,
83
83
  reason: n,
84
- clientId: I.current[e] || null
84
+ clientId: _.current[e] || null
85
85
  }
86
86
  }), v(e));
87
87
  },
88
88
  [v]
89
- ), a = f(
90
- (e, { v2: n = !1, origin: t = null } = {}) => {
91
- var s;
92
- if (t) {
93
- if (n && S.current[t]) {
94
- if (!((s = O.current[t]) != null && s.has(e.instanceId)))
89
+ ), a = p(
90
+ (e, { v2: n = !1, origin: r = null } = {}) => {
91
+ var i;
92
+ if (r) {
93
+ if (n && F.current[r]) {
94
+ if (!((i = L.current[r]) != null && i.has(e.instanceId)))
95
95
  return;
96
- const E = Date.now();
97
- if (E - (F.current[t] || 0) < we)
96
+ const l = Date.now();
97
+ if (l - (P.current[r] || 0) < we)
98
98
  return;
99
- F.current[t] = E, O.current[t].clear();
100
- const W = { ...S.current };
101
- delete W[t], S.current = W, T(W);
99
+ P.current[r] = l, L.current[r].clear();
100
+ const x = { ...F.current };
101
+ delete x[r], F.current = x, T(x);
102
102
  }
103
- M((E) => E[t] ? E : {
104
- ...E,
105
- [t]: {
106
- origin: t,
103
+ C((l) => l[r] ? l : {
104
+ ...l,
105
+ [r]: {
106
+ origin: r,
107
107
  authUrl: e.authUrl,
108
108
  status: n && K.current ? "broker" : "interactive",
109
109
  v2: n,
110
110
  scope: e.scope || null,
111
- acceptsCredentials: H.current[t] || null,
111
+ acceptsCredentials: H.current[r] || null,
112
112
  consent: null,
113
113
  error: null,
114
- clientId: e.clientId || I.current[t] || null,
114
+ clientId: e.clientId || _.current[r] || null,
115
115
  popupBlocked: !1
116
116
  }
117
- }), v(t);
117
+ }), v(r);
118
118
  }
119
119
  },
120
120
  [v]
121
- ), c = h({}), d = f((e) => {
122
- c.current[e] && (clearTimeout(c.current[e]), delete c.current[e]);
123
- }, []), l = f(
121
+ ), o = h({}), f = p((e) => {
122
+ o.current[e] && (clearTimeout(o.current[e]), delete o.current[e]);
123
+ }, []), d = p(
124
124
  (e) => {
125
- d(e), M((n) => {
125
+ f(e), C((n) => {
126
126
  if (!n[e])
127
127
  return n;
128
- const t = { ...n };
129
- return delete t[e], t;
128
+ const r = { ...n };
129
+ return delete r[e], r;
130
130
  });
131
131
  },
132
- [d]
133
- ), g = f(
132
+ [f]
133
+ ), g = p(
134
134
  (e) => {
135
- e && (l(e), V((n) => ({
135
+ e && (d(e), V((n) => ({
136
136
  ...n,
137
137
  [e]: (n[e] || 0) + 1
138
138
  })));
139
139
  },
140
- [l]
141
- ), D = f(
140
+ [d]
141
+ ), $ = p(
142
142
  (e) => {
143
- l(e.origin);
143
+ d(e.origin);
144
144
  },
145
- [l]
146
- ), _ = f(
145
+ [d]
146
+ ), S = p(
147
147
  (e, n) => {
148
- const t = ue(e, n);
149
- if (t) {
150
- if (le(t, window.location.origin)) {
151
- i(t, "cross-site-legacy");
148
+ const r = ue(e, n);
149
+ if (r) {
150
+ if (le(r, window.location.origin)) {
151
+ c(r, "cross-site-legacy");
152
152
  return;
153
153
  }
154
- a(e, { origin: t });
154
+ a(e, { origin: r });
155
155
  }
156
156
  },
157
- [a, i]
157
+ [a, c]
158
158
  );
159
159
  R(() => {
160
- if (!b)
160
+ if (!E)
161
161
  return;
162
162
  const e = [
163
- b.addListener("*", "init", (n, t) => {
164
- t != null && t.origin && (n != null && n.clientId) && (I.current[t.origin] = n.clientId, v(t.origin)), t != null && t.origin && Array.isArray(n == null ? void 0 : n.acceptsCredentials) ? H.current[t.origin] = n.acceptsCredentials : t != null && t.origin && le(t.origin, window.location.origin) && i(t.origin, "cross-site-legacy");
163
+ E.addListener("*", "init", (n, r) => {
164
+ r != null && r.origin && (n != null && n.clientId) && (_.current[r.origin] = n.clientId, v(r.origin)), r != null && r.origin && Array.isArray(n == null ? void 0 : n.acceptsCredentials) ? H.current[r.origin] = n.acceptsCredentials : r != null && r.origin && le(r.origin, window.location.origin) && c(r.origin, "cross-site-legacy");
165
165
  }),
166
- b.addListener("*", "authorize", _),
167
- b.addListener("*", "login", _),
168
- b.addListener(
166
+ E.addListener("*", "authorize", S),
167
+ E.addListener("*", "login", S),
168
+ E.addListener(
169
169
  "*",
170
170
  "credential-request",
171
- (n, t) => a(n, { v2: !0, origin: ue(n, t) })
171
+ (n, r) => a(n, { v2: !0, origin: ue(n, r) })
172
172
  )
173
173
  ];
174
174
  return () => e.forEach((n) => n());
175
- }, [b, _, a, v, i]), R(() => {
175
+ }, [E, S, a, v, c]), R(() => {
176
176
  const e = (n) => {
177
- const t = n == null ? void 0 : n.data;
178
- if (!t || t.type !== "authorized")
177
+ const r = n == null ? void 0 : n.data;
178
+ if (!r || r.type !== "authorized")
179
179
  return;
180
- const s = ee(t.authUrl);
181
- if (!s || n.origin !== s)
180
+ const i = ee(r.authUrl);
181
+ if (!i || n.origin !== i)
182
182
  return;
183
- const E = C.current[s];
184
- if (!(!E || E.status !== "interactive")) {
185
- if (t.accessToken) {
186
- T((W) => ({
187
- ...W,
188
- [s]: ie({ accessToken: t.accessToken })
189
- })), l(s);
183
+ const l = y.current[i];
184
+ if (!(!l || l.status !== "interactive")) {
185
+ if (r.accessToken) {
186
+ T((x) => ({
187
+ ...x,
188
+ [i]: ie({ accessToken: r.accessToken })
189
+ })), d(i);
190
190
  return;
191
191
  }
192
- g(s);
192
+ g(i);
193
193
  }
194
194
  };
195
195
  return window.addEventListener("message", e), () => window.removeEventListener("message", e);
196
- }, [l, g]);
197
- const L = f(
196
+ }, [d, g]);
197
+ const I = p(
198
198
  (e, n) => {
199
- const t = e == null ? void 0 : e.origin, s = ie(n);
200
- !t || !s || (T((E) => ({ ...E, [t]: s })), l(t));
199
+ const r = e == null ? void 0 : e.origin, i = ie(n);
200
+ !r || !i || (T((l) => ({ ...l, [r]: i })), d(r));
201
201
  },
202
- [l]
203
- ), y = f((e, n) => {
204
- M((t) => t[e] ? { ...t, [e]: { ...t[e], ...n } } : t);
205
- }, []), U = h({}), x = f(
202
+ [d]
203
+ ), U = p((e, n) => {
204
+ C((r) => r[e] ? { ...r, [e]: { ...r[e], ...n } } : r);
205
+ }, []), M = h({}), q = p(
206
206
  async (e, { approve: n } = {}) => {
207
- const t = K.current, { origin: s } = e;
208
- let E;
207
+ const r = K.current, { origin: i } = e;
208
+ let l;
209
209
  try {
210
- E = await t(
210
+ l = await r(
211
211
  {
212
- origin: s,
212
+ origin: i,
213
213
  clientId: e.clientId,
214
214
  scope: e.scope,
215
215
  authUrl: e.authUrl
@@ -217,16 +217,16 @@ const se = fe(null), te = fe({
217
217
  { approve: n }
218
218
  );
219
219
  } catch {
220
- n ? y(s, { error: { reason: "broker_unavailable" } }) : y(s, { status: "interactive" });
220
+ n ? U(i, { error: { reason: "broker_unavailable" } }) : U(i, { status: "interactive" });
221
221
  return;
222
222
  }
223
- const W = E == null ? void 0 : E.status, G = (E == null ? void 0 : E.body) || {};
224
- if (W === 200 && G.credential) {
225
- L(e, G.credential);
223
+ const x = l == null ? void 0 : l.status, G = (l == null ? void 0 : l.body) || {};
224
+ if (x === 200 && G.credential) {
225
+ I(e, G.credential);
226
226
  return;
227
227
  }
228
- if (W === 409 && G.consentRequired) {
229
- y(s, {
228
+ if (x === 409 && G.consentRequired) {
229
+ U(i, {
230
230
  status: "interactive",
231
231
  consent: {
232
232
  client: G.client || null,
@@ -239,11 +239,11 @@ const se = fe(null), te = fe({
239
239
  }
240
240
  const re = G.error || "broker_error";
241
241
  if (!n && ke.has(re)) {
242
- y(s, { status: "interactive" });
242
+ U(i, { status: "interactive" });
243
243
  return;
244
244
  }
245
245
  if (n && re === "consent_denied") {
246
- y(s, { error: null });
246
+ U(i, { error: null });
247
247
  return;
248
248
  }
249
249
  if (re === "rate_limited" && !e.rateLimitRetried) {
@@ -251,77 +251,77 @@ const se = fe(null), te = fe({
251
251
  Number(G.retryAfter) > 0 ? Number(G.retryAfter) : Ee,
252
252
  Re
253
253
  ), me = { ...e, rateLimitRetried: !0 };
254
- d(s), c.current[s] = setTimeout(() => {
255
- delete c.current[s], U.current[s] = !0, Y.current(me, { approve: n }).finally(() => {
256
- delete U.current[s];
254
+ f(i), o.current[i] = setTimeout(() => {
255
+ delete o.current[i], M.current[i] = !0, B.current(me, { approve: n }).finally(() => {
256
+ delete M.current[i];
257
257
  });
258
- }, ne * 1e3), y(s, { rateLimitRetried: !0 });
258
+ }, ne * 1e3), U(i, { rateLimitRetried: !0 });
259
259
  return;
260
260
  }
261
- l(s), A((ne) => ({
261
+ d(i), A((ne) => ({
262
262
  ...ne,
263
- [s]: {
264
- origin: s,
263
+ [i]: {
264
+ origin: i,
265
265
  reason: `broker:${re}`,
266
- detail: { status: W != null ? W : null, reason: re },
267
- clientId: e.clientId || I.current[s] || null
266
+ detail: { status: x != null ? x : null, reason: re },
267
+ clientId: e.clientId || _.current[i] || null
268
268
  }
269
269
  }));
270
270
  },
271
- [L, y, l, d]
272
- ), Y = h(x);
273
- Y.current = x, R(() => {
271
+ [I, U, d, f]
272
+ ), B = h(q);
273
+ B.current = q, R(() => {
274
274
  Object.values(k).forEach((e) => {
275
- e.status !== "broker" || U.current[e.origin] || c.current[e.origin] || (U.current[e.origin] = !0, x(e).finally(() => {
276
- delete U.current[e.origin];
275
+ e.status !== "broker" || M.current[e.origin] || o.current[e.origin] || (M.current[e.origin] = !0, q(e).finally(() => {
276
+ delete M.current[e.origin];
277
277
  }));
278
278
  });
279
- }, [k, x]);
280
- const X = f(
281
- (e) => !K.current || !(e != null && e.consent) || U.current[e.origin] ? Promise.resolve() : (U.current[e.origin] = !0, x(e, { approve: !0 }).finally(() => {
282
- delete U.current[e.origin];
279
+ }, [k, q]);
280
+ const Y = p(
281
+ (e) => !K.current || !(e != null && e.consent) || M.current[e.origin] ? Promise.resolve() : (M.current[e.origin] = !0, q(e, { approve: !0 }).finally(() => {
282
+ delete M.current[e.origin];
283
283
  })),
284
- [x]
284
+ [q]
285
285
  );
286
286
  R(() => () => {
287
- $.current && $.current(), Object.values(c.current).forEach(clearTimeout);
287
+ z.current && z.current(), Object.values(o.current).forEach(clearTimeout);
288
288
  }, []), R(() => {
289
- p === !1 && (Object.values(c.current).forEach(clearTimeout), c.current = {}, U.current = {}, I.current = {}, H.current = {}, O.current = {}, F.current = {}, S.current = {}, T({}), M({}), A({}));
290
- }, [p]);
291
- const Q = f(
289
+ m === !1 && (Object.values(o.current).forEach(clearTimeout), o.current = {}, M.current = {}, _.current = {}, H.current = {}, L.current = {}, P.current = {}, F.current = {}, T({}), C({}), A({}));
290
+ }, [m]);
291
+ const X = p(
292
292
  (e) => {
293
- $.current && ($.current(), $.current = null);
294
- const n = o || Te;
295
- $.current = n(e, {
293
+ z.current && (z.current(), z.current = null);
294
+ const n = s || Te;
295
+ z.current = n(e, {
296
296
  onBlocked: () => {
297
- M((t) => t[e.origin] ? {
298
- ...t,
299
- [e.origin]: { ...t[e.origin], popupBlocked: !0 }
300
- } : t);
297
+ C((r) => r[e.origin] ? {
298
+ ...r,
299
+ [e.origin]: { ...r[e.origin], popupBlocked: !0 }
300
+ } : r);
301
301
  },
302
302
  // A completed login already removed the entry. A v2 entry stays pending so the prompt remains;
303
303
  // a legacy guest is remounted because it only learns of a login by reloading.
304
304
  onClosed: () => {
305
- const t = C.current[e.origin];
306
- !t || t.v2 || g(e.origin);
305
+ const r = y.current[e.origin];
306
+ !r || r.v2 || g(e.origin);
307
307
  }
308
308
  });
309
309
  },
310
- [o, g]
311
- ), q = {
310
+ [s, g]
311
+ ), Q = {
312
312
  pending: Object.values(k).filter(
313
313
  (e) => e.status === "interactive"
314
314
  ),
315
- authorize: Q,
316
- approve: X,
317
- complete: L,
318
- dismiss: D,
315
+ authorize: X,
316
+ approve: Y,
317
+ complete: I,
318
+ dismiss: $,
319
319
  originEpochs: j,
320
320
  credentials: Z,
321
- unsupported: m,
322
- setDelivered: P
321
+ unsupported: b,
322
+ setDelivered: D
323
323
  };
324
- return /* @__PURE__ */ B.createElement(te.Provider, { value: q }, r);
324
+ return /* @__PURE__ */ W.createElement(te.Provider, { value: Q }, t);
325
325
  };
326
326
  pe.propTypes = {
327
327
  children: w.node,
@@ -337,166 +337,166 @@ pe.propTypes = {
337
337
  */
338
338
  broker: w.func
339
339
  };
340
- const Ie = () => J(te), _e = (r) => {
341
- const { originEpochs: o } = J(te), u = ee(r);
342
- return u && o[u] || 0;
343
- }, Me = (r) => {
344
- const { credentials: o } = J(te), u = ee(r);
345
- return u && o[u] || null;
346
- }, Ce = (r) => {
347
- const { unsupported: o } = J(te), u = ee(r);
348
- return u && o[u] || null;
349
- }, de = "MMEmbeddableZoneProvider requires a boolean `ready` prop (true once the host holds the bearer its credentialBroker needs). Embedded apps will not load until it is provided.", Ae = ({
350
- children: r,
351
- authorizationLauncher: o,
340
+ const Ie = () => J(te), _e = (t) => {
341
+ const { originEpochs: s } = J(te), u = ee(t);
342
+ return u && s[u] || 0;
343
+ }, Me = (t) => {
344
+ const { credentials: s } = J(te), u = ee(t);
345
+ return u && s[u] || null;
346
+ }, Ce = (t) => {
347
+ const { unsupported: s } = J(te), u = ee(t);
348
+ return u && s[u] || null;
349
+ }, de = "MMEmbeddableZoneProvider requires a boolean `ready` prop (true once the host holds the bearer its credentialBroker needs). Embedded apps will not load until it is provided.", ye = ({
350
+ children: t,
351
+ authorizationLauncher: s,
352
352
  credentialBroker: u,
353
- ready: p
353
+ ready: m
354
354
  }) => {
355
- const b = p === !0, k = h(!1);
355
+ const E = m === !0, k = h(!1);
356
356
  R(() => {
357
- p !== void 0 || k.current || (k.current = !0, console.error(de), typeof window != "undefined" && typeof window.alert == "function" && window.alert(de));
358
- }, [p]);
359
- const [M, j] = z({}), [V, Z] = z({}), T = h({}), m = h({}), A = h({}), S = f((i, a) => {
360
- var c;
361
- return !!((c = A.current[i]) != null && c.has(a));
362
- }, []), C = f((i, a, c) => {
363
- j((d) => ({ ...d, [i]: { origin: a, frameRef: c } }));
364
- }, []), $ = f((i) => {
357
+ m !== void 0 || k.current || (k.current = !0, console.error(de), typeof window != "undefined" && typeof window.alert == "function" && window.alert(de));
358
+ }, [m]);
359
+ const [C, j] = O({}), [V, Z] = O({}), T = h({}), b = h({}), A = h({}), F = p((c, a) => {
360
+ var o;
361
+ return !!((o = A.current[c]) != null && o.has(a));
362
+ }, []), y = p((c, a, o) => {
363
+ j((f) => ({ ...f, [c]: { origin: a, frameRef: o } }));
364
+ }, []), z = p((c) => {
365
365
  j((a) => {
366
- const c = { ...a };
367
- return delete c[i], c;
366
+ const o = { ...a };
367
+ return delete o[c], o;
368
368
  }), Z((a) => {
369
- const c = { ...a };
370
- return delete c[i], c;
371
- }), delete A.current[i], Object.keys(m.current).forEach((a) => {
372
- m.current[a].instanceId === i && delete m.current[a];
369
+ const o = { ...a };
370
+ return delete o[c], o;
371
+ }), delete A.current[c], Object.keys(b.current).forEach((a) => {
372
+ b.current[a].instanceId === c && delete b.current[a];
373
373
  });
374
374
  }, []);
375
375
  R(() => () => {
376
- m.current = {};
376
+ b.current = {};
377
377
  }, []), R(() => {
378
- const i = (c = [], d, l) => {
379
- c.forEach((g) => g(d, l));
380
- }, a = (c) => {
381
- var y, U, x, Y, X, Q, q;
382
- if (!((y = c == null ? void 0 : c.data) != null && y.instanceId))
378
+ const c = (o = [], f, d) => {
379
+ o.forEach((g) => g(f, d));
380
+ }, a = (o) => {
381
+ var U, M, q, B, Y, X, Q;
382
+ if (!((U = o == null ? void 0 : o.data) != null && U.instanceId))
383
383
  return;
384
- const { instanceId: d, type: l } = c.data, g = M[d], D = (x = (U = g == null ? void 0 : g.frameRef) == null ? void 0 : U.current) == null ? void 0 : x.contentWindow;
385
- if (!D || c.source !== D || c.origin !== g.origin)
384
+ const { instanceId: f, type: d } = o.data, g = C[f], $ = (q = (M = g == null ? void 0 : g.frameRef) == null ? void 0 : M.current) == null ? void 0 : q.contentWindow;
385
+ if (!$ || o.source !== $ || o.origin !== g.origin)
386
386
  return;
387
- const _ = { origin: c.origin }, L = T.current;
388
- if (l === "response") {
389
- const { callbackId: e, response: n, error: t } = c.data, s = m.current[e];
390
- s && s.instanceId === d && (s.callback(n, t), delete m.current[e]);
387
+ const S = { origin: o.origin }, I = T.current;
388
+ if (d === "response") {
389
+ const { callbackId: e, response: n, error: r } = o.data, i = b.current[e];
390
+ i && i.instanceId === f && (i.callback(n, r), delete b.current[e]);
391
391
  return;
392
392
  }
393
- if (l === "mark-registered") {
394
- const { requestType: e } = c.data;
395
- A.current[d] || (A.current[d] = /* @__PURE__ */ new Set()), A.current[d].add(e);
393
+ if (d === "mark-registered") {
394
+ const { requestType: e } = o.data;
395
+ A.current[f] || (A.current[f] = /* @__PURE__ */ new Set()), A.current[f].add(e);
396
396
  return;
397
397
  }
398
- l === "ready" && Z((e) => ({ ...e, [d]: !0 })), i((Y = L[d]) == null ? void 0 : Y[l], c.data, _), i((X = L["*"]) == null ? void 0 : X[l], c.data, _), i((Q = L[d]) == null ? void 0 : Q["*"], c.data, _), i((q = L["*"]) == null ? void 0 : q["*"], c.data, _);
398
+ d === "ready" && Z((e) => ({ ...e, [f]: !0 })), c((B = I[f]) == null ? void 0 : B[d], o.data, S), c((Y = I["*"]) == null ? void 0 : Y[d], o.data, S), c((X = I[f]) == null ? void 0 : X["*"], o.data, S), c((Q = I["*"]) == null ? void 0 : Q["*"], o.data, S);
399
399
  };
400
400
  return window.addEventListener("message", a), () => {
401
401
  window.removeEventListener("message", a);
402
402
  };
403
- }, [M]);
404
- const I = f(
405
- (i, a, c, d) => {
406
- var g, D;
407
- const l = M[i];
408
- if (!l) {
409
- console.warn(`Origin not set for id: ${i}. Unable to send message.`);
403
+ }, [C]);
404
+ const _ = p(
405
+ (c, a, o, f) => {
406
+ var g, $;
407
+ const d = C[c];
408
+ if (!d) {
409
+ console.warn(`Origin not set for id: ${c}. Unable to send message.`);
410
410
  return;
411
411
  }
412
- (D = (g = l == null ? void 0 : l.frameRef) == null ? void 0 : g.current) != null && D.contentWindow && l.frameRef.current.contentWindow.postMessage(
413
- { type: a, ...c, instanceId: i },
414
- d || l.origin
412
+ ($ = (g = d == null ? void 0 : d.frameRef) == null ? void 0 : g.current) != null && $.contentWindow && d.frameRef.current.contentWindow.postMessage(
413
+ { type: a, ...o, instanceId: c },
414
+ f || d.origin
415
415
  );
416
416
  },
417
- [M]
418
- ), H = h(0), K = f(() => `${Date.now()}-${++H.current}`, []), O = f(
419
- async (i, a, c = {}) => new Promise((d, l) => {
420
- const g = K(), D = (_, L) => {
421
- delete m.current[g], L ? l(L) : d(_);
417
+ [C]
418
+ ), H = h(0), K = p(() => `${Date.now()}-${++H.current}`, []), L = p(
419
+ async (c, a, o = {}) => new Promise((f, d) => {
420
+ const g = K(), $ = (S, I) => {
421
+ delete b.current[g], I ? d(I) : f(S);
422
422
  };
423
- m.current[g] = { instanceId: i, callback: D }, I(i, "request", { callbackId: g, requestType: a, data: c });
423
+ b.current[g] = { instanceId: c, callback: $ }, _(c, "request", { callbackId: g, requestType: a, data: o });
424
424
  }),
425
- [I]
426
- ), F = f(
427
- (i, a) => {
428
- I(i, "load-options", a);
425
+ [_]
426
+ ), P = p(
427
+ (c, a) => {
428
+ _(c, "load-options", a);
429
429
  },
430
- [I]
431
- ), P = f(
432
- (i, a) => {
433
- I(i, "validate", a);
430
+ [_]
431
+ ), D = p(
432
+ (c, a) => {
433
+ _(c, "validate", a);
434
434
  },
435
- [I]
435
+ [_]
436
436
  ), v = be(
437
437
  () => ({
438
- registerFrame: C,
439
- unregisterFrame: $,
440
- sendMessage: I,
441
- sendRequest: O,
442
- loadOptions: F,
443
- validate: P,
444
- hasHandler: S,
438
+ registerFrame: y,
439
+ unregisterFrame: z,
440
+ sendMessage: _,
441
+ sendRequest: L,
442
+ loadOptions: P,
443
+ validate: D,
444
+ hasHandler: F,
445
445
  readyFrames: V,
446
- ready: b,
447
- addListener: (i, a, c) => (T.current[i] || (T.current[i] = {}), T.current[i][a] || (T.current[i][a] = []), T.current[i][a].push(c), () => {
448
- T.current[i][a] = T.current[i][a].filter((d) => d !== c);
446
+ ready: E,
447
+ addListener: (c, a, o) => (T.current[c] || (T.current[c] = {}), T.current[c][a] || (T.current[c][a] = []), T.current[c][a].push(o), () => {
448
+ T.current[c][a] = T.current[c][a].filter((f) => f !== o);
449
449
  })
450
450
  }),
451
451
  [
452
- C,
453
- $,
454
- I,
455
- O,
456
- F,
452
+ y,
453
+ z,
454
+ _,
455
+ L,
457
456
  P,
458
- S,
457
+ D,
458
+ F,
459
459
  V,
460
- b
460
+ E
461
461
  ]
462
462
  );
463
- return /* @__PURE__ */ B.createElement(se.Provider, { value: v }, /* @__PURE__ */ B.createElement(
463
+ return /* @__PURE__ */ W.createElement(se.Provider, { value: v }, /* @__PURE__ */ W.createElement(
464
464
  pe,
465
465
  {
466
- launcher: o,
466
+ launcher: s,
467
467
  broker: u,
468
- ready: b
468
+ ready: E
469
469
  },
470
- r
470
+ t
471
471
  ));
472
- }, N = (r, o, u) => {
473
- const p = J(se);
474
- if (p === null)
472
+ }, N = (t, s, u) => {
473
+ const m = J(se);
474
+ if (m === null)
475
475
  throw new Error(
476
476
  "useEmbeddedEffect must be used within a MMEmbeddableZoneProvider"
477
477
  );
478
- const b = h(u);
478
+ const E = h(u);
479
479
  R(() => {
480
- b.current = u;
480
+ E.current = u;
481
481
  }, [u]), R(() => {
482
- if (!(!r || !o)) {
483
- if (o.startsWith("key:")) {
484
- const k = o.substring(4);
485
- return p.readyFrames[r] && p.sendMessage(r, "subscribe-key", { keyChord: k }), p.addListener(
486
- r,
482
+ if (!(!t || !s)) {
483
+ if (s.startsWith("key:")) {
484
+ const k = s.substring(4);
485
+ return m.readyFrames[t] && m.sendMessage(t, "subscribe-key", { keyChord: k }), m.addListener(
486
+ t,
487
487
  `key-pressed:${k}`,
488
- (...j) => b.current(...j)
488
+ (...j) => E.current(...j)
489
489
  );
490
490
  }
491
- return p.addListener(
492
- r,
493
- o,
494
- (...k) => b.current(...k)
491
+ return m.addListener(
492
+ t,
493
+ s,
494
+ (...k) => E.current(...k)
495
495
  );
496
496
  }
497
- }, [p, r, o]);
497
+ }, [m, t, s]);
498
498
  };
499
- Ae.propTypes = {
499
+ ye.propTypes = {
500
500
  children: w.node.isRequired,
501
501
  /**
502
502
  * Required. True once the host holds its bearer; zones mount no iframe until then. Missing =
@@ -519,13 +519,13 @@ Ae.propTypes = {
519
519
  */
520
520
  credentialBroker: w.func
521
521
  };
522
- const oe = ce.default || ce, Le = 1e4, ye = "credentials", Ue = (r, o) => `${r}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(
522
+ const oe = ce.default || ce, Ae = 1e4, Le = "credentials", Ue = (t, s) => `${t}/mm-embedded-interop?id=${encodeURIComponent(s)}&origin=${encodeURIComponent(
523
523
  window.location.origin
524
- )}&caps=${ye}`, xe = oe.iframe`
524
+ )}&caps=${Le}`, xe = oe.iframe`
525
525
  width: 100%;
526
526
  height: 100%;
527
527
  border: none;
528
- visibility: ${(r) => r.$isReady ? "visible" : "hidden"};
528
+ visibility: ${(t) => t.$isReady ? "visible" : "hidden"};
529
529
  `, Oe = oe.div`
530
530
  width: 100%;
531
531
  height: 100%;
@@ -539,37 +539,37 @@ const oe = ce.default || ce, Le = 1e4, ye = "credentials", Ue = (r, o) => `${r}/
539
539
  text-align: center;
540
540
  color: #555;
541
541
  font-size: 14px;
542
- `, ze = (r) => {
543
- const o = r && r.origin || "This app", u = r && r.reason || "";
542
+ `, ze = (t) => {
543
+ const s = t && t.origin || "This app", u = t && t.reason || "";
544
544
  switch (u) {
545
545
  case "broker:scope_above_ceiling":
546
546
  return {
547
- title: `${o} can’t be authorized here`,
547
+ title: `${s} can’t be authorized here`,
548
548
  detail: "It asks for permissions your role doesn’t have."
549
549
  };
550
550
  case "broker:origin_mismatch":
551
551
  case "broker:unknown_client":
552
552
  return {
553
- title: `${o} can’t be authorized here`,
553
+ title: `${s} can’t be authorized here`,
554
554
  detail: "It isn’t registered to run at this address."
555
555
  };
556
556
  case "broker:cross_company_principal":
557
557
  return {
558
- title: `${o} can’t be authorized here`,
558
+ title: `${s} can’t be authorized here`,
559
559
  detail: "It can’t be authorized for this account."
560
560
  };
561
561
  default:
562
562
  return u.startsWith("broker:") ? {
563
- title: `${o} can’t be authorized here`,
563
+ title: `${s} can’t be authorized here`,
564
564
  detail: "Authorization was refused."
565
565
  } : {
566
- title: `${o} can’t be embedded here`,
566
+ title: `${s} can’t be embedded here`,
567
567
  detail: "It needs an update to support embedding from a different domain."
568
568
  };
569
569
  }
570
- }, he = ({ entry: r }) => {
571
- const o = ze(r);
572
- return /* @__PURE__ */ B.createElement(Oe, { "data-reason": r && r.reason || void 0 }, /* @__PURE__ */ B.createElement("div", { style: { fontWeight: 600 } }, o.title), /* @__PURE__ */ B.createElement("div", { style: { fontSize: 12, color: "#888" } }, o.detail));
570
+ }, he = ({ entry: t }) => {
571
+ const s = ze(t);
572
+ return /* @__PURE__ */ W.createElement(Oe, { "data-reason": t && t.reason || void 0 }, /* @__PURE__ */ W.createElement("div", { style: { fontWeight: 600 } }, s.title), /* @__PURE__ */ W.createElement("div", { style: { fontSize: 12, color: "#888" } }, s.detail));
573
573
  };
574
574
  he.propTypes = {
575
575
  entry: w.shape({
@@ -579,21 +579,21 @@ he.propTypes = {
579
579
  detail: w.object
580
580
  })
581
581
  };
582
- const $e = oe.div`
582
+ const ve = oe.div`
583
583
  height: 100%;
584
584
  display: flex;
585
585
  flex: 1;
586
586
  align-items: center;
587
587
  justify-content: center;
588
- `, ve = () => /* @__PURE__ */ B.createElement($e, null, /* @__PURE__ */ B.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), Se = ({
589
- id: r,
590
- src: o,
588
+ `, $e = () => /* @__PURE__ */ W.createElement(ve, null, /* @__PURE__ */ W.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), Se = ({
589
+ id: t,
590
+ src: s,
591
591
  path: u,
592
- onInit: p = () => {
592
+ onInit: m = () => {
593
593
  },
594
- onTimeout: b,
594
+ onTimeout: E,
595
595
  context: k = {},
596
- params: M = {},
596
+ params: C = {},
597
597
  renderUnsupported: j,
598
598
  renderTimeout: V,
599
599
  ...Z
@@ -610,96 +610,96 @@ const $e = oe.div`
610
610
  return console.error(
611
611
  "isFullScreen must be passed via the params prop to MMEmbeddableZone"
612
612
  ), null;
613
- const T = h(), m = ee(o), [A, S] = z(), [C, $] = z(0), [I, H] = z(!1), [K, O] = z(!1), F = _e(o), P = Me(o), v = Ce(o), { setDelivered: i } = Ie(), [a, c] = z(0), [d, l] = z(null), { registerFrame: g, unregisterFrame: D, sendMessage: _, ready: L } = J(
613
+ const T = h(), b = ee(s), [A, F] = O(), [y, z] = O(0), [_, H] = O(!1), [K, L] = O(!1), P = _e(s), D = Me(s), v = Ce(s), { setDelivered: c } = Ie(), [a, o] = O(0), [f, d] = O(null), g = h(!0), { registerFrame: $, unregisterFrame: S, sendMessage: I, ready: U } = J(
614
614
  se
615
- ), [y, U] = z(), x = h(), Y = h(b), X = h(p), Q = h(!1), q = h(), e = f(() => {
616
- Q.current = !1, clearTimeout(x.current), clearTimeout(q.current), $(0), H(!1), O(!1), l(null), i(m, r, !1);
617
- }, [i, m, r]);
615
+ ), [M, q] = O(), B = h(), Y = h(E), X = h(m), Q = h(!1), e = h(), n = p(() => {
616
+ Q.current = !1, clearTimeout(B.current), clearTimeout(e.current), z(0), H(!1), L(!1), d(null), g.current = !0, c(b, t, !1);
617
+ }, [c, b, t]);
618
618
  R(() => {
619
- (F > 0 || a > 0) && e();
620
- }, [F, a, e]), R(() => {
621
- Y.current = b;
622
- }, [b]), R(() => {
623
- X.current = p;
624
- }, [p]), R(() => {
625
- C && _(
626
- r,
619
+ (P > 0 || a > 0) && n();
620
+ }, [P, a, n]), R(() => {
621
+ Y.current = E;
622
+ }, [E]), R(() => {
623
+ X.current = m;
624
+ }, [m]), R(() => {
625
+ y && I(
626
+ t,
627
627
  "set-context",
628
628
  {
629
629
  context: {
630
630
  ...k
631
631
  }
632
632
  },
633
- m
633
+ b
634
634
  );
635
- }, [k, r, C, m]), R(() => {
636
- C && _(r, "set-params", { params: M }, m);
637
- }, [M, r, C, m]), R(() => {
638
- u !== void 0 && U((u == null ? void 0 : u.indexOf("/")) === 0 ? u : `/${u}`);
635
+ }, [k, t, y, b]), R(() => {
636
+ y && I(t, "set-params", { params: C }, b);
637
+ }, [C, t, y, b]), R(() => {
638
+ u !== void 0 && q((u == null ? void 0 : u.indexOf("/")) === 0 ? u : `/${u}`);
639
639
  }, [u]), R(() => {
640
- y === void 0 || !C || _(r, "navigate", { path: y }, m);
641
- }, [y, C, r, _, m]), R(() => {
642
- if (!o || !r || !T)
640
+ M === void 0 || !y || I(t, "navigate", { path: M }, b);
641
+ }, [M, y, t, I, b]), R(() => {
642
+ if (!s || !t || !T)
643
643
  return;
644
- if (!L) {
645
- e(), S(void 0);
644
+ if (!U) {
645
+ n(), F(void 0);
646
646
  return;
647
647
  }
648
- e();
649
- const s = new URL(o);
650
- return g(r, s.origin, T), X.current(), S(Ue(s.origin, r)), () => {
651
- D(r);
648
+ n();
649
+ const l = new URL(s);
650
+ return $(t, l.origin, T), X.current(), F(Ue(l.origin, t)), () => {
651
+ S(t);
652
652
  };
653
- }, [o, r, L, g, T, e]), R(() => {
653
+ }, [s, t, U, $, T, n]), R(() => {
654
654
  if (!(!A || Q.current))
655
- return x.current = setTimeout(() => {
655
+ return B.current = setTimeout(() => {
656
656
  H(!0), Y.current && Y.current();
657
- }, Le), () => clearTimeout(x.current);
658
- }, [A, o, F, a]);
659
- const n = f(() => {
660
- Q.current = !0, clearTimeout(x.current), H(!1);
657
+ }, Ae), () => clearTimeout(B.current);
658
+ }, [A, s, P, a]);
659
+ const r = p(() => {
660
+ Q.current = !0, clearTimeout(B.current), H(!1);
661
661
  }, []);
662
- if (N(r, "init", (s) => {
663
- n(), Array.isArray(s == null ? void 0 : s.acceptsCredentials) && l(s.acceptsCredentials);
664
- }), N(r, "authorize", n), N(r, "login", n), N(r, "credential-request", () => {
665
- n(), O(!0);
662
+ if (N(t, "init", (l) => {
663
+ r(), Array.isArray(l == null ? void 0 : l.acceptsCredentials) && (d(l.acceptsCredentials), g.current = !1, clearTimeout(e.current), e.current = void 0);
664
+ }), N(t, "authorize", r), N(t, "login", r), N(t, "credential-request", () => {
665
+ r(), L(!0);
666
666
  }), R(() => {
667
- if (!K || !P)
667
+ if (!K || !D)
668
668
  return;
669
- const s = d;
670
- if (Array.isArray(s) && !s.includes(P.kind))
669
+ const l = f;
670
+ if (Array.isArray(l) && !l.includes(D.kind))
671
671
  return;
672
- const E = P.kind === "access_token" ? { accessToken: P.accessToken } : {};
673
- _(r, "credential", { ...E, credential: P }, m), i(m, r, !0);
672
+ const x = D.kind === "access_token" ? { accessToken: D.accessToken } : {};
673
+ I(t, "credential", { ...x, credential: D }, b), c(b, t, !0);
674
674
  }, [
675
675
  K,
676
- P,
677
- d,
678
- r,
679
- _,
680
- m,
681
- i
682
- ]), N(r, "ready", () => {
683
- n(), $((s) => s + 1);
684
- }), N(r, "heartbeat", () => {
685
- q.current && clearTimeout(q.current), q.current = setTimeout(() => {
686
- c((s) => s + 1);
687
- }, 6e3);
676
+ D,
677
+ f,
678
+ t,
679
+ I,
680
+ b,
681
+ c
682
+ ]), N(t, "ready", () => {
683
+ r(), z((l) => l + 1);
684
+ }), N(t, "heartbeat", () => {
685
+ g.current && (e.current && clearTimeout(e.current), e.current = setTimeout(() => {
686
+ o((l) => l + 1);
687
+ }, 6e3));
688
688
  }), R(() => () => {
689
- q.current && clearTimeout(q.current);
689
+ e.current && clearTimeout(e.current);
690
690
  }, []), v)
691
- return j ? j(v) : /* @__PURE__ */ B.createElement(he, { entry: v });
692
- if (I && !C)
693
- return V ? V() : /* @__PURE__ */ B.createElement(ve, null);
694
- const t = { ...Z };
695
- return delete t.skipManifestCheck, /* @__PURE__ */ B.createElement(
691
+ return j ? j(v) : /* @__PURE__ */ W.createElement(he, { entry: v });
692
+ if (_ && !y)
693
+ return V ? V() : /* @__PURE__ */ W.createElement($e, null);
694
+ const i = { ...Z };
695
+ return delete i.skipManifestCheck, /* @__PURE__ */ W.createElement(
696
696
  xe,
697
697
  {
698
- key: `auth-epoch-${F}-frame-${a}`,
699
- $isReady: C,
698
+ key: `auth-epoch-${P}-frame-${a}`,
699
+ $isReady: y,
700
700
  ref: T,
701
701
  src: A,
702
- ...t
702
+ ...i
703
703
  }
704
704
  );
705
705
  };
@@ -727,7 +727,7 @@ export {
727
727
  te as EmbeddedAuthorizationContext,
728
728
  Se as MMEmbeddableZone,
729
729
  se as MMEmbeddableZoneContext,
730
- Ae as MMEmbeddableZoneProvider,
730
+ ye as MMEmbeddableZoneProvider,
731
731
  le as isCrossSite,
732
732
  ie as normalizeCredential,
733
733
  Te as popupAuthorizationLauncher,
@@ -1,4 +1,4 @@
1
- (function(b,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],r):(b=typeof globalThis!="undefined"?globalThis:b||self,r(b["mm-react-embeddable"]={},b.React,b.PropTypes,b.styled))})(this,(function(b,r,we,Te){"use strict";const te=t=>t&&t.__esModule?t:{default:t},x=te(r),k=te(we),oe=te(Te),J=r.createContext(null),V=r.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),ie="access_token",ne=t=>t?t.kind?t:t.accessToken?{kind:ie,accessToken:t.accessToken,expiresAt:t.expiresAt||null}:null:null,_e=60,Ie=120,Me=3e4,ye=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),X=t=>{try{return new URL(t).origin}catch{return null}},ce=(t,o)=>{const l=o==null?void 0:o.origin;return!l||X(t==null?void 0:t.authUrl)!==l?null:l},le=t=>{if(!t||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(t)||t.includes(":"))return t;const o=t.split(".");return o.length<=2?t:o.slice(-2).join(".")},se=(t,o)=>{try{const l=new URL(t),p=new URL(o);return l.protocol!==p.protocol?!0:le(l.hostname)!==le(p.hostname)}catch{return!0}},de=(t,{onBlocked:o,onClosed:l})=>{const p=window.open(t.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!p)return o(),()=>{};const m=setInterval(()=>{p.closed&&(clearInterval(m),l())},1e3);return()=>clearInterval(m)},ae=({children:t,launcher:o,broker:l,ready:p})=>{const m=r.useContext(J),[C,I]=r.useState({}),[j,Q]=r.useState({}),[B,w]=r.useState({}),[h,y]=r.useState({}),$=r.useRef(B);$.current=B;const M=r.useRef(C);M.current=C;const O=r.useRef(null),T=r.useRef({}),Z=r.useRef({}),H=r.useRef(l);H.current=l;const z=r.useRef({}),P=r.useRef({}),D=r.useCallback((e,s,n)=>{!e||!s||(z.current[e]||(z.current[e]=new Set),n?z.current[e].add(s):z.current[e].delete(s))},[]),v=r.useCallback(e=>{const s=T.current[e];if(!s)return;const n=u=>!u[e]||u[e].clientId?u:{...u,[e]:{...u[e],clientId:s}};I(n),y(n)},[]),c=r.useCallback((e,s)=>{e&&(y(n=>n[e]?n:{...n,[e]:{origin:e,reason:s,clientId:T.current[e]||null}}),v(e))},[v]),d=r.useCallback((e,{v2:s=!1,origin:n=null}={})=>{var u;if(n){if(s&&$.current[n]){if(!((u=z.current[n])!=null&&u.has(e.instanceId)))return;const g=Date.now();if(g-(P.current[n]||0)<Me)return;P.current[n]=g,z.current[n].clear();const W={...$.current};delete W[n],$.current=W,w(W)}I(g=>g[n]?g:{...g,[n]:{origin:n,authUrl:e.authUrl,status:s&&H.current?"broker":"interactive",v2:s,scope:e.scope||null,acceptsCredentials:Z.current[n]||null,consent:null,error:null,clientId:e.clientId||T.current[n]||null,popupBlocked:!1}}),v(n)}},[v]),i=r.useRef({}),f=r.useCallback(e=>{i.current[e]&&(clearTimeout(i.current[e]),delete i.current[e])},[]),a=r.useCallback(e=>{f(e),I(s=>{if(!s[e])return s;const n={...s};return delete n[e],n})},[f]),E=r.useCallback(e=>{e&&(a(e),Q(s=>({...s,[e]:(s[e]||0)+1})))},[a]),F=r.useCallback(e=>{a(e.origin)},[a]),_=r.useCallback((e,s)=>{const n=ce(e,s);if(n){if(se(n,window.location.origin)){c(n,"cross-site-legacy");return}d(e,{origin:n})}},[d,c]);r.useEffect(()=>{if(!m)return;const e=[m.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(T.current[n.origin]=s.clientId,v(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?Z.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&se(n.origin,window.location.origin)&&c(n.origin,"cross-site-legacy")}),m.addListener("*","authorize",_),m.addListener("*","login",_),m.addListener("*","credential-request",(s,n)=>d(s,{v2:!0,origin:ce(s,n)}))];return()=>e.forEach(s=>s())},[m,_,d,v,c]),r.useEffect(()=>{const e=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const u=X(n.authUrl);if(!u||s.origin!==u)return;const g=M.current[u];if(!(!g||g.status!=="interactive")){if(n.accessToken){w(W=>({...W,[u]:ne({accessToken:n.accessToken})})),a(u);return}E(u)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[a,E]);const A=r.useCallback((e,s)=>{const n=e==null?void 0:e.origin,u=ne(s);!n||!u||(w(g=>({...g,[n]:u})),a(n))},[a]),S=r.useCallback((e,s)=>{I(n=>n[e]?{...n,[e]:{...n[e],...s}}:n)},[]),L=r.useRef({}),U=r.useCallback(async(e,{approve:s}={})=>{const n=H.current,{origin:u}=e;let g;try{g=await n({origin:u,clientId:e.clientId,scope:e.scope,authUrl:e.authUrl},{approve:s})}catch{s?S(u,{error:{reason:"broker_unavailable"}}):S(u,{status:"interactive"});return}const W=g==null?void 0:g.status,Y=(g==null?void 0:g.body)||{};if(W===200&&Y.credential){A(e,Y.credential);return}if(W===409&&Y.consentRequired){S(u,{status:"interactive",consent:{client:Y.client||null,stepUp:!!Y.stepUp,scope:Y.scope||e.scope},error:null});return}const ee=Y.error||"broker_error";if(!s&&ye.has(ee)){S(u,{status:"interactive"});return}if(s&&ee==="consent_denied"){S(u,{error:null});return}if(ee==="rate_limited"&&!e.rateLimitRetried){const re=Math.min(Number(Y.retryAfter)>0?Number(Y.retryAfter):_e,Ie),xe={...e,rateLimitRetried:!0};f(u),i.current[u]=setTimeout(()=>{delete i.current[u],L.current[u]=!0,K.current(xe,{approve:s}).finally(()=>{delete L.current[u]})},re*1e3),S(u,{rateLimitRetried:!0});return}a(u),y(re=>({...re,[u]:{origin:u,reason:`broker:${ee}`,detail:{status:W!=null?W:null,reason:ee},clientId:e.clientId||T.current[u]||null}}))},[A,S,a,f]),K=r.useRef(U);K.current=U,r.useEffect(()=>{Object.values(C).forEach(e=>{e.status!=="broker"||L.current[e.origin]||i.current[e.origin]||(L.current[e.origin]=!0,U(e).finally(()=>{delete L.current[e.origin]}))})},[C,U]);const R=r.useCallback(e=>!H.current||!(e!=null&&e.consent)||L.current[e.origin]?Promise.resolve():(L.current[e.origin]=!0,U(e,{approve:!0}).finally(()=>{delete L.current[e.origin]})),[U]);r.useEffect(()=>()=>{O.current&&O.current(),Object.values(i.current).forEach(clearTimeout)},[]),r.useEffect(()=>{p===!1&&(Object.values(i.current).forEach(clearTimeout),i.current={},L.current={},T.current={},Z.current={},z.current={},P.current={},$.current={},w({}),I({}),y({}))},[p]);const G=r.useCallback(e=>{O.current&&(O.current(),O.current=null);const s=o||de;O.current=s(e,{onBlocked:()=>{I(n=>n[e.origin]?{...n,[e.origin]:{...n[e.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=M.current[e.origin];!n||n.v2||E(e.origin)}})},[o,E]),q={pending:Object.values(C).filter(e=>e.status==="interactive"),authorize:G,approve:R,complete:A,dismiss:F,originEpochs:j,credentials:B,unsupported:h,setDelivered:D};return x.default.createElement(V.Provider,{value:q},t)};ae.propTypes={children:k.default.node,launcher:k.default.func,ready:k.default.bool,broker:k.default.func};const fe=()=>r.useContext(V),pe=t=>{const{originEpochs:o}=r.useContext(V),l=X(t);return l&&o[l]||0},be=t=>{const{credentials:o}=r.useContext(V),l=X(t);return l&&o[l]||null},he=t=>{const{unsupported:o}=r.useContext(V),l=X(t);return l&&o[l]||null},me="MMEmbeddableZoneProvider requires a boolean `ready` prop (true once the host holds the bearer its credentialBroker needs). Embedded apps will not load until it is provided.",Ee=({children:t,authorizationLauncher:o,credentialBroker:l,ready:p})=>{const m=p===!0,C=r.useRef(!1);r.useEffect(()=>{p!==void 0||C.current||(C.current=!0,console.error(me),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(me))},[p]);const[I,j]=r.useState({}),[Q,B]=r.useState({}),w=r.useRef({}),h=r.useRef({}),y=r.useRef({}),$=r.useCallback((c,d)=>{var i;return!!((i=y.current[c])!=null&&i.has(d))},[]),M=r.useCallback((c,d,i)=>{j(f=>({...f,[c]:{origin:d,frameRef:i}}))},[]),O=r.useCallback(c=>{j(d=>{const i={...d};return delete i[c],i}),B(d=>{const i={...d};return delete i[c],i}),delete y.current[c],Object.keys(h.current).forEach(d=>{h.current[d].instanceId===c&&delete h.current[d]})},[]);r.useEffect(()=>()=>{h.current={}},[]),r.useEffect(()=>{const c=(i=[],f,a)=>{i.forEach(E=>E(f,a))},d=i=>{var S,L,U,K,R,G,q;if(!((S=i==null?void 0:i.data)!=null&&S.instanceId))return;const{instanceId:f,type:a}=i.data,E=I[f],F=(U=(L=E==null?void 0:E.frameRef)==null?void 0:L.current)==null?void 0:U.contentWindow;if(!F||i.source!==F||i.origin!==E.origin)return;const _={origin:i.origin},A=w.current;if(a==="response"){const{callbackId:e,response:s,error:n}=i.data,u=h.current[e];u&&u.instanceId===f&&(u.callback(s,n),delete h.current[e]);return}if(a==="mark-registered"){const{requestType:e}=i.data;y.current[f]||(y.current[f]=new Set),y.current[f].add(e);return}a==="ready"&&B(e=>({...e,[f]:!0})),c((K=A[f])==null?void 0:K[a],i.data,_),c((R=A["*"])==null?void 0:R[a],i.data,_),c((G=A[f])==null?void 0:G["*"],i.data,_),c((q=A["*"])==null?void 0:q["*"],i.data,_)};return window.addEventListener("message",d),()=>{window.removeEventListener("message",d)}},[I]);const T=r.useCallback((c,d,i,f)=>{var E,F;const a=I[c];if(!a){console.warn(`Origin not set for id: ${c}. Unable to send message.`);return}(F=(E=a==null?void 0:a.frameRef)==null?void 0:E.current)!=null&&F.contentWindow&&a.frameRef.current.contentWindow.postMessage({type:d,...i,instanceId:c},f||a.origin)},[I]),Z=r.useRef(0),H=r.useCallback(()=>`${Date.now()}-${++Z.current}`,[]),z=r.useCallback(async(c,d,i={})=>new Promise((f,a)=>{const E=H(),F=(_,A)=>{delete h.current[E],A?a(A):f(_)};h.current[E]={instanceId:c,callback:F},T(c,"request",{callbackId:E,requestType:d,data:i})}),[T]),P=r.useCallback((c,d)=>{T(c,"load-options",d)},[T]),D=r.useCallback((c,d)=>{T(c,"validate",d)},[T]),v=r.useMemo(()=>({registerFrame:M,unregisterFrame:O,sendMessage:T,sendRequest:z,loadOptions:P,validate:D,hasHandler:$,readyFrames:Q,ready:m,addListener:(c,d,i)=>(w.current[c]||(w.current[c]={}),w.current[c][d]||(w.current[c][d]=[]),w.current[c][d].push(i),()=>{w.current[c][d]=w.current[c][d].filter(f=>f!==i)})}),[M,O,T,z,P,D,$,Q,m]);return x.default.createElement(J.Provider,{value:v},x.default.createElement(ae,{launcher:o,broker:l,ready:m},t))},N=(t,o,l)=>{const p=r.useContext(J);if(p===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const m=r.useRef(l);r.useEffect(()=>{m.current=l},[l]),r.useEffect(()=>{if(!(!t||!o)){if(o.startsWith("key:")){const C=o.substring(4);return p.readyFrames[t]&&p.sendMessage(t,"subscribe-key",{keyChord:C}),p.addListener(t,`key-pressed:${C}`,(...j)=>m.current(...j))}return p.addListener(t,o,(...C)=>m.current(...C))}},[p,t,o])};Ee.propTypes={children:k.default.node.isRequired,ready:k.default.bool.isRequired,authorizationLauncher:k.default.func,credentialBroker:k.default.func};const ue=oe.default.default||oe.default,Ae=1e4,Se="credentials",Le=(t,o)=>`${t}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Se}`,Ue=ue.iframe`
1
+ (function(h,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],r):(h=typeof globalThis!="undefined"?globalThis:h||self,r(h["mm-react-embeddable"]={},h.React,h.PropTypes,h.styled))})(this,(function(h,r,we,Te){"use strict";const te=t=>t&&t.__esModule?t:{default:t},$=te(r),k=te(we),oe=te(Te),J=r.createContext(null),V=r.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),ie="access_token",ne=t=>t?t.kind?t:t.accessToken?{kind:ie,accessToken:t.accessToken,expiresAt:t.expiresAt||null}:null:null,_e=60,Ie=120,ye=3e4,Me=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),X=t=>{try{return new URL(t).origin}catch{return null}},ce=(t,u)=>{const l=u==null?void 0:u.origin;return!l||X(t==null?void 0:t.authUrl)!==l?null:l},le=t=>{if(!t||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(t)||t.includes(":"))return t;const u=t.split(".");return u.length<=2?t:u.slice(-2).join(".")},se=(t,u)=>{try{const l=new URL(t),b=new URL(u);return l.protocol!==b.protocol?!0:le(l.hostname)!==le(b.hostname)}catch{return!0}},de=(t,{onBlocked:u,onClosed:l})=>{const b=window.open(t.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!b)return u(),()=>{};const g=setInterval(()=>{b.closed&&(clearInterval(g),l())},1e3);return()=>clearInterval(g)},ae=({children:t,launcher:u,broker:l,ready:b})=>{const g=r.useContext(J),[C,y]=r.useState({}),[j,R]=r.useState({}),[B,w]=r.useState({}),[m,A]=r.useState({}),P=r.useRef(B);P.current=B;const M=r.useRef(C);M.current=C;const z=r.useRef(null),_=r.useRef({}),Z=r.useRef({}),H=r.useRef(l);H.current=l;const S=r.useRef({}),D=r.useRef({}),F=r.useCallback((e,s,n)=>{!e||!s||(S.current[e]||(S.current[e]=new Set),n?S.current[e].add(s):S.current[e].delete(s))},[]),O=r.useCallback(e=>{const s=_.current[e];if(!s)return;const n=c=>!c[e]||c[e].clientId?c:{...c,[e]:{...c[e],clientId:s}};y(n),A(n)},[]),i=r.useCallback((e,s)=>{e&&(A(n=>n[e]?n:{...n,[e]:{origin:e,reason:s,clientId:_.current[e]||null}}),O(e))},[O]),d=r.useCallback((e,{v2:s=!1,origin:n=null}={})=>{var c;if(n){if(s&&P.current[n]){if(!((c=S.current[n])!=null&&c.has(e.instanceId)))return;const a=Date.now();if(a-(D.current[n]||0)<ye)return;D.current[n]=a,S.current[n].clear();const U={...P.current};delete U[n],P.current=U,w(U)}y(a=>a[n]?a:{...a,[n]:{origin:n,authUrl:e.authUrl,status:s&&H.current?"broker":"interactive",v2:s,scope:e.scope||null,acceptsCredentials:Z.current[n]||null,consent:null,error:null,clientId:e.clientId||_.current[n]||null,popupBlocked:!1}}),O(n)}},[O]),o=r.useRef({}),p=r.useCallback(e=>{o.current[e]&&(clearTimeout(o.current[e]),delete o.current[e])},[]),f=r.useCallback(e=>{p(e),y(s=>{if(!s[e])return s;const n={...s};return delete n[e],n})},[p]),E=r.useCallback(e=>{e&&(f(e),R(s=>({...s,[e]:(s[e]||0)+1})))},[f]),v=r.useCallback(e=>{f(e.origin)},[f]),x=r.useCallback((e,s)=>{const n=ce(e,s);if(n){if(se(n,window.location.origin)){i(n,"cross-site-legacy");return}d(e,{origin:n})}},[d,i]);r.useEffect(()=>{if(!g)return;const e=[g.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(_.current[n.origin]=s.clientId,O(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?Z.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&se(n.origin,window.location.origin)&&i(n.origin,"cross-site-legacy")}),g.addListener("*","authorize",x),g.addListener("*","login",x),g.addListener("*","credential-request",(s,n)=>d(s,{v2:!0,origin:ce(s,n)}))];return()=>e.forEach(s=>s())},[g,x,d,O,i]),r.useEffect(()=>{const e=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const c=X(n.authUrl);if(!c||s.origin!==c)return;const a=M.current[c];if(!(!a||a.status!=="interactive")){if(n.accessToken){w(U=>({...U,[c]:ne({accessToken:n.accessToken})})),f(c);return}E(c)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[f,E]);const T=r.useCallback((e,s)=>{const n=e==null?void 0:e.origin,c=ne(s);!n||!c||(w(a=>({...a,[n]:c})),f(n))},[f]),L=r.useCallback((e,s)=>{y(n=>n[e]?{...n,[e]:{...n[e],...s}}:n)},[]),I=r.useRef({}),q=r.useCallback(async(e,{approve:s}={})=>{const n=H.current,{origin:c}=e;let a;try{a=await n({origin:c,clientId:e.clientId,scope:e.scope,authUrl:e.authUrl},{approve:s})}catch{s?L(c,{error:{reason:"broker_unavailable"}}):L(c,{status:"interactive"});return}const U=a==null?void 0:a.status,K=(a==null?void 0:a.body)||{};if(U===200&&K.credential){T(e,K.credential);return}if(U===409&&K.consentRequired){L(c,{status:"interactive",consent:{client:K.client||null,stepUp:!!K.stepUp,scope:K.scope||e.scope},error:null});return}const ee=K.error||"broker_error";if(!s&&Me.has(ee)){L(c,{status:"interactive"});return}if(s&&ee==="consent_denied"){L(c,{error:null});return}if(ee==="rate_limited"&&!e.rateLimitRetried){const re=Math.min(Number(K.retryAfter)>0?Number(K.retryAfter):_e,Ie),xe={...e,rateLimitRetried:!0};p(c),o.current[c]=setTimeout(()=>{delete o.current[c],I.current[c]=!0,W.current(xe,{approve:s}).finally(()=>{delete I.current[c]})},re*1e3),L(c,{rateLimitRetried:!0});return}f(c),A(re=>({...re,[c]:{origin:c,reason:`broker:${ee}`,detail:{status:U!=null?U:null,reason:ee},clientId:e.clientId||_.current[c]||null}}))},[T,L,f,p]),W=r.useRef(q);W.current=q,r.useEffect(()=>{Object.values(C).forEach(e=>{e.status!=="broker"||I.current[e.origin]||o.current[e.origin]||(I.current[e.origin]=!0,q(e).finally(()=>{delete I.current[e.origin]}))})},[C,q]);const G=r.useCallback(e=>!H.current||!(e!=null&&e.consent)||I.current[e.origin]?Promise.resolve():(I.current[e.origin]=!0,q(e,{approve:!0}).finally(()=>{delete I.current[e.origin]})),[q]);r.useEffect(()=>()=>{z.current&&z.current(),Object.values(o.current).forEach(clearTimeout)},[]),r.useEffect(()=>{b===!1&&(Object.values(o.current).forEach(clearTimeout),o.current={},I.current={},_.current={},Z.current={},S.current={},D.current={},P.current={},w({}),y({}),A({}))},[b]);const Q=r.useCallback(e=>{z.current&&(z.current(),z.current=null);const s=u||de;z.current=s(e,{onBlocked:()=>{y(n=>n[e.origin]?{...n,[e.origin]:{...n[e.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=M.current[e.origin];!n||n.v2||E(e.origin)}})},[u,E]),Y={pending:Object.values(C).filter(e=>e.status==="interactive"),authorize:Q,approve:G,complete:T,dismiss:v,originEpochs:j,credentials:B,unsupported:m,setDelivered:F};return $.default.createElement(V.Provider,{value:Y},t)};ae.propTypes={children:k.default.node,launcher:k.default.func,ready:k.default.bool,broker:k.default.func};const fe=()=>r.useContext(V),pe=t=>{const{originEpochs:u}=r.useContext(V),l=X(t);return l&&u[l]||0},be=t=>{const{credentials:u}=r.useContext(V),l=X(t);return l&&u[l]||null},he=t=>{const{unsupported:u}=r.useContext(V),l=X(t);return l&&u[l]||null},me="MMEmbeddableZoneProvider requires a boolean `ready` prop (true once the host holds the bearer its credentialBroker needs). Embedded apps will not load until it is provided.",Ee=({children:t,authorizationLauncher:u,credentialBroker:l,ready:b})=>{const g=b===!0,C=r.useRef(!1);r.useEffect(()=>{b!==void 0||C.current||(C.current=!0,console.error(me),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(me))},[b]);const[y,j]=r.useState({}),[R,B]=r.useState({}),w=r.useRef({}),m=r.useRef({}),A=r.useRef({}),P=r.useCallback((i,d)=>{var o;return!!((o=A.current[i])!=null&&o.has(d))},[]),M=r.useCallback((i,d,o)=>{j(p=>({...p,[i]:{origin:d,frameRef:o}}))},[]),z=r.useCallback(i=>{j(d=>{const o={...d};return delete o[i],o}),B(d=>{const o={...d};return delete o[i],o}),delete A.current[i],Object.keys(m.current).forEach(d=>{m.current[d].instanceId===i&&delete m.current[d]})},[]);r.useEffect(()=>()=>{m.current={}},[]),r.useEffect(()=>{const i=(o=[],p,f)=>{o.forEach(E=>E(p,f))},d=o=>{var L,I,q,W,G,Q,Y;if(!((L=o==null?void 0:o.data)!=null&&L.instanceId))return;const{instanceId:p,type:f}=o.data,E=y[p],v=(q=(I=E==null?void 0:E.frameRef)==null?void 0:I.current)==null?void 0:q.contentWindow;if(!v||o.source!==v||o.origin!==E.origin)return;const x={origin:o.origin},T=w.current;if(f==="response"){const{callbackId:e,response:s,error:n}=o.data,c=m.current[e];c&&c.instanceId===p&&(c.callback(s,n),delete m.current[e]);return}if(f==="mark-registered"){const{requestType:e}=o.data;A.current[p]||(A.current[p]=new Set),A.current[p].add(e);return}f==="ready"&&B(e=>({...e,[p]:!0})),i((W=T[p])==null?void 0:W[f],o.data,x),i((G=T["*"])==null?void 0:G[f],o.data,x),i((Q=T[p])==null?void 0:Q["*"],o.data,x),i((Y=T["*"])==null?void 0:Y["*"],o.data,x)};return window.addEventListener("message",d),()=>{window.removeEventListener("message",d)}},[y]);const _=r.useCallback((i,d,o,p)=>{var E,v;const f=y[i];if(!f){console.warn(`Origin not set for id: ${i}. Unable to send message.`);return}(v=(E=f==null?void 0:f.frameRef)==null?void 0:E.current)!=null&&v.contentWindow&&f.frameRef.current.contentWindow.postMessage({type:d,...o,instanceId:i},p||f.origin)},[y]),Z=r.useRef(0),H=r.useCallback(()=>`${Date.now()}-${++Z.current}`,[]),S=r.useCallback(async(i,d,o={})=>new Promise((p,f)=>{const E=H(),v=(x,T)=>{delete m.current[E],T?f(T):p(x)};m.current[E]={instanceId:i,callback:v},_(i,"request",{callbackId:E,requestType:d,data:o})}),[_]),D=r.useCallback((i,d)=>{_(i,"load-options",d)},[_]),F=r.useCallback((i,d)=>{_(i,"validate",d)},[_]),O=r.useMemo(()=>({registerFrame:M,unregisterFrame:z,sendMessage:_,sendRequest:S,loadOptions:D,validate:F,hasHandler:P,readyFrames:R,ready:g,addListener:(i,d,o)=>(w.current[i]||(w.current[i]={}),w.current[i][d]||(w.current[i][d]=[]),w.current[i][d].push(o),()=>{w.current[i][d]=w.current[i][d].filter(p=>p!==o)})}),[M,z,_,S,D,F,P,R,g]);return $.default.createElement(J.Provider,{value:O},$.default.createElement(ae,{launcher:u,broker:l,ready:g},t))},N=(t,u,l)=>{const b=r.useContext(J);if(b===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const g=r.useRef(l);r.useEffect(()=>{g.current=l},[l]),r.useEffect(()=>{if(!(!t||!u)){if(u.startsWith("key:")){const C=u.substring(4);return b.readyFrames[t]&&b.sendMessage(t,"subscribe-key",{keyChord:C}),b.addListener(t,`key-pressed:${C}`,(...j)=>g.current(...j))}return b.addListener(t,u,(...C)=>g.current(...C))}},[b,t,u])};Ee.propTypes={children:k.default.node.isRequired,ready:k.default.bool.isRequired,authorizationLauncher:k.default.func,credentialBroker:k.default.func};const ue=oe.default.default||oe.default,Ae=1e4,Se="credentials",Le=(t,u)=>`${t}/mm-embedded-interop?id=${encodeURIComponent(u)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Se}`,Ue=ue.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
@@ -16,10 +16,10 @@
16
16
  text-align: center;
17
17
  color: #555;
18
18
  font-size: 14px;
19
- `,ge=t=>{const o=t&&t.origin||"This app",l=t&&t.reason||"";switch(l){case"broker:scope_above_ceiling":return{title:`${o} can’t be authorized here`,detail:"It asks for permissions your role doesn’t have."};case"broker:origin_mismatch":case"broker:unknown_client":return{title:`${o} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${o} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return l.startsWith("broker:")?{title:`${o} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${o} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},ke=({entry:t})=>{const o=ge(t);return x.default.createElement(ze,{"data-reason":t&&t.reason||void 0},x.default.createElement("div",{style:{fontWeight:600}},o.title),x.default.createElement("div",{style:{fontSize:12,color:"#888"}},o.detail))};ke.propTypes={entry:k.default.shape({origin:k.default.string,name:k.default.string,reason:k.default.string,detail:k.default.object})};const Oe=ue.div`
19
+ `,ge=t=>{const u=t&&t.origin||"This app",l=t&&t.reason||"";switch(l){case"broker:scope_above_ceiling":return{title:`${u} can’t be authorized here`,detail:"It asks for permissions your role doesn’t have."};case"broker:origin_mismatch":case"broker:unknown_client":return{title:`${u} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${u} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return l.startsWith("broker:")?{title:`${u} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${u} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},ke=({entry:t})=>{const u=ge(t);return $.default.createElement(ze,{"data-reason":t&&t.reason||void 0},$.default.createElement("div",{style:{fontWeight:600}},u.title),$.default.createElement("div",{style:{fontSize:12,color:"#888"}},u.detail))};ke.propTypes={entry:k.default.shape({origin:k.default.string,name:k.default.string,reason:k.default.string,detail:k.default.object})};const Oe=ue.div`
20
20
  height: 100%;
21
21
  display: flex;
22
22
  flex: 1;
23
23
  align-items: center;
24
24
  justify-content: center;
25
- `,ve=()=>x.default.createElement(Oe,null,x.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),Ce=({id:t,src:o,path:l,onInit:p=()=>{},onTimeout:m,context:C={},params:I={},renderUnsupported:j,renderTimeout:Q,...B})=>{if("isConfiguring"in B)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in C)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in C)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const w=r.useRef(),h=X(o),[y,$]=r.useState(),[M,O]=r.useState(0),[T,Z]=r.useState(!1),[H,z]=r.useState(!1),P=pe(o),D=be(o),v=he(o),{setDelivered:c}=fe(),[d,i]=r.useState(0),[f,a]=r.useState(null),{registerFrame:E,unregisterFrame:F,sendMessage:_,ready:A}=r.useContext(J),[S,L]=r.useState(),U=r.useRef(),K=r.useRef(m),R=r.useRef(p),G=r.useRef(!1),q=r.useRef(),e=r.useCallback(()=>{G.current=!1,clearTimeout(U.current),clearTimeout(q.current),O(0),Z(!1),z(!1),a(null),c(h,t,!1)},[c,h,t]);r.useEffect(()=>{(P>0||d>0)&&e()},[P,d,e]),r.useEffect(()=>{K.current=m},[m]),r.useEffect(()=>{R.current=p},[p]),r.useEffect(()=>{M&&_(t,"set-context",{context:{...C}},h)},[C,t,M,h]),r.useEffect(()=>{M&&_(t,"set-params",{params:I},h)},[I,t,M,h]),r.useEffect(()=>{l!==void 0&&L((l==null?void 0:l.indexOf("/"))===0?l:`/${l}`)},[l]),r.useEffect(()=>{S===void 0||!M||_(t,"navigate",{path:S},h)},[S,M,t,_,h]),r.useEffect(()=>{if(!o||!t||!w)return;if(!A){e(),$(void 0);return}e();const u=new URL(o);return E(t,u.origin,w),R.current(),$(Le(u.origin,t)),()=>{F(t)}},[o,t,A,E,w,e]),r.useEffect(()=>{if(!(!y||G.current))return U.current=setTimeout(()=>{Z(!0),K.current&&K.current()},Ae),()=>clearTimeout(U.current)},[y,o,P,d]);const s=r.useCallback(()=>{G.current=!0,clearTimeout(U.current),Z(!1)},[]);if(N(t,"init",u=>{s(),Array.isArray(u==null?void 0:u.acceptsCredentials)&&a(u.acceptsCredentials)}),N(t,"authorize",s),N(t,"login",s),N(t,"credential-request",()=>{s(),z(!0)}),r.useEffect(()=>{if(!H||!D)return;const u=f;if(Array.isArray(u)&&!u.includes(D.kind))return;const g=D.kind==="access_token"?{accessToken:D.accessToken}:{};_(t,"credential",{...g,credential:D},h),c(h,t,!0)},[H,D,f,t,_,h,c]),N(t,"ready",()=>{s(),O(u=>u+1)}),N(t,"heartbeat",()=>{q.current&&clearTimeout(q.current),q.current=setTimeout(()=>{i(u=>u+1)},6e3)}),r.useEffect(()=>()=>{q.current&&clearTimeout(q.current)},[]),v)return j?j(v):x.default.createElement(ke,{entry:v});if(T&&!M)return Q?Q():x.default.createElement(ve,null);const n={...B};return delete n.skipManifestCheck,x.default.createElement(Ue,{key:`auth-epoch-${P}-frame-${d}`,$isReady:M,ref:w,src:y,...n})};Ce.propTypes={id:k.default.string,src:k.default.string.isRequired,path:k.default.string,onInit:k.default.func,onTimeout:k.default.func,renderUnsupported:k.default.func,renderTimeout:k.default.func},b.CREDENTIAL_KIND_ACCESS_TOKEN=ie,b.EmbeddedAuthorizationContext=V,b.MMEmbeddableZone=Ce,b.MMEmbeddableZoneContext=J,b.MMEmbeddableZoneProvider=Ee,b.isCrossSite=se,b.normalizeCredential=ne,b.popupAuthorizationLauncher=de,b.unsupportedCopy=ge,b.useEmbeddedAuthorizations=fe,b.useEmbeddedCredential=be,b.useEmbeddedEffect=N,b.useEmbeddedOriginEpoch=pe,b.useEmbeddedUnsupported=he,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
25
+ `,ve=()=>$.default.createElement(Oe,null,$.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),Ce=({id:t,src:u,path:l,onInit:b=()=>{},onTimeout:g,context:C={},params:y={},renderUnsupported:j,renderTimeout:R,...B})=>{if("isConfiguring"in B)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in C)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in C)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const w=r.useRef(),m=X(u),[A,P]=r.useState(),[M,z]=r.useState(0),[_,Z]=r.useState(!1),[H,S]=r.useState(!1),D=pe(u),F=be(u),O=he(u),{setDelivered:i}=fe(),[d,o]=r.useState(0),[p,f]=r.useState(null),E=r.useRef(!0),{registerFrame:v,unregisterFrame:x,sendMessage:T,ready:L}=r.useContext(J),[I,q]=r.useState(),W=r.useRef(),G=r.useRef(g),Q=r.useRef(b),Y=r.useRef(!1),e=r.useRef(),s=r.useCallback(()=>{Y.current=!1,clearTimeout(W.current),clearTimeout(e.current),z(0),Z(!1),S(!1),f(null),E.current=!0,i(m,t,!1)},[i,m,t]);r.useEffect(()=>{(D>0||d>0)&&s()},[D,d,s]),r.useEffect(()=>{G.current=g},[g]),r.useEffect(()=>{Q.current=b},[b]),r.useEffect(()=>{M&&T(t,"set-context",{context:{...C}},m)},[C,t,M,m]),r.useEffect(()=>{M&&T(t,"set-params",{params:y},m)},[y,t,M,m]),r.useEffect(()=>{l!==void 0&&q((l==null?void 0:l.indexOf("/"))===0?l:`/${l}`)},[l]),r.useEffect(()=>{I===void 0||!M||T(t,"navigate",{path:I},m)},[I,M,t,T,m]),r.useEffect(()=>{if(!u||!t||!w)return;if(!L){s(),P(void 0);return}s();const a=new URL(u);return v(t,a.origin,w),Q.current(),P(Le(a.origin,t)),()=>{x(t)}},[u,t,L,v,w,s]),r.useEffect(()=>{if(!(!A||Y.current))return W.current=setTimeout(()=>{Z(!0),G.current&&G.current()},Ae),()=>clearTimeout(W.current)},[A,u,D,d]);const n=r.useCallback(()=>{Y.current=!0,clearTimeout(W.current),Z(!1)},[]);if(N(t,"init",a=>{n(),Array.isArray(a==null?void 0:a.acceptsCredentials)&&(f(a.acceptsCredentials),E.current=!1,clearTimeout(e.current),e.current=void 0)}),N(t,"authorize",n),N(t,"login",n),N(t,"credential-request",()=>{n(),S(!0)}),r.useEffect(()=>{if(!H||!F)return;const a=p;if(Array.isArray(a)&&!a.includes(F.kind))return;const U=F.kind==="access_token"?{accessToken:F.accessToken}:{};T(t,"credential",{...U,credential:F},m),i(m,t,!0)},[H,F,p,t,T,m,i]),N(t,"ready",()=>{n(),z(a=>a+1)}),N(t,"heartbeat",()=>{E.current&&(e.current&&clearTimeout(e.current),e.current=setTimeout(()=>{o(a=>a+1)},6e3))}),r.useEffect(()=>()=>{e.current&&clearTimeout(e.current)},[]),O)return j?j(O):$.default.createElement(ke,{entry:O});if(_&&!M)return R?R():$.default.createElement(ve,null);const c={...B};return delete c.skipManifestCheck,$.default.createElement(Ue,{key:`auth-epoch-${D}-frame-${d}`,$isReady:M,ref:w,src:A,...c})};Ce.propTypes={id:k.default.string,src:k.default.string.isRequired,path:k.default.string,onInit:k.default.func,onTimeout:k.default.func,renderUnsupported:k.default.func,renderTimeout:k.default.func},h.CREDENTIAL_KIND_ACCESS_TOKEN=ie,h.EmbeddedAuthorizationContext=V,h.MMEmbeddableZone=Ce,h.MMEmbeddableZoneContext=J,h.MMEmbeddableZoneProvider=Ee,h.isCrossSite=se,h.normalizeCredential=ne,h.popupAuthorizationLauncher=de,h.unsupportedCopy=ge,h.useEmbeddedAuthorizations=fe,h.useEmbeddedCredential=be,h.useEmbeddedEffect=N,h.useEmbeddedOriginEpoch=pe,h.useEmbeddedUnsupported=he,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machinemetrics/mm-react-embeddable",
3
- "version": "2.0.2-0",
3
+ "version": "2.0.3-0",
4
4
  "license": "MIT",
5
5
  "module": "dist/mm-react-embeddable.es.js",
6
6
  "main": "dist/mm-react-embeddable.cjs.js",