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

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