@machinemetrics/mm-react-embeddable 2.0.3-3 → 2.0.3-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),Ue=require("prop-types"),Oe=require("styled-components"),de=e=>e&&e.__esModule?e:{default:e},z=de(t),R=de(Ue),Ee=de(Oe),ce=t.createContext(null),re=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),ke="access_token",ae=e=>e?e.kind?e:e.accessToken?{kind:ke,accessToken:e.accessToken,expiresAt:e.expiresAt||null}:null:null,ze=60,$e=120,De=3e4,Fe=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),ne=e=>{try{return new URL(e).origin}catch{return null}},me=(e,c)=>{const a=c==null?void 0:c.origin;return!a||ne(e==null?void 0:e.authUrl)!==a?null:a},Re=e=>{if(!e||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(e)||e.includes(":"))return e;const c=e.split(".");return c.length<=2?e:c.slice(-2).join(".")},le=(e,c)=>{try{const a=new URL(e),b=new URL(c);return a.protocol!==b.protocol?!0:Re(a.hostname)!==Re(b.hostname)}catch{return!0}},Ce=(e,{onBlocked:c,onClosed:a})=>{const b=window.open(e.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!b)return c(),()=>{};const E=setInterval(()=>{b.closed&&(clearInterval(E),a())},1e3);return()=>clearInterval(E)},we=({children:e,launcher:c,broker:a,ready:b})=>{const E=t.useContext(ce),[C,_]=t.useState({}),[P,Y]=t.useState({}),[W,T]=t.useState({}),[L,I]=t.useState({}),m=t.useRef(W);m.current=W;const q=t.useRef(C);q.current=C;const $=t.useRef(null),h=t.useRef({}),K=t.useRef({}),G=t.useRef(a);G.current=a;const S=t.useRef({}),Z=t.useRef({}),N=t.useCallback((r,s,n)=>{!r||!s||(S.current[r]||(S.current[r]=new Set),n?S.current[r].add(s):S.current[r].delete(s))},[]),v=t.useCallback(r=>{const s=h.current[r];if(!s)return;const n=o=>!o[r]||o[r].clientId?o:{...o,[r]:{...o[r],clientId:s}};_(n),I(n)},[]),i=t.useCallback((r,s)=>{r&&(I(n=>n[r]?n:{...n,[r]:{origin:r,reason:s,clientId:h.current[r]||null}}),v(r))},[v]),l=t.useCallback((r,{v2:s=!1,origin:n=null}={})=>{var o;if(n){if(s&&m.current[n]){if(!((o=S.current[n])!=null&&o.has(r.instanceId)))return;const p=Date.now();if(p-(Z.current[n]||0)<De)return;Z.current[n]=p,S.current[n].clear();const M={...m.current};delete M[n],m.current=M,T(M)}_(p=>p[n]?p:{...p,[n]:{origin:n,authUrl:r.authUrl,status:s&&G.current?"broker":"interactive",v2:s,scope:r.scope||null,acceptsCredentials:K.current[n]||null,consent:null,error:null,clientId:r.clientId||h.current[n]||null,popupBlocked:!1}}),v(n)}},[v]),u=t.useRef({}),f=t.useCallback(r=>{u.current[r]&&(clearTimeout(u.current[r]),delete u.current[r])},[]),d=t.useCallback(r=>{f(r),_(s=>{if(!s[r])return s;const n={...s};return delete n[r],n})},[f]),g=t.useCallback(r=>{r&&(d(r),Y(s=>({...s,[r]:(s[r]||0)+1})))},[d]),D=t.useCallback(r=>{d(r.origin)},[d]),x=t.useCallback((r,s)=>{const n=me(r,s);if(n){if(le(n,window.location.origin)){i(n,"cross-site-legacy");return}l(r,{origin:n})}},[l,i]);t.useEffect(()=>{if(!E)return;const r=[E.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(h.current[n.origin]=s.clientId,v(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?K.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&le(n.origin,window.location.origin)&&i(n.origin,"cross-site-legacy")}),E.addListener("*","authorize",x),E.addListener("*","login",x),E.addListener("*","credential-request",(s,n)=>l(s,{v2:!0,origin:me(s,n)}))];return()=>r.forEach(s=>s())},[E,x,l,v,i]),t.useEffect(()=>{const r=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const o=ne(n.authUrl);if(!o||s.origin!==o)return;const p=q.current[o];if(!(!p||p.status!=="interactive")){if(n.accessToken){T(M=>({...M,[o]:ae({accessToken:n.accessToken})})),d(o);return}g(o)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[d,g]);const U=t.useCallback((r,s)=>{const n=r==null?void 0:r.origin,o=ae(s);!n||!o||(T(p=>({...p,[n]:o})),d(n))},[d]),k=t.useCallback((r,s)=>{_(n=>n[r]?{...n,[r]:{...n[r],...s}}:n)},[]),A=t.useRef({}),O=t.useCallback(async(r,{approve:s}={})=>{const n=G.current,{origin:o}=r;let p;try{p=await n({origin:o,clientId:r.clientId,scope:r.scope,authUrl:r.authUrl},{approve:s})}catch{s?k(o,{error:{reason:"broker_unavailable"}}):k(o,{status:"interactive"});return}const M=p==null?void 0:p.status,y=(p==null?void 0:p.body)||{};if(M===200&&y.credential){U(r,y.credential);return}if(M===409&&y.consentRequired){k(o,{status:"interactive",consent:{client:y.client||null,stepUp:!!y.stepUp,scope:y.scope||r.scope},error:null});return}const j=y.error||"broker_error";if(!s&&Fe.has(j)){k(o,{status:"interactive"});return}if(s&&j==="consent_denied"){k(o,{error:null});return}if(j==="rate_limited"&&!r.rateLimitRetried){const B=Math.min(Number(y.retryAfter)>0?Number(y.retryAfter):ze,$e),ee={...r,rateLimitRetried:!0};f(o),u.current[o]=setTimeout(()=>{delete u.current[o],A.current[o]=!0,Q.current(ee,{approve:s}).finally(()=>{delete A.current[o]})},B*1e3),k(o,{rateLimitRetried:!0});return}d(o),I(B=>({...B,[o]:{origin:o,reason:`broker:${j}`,detail:{status:M!=null?M:null,reason:j},clientId:r.clientId||h.current[o]||null}}))},[U,k,d,f]),Q=t.useRef(O);Q.current=O,t.useEffect(()=>{Object.values(C).forEach(r=>{r.status!=="broker"||A.current[r.origin]||u.current[r.origin]||(A.current[r.origin]=!0,O(r).finally(()=>{delete A.current[r.origin]}))})},[C,O]);const F=t.useCallback(r=>!G.current||!(r!=null&&r.consent)||A.current[r.origin]?Promise.resolve():(A.current[r.origin]=!0,O(r,{approve:!0}).finally(()=>{delete A.current[r.origin]})),[O]);t.useEffect(()=>()=>{$.current&&$.current(),Object.values(u.current).forEach(clearTimeout)},[]),t.useEffect(()=>{b===!1&&(Object.values(u.current).forEach(clearTimeout),u.current={},A.current={},h.current={},K.current={},S.current={},Z.current={},m.current={},T({}),_({}),I({}))},[b]);const V=t.useCallback(r=>{$.current&&($.current(),$.current=null);const s=c||Ce;$.current=s(r,{onBlocked:()=>{_(n=>n[r.origin]?{...n,[r.origin]:{...n[r.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=q.current[r.origin];!n||n.v2||g(r.origin)}})},[c,g]),X={pending:Object.values(C).filter(r=>r.status==="interactive"),authorize:V,approve:F,complete:U,dismiss:D,originEpochs:P,credentials:W,unsupported:L,setDelivered:N};return z.default.createElement(re.Provider,{value:X},e)};we.propTypes={children:R.default.node,launcher:R.default.func,ready:R.default.bool,broker:R.default.func};const _e=()=>t.useContext(re),Te=e=>{const{originEpochs:c}=t.useContext(re),a=ne(e);return a&&c[a]||0},Ie=e=>{const{credentials:c}=t.useContext(re),a=ne(e);return a&&c[a]||null},Ae=e=>{const{unsupported:c}=t.useContext(re),a=ne(e);return a&&c[a]||null},ge="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.",Me=({children:e,authorizationLauncher:c,credentialBroker:a,ready:b})=>{const E=b===!0,C=t.useRef(!1);t.useEffect(()=>{b!==void 0||C.current||(C.current=!0,console.error(ge),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ge))},[b]);const[_,P]=t.useState({}),[Y,W]=t.useState({}),T=t.useRef({}),L=t.useRef({}),I=t.useRef({}),m=t.useCallback((i,l)=>{var u;return!!((u=I.current[i])!=null&&u.has(l))},[]),q=t.useCallback((i,l,u)=>{P(f=>({...f,[i]:{origin:l,frameRef:u}}))},[]),$=t.useCallback(i=>{P(l=>{const u={...l};return delete u[i],u}),W(l=>{const u={...l};return delete u[i],u}),delete I.current[i],Object.keys(L.current).forEach(l=>{L.current[l].instanceId===i&&delete L.current[l]})},[]);t.useEffect(()=>()=>{L.current={}},[]),t.useEffect(()=>{const i=(u=[],f,d)=>{u.forEach(g=>g(f,d))},l=u=>{var k,A,O,Q,F,V,X;if(!((k=u==null?void 0:u.data)!=null&&k.instanceId))return;const{instanceId:f,type:d}=u.data,g=_[f],D=(O=(A=g==null?void 0:g.frameRef)==null?void 0:A.current)==null?void 0:O.contentWindow;if(!D||u.source!==D||u.origin!==g.origin)return;const x={origin:u.origin},U=T.current;if(d==="response"){const{callbackId:r,response:s,error:n}=u.data,o=L.current[r];o&&o.instanceId===f&&(o.callback(s,n),delete L.current[r]);return}if(d==="mark-registered"){const{requestType:r}=u.data;I.current[f]||(I.current[f]=new Set),I.current[f].add(r);return}d==="ready"&&W(r=>({...r,[f]:!0})),i((Q=U[f])==null?void 0:Q[d],u.data,x),i((F=U["*"])==null?void 0:F[d],u.data,x),i((V=U[f])==null?void 0:V["*"],u.data,x),i((X=U["*"])==null?void 0:X["*"],u.data,x)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[_]);const h=t.useCallback((i,l,u,f)=>{var g,D;const d=_[i];if(!d){console.warn(`Origin not set for id: ${i}. Unable to send message.`);return}(D=(g=d==null?void 0:d.frameRef)==null?void 0:g.current)!=null&&D.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:l,...u,instanceId:i},f||d.origin)},[_]),K=t.useRef(0),G=t.useCallback(()=>`${Date.now()}-${++K.current}`,[]),S=t.useCallback(async(i,l,u={})=>new Promise((f,d)=>{const g=G(),D=(x,U)=>{delete L.current[g],U?d(U):f(x)};L.current[g]={instanceId:i,callback:D},h(i,"request",{callbackId:g,requestType:l,data:u})}),[h]),Z=t.useCallback((i,l)=>{h(i,"load-options",l)},[h]),N=t.useCallback((i,l)=>{h(i,"validate",l)},[h]),v=t.useMemo(()=>({registerFrame:q,unregisterFrame:$,sendMessage:h,sendRequest:S,loadOptions:Z,validate:N,hasHandler:m,readyFrames:Y,ready:E,addListener:(i,l,u)=>(T.current[i]||(T.current[i]={}),T.current[i][l]||(T.current[i][l]=[]),T.current[i][l].push(u),()=>{T.current[i][l]=T.current[i][l].filter(f=>f!==u)})}),[q,$,h,S,Z,N,m,Y,E]);return z.default.createElement(ce.Provider,{value:v},z.default.createElement(we,{launcher:c,broker:a,ready:E},e))},J=(e,c,a)=>{const b=t.useContext(ce);if(b===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const E=t.useRef(a);t.useEffect(()=>{E.current=a},[a]),t.useEffect(()=>{if(!(!e||!c)){if(c.startsWith("key:")){const C=c.substring(4);return b.readyFrames[e]&&b.sendMessage(e,"subscribe-key",{keyChord:C}),b.addListener(e,`key-pressed:${C}`,(...P)=>E.current(...P))}return b.addListener(e,c,(...C)=>E.current(...C))}},[b,e,c])};Me.propTypes={children:R.default.node.isRequired,ready:R.default.bool.isRequired,authorizationLauncher:R.default.func,credentialBroker:R.default.func};const fe=Ee.default.default||Ee.default,Pe=1e4,qe=6e3,Be=5e3,We=2e4,Ze=3e3,Se=()=>typeof document!="undefined"&&document.visibilityState==="hidden",te=(e,c,a)=>{if(e.current&&clearTimeout(e.current.handle),Se()){e.current={ms:c,fn:a,suspended:!0};return}const b=Date.now(),E=setTimeout(()=>{if(Date.now()-b-c>Ze){te(e,c,a);return}e.current=void 0,a()},c);e.current={handle:E,ms:c,fn:a}},H=e=>{e.current&&clearTimeout(e.current.handle),e.current=void 0},oe=e=>{e.current&&!e.current.suspended&&(clearTimeout(e.current.handle),e.current={ms:e.current.ms,fn:e.current.fn,suspended:!0})},ie=e=>{e.current&&e.current.suspended&&te(e,e.current.ms,e.current.fn)},je="credentials",He=(e,c)=>`${e}/mm-embedded-interop?id=${encodeURIComponent(c)}&origin=${encodeURIComponent(window.location.origin)}&caps=${je}`,Ke=fe.iframe`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),Oe=require("prop-types"),ze=require("styled-components"),fe=e=>e&&e.__esModule?e:{default:e},z=fe(t),R=fe(Oe),me=fe(ze),ce=t.createContext(null),re=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),Ce="access_token",le=e=>e?e.kind?e:e.accessToken?{kind:Ce,accessToken:e.accessToken,expiresAt:e.expiresAt||null}:null:null,$e=60,De=120,Fe=3e4,Pe=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),ne=e=>{try{return new URL(e).origin}catch{return null}},Re=(e,c)=>{const a=c==null?void 0:c.origin;return!a||ne(e==null?void 0:e.authUrl)!==a?null:a},ge=e=>{if(!e||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(e)||e.includes(":"))return e;const c=e.split(".");return c.length<=2?e:c.slice(-2).join(".")},de=(e,c)=>{try{const a=new URL(e),b=new URL(c);return a.protocol!==b.protocol?!0:ge(a.hostname)!==ge(b.hostname)}catch{return!0}},we=(e,{onBlocked:c,onClosed:a})=>{const b=window.open(e.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!b)return c(),()=>{};const E=setInterval(()=>{b.closed&&(clearInterval(E),a())},1e3);return()=>clearInterval(E)},_e=({children:e,launcher:c,broker:a,ready:b})=>{const E=t.useContext(ce),[C,_]=t.useState({}),[P,Y]=t.useState({}),[W,T]=t.useState({}),[y,I]=t.useState({}),m=t.useRef(W);m.current=W;const q=t.useRef(C);q.current=C;const $=t.useRef(null),h=t.useRef({}),H=t.useRef({}),K=t.useRef(a);K.current=a;const S=t.useRef({}),Z=t.useRef({}),N=t.useCallback((r,s,n)=>{!r||!s||(S.current[r]||(S.current[r]=new Set),n?S.current[r].add(s):S.current[r].delete(s))},[]),L=t.useCallback(r=>{const s=h.current[r];if(!s)return;const n=o=>!o[r]||o[r].clientId?o:{...o,[r]:{...o[r],clientId:s}};_(n),I(n)},[]),i=t.useCallback((r,s)=>{r&&(I(n=>n[r]?n:{...n,[r]:{origin:r,reason:s,clientId:h.current[r]||null}}),L(r))},[L]),l=t.useCallback((r,{v2:s=!1,origin:n=null}={})=>{var o;if(n){if(s&&m.current[n]){if(!((o=S.current[n])!=null&&o.has(r.instanceId)))return;const p=Date.now();if(p-(Z.current[n]||0)<Fe)return;Z.current[n]=p,S.current[n].clear();const M={...m.current};delete M[n],m.current=M,T(M)}_(p=>p[n]?p:{...p,[n]:{origin:n,authUrl:r.authUrl,status:s&&K.current?"broker":"interactive",v2:s,scope:r.scope||null,acceptsCredentials:H.current[n]||null,consent:null,error:null,clientId:r.clientId||h.current[n]||null,popupBlocked:!1}}),L(n)}},[L]),u=t.useRef({}),f=t.useCallback(r=>{u.current[r]&&(clearTimeout(u.current[r]),delete u.current[r])},[]),d=t.useCallback(r=>{f(r),_(s=>{if(!s[r])return s;const n={...s};return delete n[r],n})},[f]),g=t.useCallback(r=>{r&&(d(r),Y(s=>({...s,[r]:(s[r]||0)+1})))},[d]),D=t.useCallback(r=>{d(r.origin)},[d]),v=t.useCallback((r,s)=>{const n=Re(r,s);if(n){if(de(n,window.location.origin)){i(n,"cross-site-legacy");return}l(r,{origin:n})}},[l,i]);t.useEffect(()=>{if(!E)return;const r=[E.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(h.current[n.origin]=s.clientId,L(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?H.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&de(n.origin,window.location.origin)&&i(n.origin,"cross-site-legacy")}),E.addListener("*","authorize",v),E.addListener("*","login",v),E.addListener("*","credential-request",(s,n)=>l(s,{v2:!0,origin:Re(s,n)}))];return()=>r.forEach(s=>s())},[E,v,l,L,i]),t.useEffect(()=>{const r=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const o=ne(n.authUrl);if(!o||s.origin!==o)return;const p=q.current[o];if(!(!p||p.status!=="interactive")){if(n.accessToken){T(M=>({...M,[o]:le({accessToken:n.accessToken})})),d(o);return}g(o)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[d,g]);const x=t.useCallback((r,s)=>{const n=r==null?void 0:r.origin,o=le(s);!n||!o||(T(p=>({...p,[n]:o})),d(n))},[d]),k=t.useCallback((r,s)=>{_(n=>n[r]?{...n,[r]:{...n[r],...s}}:n)},[]),A=t.useRef({}),U=t.useCallback(async(r,{approve:s}={})=>{const n=K.current,{origin:o}=r;let p;try{p=await n({origin:o,clientId:r.clientId,scope:r.scope,authUrl:r.authUrl},{approve:s})}catch{s?k(o,{error:{reason:"broker_unavailable"}}):k(o,{status:"interactive"});return}const M=p==null?void 0:p.status,O=(p==null?void 0:p.body)||{};if(M===200&&O.credential){x(r,O.credential);return}if(M===409&&O.consentRequired){k(o,{status:"interactive",consent:{client:O.client||null,stepUp:!!O.stepUp,scope:O.scope||r.scope},error:null});return}const B=O.error||"broker_error";if(!s&&Pe.has(B)){k(o,{status:"interactive"});return}if(s&&B==="consent_denied"){k(o,{error:null});return}if(B==="rate_limited"&&!r.rateLimitRetried){const V=Math.min(Number(O.retryAfter)>0?Number(O.retryAfter):$e,De),J={...r,rateLimitRetried:!0};f(o),u.current[o]=setTimeout(()=>{delete u.current[o],A.current[o]=!0,Q.current(J,{approve:s}).finally(()=>{delete A.current[o]})},V*1e3),k(o,{rateLimitRetried:!0});return}d(o),I(V=>({...V,[o]:{origin:o,reason:`broker:${B}`,detail:{status:M!=null?M:null,reason:B},clientId:r.clientId||h.current[o]||null}}))},[x,k,d,f]),Q=t.useRef(U);Q.current=U,t.useEffect(()=>{Object.values(C).forEach(r=>{r.status!=="broker"||A.current[r.origin]||u.current[r.origin]||(A.current[r.origin]=!0,U(r).finally(()=>{delete A.current[r.origin]}))})},[C,U]);const F=t.useCallback(r=>!K.current||!(r!=null&&r.consent)||A.current[r.origin]?Promise.resolve():(A.current[r.origin]=!0,U(r,{approve:!0}).finally(()=>{delete A.current[r.origin]})),[U]);t.useEffect(()=>()=>{$.current&&$.current(),Object.values(u.current).forEach(clearTimeout)},[]),t.useEffect(()=>{b===!1&&(Object.values(u.current).forEach(clearTimeout),u.current={},A.current={},h.current={},H.current={},S.current={},Z.current={},m.current={},T({}),_({}),I({}))},[b]);const G=t.useCallback(r=>{$.current&&($.current(),$.current=null);const s=c||we;$.current=s(r,{onBlocked:()=>{_(n=>n[r.origin]?{...n,[r.origin]:{...n[r.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=q.current[r.origin];!n||n.v2||g(r.origin)}})},[c,g]),X={pending:Object.values(C).filter(r=>r.status==="interactive"),authorize:G,approve:F,complete:x,dismiss:D,originEpochs:P,credentials:W,unsupported:y,setDelivered:N};return z.default.createElement(re.Provider,{value:X},e)};_e.propTypes={children:R.default.node,launcher:R.default.func,ready:R.default.bool,broker:R.default.func};const Te=()=>t.useContext(re),Ie=e=>{const{originEpochs:c}=t.useContext(re),a=ne(e);return a&&c[a]||0},Ae=e=>{const{credentials:c}=t.useContext(re),a=ne(e);return a&&c[a]||null},Me=e=>{const{unsupported:c}=t.useContext(re),a=ne(e);return a&&c[a]||null},ke="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.",Se=({children:e,authorizationLauncher:c,credentialBroker:a,ready:b})=>{const E=b===!0,C=t.useRef(!1);t.useEffect(()=>{b!==void 0||C.current||(C.current=!0,console.error(ke),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ke))},[b]);const[_,P]=t.useState({}),[Y,W]=t.useState({}),T=t.useRef({}),y=t.useRef({}),I=t.useRef({}),m=t.useCallback((i,l)=>{var u;return!!((u=I.current[i])!=null&&u.has(l))},[]),q=t.useCallback((i,l,u)=>{P(f=>({...f,[i]:{origin:l,frameRef:u}}))},[]),$=t.useCallback(i=>{P(l=>{const u={...l};return delete u[i],u}),W(l=>{const u={...l};return delete u[i],u}),delete I.current[i],Object.keys(y.current).forEach(l=>{y.current[l].instanceId===i&&delete y.current[l]})},[]);t.useEffect(()=>()=>{y.current={}},[]),t.useEffect(()=>{const i=(u=[],f,d)=>{u.forEach(g=>g(f,d))},l=u=>{var k,A,U,Q,F,G,X;if(!((k=u==null?void 0:u.data)!=null&&k.instanceId))return;const{instanceId:f,type:d}=u.data,g=_[f],D=(U=(A=g==null?void 0:g.frameRef)==null?void 0:A.current)==null?void 0:U.contentWindow;if(!D||u.source!==D||u.origin!==g.origin)return;const v={origin:u.origin},x=T.current;if(d==="response"){const{callbackId:r,response:s,error:n}=u.data,o=y.current[r];o&&o.instanceId===f&&(o.callback(s,n),delete y.current[r]);return}if(d==="mark-registered"){const{requestType:r}=u.data;I.current[f]||(I.current[f]=new Set),I.current[f].add(r);return}d==="ready"&&W(r=>({...r,[f]:!0})),i((Q=x[f])==null?void 0:Q[d],u.data,v),i((F=x["*"])==null?void 0:F[d],u.data,v),i((G=x[f])==null?void 0:G["*"],u.data,v),i((X=x["*"])==null?void 0:X["*"],u.data,v)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[_]);const h=t.useCallback((i,l,u,f)=>{var g,D;const d=_[i];if(!d){console.warn(`Origin not set for id: ${i}. Unable to send message.`);return}(D=(g=d==null?void 0:d.frameRef)==null?void 0:g.current)!=null&&D.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:l,...u,instanceId:i},f||d.origin)},[_]),H=t.useRef(0),K=t.useCallback(()=>`${Date.now()}-${++H.current}`,[]),S=t.useCallback(async(i,l,u={})=>new Promise((f,d)=>{const g=K(),D=(v,x)=>{delete y.current[g],x?d(x):f(v)};y.current[g]={instanceId:i,callback:D},h(i,"request",{callbackId:g,requestType:l,data:u})}),[h]),Z=t.useCallback((i,l)=>{h(i,"load-options",l)},[h]),N=t.useCallback((i,l)=>{h(i,"validate",l)},[h]),L=t.useMemo(()=>({registerFrame:q,unregisterFrame:$,sendMessage:h,sendRequest:S,loadOptions:Z,validate:N,hasHandler:m,readyFrames:Y,ready:E,addListener:(i,l,u)=>(T.current[i]||(T.current[i]={}),T.current[i][l]||(T.current[i][l]=[]),T.current[i][l].push(u),()=>{T.current[i][l]=T.current[i][l].filter(f=>f!==u)})}),[q,$,h,S,Z,N,m,Y,E]);return z.default.createElement(ce.Provider,{value:L},z.default.createElement(_e,{launcher:c,broker:a,ready:E},e))},ee=(e,c,a)=>{const b=t.useContext(ce);if(b===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const E=t.useRef(a);t.useEffect(()=>{E.current=a},[a]),t.useEffect(()=>{if(!(!e||!c)){if(c.startsWith("key:")){const C=c.substring(4);return b.readyFrames[e]&&b.sendMessage(e,"subscribe-key",{keyChord:C}),b.addListener(e,`key-pressed:${C}`,(...P)=>E.current(...P))}return b.addListener(e,c,(...C)=>E.current(...C))}},[b,e,c])};Se.propTypes={children:R.default.node.isRequired,ready:R.default.bool.isRequired,authorizationLauncher:R.default.func,credentialBroker:R.default.func};const pe=me.default.default||me.default,qe=1e4,Be=6e3,We=5e3,Ze=2e4,je=3e3,ye=()=>typeof document!="undefined"&&document.visibilityState==="hidden",te=(e,c,a)=>{if(e.current&&clearTimeout(e.current.handle),ye()){e.current={ms:c,fn:a,suspended:!0};return}const b=Date.now(),E=setTimeout(()=>{if(Date.now()-b-c>je){te(e,c,a);return}e.current=void 0,a()},c);e.current={handle:E,ms:c,fn:a}},j=e=>{e.current&&clearTimeout(e.current.handle),e.current=void 0},ie=e=>{e.current&&!e.current.suspended&&(clearTimeout(e.current.handle),e.current={ms:e.current.ms,fn:e.current.fn,suspended:!0})},ae=e=>{e.current&&e.current.suspended&&te(e,e.current.ms,e.current.fn)},He="credentials",Ke=(e,c)=>`${e}/mm-embedded-interop?id=${encodeURIComponent(c)}&origin=${encodeURIComponent(window.location.origin)}&caps=${He}`,Ge=pe.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
5
5
  visibility: ${e=>e.$isReady?"visible":"hidden"};
6
6
  ${e=>e.$collapsed?"position: absolute; width: 1px; height: 1px; overflow: hidden;":""}
7
- `,Ge=fe.div`
7
+ `,Ve=pe.div`
8
8
  width: 100%;
9
9
  height: 100%;
10
10
  display: flex;
@@ -17,10 +17,10 @@
17
17
  text-align: center;
18
18
  color: #555;
19
19
  font-size: 14px;
20
- `,ye=e=>{const c=e&&e.origin||"This app",a=e&&e.reason||"";switch(a){case"broker:scope_above_ceiling":return{title:`${c} 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:`${c} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${c} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return a.startsWith("broker:")?{title:`${c} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${c} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},Le=({entry:e})=>{const c=ye(e);return z.default.createElement(Ge,{"data-reason":e&&e.reason||void 0},z.default.createElement("div",{style:{fontWeight:600}},c.title),z.default.createElement("div",{style:{fontSize:12,color:"#888"}},c.detail))};Le.propTypes={entry:R.default.shape({origin:R.default.string,name:R.default.string,reason:R.default.string,detail:R.default.object})};const Ve=fe.div`
20
+ `,Le=e=>{const c=e&&e.origin||"This app",a=e&&e.reason||"";switch(a){case"broker:scope_above_ceiling":return{title:`${c} 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:`${c} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${c} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return a.startsWith("broker:")?{title:`${c} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${c} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},ve=({entry:e})=>{const c=Le(e);return z.default.createElement(Ve,{"data-reason":e&&e.reason||void 0},z.default.createElement("div",{style:{fontWeight:600}},c.title),z.default.createElement("div",{style:{fontSize:12,color:"#888"}},c.detail))};ve.propTypes={entry:R.default.shape({origin:R.default.string,name:R.default.string,reason:R.default.string,detail:R.default.object})};const Ye=pe.div`
21
21
  height: 100%;
22
22
  display: flex;
23
23
  flex: 1;
24
24
  align-items: center;
25
25
  justify-content: center;
26
- `,Ye=()=>z.default.createElement(Ve,null,z.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),ve=({id:e,src:c,path:a,onInit:b=()=>{},onTimeout:E,onRemount:C,onStall:_,context:P={},params:Y={},renderUnsupported:W,renderTimeout:T,...L})=>{if("isConfiguring"in L)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in P)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in P)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const I=t.useRef(),m=ne(c),[q,$]=t.useState(),[h,K]=t.useState(0),[G,S]=t.useState(!1),[Z,N]=t.useState(!1),v=Te(c),i=Ie(c),l=Ae(c),{setDelivered:u}=_e(),[f,d]=t.useState(0),[g,D]=t.useState(null),{registerFrame:x,unregisterFrame:U,sendMessage:k,ready:A}=t.useContext(ce),[O,Q]=t.useState(),F=t.useRef(),V=t.useRef(E),X=t.useRef(b),r=t.useRef(C),s=t.useRef(_),n=t.useRef(!1),o=t.useRef(),p=t.useRef(),M=t.useRef(!1),y=t.useRef(!1),j=t.useRef(null),B=t.useCallback(()=>{n.current=!1,M.current=!1,y.current=!1,j.current=null,H(F),H(o),H(p),K(0),S(!1),N(!1),D(null),u(m,e,!1)},[u,m,e]);t.useEffect(()=>{(v>0||f>0)&&B()},[v,f,B]),t.useEffect(()=>{V.current=E},[E]),t.useEffect(()=>{X.current=b},[b]),t.useEffect(()=>{r.current=C},[C]),t.useEffect(()=>{s.current=_},[_]),t.useEffect(()=>{const w=()=>{if(Se()){oe(F),oe(o),oe(p);return}ie(F),ie(p),M.current&&ie(o)};return document.addEventListener("visibilitychange",w),()=>document.removeEventListener("visibilitychange",w)},[]),t.useEffect(()=>{h&&k(e,"set-context",{context:{...P}},m)},[P,e,h,m]),t.useEffect(()=>{h&&k(e,"set-params",{params:Y},m)},[Y,e,h,m]),t.useEffect(()=>{a!==void 0&&Q((a==null?void 0:a.indexOf("/"))===0?a:`/${a}`)},[a]),t.useEffect(()=>{O===void 0||!h||k(e,"navigate",{path:O},m)},[O,h,e,k,m]),t.useEffect(()=>{if(!c||!e||!I)return;if(!A){B(),$(void 0);return}B();const w=new URL(c);return x(e,w.origin,I),X.current(),$(He(w.origin,e)),()=>{U(e)}},[c,e,A,x,I,B]);const ee=t.useCallback(()=>{S(!0),V.current&&V.current()},[]);t.useEffect(()=>{if(!(!q||n.current))return te(F,Pe,ee),()=>H(F)},[q,c,v,f,ee]);const se=t.useCallback(()=>{n.current=!0,H(F),S(!1)},[]),ue=t.useCallback(()=>{if(!y.current){y.current=!0,k(e,"credential",j.current,m),s.current&&s.current("redelivered"),te(p,We,ue);return}s.current&&s.current("ready"),ee()},[e,k,m,ee]);J(e,"init",w=>{se(),Array.isArray(w==null?void 0:w.acceptsCredentials)&&D(w.acceptsCredentials)}),J(e,"authorize",se),J(e,"login",se),J(e,"credential-request",()=>{se(),N(!0)}),t.useEffect(()=>{if(!Z||!i)return;const w=g;if(Array.isArray(w)&&!w.includes(i.kind))return;const he={...i.kind==="access_token"?{accessToken:i.accessToken}:{},credential:i};j.current=he,y.current=!1,k(e,"credential",he,m),u(m,e,!0),te(p,Be,ue)},[ue,Z,i,g,e,k,m,u]),J(e,"ready",()=>{se(),H(p),K(w=>w+1)});const xe=t.useCallback(()=>{r.current&&r.current("heartbeat"),d(w=>w+1)},[]);if(J(e,"heartbeat",()=>{M.current=!0,te(o,qe,xe)}),t.useEffect(()=>()=>{H(o),H(p),H(F)},[]),l)return W?W(l):z.default.createElement(Le,{entry:l});const pe=!!(G&&!h),be={...L};return delete be.skipManifestCheck,z.default.createElement(z.default.Fragment,null,pe&&(T?T():z.default.createElement(Ye,null)),z.default.createElement(Ke,{key:`auth-epoch-${v}-frame-${f}`,$isReady:h,$collapsed:pe,ref:I,src:q,...be}))};ve.propTypes={id:R.default.string,src:R.default.string.isRequired,path:R.default.string,onInit:R.default.func,onTimeout:R.default.func,onRemount:R.default.func,onStall:R.default.func,renderUnsupported:R.default.func,renderTimeout:R.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=ke;exports.EmbeddedAuthorizationContext=re;exports.MMEmbeddableZone=ve;exports.MMEmbeddableZoneContext=ce;exports.MMEmbeddableZoneProvider=Me;exports.isCrossSite=le;exports.normalizeCredential=ae;exports.popupAuthorizationLauncher=Ce;exports.unsupportedCopy=ye;exports.useEmbeddedAuthorizations=_e;exports.useEmbeddedCredential=Ie;exports.useEmbeddedEffect=J;exports.useEmbeddedOriginEpoch=Te;exports.useEmbeddedUnsupported=Ae;
26
+ `,Ne=()=>z.default.createElement(Ye,null,z.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),xe=({id:e,src:c,path:a,onInit:b=()=>{},onTimeout:E,onRemount:C,onStall:_,context:P={},params:Y={},renderUnsupported:W,renderTimeout:T,...y})=>{if("isConfiguring"in y)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in P)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in P)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const I=t.useRef(),m=ne(c),[q,$]=t.useState(),[h,H]=t.useState(0),[K,S]=t.useState(!1),[Z,N]=t.useState(!1),L=Ie(c),i=Ae(c),l=Me(c),{setDelivered:u}=Te(),[f,d]=t.useState(0),[g,D]=t.useState(null),{registerFrame:v,unregisterFrame:x,sendMessage:k,ready:A}=t.useContext(ce),[U,Q]=t.useState(),F=t.useRef(),G=t.useRef(E),X=t.useRef(b),r=t.useRef(C),s=t.useRef(_),n=t.useRef(!1),o=t.useRef(),p=t.useRef(),M=t.useRef(!1),O=t.useRef(!1),B=t.useRef(!1),V=t.useRef(null),J=t.useCallback(()=>{n.current=!1,M.current=!1,O.current=!1,B.current=!1,V.current=null,j(F),j(o),j(p),H(0),S(!1),N(!1),D(null),u(m,e,!1)},[u,m,e]);t.useEffect(()=>{(L>0||f>0)&&J()},[L,f,J]),t.useEffect(()=>{G.current=E},[E]),t.useEffect(()=>{X.current=b},[b]),t.useEffect(()=>{r.current=C},[C]),t.useEffect(()=>{s.current=_},[_]),t.useEffect(()=>{const w=()=>{if(ye()){ie(F),ie(o),ie(p);return}ae(F),ae(p),M.current&&ae(o)};return document.addEventListener("visibilitychange",w),()=>document.removeEventListener("visibilitychange",w)},[]),t.useEffect(()=>{h&&k(e,"set-context",{context:{...P}},m)},[P,e,h,m]),t.useEffect(()=>{h&&k(e,"set-params",{params:Y},m)},[Y,e,h,m]),t.useEffect(()=>{a!==void 0&&Q((a==null?void 0:a.indexOf("/"))===0?a:`/${a}`)},[a]),t.useEffect(()=>{U===void 0||!h||k(e,"navigate",{path:U},m)},[U,h,e,k,m]),t.useEffect(()=>{if(!c||!e||!I)return;if(!A){J(),$(void 0);return}J();const w=new URL(c);return v(e,w.origin,I),X.current(),$(Ke(w.origin,e)),()=>{x(e)}},[c,e,A,v,I,J]);const ue=t.useCallback(()=>{S(!0),G.current&&G.current()},[]);t.useEffect(()=>{if(!(!q||n.current))return te(F,qe,ue),()=>j(F)},[q,c,L,f,ue]);const se=t.useCallback(()=>{n.current=!0,j(F),S(!1)},[]),oe=t.useCallback(()=>{if(!B.current){B.current=!0,k(e,"credential",V.current,m),s.current&&s.current("redelivered"),te(p,Ze,oe);return}s.current&&s.current("ready"),ue()},[e,k,m,ue]);ee(e,"init",w=>{se(),Array.isArray(w==null?void 0:w.acceptsCredentials)&&D(w.acceptsCredentials)}),ee(e,"authorize",se),ee(e,"login",se),ee(e,"credential-request",()=>{se(),N(!0)}),t.useEffect(()=>{if(!Z||!i||O.current)return;const w=g;if(Array.isArray(w)&&!w.includes(i.kind))return;const Ee={...i.kind==="access_token"?{accessToken:i.accessToken}:{},credential:i};V.current=Ee,B.current=!1,k(e,"credential",Ee,m),u(m,e,!0),te(p,We,oe)},[oe,Z,i,g,e,k,m,u]),ee(e,"ready",()=>{se(),j(p),O.current=!0,H(w=>w+1)});const Ue=t.useCallback(()=>{r.current&&r.current("heartbeat"),d(w=>w+1)},[]);if(ee(e,"heartbeat",()=>{M.current=!0,te(o,Be,Ue)}),t.useEffect(()=>()=>{j(o),j(p),j(F)},[]),l)return W?W(l):z.default.createElement(ve,{entry:l});const be=!!(K&&!h),he={...y};return delete he.skipManifestCheck,z.default.createElement(z.default.Fragment,null,be&&(T?T():z.default.createElement(Ne,null)),z.default.createElement(Ge,{key:`auth-epoch-${L}-frame-${f}`,$isReady:h,$collapsed:be,ref:I,src:q,...he}))};xe.propTypes={id:R.default.string,src:R.default.string.isRequired,path:R.default.string,onInit:R.default.func,onTimeout:R.default.func,onRemount:R.default.func,onStall:R.default.func,renderUnsupported:R.default.func,renderTimeout:R.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=Ce;exports.EmbeddedAuthorizationContext=re;exports.MMEmbeddableZone=xe;exports.MMEmbeddableZoneContext=ce;exports.MMEmbeddableZoneProvider=Se;exports.isCrossSite=de;exports.normalizeCredential=le;exports.popupAuthorizationLauncher=we;exports.unsupportedCopy=Le;exports.useEmbeddedAuthorizations=Te;exports.useEmbeddedCredential=Ae;exports.useEmbeddedEffect=ee;exports.useEmbeddedOriginEpoch=Ie;exports.useEmbeddedUnsupported=Me;
@@ -1,7 +1,7 @@
1
- import D, { createContext as Ie, useContext as te, useState as F, useRef as d, useCallback as h, useEffect as g, useMemo as Me } from "react";
1
+ import D, { createContext as _e, useContext as ne, useState as F, useRef as l, useCallback as h, useEffect as g, useMemo as Ce } from "react";
2
2
  import w from "prop-types";
3
- import ge from "styled-components";
4
- const ae = Ie(null), ue = Ie({
3
+ import Re from "styled-components";
4
+ const le = _e(null), ue = _e({
5
5
  pending: [],
6
6
  authorize: () => {
7
7
  },
@@ -16,11 +16,11 @@ const ae = Ie(null), ue = Ie({
16
16
  unsupported: {},
17
17
  setDelivered: () => {
18
18
  }
19
- }), Ce = "access_token", Ee = (e) => e ? e.kind ? e : e.accessToken ? {
20
- kind: Ce,
19
+ }), ve = "access_token", Ee = (e) => e ? e.kind ? e : e.accessToken ? {
20
+ kind: ve,
21
21
  accessToken: e.accessToken,
22
22
  expiresAt: e.expiresAt || null
23
- } : null : null, ve = 60, Se = 120, Ue = 3e4, xe = /* @__PURE__ */ new Set([
23
+ } : null : null, Se = 60, Ue = 120, xe = 3e4, Oe = /* @__PURE__ */ new Set([
24
24
  "host_not_allowed",
25
25
  "unbound_host_bound_guest",
26
26
  "invalid_token",
@@ -31,22 +31,22 @@ const ae = Ie(null), ue = Ie({
31
31
  } catch {
32
32
  return null;
33
33
  }
34
- }, Re = (e, s) => {
34
+ }, we = (e, s) => {
35
35
  const u = s == null ? void 0 : s.origin;
36
36
  return !u || oe(e == null ? void 0 : e.authUrl) !== u ? null : u;
37
- }, we = (e) => {
37
+ }, ke = (e) => {
38
38
  if (!e || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(e) || e.includes(":"))
39
39
  return e;
40
40
  const s = e.split(".");
41
41
  return s.length <= 2 ? e : s.slice(-2).join(".");
42
- }, ke = (e, s) => {
42
+ }, Te = (e, s) => {
43
43
  try {
44
44
  const u = new URL(e), m = new URL(s);
45
- return u.protocol !== m.protocol ? !0 : we(u.hostname) !== we(m.hostname);
45
+ return u.protocol !== m.protocol ? !0 : ke(u.hostname) !== ke(m.hostname);
46
46
  } catch {
47
47
  return !0;
48
48
  }
49
- }, Oe = (e, { onBlocked: s, onClosed: u }) => {
49
+ }, $e = (e, { onBlocked: s, onClosed: u }) => {
50
50
  const m = window.open(
51
51
  e.authUrl,
52
52
  "mm-embed-auth",
@@ -55,20 +55,20 @@ const ae = Ie(null), ue = Ie({
55
55
  if (!m)
56
56
  return s(), () => {
57
57
  };
58
- const E = setInterval(() => {
59
- m.closed && (clearInterval(E), u());
58
+ const R = setInterval(() => {
59
+ m.closed && (clearInterval(R), u());
60
60
  }, 1e3);
61
- return () => clearInterval(E);
62
- }, _e = ({ children: e, launcher: s, broker: u, ready: m }) => {
63
- const E = te(ae), [I, A] = F({}), [q, J] = F({}), [Z, L] = F({}), [U, y] = F({}), R = d(Z);
64
- R.current = Z;
65
- const j = d(I);
61
+ return () => clearInterval(R);
62
+ }, Ae = ({ children: e, launcher: s, broker: u, ready: m }) => {
63
+ const R = ne(le), [I, A] = F({}), [q, J] = F({}), [Z, L] = F({}), [S, y] = F({}), E = l(Z);
64
+ E.current = Z;
65
+ const j = l(I);
66
66
  j.current = I;
67
- const P = d(null), b = d({}), Y = d({}), Q = d(u);
68
- Q.current = u;
69
- const v = d({}), K = d({}), N = h((r, n, t) => {
67
+ const P = l(null), b = l({}), V = l({}), Y = l(u);
68
+ Y.current = u;
69
+ const v = l({}), K = l({}), N = h((r, n, t) => {
70
70
  !r || !n || (v.current[r] || (v.current[r] = /* @__PURE__ */ new Set()), t ? v.current[r].add(n) : v.current[r].delete(n));
71
- }, []), x = h((r) => {
71
+ }, []), U = h((r) => {
72
72
  const n = b.current[r];
73
73
  if (!n)
74
74
  return;
@@ -83,44 +83,44 @@ const ae = Ie(null), ue = Ie({
83
83
  reason: n,
84
84
  clientId: b.current[r] || null
85
85
  }
86
- }), x(r));
86
+ }), U(r));
87
87
  },
88
- [x]
88
+ [U]
89
89
  ), a = h(
90
90
  (r, { v2: n = !1, origin: t = null } = {}) => {
91
91
  var o;
92
92
  if (t) {
93
- if (n && R.current[t]) {
93
+ if (n && E.current[t]) {
94
94
  if (!((o = v.current[t]) != null && o.has(r.instanceId)))
95
95
  return;
96
96
  const p = Date.now();
97
- if (p - (K.current[t] || 0) < Ue)
97
+ if (p - (K.current[t] || 0) < xe)
98
98
  return;
99
99
  K.current[t] = p, v.current[t].clear();
100
- const C = { ...R.current };
101
- delete C[t], R.current = C, L(C);
100
+ const C = { ...E.current };
101
+ delete C[t], E.current = C, L(C);
102
102
  }
103
103
  A((p) => p[t] ? p : {
104
104
  ...p,
105
105
  [t]: {
106
106
  origin: t,
107
107
  authUrl: r.authUrl,
108
- status: n && Q.current ? "broker" : "interactive",
108
+ status: n && Y.current ? "broker" : "interactive",
109
109
  v2: n,
110
110
  scope: r.scope || null,
111
- acceptsCredentials: Y.current[t] || null,
111
+ acceptsCredentials: V.current[t] || null,
112
112
  consent: null,
113
113
  error: null,
114
114
  clientId: r.clientId || b.current[t] || null,
115
115
  popupBlocked: !1
116
116
  }
117
- }), x(t);
117
+ }), U(t);
118
118
  }
119
119
  },
120
- [x]
121
- ), c = d({}), f = h((r) => {
120
+ [U]
121
+ ), c = l({}), f = h((r) => {
122
122
  c.current[r] && (clearTimeout(c.current[r]), delete c.current[r]);
123
- }, []), l = h(
123
+ }, []), d = h(
124
124
  (r) => {
125
125
  f(r), A((n) => {
126
126
  if (!n[r])
@@ -132,22 +132,22 @@ const ae = Ie(null), ue = Ie({
132
132
  [f]
133
133
  ), k = h(
134
134
  (r) => {
135
- r && (l(r), J((n) => ({
135
+ r && (d(r), J((n) => ({
136
136
  ...n,
137
137
  [r]: (n[r] || 0) + 1
138
138
  })));
139
139
  },
140
- [l]
140
+ [d]
141
141
  ), B = h(
142
142
  (r) => {
143
- l(r.origin);
143
+ d(r.origin);
144
144
  },
145
- [l]
146
- ), O = h(
145
+ [d]
146
+ ), x = h(
147
147
  (r, n) => {
148
- const t = Re(r, n);
148
+ const t = we(r, n);
149
149
  if (t) {
150
- if (ke(t, window.location.origin)) {
150
+ if (Te(t, window.location.origin)) {
151
151
  i(t, "cross-site-legacy");
152
152
  return;
153
153
  }
@@ -157,22 +157,22 @@ const ae = Ie(null), ue = Ie({
157
157
  [a, i]
158
158
  );
159
159
  g(() => {
160
- if (!E)
160
+ if (!R)
161
161
  return;
162
162
  const r = [
163
- E.addListener("*", "init", (n, t) => {
164
- t != null && t.origin && (n != null && n.clientId) && (b.current[t.origin] = n.clientId, x(t.origin)), t != null && t.origin && Array.isArray(n == null ? void 0 : n.acceptsCredentials) ? Y.current[t.origin] = n.acceptsCredentials : t != null && t.origin && ke(t.origin, window.location.origin) && i(t.origin, "cross-site-legacy");
163
+ R.addListener("*", "init", (n, t) => {
164
+ t != null && t.origin && (n != null && n.clientId) && (b.current[t.origin] = n.clientId, U(t.origin)), t != null && t.origin && Array.isArray(n == null ? void 0 : n.acceptsCredentials) ? V.current[t.origin] = n.acceptsCredentials : t != null && t.origin && Te(t.origin, window.location.origin) && i(t.origin, "cross-site-legacy");
165
165
  }),
166
- E.addListener("*", "authorize", O),
167
- E.addListener("*", "login", O),
168
- E.addListener(
166
+ R.addListener("*", "authorize", x),
167
+ R.addListener("*", "login", x),
168
+ R.addListener(
169
169
  "*",
170
170
  "credential-request",
171
- (n, t) => a(n, { v2: !0, origin: Re(n, t) })
171
+ (n, t) => a(n, { v2: !0, origin: we(n, t) })
172
172
  )
173
173
  ];
174
174
  return () => r.forEach((n) => n());
175
- }, [E, O, a, x, i]), g(() => {
175
+ }, [R, x, a, U, i]), g(() => {
176
176
  const r = (n) => {
177
177
  const t = n == null ? void 0 : n.data;
178
178
  if (!t || t.type !== "authorized")
@@ -186,25 +186,25 @@ const ae = Ie(null), ue = Ie({
186
186
  L((C) => ({
187
187
  ...C,
188
188
  [o]: Ee({ accessToken: t.accessToken })
189
- })), l(o);
189
+ })), d(o);
190
190
  return;
191
191
  }
192
192
  k(o);
193
193
  }
194
194
  };
195
195
  return window.addEventListener("message", r), () => window.removeEventListener("message", r);
196
- }, [l, k]);
197
- const $ = h(
196
+ }, [d, k]);
197
+ const O = h(
198
198
  (r, n) => {
199
199
  const t = r == null ? void 0 : r.origin, o = Ee(n);
200
- !t || !o || (L((p) => ({ ...p, [t]: o })), l(t));
200
+ !t || !o || (L((p) => ({ ...p, [t]: o })), d(t));
201
201
  },
202
- [l]
202
+ [d]
203
203
  ), T = h((r, n) => {
204
204
  A((t) => t[r] ? { ...t, [r]: { ...t[r], ...n } } : t);
205
- }, []), M = d({}), z = h(
205
+ }, []), M = l({}), $ = h(
206
206
  async (r, { approve: n } = {}) => {
207
- const t = Q.current, { origin: o } = r;
207
+ const t = Y.current, { origin: o } = r;
208
208
  let p;
209
209
  try {
210
210
  p = await t(
@@ -220,78 +220,78 @@ const ae = Ie(null), ue = Ie({
220
220
  n ? T(o, { error: { reason: "broker_unavailable" } }) : T(o, { status: "interactive" });
221
221
  return;
222
222
  }
223
- const C = p == null ? void 0 : p.status, S = (p == null ? void 0 : p.body) || {};
224
- if (C === 200 && S.credential) {
225
- $(r, S.credential);
223
+ const C = p == null ? void 0 : p.status, z = (p == null ? void 0 : p.body) || {};
224
+ if (C === 200 && z.credential) {
225
+ O(r, z.credential);
226
226
  return;
227
227
  }
228
- if (C === 409 && S.consentRequired) {
228
+ if (C === 409 && z.consentRequired) {
229
229
  T(o, {
230
230
  status: "interactive",
231
231
  consent: {
232
- client: S.client || null,
233
- stepUp: !!S.stepUp,
234
- scope: S.scope || r.scope
232
+ client: z.client || null,
233
+ stepUp: !!z.stepUp,
234
+ scope: z.scope || r.scope
235
235
  },
236
236
  error: null
237
237
  });
238
238
  return;
239
239
  }
240
- const G = S.error || "broker_error";
241
- if (!n && xe.has(G)) {
240
+ const H = z.error || "broker_error";
241
+ if (!n && Oe.has(H)) {
242
242
  T(o, { status: "interactive" });
243
243
  return;
244
244
  }
245
- if (n && G === "consent_denied") {
245
+ if (n && H === "consent_denied") {
246
246
  T(o, { error: null });
247
247
  return;
248
248
  }
249
- if (G === "rate_limited" && !r.rateLimitRetried) {
250
- const H = Math.min(
251
- Number(S.retryAfter) > 0 ? Number(S.retryAfter) : ve,
252
- Se
253
- ), ne = { ...r, rateLimitRetried: !0 };
249
+ if (H === "rate_limited" && !r.rateLimitRetried) {
250
+ const X = Math.min(
251
+ Number(z.retryAfter) > 0 ? Number(z.retryAfter) : Se,
252
+ Ue
253
+ ), te = { ...r, rateLimitRetried: !0 };
254
254
  f(o), c.current[o] = setTimeout(() => {
255
- delete c.current[o], M.current[o] = !0, ee.current(ne, { approve: n }).finally(() => {
255
+ delete c.current[o], M.current[o] = !0, ee.current(te, { approve: n }).finally(() => {
256
256
  delete M.current[o];
257
257
  });
258
- }, H * 1e3), T(o, { rateLimitRetried: !0 });
258
+ }, X * 1e3), T(o, { rateLimitRetried: !0 });
259
259
  return;
260
260
  }
261
- l(o), y((H) => ({
262
- ...H,
261
+ d(o), y((X) => ({
262
+ ...X,
263
263
  [o]: {
264
264
  origin: o,
265
- reason: `broker:${G}`,
266
- detail: { status: C != null ? C : null, reason: G },
265
+ reason: `broker:${H}`,
266
+ detail: { status: C != null ? C : null, reason: H },
267
267
  clientId: r.clientId || b.current[o] || null
268
268
  }
269
269
  }));
270
270
  },
271
- [$, T, l, f]
272
- ), ee = d(z);
273
- ee.current = z, g(() => {
271
+ [O, T, d, f]
272
+ ), ee = l($);
273
+ ee.current = $, g(() => {
274
274
  Object.values(I).forEach((r) => {
275
- r.status !== "broker" || M.current[r.origin] || c.current[r.origin] || (M.current[r.origin] = !0, z(r).finally(() => {
275
+ r.status !== "broker" || M.current[r.origin] || c.current[r.origin] || (M.current[r.origin] = !0, $(r).finally(() => {
276
276
  delete M.current[r.origin];
277
277
  }));
278
278
  });
279
- }, [I, z]);
279
+ }, [I, $]);
280
280
  const W = h(
281
- (r) => !Q.current || !(r != null && r.consent) || M.current[r.origin] ? Promise.resolve() : (M.current[r.origin] = !0, z(r, { approve: !0 }).finally(() => {
281
+ (r) => !Y.current || !(r != null && r.consent) || M.current[r.origin] ? Promise.resolve() : (M.current[r.origin] = !0, $(r, { approve: !0 }).finally(() => {
282
282
  delete M.current[r.origin];
283
283
  })),
284
- [z]
284
+ [$]
285
285
  );
286
286
  g(() => () => {
287
287
  P.current && P.current(), Object.values(c.current).forEach(clearTimeout);
288
288
  }, []), g(() => {
289
- m === !1 && (Object.values(c.current).forEach(clearTimeout), c.current = {}, M.current = {}, b.current = {}, Y.current = {}, v.current = {}, K.current = {}, R.current = {}, L({}), A({}), y({}));
289
+ m === !1 && (Object.values(c.current).forEach(clearTimeout), c.current = {}, M.current = {}, b.current = {}, V.current = {}, v.current = {}, K.current = {}, E.current = {}, L({}), A({}), y({}));
290
290
  }, [m]);
291
- const X = h(
291
+ const Q = h(
292
292
  (r) => {
293
293
  P.current && (P.current(), P.current = null);
294
- const n = s || Oe;
294
+ const n = s || $e;
295
295
  P.current = n(r, {
296
296
  onBlocked: () => {
297
297
  A((t) => t[r.origin] ? {
@@ -312,18 +312,18 @@ const ae = Ie(null), ue = Ie({
312
312
  pending: Object.values(I).filter(
313
313
  (r) => r.status === "interactive"
314
314
  ),
315
- authorize: X,
315
+ authorize: Q,
316
316
  approve: W,
317
- complete: $,
317
+ complete: O,
318
318
  dismiss: B,
319
319
  originEpochs: q,
320
320
  credentials: Z,
321
- unsupported: U,
321
+ unsupported: S,
322
322
  setDelivered: N
323
323
  };
324
324
  return /* @__PURE__ */ D.createElement(ue.Provider, { value: re }, e);
325
325
  };
326
- _e.propTypes = {
326
+ Ae.propTypes = {
327
327
  children: w.node,
328
328
  launcher: w.func,
329
329
  ready: w.bool,
@@ -337,26 +337,26 @@ _e.propTypes = {
337
337
  */
338
338
  broker: w.func
339
339
  };
340
- const $e = () => te(ue), ze = (e) => {
341
- const { originEpochs: s } = te(ue), u = oe(e);
340
+ const ze = () => ne(ue), Fe = (e) => {
341
+ const { originEpochs: s } = ne(ue), u = oe(e);
342
342
  return u && s[u] || 0;
343
- }, Fe = (e) => {
344
- const { credentials: s } = te(ue), u = oe(e);
345
- return u && s[u] || null;
346
343
  }, De = (e) => {
347
- const { unsupported: s } = te(ue), u = oe(e);
344
+ const { credentials: s } = ne(ue), u = oe(e);
345
+ return u && s[u] || null;
346
+ }, Pe = (e) => {
347
+ const { unsupported: s } = ne(ue), u = oe(e);
348
348
  return u && s[u] || null;
349
- }, Te = "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.", Pe = ({
349
+ }, 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.", Be = ({
350
350
  children: e,
351
351
  authorizationLauncher: s,
352
352
  credentialBroker: u,
353
353
  ready: m
354
354
  }) => {
355
- const E = m === !0, I = d(!1);
355
+ const R = m === !0, I = l(!1);
356
356
  g(() => {
357
- m !== void 0 || I.current || (I.current = !0, console.error(Te), typeof window != "undefined" && typeof window.alert == "function" && window.alert(Te));
357
+ m !== void 0 || I.current || (I.current = !0, console.error(Ie), typeof window != "undefined" && typeof window.alert == "function" && window.alert(Ie));
358
358
  }, [m]);
359
- const [A, q] = F({}), [J, Z] = F({}), L = d({}), U = d({}), y = d({}), R = h((i, a) => {
359
+ const [A, q] = F({}), [J, Z] = F({}), L = l({}), S = l({}), y = l({}), E = h((i, a) => {
360
360
  var c;
361
361
  return !!((c = y.current[i]) != null && c.has(a));
362
362
  }, []), j = h((i, a, c) => {
@@ -368,34 +368,34 @@ const $e = () => te(ue), ze = (e) => {
368
368
  }), Z((a) => {
369
369
  const c = { ...a };
370
370
  return delete c[i], c;
371
- }), delete y.current[i], Object.keys(U.current).forEach((a) => {
372
- U.current[a].instanceId === i && delete U.current[a];
371
+ }), delete y.current[i], Object.keys(S.current).forEach((a) => {
372
+ S.current[a].instanceId === i && delete S.current[a];
373
373
  });
374
374
  }, []);
375
375
  g(() => () => {
376
- U.current = {};
376
+ S.current = {};
377
377
  }, []), g(() => {
378
- const i = (c = [], f, l) => {
379
- c.forEach((k) => k(f, l));
378
+ const i = (c = [], f, d) => {
379
+ c.forEach((k) => k(f, d));
380
380
  }, a = (c) => {
381
- var T, M, z, ee, W, X, re;
381
+ var T, M, $, ee, W, Q, re;
382
382
  if (!((T = c == null ? void 0 : c.data) != null && T.instanceId))
383
383
  return;
384
- const { instanceId: f, type: l } = c.data, k = A[f], B = (z = (M = k == null ? void 0 : k.frameRef) == null ? void 0 : M.current) == null ? void 0 : z.contentWindow;
384
+ const { instanceId: f, type: d } = c.data, k = A[f], B = ($ = (M = k == null ? void 0 : k.frameRef) == null ? void 0 : M.current) == null ? void 0 : $.contentWindow;
385
385
  if (!B || c.source !== B || c.origin !== k.origin)
386
386
  return;
387
- const O = { origin: c.origin }, $ = L.current;
388
- if (l === "response") {
389
- const { callbackId: r, response: n, error: t } = c.data, o = U.current[r];
390
- o && o.instanceId === f && (o.callback(n, t), delete U.current[r]);
387
+ const x = { origin: c.origin }, O = L.current;
388
+ if (d === "response") {
389
+ const { callbackId: r, response: n, error: t } = c.data, o = S.current[r];
390
+ o && o.instanceId === f && (o.callback(n, t), delete S.current[r]);
391
391
  return;
392
392
  }
393
- if (l === "mark-registered") {
393
+ if (d === "mark-registered") {
394
394
  const { requestType: r } = c.data;
395
395
  y.current[f] || (y.current[f] = /* @__PURE__ */ new Set()), y.current[f].add(r);
396
396
  return;
397
397
  }
398
- l === "ready" && Z((r) => ({ ...r, [f]: !0 })), i((ee = $[f]) == null ? void 0 : ee[l], c.data, O), i((W = $["*"]) == null ? void 0 : W[l], c.data, O), i((X = $[f]) == null ? void 0 : X["*"], c.data, O), i((re = $["*"]) == null ? void 0 : re["*"], c.data, O);
398
+ d === "ready" && Z((r) => ({ ...r, [f]: !0 })), i((ee = O[f]) == null ? void 0 : ee[d], c.data, x), i((W = O["*"]) == null ? void 0 : W[d], c.data, x), i((Q = O[f]) == null ? void 0 : Q["*"], c.data, x), i((re = O["*"]) == null ? void 0 : re["*"], c.data, x);
399
399
  };
400
400
  return window.addEventListener("message", a), () => {
401
401
  window.removeEventListener("message", a);
@@ -404,23 +404,23 @@ const $e = () => te(ue), ze = (e) => {
404
404
  const b = h(
405
405
  (i, a, c, f) => {
406
406
  var k, B;
407
- const l = A[i];
408
- if (!l) {
407
+ const d = A[i];
408
+ if (!d) {
409
409
  console.warn(`Origin not set for id: ${i}. Unable to send message.`);
410
410
  return;
411
411
  }
412
- (B = (k = l == null ? void 0 : l.frameRef) == null ? void 0 : k.current) != null && B.contentWindow && l.frameRef.current.contentWindow.postMessage(
412
+ (B = (k = d == null ? void 0 : d.frameRef) == null ? void 0 : k.current) != null && B.contentWindow && d.frameRef.current.contentWindow.postMessage(
413
413
  { type: a, ...c, instanceId: i },
414
- f || l.origin
414
+ f || d.origin
415
415
  );
416
416
  },
417
417
  [A]
418
- ), Y = d(0), Q = h(() => `${Date.now()}-${++Y.current}`, []), v = h(
419
- async (i, a, c = {}) => new Promise((f, l) => {
420
- const k = Q(), B = (O, $) => {
421
- delete U.current[k], $ ? l($) : f(O);
418
+ ), V = l(0), Y = h(() => `${Date.now()}-${++V.current}`, []), v = h(
419
+ async (i, a, c = {}) => new Promise((f, d) => {
420
+ const k = Y(), B = (x, O) => {
421
+ delete S.current[k], O ? d(O) : f(x);
422
422
  };
423
- U.current[k] = { instanceId: i, callback: B }, b(i, "request", { callbackId: k, requestType: a, data: c });
423
+ S.current[k] = { instanceId: i, callback: B }, b(i, "request", { callbackId: k, requestType: a, data: c });
424
424
  }),
425
425
  [b]
426
426
  ), K = h(
@@ -433,7 +433,7 @@ const $e = () => te(ue), ze = (e) => {
433
433
  b(i, "validate", a);
434
434
  },
435
435
  [b]
436
- ), x = Me(
436
+ ), U = Ce(
437
437
  () => ({
438
438
  registerFrame: j,
439
439
  unregisterFrame: P,
@@ -441,9 +441,9 @@ const $e = () => te(ue), ze = (e) => {
441
441
  sendRequest: v,
442
442
  loadOptions: K,
443
443
  validate: N,
444
- hasHandler: R,
444
+ hasHandler: E,
445
445
  readyFrames: J,
446
- ready: E,
446
+ ready: R,
447
447
  addListener: (i, a, c) => (L.current[i] || (L.current[i] = {}), L.current[i][a] || (L.current[i][a] = []), L.current[i][a].push(c), () => {
448
448
  L.current[i][a] = L.current[i][a].filter((f) => f !== c);
449
449
  })
@@ -455,29 +455,29 @@ const $e = () => te(ue), ze = (e) => {
455
455
  v,
456
456
  K,
457
457
  N,
458
- R,
458
+ E,
459
459
  J,
460
- E
460
+ R
461
461
  ]
462
462
  );
463
- return /* @__PURE__ */ D.createElement(ae.Provider, { value: x }, /* @__PURE__ */ D.createElement(
464
- _e,
463
+ return /* @__PURE__ */ D.createElement(le.Provider, { value: U }, /* @__PURE__ */ D.createElement(
464
+ Ae,
465
465
  {
466
466
  launcher: s,
467
467
  broker: u,
468
- ready: E
468
+ ready: R
469
469
  },
470
470
  e
471
471
  ));
472
472
  }, se = (e, s, u) => {
473
- const m = te(ae);
473
+ const m = ne(le);
474
474
  if (m === null)
475
475
  throw new Error(
476
476
  "useEmbeddedEffect must be used within a MMEmbeddableZoneProvider"
477
477
  );
478
- const E = d(u);
478
+ const R = l(u);
479
479
  g(() => {
480
- E.current = u;
480
+ R.current = u;
481
481
  }, [u]), g(() => {
482
482
  if (!(!e || !s)) {
483
483
  if (s.startsWith("key:")) {
@@ -485,18 +485,18 @@ const $e = () => te(ue), ze = (e) => {
485
485
  return m.readyFrames[e] && m.sendMessage(e, "subscribe-key", { keyChord: I }), m.addListener(
486
486
  e,
487
487
  `key-pressed:${I}`,
488
- (...q) => E.current(...q)
488
+ (...q) => R.current(...q)
489
489
  );
490
490
  }
491
491
  return m.addListener(
492
492
  e,
493
493
  s,
494
- (...I) => E.current(...I)
494
+ (...I) => R.current(...I)
495
495
  );
496
496
  }
497
497
  }, [m, e, s]);
498
498
  };
499
- Pe.propTypes = {
499
+ Be.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,34 +519,34 @@ Pe.propTypes = {
519
519
  */
520
520
  credentialBroker: w.func
521
521
  };
522
- const pe = ge.default || ge, Be = 1e4, We = 6e3, qe = 5e3, je = 2e4, He = 3e3, Ae = () => typeof document != "undefined" && document.visibilityState === "hidden", ce = (e, s, u) => {
523
- if (e.current && clearTimeout(e.current.handle), Ae()) {
522
+ const he = Re.default || Re, We = 1e4, qe = 6e3, je = 5e3, He = 2e4, Ze = 3e3, Le = () => typeof document != "undefined" && document.visibilityState === "hidden", ce = (e, s, u) => {
523
+ if (e.current && clearTimeout(e.current.handle), Le()) {
524
524
  e.current = { ms: s, fn: u, suspended: !0 };
525
525
  return;
526
526
  }
527
- const m = Date.now(), E = setTimeout(() => {
528
- if (Date.now() - m - s > He) {
527
+ const m = Date.now(), R = setTimeout(() => {
528
+ if (Date.now() - m - s > Ze) {
529
529
  ce(e, s, u);
530
530
  return;
531
531
  }
532
532
  e.current = void 0, u();
533
533
  }, s);
534
- e.current = { handle: E, ms: s, fn: u };
535
- }, V = (e) => {
534
+ e.current = { handle: R, ms: s, fn: u };
535
+ }, G = (e) => {
536
536
  e.current && clearTimeout(e.current.handle), e.current = void 0;
537
- }, de = (e) => {
538
- e.current && !e.current.suspended && (clearTimeout(e.current.handle), e.current = { ms: e.current.ms, fn: e.current.fn, suspended: !0 });
539
537
  }, fe = (e) => {
538
+ e.current && !e.current.suspended && (clearTimeout(e.current.handle), e.current = { ms: e.current.ms, fn: e.current.fn, suspended: !0 });
539
+ }, pe = (e) => {
540
540
  e.current && e.current.suspended && ce(e, e.current.ms, e.current.fn);
541
- }, Ze = "credentials", Ke = (e, s) => `${e}/mm-embedded-interop?id=${encodeURIComponent(s)}&origin=${encodeURIComponent(
541
+ }, Ke = "credentials", Ge = (e, s) => `${e}/mm-embedded-interop?id=${encodeURIComponent(s)}&origin=${encodeURIComponent(
542
542
  window.location.origin
543
- )}&caps=${Ze}`, Ge = pe.iframe`
543
+ )}&caps=${Ke}`, Ve = he.iframe`
544
544
  width: 100%;
545
545
  height: 100%;
546
546
  border: none;
547
547
  visibility: ${(e) => e.$isReady ? "visible" : "hidden"};
548
548
  ${(e) => e.$collapsed ? "position: absolute; width: 1px; height: 1px; overflow: hidden;" : ""}
549
- `, Ve = pe.div`
549
+ `, Ye = he.div`
550
550
  width: 100%;
551
551
  height: 100%;
552
552
  display: flex;
@@ -559,7 +559,7 @@ const pe = ge.default || ge, Be = 1e4, We = 6e3, qe = 5e3, je = 2e4, He = 3e3, A
559
559
  text-align: center;
560
560
  color: #555;
561
561
  font-size: 14px;
562
- `, Ye = (e) => {
562
+ `, Qe = (e) => {
563
563
  const s = e && e.origin || "This app", u = e && e.reason || "";
564
564
  switch (u) {
565
565
  case "broker:scope_above_ceiling":
@@ -587,11 +587,11 @@ const pe = ge.default || ge, Be = 1e4, We = 6e3, qe = 5e3, je = 2e4, He = 3e3, A
587
587
  detail: "It needs an update to support embedding from a different domain."
588
588
  };
589
589
  }
590
- }, Le = ({ entry: e }) => {
591
- const s = Ye(e);
592
- return /* @__PURE__ */ D.createElement(Ve, { "data-reason": e && e.reason || void 0 }, /* @__PURE__ */ D.createElement("div", { style: { fontWeight: 600 } }, s.title), /* @__PURE__ */ D.createElement("div", { style: { fontSize: 12, color: "#888" } }, s.detail));
590
+ }, ye = ({ entry: e }) => {
591
+ const s = Qe(e);
592
+ return /* @__PURE__ */ D.createElement(Ye, { "data-reason": e && e.reason || void 0 }, /* @__PURE__ */ D.createElement("div", { style: { fontWeight: 600 } }, s.title), /* @__PURE__ */ D.createElement("div", { style: { fontSize: 12, color: "#888" } }, s.detail));
593
593
  };
594
- Le.propTypes = {
594
+ ye.propTypes = {
595
595
  entry: w.shape({
596
596
  origin: w.string,
597
597
  name: w.string,
@@ -599,28 +599,28 @@ Le.propTypes = {
599
599
  detail: w.object
600
600
  })
601
601
  };
602
- const Qe = pe.div`
602
+ const Xe = he.div`
603
603
  height: 100%;
604
604
  display: flex;
605
605
  flex: 1;
606
606
  align-items: center;
607
607
  justify-content: center;
608
- `, Xe = () => /* @__PURE__ */ D.createElement(Qe, null, /* @__PURE__ */ D.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), Je = ({
608
+ `, Je = () => /* @__PURE__ */ D.createElement(Xe, null, /* @__PURE__ */ D.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), Ne = ({
609
609
  id: e,
610
610
  src: s,
611
611
  path: u,
612
612
  onInit: m = () => {
613
613
  },
614
- onTimeout: E,
614
+ onTimeout: R,
615
615
  onRemount: I,
616
616
  onStall: A,
617
617
  context: q = {},
618
618
  params: J = {},
619
619
  renderUnsupported: Z,
620
620
  renderTimeout: L,
621
- ...U
621
+ ...S
622
622
  }) => {
623
- if ("isConfiguring" in U)
623
+ if ("isConfiguring" in S)
624
624
  return console.error(
625
625
  "isConfiguring must be passed via the params prop to MMEmbeddableZone"
626
626
  ), null;
@@ -632,16 +632,16 @@ const Qe = pe.div`
632
632
  return console.error(
633
633
  "isFullScreen must be passed via the params prop to MMEmbeddableZone"
634
634
  ), null;
635
- const y = d(), R = oe(s), [j, P] = F(), [b, Y] = F(0), [Q, v] = F(!1), [K, N] = F(!1), x = ze(s), i = Fe(s), a = De(s), { setDelivered: c } = $e(), [f, l] = F(0), [k, B] = F(null), { registerFrame: O, unregisterFrame: $, sendMessage: T, ready: M } = te(
636
- ae
637
- ), [z, ee] = F(), W = d(), X = d(E), re = d(m), r = d(I), n = d(A), t = d(!1), o = d(), p = d(), C = d(!1), S = d(!1), G = d(null), H = h(() => {
638
- t.current = !1, C.current = !1, S.current = !1, G.current = null, V(W), V(o), V(p), Y(0), v(!1), N(!1), B(null), c(R, e, !1);
639
- }, [c, R, e]);
635
+ const y = l(), E = oe(s), [j, P] = F(), [b, V] = F(0), [Y, v] = F(!1), [K, N] = F(!1), U = Fe(s), i = De(s), a = Pe(s), { setDelivered: c } = ze(), [f, d] = F(0), [k, B] = F(null), { registerFrame: x, unregisterFrame: O, sendMessage: T, ready: M } = ne(
636
+ le
637
+ ), [$, ee] = F(), W = l(), Q = l(R), re = l(m), r = l(I), n = l(A), t = l(!1), o = l(), p = l(), C = l(!1), z = l(!1), H = l(!1), X = l(null), te = h(() => {
638
+ t.current = !1, C.current = !1, z.current = !1, H.current = !1, X.current = null, G(W), G(o), G(p), V(0), v(!1), N(!1), B(null), c(E, e, !1);
639
+ }, [c, E, e]);
640
640
  g(() => {
641
- (x > 0 || f > 0) && H();
642
- }, [x, f, H]), g(() => {
643
- X.current = E;
644
- }, [E]), g(() => {
641
+ (U > 0 || f > 0) && te();
642
+ }, [U, f, te]), g(() => {
643
+ Q.current = R;
644
+ }, [R]), g(() => {
645
645
  re.current = m;
646
646
  }, [m]), g(() => {
647
647
  r.current = I;
@@ -649,11 +649,11 @@ const Qe = pe.div`
649
649
  n.current = A;
650
650
  }, [A]), g(() => {
651
651
  const _ = () => {
652
- if (Ae()) {
653
- de(W), de(o), de(p);
652
+ if (Le()) {
653
+ fe(W), fe(o), fe(p);
654
654
  return;
655
655
  }
656
- fe(W), fe(p), C.current && fe(o);
656
+ pe(W), pe(p), C.current && pe(o);
657
657
  };
658
658
  return document.addEventListener("visibilitychange", _), () => document.removeEventListener("visibilitychange", _);
659
659
  }, []), g(() => {
@@ -665,90 +665,90 @@ const Qe = pe.div`
665
665
  ...q
666
666
  }
667
667
  },
668
- R
668
+ E
669
669
  );
670
- }, [q, e, b, R]), g(() => {
671
- b && T(e, "set-params", { params: J }, R);
672
- }, [J, e, b, R]), g(() => {
670
+ }, [q, e, b, E]), g(() => {
671
+ b && T(e, "set-params", { params: J }, E);
672
+ }, [J, e, b, E]), g(() => {
673
673
  u !== void 0 && ee((u == null ? void 0 : u.indexOf("/")) === 0 ? u : `/${u}`);
674
674
  }, [u]), g(() => {
675
- z === void 0 || !b || T(e, "navigate", { path: z }, R);
676
- }, [z, b, e, T, R]), g(() => {
675
+ $ === void 0 || !b || T(e, "navigate", { path: $ }, E);
676
+ }, [$, b, e, T, E]), g(() => {
677
677
  if (!s || !e || !y)
678
678
  return;
679
679
  if (!M) {
680
- H(), P(void 0);
680
+ te(), P(void 0);
681
681
  return;
682
682
  }
683
- H();
683
+ te();
684
684
  const _ = new URL(s);
685
- return O(e, _.origin, y), re.current(), P(Ke(_.origin, e)), () => {
686
- $(e);
685
+ return x(e, _.origin, y), re.current(), P(Ge(_.origin, e)), () => {
686
+ O(e);
687
687
  };
688
- }, [s, e, M, O, y, H]);
689
- const ne = h(() => {
690
- v(!0), X.current && X.current();
688
+ }, [s, e, M, x, y, te]);
689
+ const ae = h(() => {
690
+ v(!0), Q.current && Q.current();
691
691
  }, []);
692
692
  g(() => {
693
693
  if (!(!j || t.current))
694
- return ce(W, Be, ne), () => V(W);
695
- }, [j, s, x, f, ne]);
694
+ return ce(W, We, ae), () => G(W);
695
+ }, [j, s, U, f, ae]);
696
696
  const ie = h(() => {
697
- t.current = !0, V(W), v(!1);
698
- }, []), le = h(() => {
699
- if (!S.current) {
700
- S.current = !0, T(e, "credential", G.current, R), n.current && n.current("redelivered"), ce(p, je, le);
697
+ t.current = !0, G(W), v(!1);
698
+ }, []), de = h(() => {
699
+ if (!H.current) {
700
+ H.current = !0, T(e, "credential", X.current, E), n.current && n.current("redelivered"), ce(p, He, de);
701
701
  return;
702
702
  }
703
- n.current && n.current("ready"), ne();
704
- }, [e, T, R, ne]);
703
+ n.current && n.current("ready"), ae();
704
+ }, [e, T, E, ae]);
705
705
  se(e, "init", (_) => {
706
706
  ie(), Array.isArray(_ == null ? void 0 : _.acceptsCredentials) && B(_.acceptsCredentials);
707
707
  }), se(e, "authorize", ie), se(e, "login", ie), se(e, "credential-request", () => {
708
708
  ie(), N(!0);
709
709
  }), g(() => {
710
- if (!K || !i)
710
+ if (!K || !i || z.current)
711
711
  return;
712
712
  const _ = k;
713
713
  if (Array.isArray(_) && !_.includes(i.kind))
714
714
  return;
715
- const be = { ...i.kind === "access_token" ? { accessToken: i.accessToken } : {}, credential: i };
716
- G.current = be, S.current = !1, T(e, "credential", be, R), c(R, e, !0), ce(p, qe, le);
715
+ const ge = { ...i.kind === "access_token" ? { accessToken: i.accessToken } : {}, credential: i };
716
+ X.current = ge, H.current = !1, T(e, "credential", ge, E), c(E, e, !0), ce(p, je, de);
717
717
  }, [
718
- le,
718
+ de,
719
719
  K,
720
720
  i,
721
721
  k,
722
722
  e,
723
723
  T,
724
- R,
724
+ E,
725
725
  c
726
726
  ]), se(e, "ready", () => {
727
- ie(), V(p), Y((_) => _ + 1);
727
+ ie(), G(p), z.current = !0, V((_) => _ + 1);
728
728
  });
729
- const ye = h(() => {
730
- r.current && r.current("heartbeat"), l((_) => _ + 1);
729
+ const Me = h(() => {
730
+ r.current && r.current("heartbeat"), d((_) => _ + 1);
731
731
  }, []);
732
732
  if (se(e, "heartbeat", () => {
733
- C.current = !0, ce(o, We, ye);
733
+ C.current = !0, ce(o, qe, Me);
734
734
  }), g(() => () => {
735
- V(o), V(p), V(W);
735
+ G(o), G(p), G(W);
736
736
  }, []), a)
737
- return Z ? Z(a) : /* @__PURE__ */ D.createElement(Le, { entry: a });
738
- const he = !!(Q && !b), me = { ...U };
739
- return delete me.skipManifestCheck, /* @__PURE__ */ D.createElement(D.Fragment, null, he && (L ? L() : /* @__PURE__ */ D.createElement(Xe, null)), /* @__PURE__ */ D.createElement(
740
- Ge,
737
+ return Z ? Z(a) : /* @__PURE__ */ D.createElement(ye, { entry: a });
738
+ const me = !!(Y && !b), be = { ...S };
739
+ return delete be.skipManifestCheck, /* @__PURE__ */ D.createElement(D.Fragment, null, me && (L ? L() : /* @__PURE__ */ D.createElement(Je, null)), /* @__PURE__ */ D.createElement(
740
+ Ve,
741
741
  {
742
- key: `auth-epoch-${x}-frame-${f}`,
742
+ key: `auth-epoch-${U}-frame-${f}`,
743
743
  $isReady: b,
744
- $collapsed: he,
744
+ $collapsed: me,
745
745
  ref: y,
746
746
  src: j,
747
- ...me
747
+ ...be
748
748
  }
749
749
  ));
750
750
  };
751
- Je.propTypes = {
751
+ Ne.propTypes = {
752
752
  id: w.string,
753
753
  src: w.string.isRequired,
754
754
  path: w.string,
@@ -775,18 +775,18 @@ Je.propTypes = {
775
775
  renderTimeout: w.func
776
776
  };
777
777
  export {
778
- Ce as CREDENTIAL_KIND_ACCESS_TOKEN,
778
+ ve as CREDENTIAL_KIND_ACCESS_TOKEN,
779
779
  ue as EmbeddedAuthorizationContext,
780
- Je as MMEmbeddableZone,
781
- ae as MMEmbeddableZoneContext,
782
- Pe as MMEmbeddableZoneProvider,
783
- ke as isCrossSite,
780
+ Ne as MMEmbeddableZone,
781
+ le as MMEmbeddableZoneContext,
782
+ Be as MMEmbeddableZoneProvider,
783
+ Te as isCrossSite,
784
784
  Ee as normalizeCredential,
785
- Oe as popupAuthorizationLauncher,
786
- Ye as unsupportedCopy,
787
- $e as useEmbeddedAuthorizations,
788
- Fe as useEmbeddedCredential,
785
+ $e as popupAuthorizationLauncher,
786
+ Qe as unsupportedCopy,
787
+ ze as useEmbeddedAuthorizations,
788
+ De as useEmbeddedCredential,
789
789
  se as useEmbeddedEffect,
790
- ze as useEmbeddedOriginEpoch,
791
- De as useEmbeddedUnsupported
790
+ Fe as useEmbeddedOriginEpoch,
791
+ Pe as useEmbeddedUnsupported
792
792
  };
@@ -1,10 +1,10 @@
1
- (function(E,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):(E=typeof globalThis!="undefined"?globalThis:E||self,r(E["mm-react-embeddable"]={},E.React,E.PropTypes,E.styled))})(this,(function(E,r,ze,$e){"use strict";const ie=e=>e&&e.__esModule?e:{default:e},U=ie(r),g=ie(ze),be=ie($e),ue=r.createContext(null),re=r.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),he="access_token",ce=e=>e?e.kind?e:e.accessToken?{kind:he,accessToken:e.accessToken,expiresAt:e.expiresAt||null}:null:null,xe=60,De=120,Fe=3e4,Pe=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),te=e=>{try{return new URL(e).origin}catch{return null}},me=(e,u)=>{const l=u==null?void 0:u.origin;return!l||te(e==null?void 0:e.authUrl)!==l?null:l},Ee=e=>{if(!e||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(e)||e.includes(":"))return e;const u=e.split(".");return u.length<=2?e:u.slice(-2).join(".")},le=(e,u)=>{try{const l=new URL(e),b=new URL(u);return l.protocol!==b.protocol?!0:Ee(l.hostname)!==Ee(b.hostname)}catch{return!0}},ge=(e,{onBlocked:u,onClosed:l})=>{const b=window.open(e.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!b)return u(),()=>{};const m=setInterval(()=>{b.closed&&(clearInterval(m),l())},1e3);return()=>clearInterval(m)},ke=({children:e,launcher:u,broker:l,ready:b})=>{const m=r.useContext(ue),[T,y]=r.useState({}),[B,Q]=r.useState({}),[H,I]=r.useState({}),[O,A]=r.useState({}),k=r.useRef(H);k.current=H;const W=r.useRef(T);W.current=T;const F=r.useRef(null),h=r.useRef({}),G=r.useRef({}),V=r.useRef(l);V.current=l;const L=r.useRef({}),K=r.useRef({}),X=r.useCallback((t,s,n)=>{!t||!s||(L.current[t]||(L.current[t]=new Set),n?L.current[t].add(s):L.current[t].delete(s))},[]),z=r.useCallback(t=>{const s=h.current[t];if(!s)return;const n=i=>!i[t]||i[t].clientId?i:{...i,[t]:{...i[t],clientId:s}};y(n),A(n)},[]),c=r.useCallback((t,s)=>{t&&(A(n=>n[t]?n:{...n,[t]:{origin:t,reason:s,clientId:h.current[t]||null}}),z(t))},[z]),d=r.useCallback((t,{v2:s=!1,origin:n=null}={})=>{var i;if(n){if(s&&k.current[n]){if(!((i=L.current[n])!=null&&i.has(t.instanceId)))return;const p=Date.now();if(p-(K.current[n]||0)<Fe)return;K.current[n]=p,L.current[n].clear();const S={...k.current};delete S[n],k.current=S,I(S)}y(p=>p[n]?p:{...p,[n]:{origin:n,authUrl:t.authUrl,status:s&&V.current?"broker":"interactive",v2:s,scope:t.scope||null,acceptsCredentials:G.current[n]||null,consent:null,error:null,clientId:t.clientId||h.current[n]||null,popupBlocked:!1}}),z(n)}},[z]),o=r.useRef({}),f=r.useCallback(t=>{o.current[t]&&(clearTimeout(o.current[t]),delete o.current[t])},[]),a=r.useCallback(t=>{f(t),y(s=>{if(!s[t])return s;const n={...s};return delete n[t],n})},[f]),C=r.useCallback(t=>{t&&(a(t),Q(s=>({...s,[t]:(s[t]||0)+1})))},[a]),P=r.useCallback(t=>{a(t.origin)},[a]),$=r.useCallback((t,s)=>{const n=me(t,s);if(n){if(le(n,window.location.origin)){c(n,"cross-site-legacy");return}d(t,{origin:n})}},[d,c]);r.useEffect(()=>{if(!m)return;const t=[m.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(h.current[n.origin]=s.clientId,z(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?G.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&le(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:me(s,n)}))];return()=>t.forEach(s=>s())},[m,$,d,z,c]),r.useEffect(()=>{const t=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const i=te(n.authUrl);if(!i||s.origin!==i)return;const p=W.current[i];if(!(!p||p.status!=="interactive")){if(n.accessToken){I(S=>({...S,[i]:ce({accessToken:n.accessToken})})),a(i);return}C(i)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[a,C]);const x=r.useCallback((t,s)=>{const n=t==null?void 0:t.origin,i=ce(s);!n||!i||(I(p=>({...p,[n]:i})),a(n))},[a]),w=r.useCallback((t,s)=>{y(n=>n[t]?{...n,[t]:{...n[t],...s}}:n)},[]),M=r.useRef({}),D=r.useCallback(async(t,{approve:s}={})=>{const n=V.current,{origin:i}=t;let p;try{p=await n({origin:i,clientId:t.clientId,scope:t.scope,authUrl:t.authUrl},{approve:s})}catch{s?w(i,{error:{reason:"broker_unavailable"}}):w(i,{status:"interactive"});return}const S=p==null?void 0:p.status,v=(p==null?void 0:p.body)||{};if(S===200&&v.credential){x(t,v.credential);return}if(S===409&&v.consentRequired){w(i,{status:"interactive",consent:{client:v.client||null,stepUp:!!v.stepUp,scope:v.scope||t.scope},error:null});return}const R=v.error||"broker_error";if(!s&&Pe.has(R)){w(i,{status:"interactive"});return}if(s&&R==="consent_denied"){w(i,{error:null});return}if(R==="rate_limited"&&!t.rateLimitRetried){const j=Math.min(Number(v.retryAfter)>0?Number(v.retryAfter):xe,De),se={...t,rateLimitRetried:!0};f(i),o.current[i]=setTimeout(()=>{delete o.current[i],M.current[i]=!0,J.current(se,{approve:s}).finally(()=>{delete M.current[i]})},j*1e3),w(i,{rateLimitRetried:!0});return}a(i),A(j=>({...j,[i]:{origin:i,reason:`broker:${R}`,detail:{status:S!=null?S:null,reason:R},clientId:t.clientId||h.current[i]||null}}))},[x,w,a,f]),J=r.useRef(D);J.current=D,r.useEffect(()=>{Object.values(T).forEach(t=>{t.status!=="broker"||M.current[t.origin]||o.current[t.origin]||(M.current[t.origin]=!0,D(t).finally(()=>{delete M.current[t.origin]}))})},[T,D]);const q=r.useCallback(t=>!V.current||!(t!=null&&t.consent)||M.current[t.origin]?Promise.resolve():(M.current[t.origin]=!0,D(t,{approve:!0}).finally(()=>{delete M.current[t.origin]})),[D]);r.useEffect(()=>()=>{F.current&&F.current(),Object.values(o.current).forEach(clearTimeout)},[]),r.useEffect(()=>{b===!1&&(Object.values(o.current).forEach(clearTimeout),o.current={},M.current={},h.current={},G.current={},L.current={},K.current={},k.current={},I({}),y({}),A({}))},[b]);const Y=r.useCallback(t=>{F.current&&(F.current(),F.current=null);const s=u||ge;F.current=s(t,{onBlocked:()=>{y(n=>n[t.origin]?{...n,[t.origin]:{...n[t.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=W.current[t.origin];!n||n.v2||C(t.origin)}})},[u,C]),ee={pending:Object.values(T).filter(t=>t.status==="interactive"),authorize:Y,approve:q,complete:x,dismiss:P,originEpochs:B,credentials:H,unsupported:O,setDelivered:X};return U.default.createElement(re.Provider,{value:ee},e)};ke.propTypes={children:g.default.node,launcher:g.default.func,ready:g.default.bool,broker:g.default.func};const Ce=()=>r.useContext(re),we=e=>{const{originEpochs:u}=r.useContext(re),l=te(e);return l&&u[l]||0},Te=e=>{const{credentials:u}=r.useContext(re),l=te(e);return l&&u[l]||null},_e=e=>{const{unsupported:u}=r.useContext(re),l=te(e);return l&&u[l]||null},ye="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.",Ie=({children:e,authorizationLauncher:u,credentialBroker:l,ready:b})=>{const m=b===!0,T=r.useRef(!1);r.useEffect(()=>{b!==void 0||T.current||(T.current=!0,console.error(ye),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ye))},[b]);const[y,B]=r.useState({}),[Q,H]=r.useState({}),I=r.useRef({}),O=r.useRef({}),A=r.useRef({}),k=r.useCallback((c,d)=>{var o;return!!((o=A.current[c])!=null&&o.has(d))},[]),W=r.useCallback((c,d,o)=>{B(f=>({...f,[c]:{origin:d,frameRef:o}}))},[]),F=r.useCallback(c=>{B(d=>{const o={...d};return delete o[c],o}),H(d=>{const o={...d};return delete o[c],o}),delete A.current[c],Object.keys(O.current).forEach(d=>{O.current[d].instanceId===c&&delete O.current[d]})},[]);r.useEffect(()=>()=>{O.current={}},[]),r.useEffect(()=>{const c=(o=[],f,a)=>{o.forEach(C=>C(f,a))},d=o=>{var w,M,D,J,q,Y,ee;if(!((w=o==null?void 0:o.data)!=null&&w.instanceId))return;const{instanceId:f,type:a}=o.data,C=y[f],P=(D=(M=C==null?void 0:C.frameRef)==null?void 0:M.current)==null?void 0:D.contentWindow;if(!P||o.source!==P||o.origin!==C.origin)return;const $={origin:o.origin},x=I.current;if(a==="response"){const{callbackId:t,response:s,error:n}=o.data,i=O.current[t];i&&i.instanceId===f&&(i.callback(s,n),delete O.current[t]);return}if(a==="mark-registered"){const{requestType:t}=o.data;A.current[f]||(A.current[f]=new Set),A.current[f].add(t);return}a==="ready"&&H(t=>({...t,[f]:!0})),c((J=x[f])==null?void 0:J[a],o.data,$),c((q=x["*"])==null?void 0:q[a],o.data,$),c((Y=x[f])==null?void 0:Y["*"],o.data,$),c((ee=x["*"])==null?void 0:ee["*"],o.data,$)};return window.addEventListener("message",d),()=>{window.removeEventListener("message",d)}},[y]);const h=r.useCallback((c,d,o,f)=>{var C,P;const a=y[c];if(!a){console.warn(`Origin not set for id: ${c}. Unable to send message.`);return}(P=(C=a==null?void 0:a.frameRef)==null?void 0:C.current)!=null&&P.contentWindow&&a.frameRef.current.contentWindow.postMessage({type:d,...o,instanceId:c},f||a.origin)},[y]),G=r.useRef(0),V=r.useCallback(()=>`${Date.now()}-${++G.current}`,[]),L=r.useCallback(async(c,d,o={})=>new Promise((f,a)=>{const C=V(),P=($,x)=>{delete O.current[C],x?a(x):f($)};O.current[C]={instanceId:c,callback:P},h(c,"request",{callbackId:C,requestType:d,data:o})}),[h]),K=r.useCallback((c,d)=>{h(c,"load-options",d)},[h]),X=r.useCallback((c,d)=>{h(c,"validate",d)},[h]),z=r.useMemo(()=>({registerFrame:W,unregisterFrame:F,sendMessage:h,sendRequest:L,loadOptions:K,validate:X,hasHandler:k,readyFrames:Q,ready:m,addListener:(c,d,o)=>(I.current[c]||(I.current[c]={}),I.current[c][d]||(I.current[c][d]=[]),I.current[c][d].push(o),()=>{I.current[c][d]=I.current[c][d].filter(f=>f!==o)})}),[W,F,h,L,K,X,k,Q,m]);return U.default.createElement(ue.Provider,{value:z},U.default.createElement(ke,{launcher:u,broker:l,ready:m},e))},N=(e,u,l)=>{const b=r.useContext(ue);if(b===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(!(!e||!u)){if(u.startsWith("key:")){const T=u.substring(4);return b.readyFrames[e]&&b.sendMessage(e,"subscribe-key",{keyChord:T}),b.addListener(e,`key-pressed:${T}`,(...B)=>m.current(...B))}return b.addListener(e,u,(...T)=>m.current(...T))}},[b,e,u])};Ie.propTypes={children:g.default.node.isRequired,ready:g.default.bool.isRequired,authorizationLauncher:g.default.func,credentialBroker:g.default.func};const de=be.default.default||be.default,qe=1e4,Be=6e3,We=5e3,je=2e4,Ze=3e3,Ae=()=>typeof document!="undefined"&&document.visibilityState==="hidden",ne=(e,u,l)=>{if(e.current&&clearTimeout(e.current.handle),Ae()){e.current={ms:u,fn:l,suspended:!0};return}const b=Date.now(),m=setTimeout(()=>{if(Date.now()-b-u>Ze){ne(e,u,l);return}e.current=void 0,l()},u);e.current={handle:m,ms:u,fn:l}},Z=e=>{e.current&&clearTimeout(e.current.handle),e.current=void 0},ae=e=>{e.current&&!e.current.suspended&&(clearTimeout(e.current.handle),e.current={ms:e.current.ms,fn:e.current.fn,suspended:!0})},fe=e=>{e.current&&e.current.suspended&&ne(e,e.current.ms,e.current.fn)},He="credentials",Ke=(e,u)=>`${e}/mm-embedded-interop?id=${encodeURIComponent(u)}&origin=${encodeURIComponent(window.location.origin)}&caps=${He}`,Re=de.iframe`
1
+ (function(E,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):(E=typeof globalThis!="undefined"?globalThis:E||self,r(E["mm-react-embeddable"]={},E.React,E.PropTypes,E.styled))})(this,(function(E,r,$e,xe){"use strict";const ce=e=>e&&e.__esModule?e:{default:e},v=ce(r),g=ce($e),he=ce(xe),ue=r.createContext(null),te=r.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),me="access_token",le=e=>e?e.kind?e:e.accessToken?{kind:me,accessToken:e.accessToken,expiresAt:e.expiresAt||null}:null:null,De=60,Fe=120,Pe=3e4,qe=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),ne=e=>{try{return new URL(e).origin}catch{return null}},Ee=(e,u)=>{const l=u==null?void 0:u.origin;return!l||ne(e==null?void 0:e.authUrl)!==l?null:l},ge=e=>{if(!e||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(e)||e.includes(":"))return e;const u=e.split(".");return u.length<=2?e:u.slice(-2).join(".")},de=(e,u)=>{try{const l=new URL(e),b=new URL(u);return l.protocol!==b.protocol?!0:ge(l.hostname)!==ge(b.hostname)}catch{return!0}},ke=(e,{onBlocked:u,onClosed:l})=>{const b=window.open(e.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!b)return u(),()=>{};const m=setInterval(()=>{b.closed&&(clearInterval(m),l())},1e3);return()=>clearInterval(m)},Ce=({children:e,launcher:u,broker:l,ready:b})=>{const m=r.useContext(ue),[T,y]=r.useState({}),[B,Q]=r.useState({}),[H,I]=r.useState({}),[U,A]=r.useState({}),k=r.useRef(H);k.current=H;const W=r.useRef(T);W.current=T;const F=r.useRef(null),h=r.useRef({}),R=r.useRef({}),G=r.useRef(l);G.current=l;const L=r.useRef({}),K=r.useRef({}),X=r.useCallback((t,s,n)=>{!t||!s||(L.current[t]||(L.current[t]=new Set),n?L.current[t].add(s):L.current[t].delete(s))},[]),O=r.useCallback(t=>{const s=h.current[t];if(!s)return;const n=i=>!i[t]||i[t].clientId?i:{...i,[t]:{...i[t],clientId:s}};y(n),A(n)},[]),c=r.useCallback((t,s)=>{t&&(A(n=>n[t]?n:{...n,[t]:{origin:t,reason:s,clientId:h.current[t]||null}}),O(t))},[O]),d=r.useCallback((t,{v2:s=!1,origin:n=null}={})=>{var i;if(n){if(s&&k.current[n]){if(!((i=L.current[n])!=null&&i.has(t.instanceId)))return;const p=Date.now();if(p-(K.current[n]||0)<Pe)return;K.current[n]=p,L.current[n].clear();const S={...k.current};delete S[n],k.current=S,I(S)}y(p=>p[n]?p:{...p,[n]:{origin:n,authUrl:t.authUrl,status:s&&G.current?"broker":"interactive",v2:s,scope:t.scope||null,acceptsCredentials:R.current[n]||null,consent:null,error:null,clientId:t.clientId||h.current[n]||null,popupBlocked:!1}}),O(n)}},[O]),o=r.useRef({}),f=r.useCallback(t=>{o.current[t]&&(clearTimeout(o.current[t]),delete o.current[t])},[]),a=r.useCallback(t=>{f(t),y(s=>{if(!s[t])return s;const n={...s};return delete n[t],n})},[f]),C=r.useCallback(t=>{t&&(a(t),Q(s=>({...s,[t]:(s[t]||0)+1})))},[a]),P=r.useCallback(t=>{a(t.origin)},[a]),z=r.useCallback((t,s)=>{const n=Ee(t,s);if(n){if(de(n,window.location.origin)){c(n,"cross-site-legacy");return}d(t,{origin:n})}},[d,c]);r.useEffect(()=>{if(!m)return;const t=[m.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(h.current[n.origin]=s.clientId,O(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?R.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&de(n.origin,window.location.origin)&&c(n.origin,"cross-site-legacy")}),m.addListener("*","authorize",z),m.addListener("*","login",z),m.addListener("*","credential-request",(s,n)=>d(s,{v2:!0,origin:Ee(s,n)}))];return()=>t.forEach(s=>s())},[m,z,d,O,c]),r.useEffect(()=>{const t=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const i=ne(n.authUrl);if(!i||s.origin!==i)return;const p=W.current[i];if(!(!p||p.status!=="interactive")){if(n.accessToken){I(S=>({...S,[i]:le({accessToken:n.accessToken})})),a(i);return}C(i)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[a,C]);const $=r.useCallback((t,s)=>{const n=t==null?void 0:t.origin,i=le(s);!n||!i||(I(p=>({...p,[n]:i})),a(n))},[a]),w=r.useCallback((t,s)=>{y(n=>n[t]?{...n,[t]:{...n[t],...s}}:n)},[]),M=r.useRef({}),x=r.useCallback(async(t,{approve:s}={})=>{const n=G.current,{origin:i}=t;let p;try{p=await n({origin:i,clientId:t.clientId,scope:t.scope,authUrl:t.authUrl},{approve:s})}catch{s?w(i,{error:{reason:"broker_unavailable"}}):w(i,{status:"interactive"});return}const S=p==null?void 0:p.status,D=(p==null?void 0:p.body)||{};if(S===200&&D.credential){$(t,D.credential);return}if(S===409&&D.consentRequired){w(i,{status:"interactive",consent:{client:D.client||null,stepUp:!!D.stepUp,scope:D.scope||t.scope},error:null});return}const j=D.error||"broker_error";if(!s&&qe.has(j)){w(i,{status:"interactive"});return}if(s&&j==="consent_denied"){w(i,{error:null});return}if(j==="rate_limited"&&!t.rateLimitRetried){const Y=Math.min(Number(D.retryAfter)>0?Number(D.retryAfter):De,Fe),re={...t,rateLimitRetried:!0};f(i),o.current[i]=setTimeout(()=>{delete o.current[i],M.current[i]=!0,J.current(re,{approve:s}).finally(()=>{delete M.current[i]})},Y*1e3),w(i,{rateLimitRetried:!0});return}a(i),A(Y=>({...Y,[i]:{origin:i,reason:`broker:${j}`,detail:{status:S!=null?S:null,reason:j},clientId:t.clientId||h.current[i]||null}}))},[$,w,a,f]),J=r.useRef(x);J.current=x,r.useEffect(()=>{Object.values(T).forEach(t=>{t.status!=="broker"||M.current[t.origin]||o.current[t.origin]||(M.current[t.origin]=!0,x(t).finally(()=>{delete M.current[t.origin]}))})},[T,x]);const q=r.useCallback(t=>!G.current||!(t!=null&&t.consent)||M.current[t.origin]?Promise.resolve():(M.current[t.origin]=!0,x(t,{approve:!0}).finally(()=>{delete M.current[t.origin]})),[x]);r.useEffect(()=>()=>{F.current&&F.current(),Object.values(o.current).forEach(clearTimeout)},[]),r.useEffect(()=>{b===!1&&(Object.values(o.current).forEach(clearTimeout),o.current={},M.current={},h.current={},R.current={},L.current={},K.current={},k.current={},I({}),y({}),A({}))},[b]);const V=r.useCallback(t=>{F.current&&(F.current(),F.current=null);const s=u||ke;F.current=s(t,{onBlocked:()=>{y(n=>n[t.origin]?{...n,[t.origin]:{...n[t.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=W.current[t.origin];!n||n.v2||C(t.origin)}})},[u,C]),ee={pending:Object.values(T).filter(t=>t.status==="interactive"),authorize:V,approve:q,complete:$,dismiss:P,originEpochs:B,credentials:H,unsupported:U,setDelivered:X};return v.default.createElement(te.Provider,{value:ee},e)};Ce.propTypes={children:g.default.node,launcher:g.default.func,ready:g.default.bool,broker:g.default.func};const we=()=>r.useContext(te),Te=e=>{const{originEpochs:u}=r.useContext(te),l=ne(e);return l&&u[l]||0},_e=e=>{const{credentials:u}=r.useContext(te),l=ne(e);return l&&u[l]||null},ye=e=>{const{unsupported:u}=r.useContext(te),l=ne(e);return l&&u[l]||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.",Ae=({children:e,authorizationLauncher:u,credentialBroker:l,ready:b})=>{const m=b===!0,T=r.useRef(!1);r.useEffect(()=>{b!==void 0||T.current||(T.current=!0,console.error(Ie),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(Ie))},[b]);const[y,B]=r.useState({}),[Q,H]=r.useState({}),I=r.useRef({}),U=r.useRef({}),A=r.useRef({}),k=r.useCallback((c,d)=>{var o;return!!((o=A.current[c])!=null&&o.has(d))},[]),W=r.useCallback((c,d,o)=>{B(f=>({...f,[c]:{origin:d,frameRef:o}}))},[]),F=r.useCallback(c=>{B(d=>{const o={...d};return delete o[c],o}),H(d=>{const o={...d};return delete o[c],o}),delete A.current[c],Object.keys(U.current).forEach(d=>{U.current[d].instanceId===c&&delete U.current[d]})},[]);r.useEffect(()=>()=>{U.current={}},[]),r.useEffect(()=>{const c=(o=[],f,a)=>{o.forEach(C=>C(f,a))},d=o=>{var w,M,x,J,q,V,ee;if(!((w=o==null?void 0:o.data)!=null&&w.instanceId))return;const{instanceId:f,type:a}=o.data,C=y[f],P=(x=(M=C==null?void 0:C.frameRef)==null?void 0:M.current)==null?void 0:x.contentWindow;if(!P||o.source!==P||o.origin!==C.origin)return;const z={origin:o.origin},$=I.current;if(a==="response"){const{callbackId:t,response:s,error:n}=o.data,i=U.current[t];i&&i.instanceId===f&&(i.callback(s,n),delete U.current[t]);return}if(a==="mark-registered"){const{requestType:t}=o.data;A.current[f]||(A.current[f]=new Set),A.current[f].add(t);return}a==="ready"&&H(t=>({...t,[f]:!0})),c((J=$[f])==null?void 0:J[a],o.data,z),c((q=$["*"])==null?void 0:q[a],o.data,z),c((V=$[f])==null?void 0:V["*"],o.data,z),c((ee=$["*"])==null?void 0:ee["*"],o.data,z)};return window.addEventListener("message",d),()=>{window.removeEventListener("message",d)}},[y]);const h=r.useCallback((c,d,o,f)=>{var C,P;const a=y[c];if(!a){console.warn(`Origin not set for id: ${c}. Unable to send message.`);return}(P=(C=a==null?void 0:a.frameRef)==null?void 0:C.current)!=null&&P.contentWindow&&a.frameRef.current.contentWindow.postMessage({type:d,...o,instanceId:c},f||a.origin)},[y]),R=r.useRef(0),G=r.useCallback(()=>`${Date.now()}-${++R.current}`,[]),L=r.useCallback(async(c,d,o={})=>new Promise((f,a)=>{const C=G(),P=(z,$)=>{delete U.current[C],$?a($):f(z)};U.current[C]={instanceId:c,callback:P},h(c,"request",{callbackId:C,requestType:d,data:o})}),[h]),K=r.useCallback((c,d)=>{h(c,"load-options",d)},[h]),X=r.useCallback((c,d)=>{h(c,"validate",d)},[h]),O=r.useMemo(()=>({registerFrame:W,unregisterFrame:F,sendMessage:h,sendRequest:L,loadOptions:K,validate:X,hasHandler:k,readyFrames:Q,ready:m,addListener:(c,d,o)=>(I.current[c]||(I.current[c]={}),I.current[c][d]||(I.current[c][d]=[]),I.current[c][d].push(o),()=>{I.current[c][d]=I.current[c][d].filter(f=>f!==o)})}),[W,F,h,L,K,X,k,Q,m]);return v.default.createElement(ue.Provider,{value:O},v.default.createElement(Ce,{launcher:u,broker:l,ready:m},e))},N=(e,u,l)=>{const b=r.useContext(ue);if(b===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(!(!e||!u)){if(u.startsWith("key:")){const T=u.substring(4);return b.readyFrames[e]&&b.sendMessage(e,"subscribe-key",{keyChord:T}),b.addListener(e,`key-pressed:${T}`,(...B)=>m.current(...B))}return b.addListener(e,u,(...T)=>m.current(...T))}},[b,e,u])};Ae.propTypes={children:g.default.node.isRequired,ready:g.default.bool.isRequired,authorizationLauncher:g.default.func,credentialBroker:g.default.func};const ae=he.default.default||he.default,Be=1e4,We=6e3,je=5e3,Ze=2e4,He=3e3,Me=()=>typeof document!="undefined"&&document.visibilityState==="hidden",se=(e,u,l)=>{if(e.current&&clearTimeout(e.current.handle),Me()){e.current={ms:u,fn:l,suspended:!0};return}const b=Date.now(),m=setTimeout(()=>{if(Date.now()-b-u>He){se(e,u,l);return}e.current=void 0,l()},u);e.current={handle:m,ms:u,fn:l}},Z=e=>{e.current&&clearTimeout(e.current.handle),e.current=void 0},fe=e=>{e.current&&!e.current.suspended&&(clearTimeout(e.current.handle),e.current={ms:e.current.ms,fn:e.current.fn,suspended:!0})},pe=e=>{e.current&&e.current.suspended&&se(e,e.current.ms,e.current.fn)},Ke="credentials",Re=(e,u)=>`${e}/mm-embedded-interop?id=${encodeURIComponent(u)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Ke}`,Ge=ae.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
5
5
  visibility: ${e=>e.$isReady?"visible":"hidden"};
6
6
  ${e=>e.$collapsed?"position: absolute; width: 1px; height: 1px; overflow: hidden;":""}
7
- `,Ge=de.div`
7
+ `,Ve=ae.div`
8
8
  width: 100%;
9
9
  height: 100%;
10
10
  display: flex;
@@ -17,10 +17,10 @@
17
17
  text-align: center;
18
18
  color: #555;
19
19
  font-size: 14px;
20
- `,Me=e=>{const u=e&&e.origin||"This app",l=e&&e.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."}}},Se=({entry:e})=>{const u=Me(e);return U.default.createElement(Ge,{"data-reason":e&&e.reason||void 0},U.default.createElement("div",{style:{fontWeight:600}},u.title),U.default.createElement("div",{style:{fontSize:12,color:"#888"}},u.detail))};Se.propTypes={entry:g.default.shape({origin:g.default.string,name:g.default.string,reason:g.default.string,detail:g.default.object})};const Ve=de.div`
20
+ `,Se=e=>{const u=e&&e.origin||"This app",l=e&&e.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."}}},Le=({entry:e})=>{const u=Se(e);return v.default.createElement(Ve,{"data-reason":e&&e.reason||void 0},v.default.createElement("div",{style:{fontWeight:600}},u.title),v.default.createElement("div",{style:{fontSize:12,color:"#888"}},u.detail))};Le.propTypes={entry:g.default.shape({origin:g.default.string,name:g.default.string,reason:g.default.string,detail:g.default.object})};const Ye=ae.div`
21
21
  height: 100%;
22
22
  display: flex;
23
23
  flex: 1;
24
24
  align-items: center;
25
25
  justify-content: center;
26
- `,Ye=()=>U.default.createElement(Ve,null,U.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),Le=({id:e,src:u,path:l,onInit:b=()=>{},onTimeout:m,onRemount:T,onStall:y,context:B={},params:Q={},renderUnsupported:H,renderTimeout:I,...O})=>{if("isConfiguring"in O)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in B)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in B)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const A=r.useRef(),k=te(u),[W,F]=r.useState(),[h,G]=r.useState(0),[V,L]=r.useState(!1),[K,X]=r.useState(!1),z=we(u),c=Te(u),d=_e(u),{setDelivered:o}=Ce(),[f,a]=r.useState(0),[C,P]=r.useState(null),{registerFrame:$,unregisterFrame:x,sendMessage:w,ready:M}=r.useContext(ue),[D,J]=r.useState(),q=r.useRef(),Y=r.useRef(m),ee=r.useRef(b),t=r.useRef(T),s=r.useRef(y),n=r.useRef(!1),i=r.useRef(),p=r.useRef(),S=r.useRef(!1),v=r.useRef(!1),R=r.useRef(null),j=r.useCallback(()=>{n.current=!1,S.current=!1,v.current=!1,R.current=null,Z(q),Z(i),Z(p),G(0),L(!1),X(!1),P(null),o(k,e,!1)},[o,k,e]);r.useEffect(()=>{(z>0||f>0)&&j()},[z,f,j]),r.useEffect(()=>{Y.current=m},[m]),r.useEffect(()=>{ee.current=b},[b]),r.useEffect(()=>{t.current=T},[T]),r.useEffect(()=>{s.current=y},[y]),r.useEffect(()=>{const _=()=>{if(Ae()){ae(q),ae(i),ae(p);return}fe(q),fe(p),S.current&&fe(i)};return document.addEventListener("visibilitychange",_),()=>document.removeEventListener("visibilitychange",_)},[]),r.useEffect(()=>{h&&w(e,"set-context",{context:{...B}},k)},[B,e,h,k]),r.useEffect(()=>{h&&w(e,"set-params",{params:Q},k)},[Q,e,h,k]),r.useEffect(()=>{l!==void 0&&J((l==null?void 0:l.indexOf("/"))===0?l:`/${l}`)},[l]),r.useEffect(()=>{D===void 0||!h||w(e,"navigate",{path:D},k)},[D,h,e,w,k]),r.useEffect(()=>{if(!u||!e||!A)return;if(!M){j(),F(void 0);return}j();const _=new URL(u);return $(e,_.origin,A),ee.current(),F(Ke(_.origin,e)),()=>{x(e)}},[u,e,M,$,A,j]);const se=r.useCallback(()=>{L(!0),Y.current&&Y.current()},[]);r.useEffect(()=>{if(!(!W||n.current))return ne(q,qe,se),()=>Z(q)},[W,u,z,f,se]);const oe=r.useCallback(()=>{n.current=!0,Z(q),L(!1)},[]),pe=r.useCallback(()=>{if(!v.current){v.current=!0,w(e,"credential",R.current,k),s.current&&s.current("redelivered"),ne(p,je,pe);return}s.current&&s.current("ready"),se()},[e,w,k,se]);N(e,"init",_=>{oe(),Array.isArray(_==null?void 0:_.acceptsCredentials)&&P(_.acceptsCredentials)}),N(e,"authorize",oe),N(e,"login",oe),N(e,"credential-request",()=>{oe(),X(!0)}),r.useEffect(()=>{if(!K||!c)return;const _=C;if(Array.isArray(_)&&!_.includes(c.kind))return;const Oe={...c.kind==="access_token"?{accessToken:c.accessToken}:{},credential:c};R.current=Oe,v.current=!1,w(e,"credential",Oe,k),o(k,e,!0),ne(p,We,pe)},[pe,K,c,C,e,w,k,o]),N(e,"ready",()=>{oe(),Z(p),G(_=>_+1)});const Ne=r.useCallback(()=>{t.current&&t.current("heartbeat"),a(_=>_+1)},[]);if(N(e,"heartbeat",()=>{S.current=!0,ne(i,Be,Ne)}),r.useEffect(()=>()=>{Z(i),Z(p),Z(q)},[]),d)return H?H(d):U.default.createElement(Se,{entry:d});const ve=!!(V&&!h),Ue={...O};return delete Ue.skipManifestCheck,U.default.createElement(U.default.Fragment,null,ve&&(I?I():U.default.createElement(Ye,null)),U.default.createElement(Re,{key:`auth-epoch-${z}-frame-${f}`,$isReady:h,$collapsed:ve,ref:A,src:W,...Ue}))};Le.propTypes={id:g.default.string,src:g.default.string.isRequired,path:g.default.string,onInit:g.default.func,onTimeout:g.default.func,onRemount:g.default.func,onStall:g.default.func,renderUnsupported:g.default.func,renderTimeout:g.default.func},E.CREDENTIAL_KIND_ACCESS_TOKEN=he,E.EmbeddedAuthorizationContext=re,E.MMEmbeddableZone=Le,E.MMEmbeddableZoneContext=ue,E.MMEmbeddableZoneProvider=Ie,E.isCrossSite=le,E.normalizeCredential=ce,E.popupAuthorizationLauncher=ge,E.unsupportedCopy=Me,E.useEmbeddedAuthorizations=Ce,E.useEmbeddedCredential=Te,E.useEmbeddedEffect=N,E.useEmbeddedOriginEpoch=we,E.useEmbeddedUnsupported=_e,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
26
+ `,Ne=()=>v.default.createElement(Ye,null,v.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),ve=({id:e,src:u,path:l,onInit:b=()=>{},onTimeout:m,onRemount:T,onStall:y,context:B={},params:Q={},renderUnsupported:H,renderTimeout:I,...U})=>{if("isConfiguring"in U)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in B)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in B)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const A=r.useRef(),k=ne(u),[W,F]=r.useState(),[h,R]=r.useState(0),[G,L]=r.useState(!1),[K,X]=r.useState(!1),O=Te(u),c=_e(u),d=ye(u),{setDelivered:o}=we(),[f,a]=r.useState(0),[C,P]=r.useState(null),{registerFrame:z,unregisterFrame:$,sendMessage:w,ready:M}=r.useContext(ue),[x,J]=r.useState(),q=r.useRef(),V=r.useRef(m),ee=r.useRef(b),t=r.useRef(T),s=r.useRef(y),n=r.useRef(!1),i=r.useRef(),p=r.useRef(),S=r.useRef(!1),D=r.useRef(!1),j=r.useRef(!1),Y=r.useRef(null),re=r.useCallback(()=>{n.current=!1,S.current=!1,D.current=!1,j.current=!1,Y.current=null,Z(q),Z(i),Z(p),R(0),L(!1),X(!1),P(null),o(k,e,!1)},[o,k,e]);r.useEffect(()=>{(O>0||f>0)&&re()},[O,f,re]),r.useEffect(()=>{V.current=m},[m]),r.useEffect(()=>{ee.current=b},[b]),r.useEffect(()=>{t.current=T},[T]),r.useEffect(()=>{s.current=y},[y]),r.useEffect(()=>{const _=()=>{if(Me()){fe(q),fe(i),fe(p);return}pe(q),pe(p),S.current&&pe(i)};return document.addEventListener("visibilitychange",_),()=>document.removeEventListener("visibilitychange",_)},[]),r.useEffect(()=>{h&&w(e,"set-context",{context:{...B}},k)},[B,e,h,k]),r.useEffect(()=>{h&&w(e,"set-params",{params:Q},k)},[Q,e,h,k]),r.useEffect(()=>{l!==void 0&&J((l==null?void 0:l.indexOf("/"))===0?l:`/${l}`)},[l]),r.useEffect(()=>{x===void 0||!h||w(e,"navigate",{path:x},k)},[x,h,e,w,k]),r.useEffect(()=>{if(!u||!e||!A)return;if(!M){re(),F(void 0);return}re();const _=new URL(u);return z(e,_.origin,A),ee.current(),F(Re(_.origin,e)),()=>{$(e)}},[u,e,M,z,A,re]);const ie=r.useCallback(()=>{L(!0),V.current&&V.current()},[]);r.useEffect(()=>{if(!(!W||n.current))return se(q,Be,ie),()=>Z(q)},[W,u,O,f,ie]);const oe=r.useCallback(()=>{n.current=!0,Z(q),L(!1)},[]),be=r.useCallback(()=>{if(!j.current){j.current=!0,w(e,"credential",Y.current,k),s.current&&s.current("redelivered"),se(p,Ze,be);return}s.current&&s.current("ready"),ie()},[e,w,k,ie]);N(e,"init",_=>{oe(),Array.isArray(_==null?void 0:_.acceptsCredentials)&&P(_.acceptsCredentials)}),N(e,"authorize",oe),N(e,"login",oe),N(e,"credential-request",()=>{oe(),X(!0)}),r.useEffect(()=>{if(!K||!c||D.current)return;const _=C;if(Array.isArray(_)&&!_.includes(c.kind))return;const ze={...c.kind==="access_token"?{accessToken:c.accessToken}:{},credential:c};Y.current=ze,j.current=!1,w(e,"credential",ze,k),o(k,e,!0),se(p,je,be)},[be,K,c,C,e,w,k,o]),N(e,"ready",()=>{oe(),Z(p),D.current=!0,R(_=>_+1)});const Qe=r.useCallback(()=>{t.current&&t.current("heartbeat"),a(_=>_+1)},[]);if(N(e,"heartbeat",()=>{S.current=!0,se(i,We,Qe)}),r.useEffect(()=>()=>{Z(i),Z(p),Z(q)},[]),d)return H?H(d):v.default.createElement(Le,{entry:d});const Ue=!!(G&&!h),Oe={...U};return delete Oe.skipManifestCheck,v.default.createElement(v.default.Fragment,null,Ue&&(I?I():v.default.createElement(Ne,null)),v.default.createElement(Ge,{key:`auth-epoch-${O}-frame-${f}`,$isReady:h,$collapsed:Ue,ref:A,src:W,...Oe}))};ve.propTypes={id:g.default.string,src:g.default.string.isRequired,path:g.default.string,onInit:g.default.func,onTimeout:g.default.func,onRemount:g.default.func,onStall:g.default.func,renderUnsupported:g.default.func,renderTimeout:g.default.func},E.CREDENTIAL_KIND_ACCESS_TOKEN=me,E.EmbeddedAuthorizationContext=te,E.MMEmbeddableZone=ve,E.MMEmbeddableZoneContext=ue,E.MMEmbeddableZoneProvider=Ae,E.isCrossSite=de,E.normalizeCredential=le,E.popupAuthorizationLauncher=ke,E.unsupportedCopy=Se,E.useEmbeddedAuthorizations=we,E.useEmbeddedCredential=_e,E.useEmbeddedEffect=N,E.useEmbeddedOriginEpoch=Te,E.useEmbeddedUnsupported=ye,Object.defineProperty(E,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.3-3",
3
+ "version": "2.0.3-4",
4
4
  "license": "MIT",
5
5
  "module": "dist/mm-react-embeddable.es.js",
6
6
  "main": "dist/mm-react-embeddable.cjs.js",