@machinemetrics/mm-react-embeddable 2.0.1-1 → 2.0.1-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,5 +23,5 @@ the app and where it runs; footer Cancel/Approve; checkbox rows when several app
23
23
  pending; legacy rows keep their own Authorize button because a popup must open from
24
24
  the user's click on that row).
25
25
 
26
- A host without a `credentialBroker`, or a broker answer the host may not act on, gets an
27
- interactive entry, and the host's UI opens the popup for it.
26
+ A host with no `credentialBroker`, or one whose broker returns an answer it may not act on, gets
27
+ an interactive entry, and the host's UI opens the popup for it.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),ge=require("prop-types"),me=require("styled-components"),V=r=>r&&r.__esModule?r:{default:r},O=V(e),k=V(ge),te=V(me),Q=e.createContext(null),Y=e.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),oe="access_token",J=r=>r?r.kind?r:r.accessToken?{kind:oe,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,Ee=60,Re=120,ke=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),G=r=>{try{return new URL(r).origin}catch{return null}},re=(r,o)=>{const i=o==null?void 0:o.origin;return!i||G(r==null?void 0:r.authUrl)!==i?null:i},ne=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const o=r.split(".");return o.length<=2?r:o.slice(-2).join(".")},N=(r,o)=>{try{const i=new URL(r),d=new URL(o);return i.protocol!==d.protocol?!0:ne(i.hostname)!==ne(d.hostname)}catch{return!0}},ue=(r,{onBlocked:o,onClosed:i})=>{const d=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!d)return o(),()=>{};const R=setInterval(()=>{d.closed&&(clearInterval(R),i())},1e3);return()=>clearInterval(R)},ce=({children:r,launcher:o,broker:i})=>{const d=e.useContext(Q),[R,C]=e.useState({}),[$,v]=e.useState({}),[D,Z]=e.useState({}),[I,E]=e.useState({}),S=e.useRef(D);S.current=D;const W=e.useRef(R);W.current=R;const w=e.useRef(null),x=e.useRef({}),y=e.useRef({}),P=e.useRef(i);P.current=i;const U=e.useCallback(t=>{const s=x.current[t];if(!s)return;const n=c=>!c[t]||c[t].clientId?c:{...c,[t]:{...c[t],clientId:s}};C(n),E(n)},[]),F=e.useCallback((t,s)=>{t&&(E(n=>n[t]?n:{...n,[t]:{origin:t,reason:s,clientId:x.current[t]||null}}),U(t))},[U]),A=e.useCallback((t,{v2:s=!1,origin:n=null}={})=>{n&&(s&&S.current[n]||(C(c=>c[n]?c:{...c,[n]:{origin:n,authUrl:t.authUrl,status:s&&P.current?"broker":"interactive",v2:s,scope:t.scope||null,acceptsCredentials:y.current[n]||null,consent:null,error:null,clientId:t.clientId||x.current[n]||null,popupBlocked:!1}}),U(n)))},[U]),T=e.useRef({}),q=e.useCallback(t=>{T.current[t]&&(clearTimeout(T.current[t]),delete T.current[t])},[]),u=e.useCallback(t=>{q(t),C(s=>{if(!s[t])return s;const n={...s};return delete n[t],n})},[q]),l=e.useCallback(t=>{t&&(u(t),v(s=>({...s,[t]:(s[t]||0)+1})))},[u]),a=e.useCallback(t=>{u(t.origin)},[u]),p=e.useCallback((t,s)=>{const n=re(t,s);if(n){if(N(n,window.location.origin)){F(n,"cross-site-legacy");return}A(t,{origin:n})}},[A,F]);e.useEffect(()=>{if(!d)return;const t=[d.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(x.current[n.origin]=s.clientId,U(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?y.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&N(n.origin,window.location.origin)&&F(n.origin,"cross-site-legacy")}),d.addListener("*","authorize",p),d.addListener("*","login",p),d.addListener("*","credential-request",(s,n)=>A(s,{v2:!0,origin:re(s,n)}))];return()=>t.forEach(s=>s())},[d,p,A,U,F]),e.useEffect(()=>{const t=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const c=G(n.authUrl);if(!c||s.origin!==c)return;const b=W.current[c];if(!(!b||b.status!=="interactive")){if(n.accessToken){Z(L=>({...L,[c]:J({accessToken:n.accessToken})})),u(c);return}l(c)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[u,l]);const h=e.useCallback((t,s)=>{const n=t==null?void 0:t.origin,c=J(s);!n||!c||(Z(b=>({...b,[n]:c})),u(n))},[u]),g=e.useCallback((t,s)=>{C(n=>n[t]?{...n,[t]:{...n[t],...s}}:n)},[]),m=e.useRef({}),_=e.useCallback(async(t,{approve:s}={})=>{const n=P.current,{origin:c}=t;let b;try{b=await n({origin:c,clientId:t.clientId,scope:t.scope,authUrl:t.authUrl},{approve:s})}catch{s?g(c,{error:{reason:"broker_unavailable"}}):g(c,{status:"interactive"});return}const L=b==null?void 0:b.status,f=(b==null?void 0:b.body)||{};if(L===200&&f.credential){h(t,f.credential);return}if(L===409&&f.consentRequired){g(c,{status:"interactive",consent:{client:f.client||null,stepUp:!!f.stepUp,scope:f.scope||t.scope},error:null});return}const z=f.error||"broker_error";if(!s&&ke.has(z)){g(c,{status:"interactive"});return}if(s&&z==="consent_denied"){g(c,{error:null});return}if(z==="rate_limited"&&!t.rateLimitRetried){const X=Math.min(Number(f.retryAfter)>0?Number(f.retryAfter):Ee,Re),he={...t,rateLimitRetried:!0};q(c),T.current[c]=setTimeout(()=>{delete T.current[c],m.current[c]=!0,M.current(he,{approve:s}).finally(()=>{delete m.current[c]})},X*1e3),g(c,{rateLimitRetried:!0});return}u(c),E(X=>({...X,[c]:{origin:c,reason:`broker:${z}`,detail:{status:L!=null?L:null,reason:z},clientId:t.clientId||x.current[c]||null}}))},[h,g,u,q]),M=e.useRef(_);M.current=_,e.useEffect(()=>{Object.values(R).forEach(t=>{t.status!=="broker"||m.current[t.origin]||T.current[t.origin]||(m.current[t.origin]=!0,_(t).finally(()=>{delete m.current[t.origin]}))})},[R,_]);const K=e.useCallback(t=>!P.current||!(t!=null&&t.consent)||m.current[t.origin]?Promise.resolve():(m.current[t.origin]=!0,_(t,{approve:!0}).finally(()=>{delete m.current[t.origin]})),[_]);e.useEffect(()=>()=>{w.current&&w.current(),Object.values(T.current).forEach(clearTimeout)},[]);const B=e.useCallback(t=>{w.current&&(w.current(),w.current=null);const s=o||ue;w.current=s(t,{onBlocked:()=>{C(n=>n[t.origin]?{...n,[t.origin]:{...n[t.origin],popupBlocked:!0}}:n)},onClosed:()=>l(t.origin)})},[o,l]),j={pending:Object.values(R).filter(t=>t.status==="interactive"),authorize:B,approve:K,complete:h,dismiss:a,originEpochs:$,credentials:D,unsupported:I};return O.default.createElement(Y.Provider,{value:j},r)};ce.propTypes={children:k.default.node,launcher:k.default.func,broker:k.default.func};const Ce=()=>e.useContext(Y),ie=r=>{const{originEpochs:o}=e.useContext(Y),i=G(r);return i&&o[i]||0},ae=r=>{const{credentials:o}=e.useContext(Y),i=G(r);return i&&o[i]||null},le=r=>{const{unsupported:o}=e.useContext(Y),i=G(r);return i&&o[i]||null},se="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.",de=({children:r,authorizationLauncher:o,credentialBroker:i,ready:d})=>{const R=d===!0,C=e.useRef(!1);e.useEffect(()=>{d!==void 0||C.current||(C.current=!0,console.error(se),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(se))},[d]);const[$,v]=e.useState({}),[D,Z]=e.useState({}),I=e.useRef({}),E=e.useRef({}),S=e.useRef({}),W=e.useCallback((u,l)=>{var a;return!!((a=S.current[u])!=null&&a.has(l))},[]),w=e.useCallback((u,l,a)=>{v(p=>({...p,[u]:{origin:l,frameRef:a}}))},[]),x=e.useCallback(u=>{v(l=>{const a={...l};return delete a[u],a}),Z(l=>{const a={...l};return delete a[u],a}),delete S.current[u],Object.keys(E.current).forEach(l=>{E.current[l].instanceId===u&&delete E.current[l]})},[]);e.useEffect(()=>()=>{E.current={}},[]),e.useEffect(()=>{const u=(a=[],p,h)=>{a.forEach(g=>g(p,h))},l=a=>{var K,B,j,t,s,n,c;if(!((K=a==null?void 0:a.data)!=null&&K.instanceId))return;const{instanceId:p,type:h}=a.data,g=$[p],m=(j=(B=g==null?void 0:g.frameRef)==null?void 0:B.current)==null?void 0:j.contentWindow;if(!m||a.source!==m||a.origin!==g.origin)return;const _={origin:a.origin},M=I.current;if(h==="response"){const{callbackId:b,response:L,error:f}=a.data,z=E.current[b];z&&z.instanceId===p&&(z.callback(L,f),delete E.current[b]);return}if(h==="mark-registered"){const{requestType:b}=a.data;S.current[p]||(S.current[p]=new Set),S.current[p].add(b);return}h==="ready"&&Z(b=>({...b,[p]:!0})),u((t=M[p])==null?void 0:t[h],a.data,_),u((s=M["*"])==null?void 0:s[h],a.data,_),u((n=M[p])==null?void 0:n["*"],a.data,_),u((c=M["*"])==null?void 0:c["*"],a.data,_)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[$]);const y=e.useCallback((u,l,a,p)=>{var g,m;const h=$[u];if(!h){console.warn(`Origin not set for id: ${u}. Unable to send message.`);return}(m=(g=h==null?void 0:h.frameRef)==null?void 0:g.current)!=null&&m.contentWindow&&h.frameRef.current.contentWindow.postMessage({type:l,...a,instanceId:u},p||h.origin)},[$]),P=e.useRef(0),U=e.useCallback(()=>`${Date.now()}-${++P.current}`,[]),F=e.useCallback(async(u,l,a={})=>new Promise((p,h)=>{const g=U(),m=(_,M)=>{delete E.current[g],M?h(M):p(_)};E.current[g]={instanceId:u,callback:m},y(u,"request",{callbackId:g,requestType:l,data:a})}),[y]),A=e.useCallback((u,l)=>{y(u,"load-options",l)},[y]),T=e.useCallback((u,l)=>{y(u,"validate",l)},[y]),q=e.useMemo(()=>({registerFrame:w,unregisterFrame:x,sendMessage:y,sendRequest:F,loadOptions:A,validate:T,hasHandler:W,readyFrames:D,ready:R,addListener:(u,l,a)=>(I.current[u]||(I.current[u]={}),I.current[u][l]||(I.current[u][l]=[]),I.current[u][l].push(a),()=>{I.current[u][l]=I.current[u][l].filter(p=>p!==a)})}),[w,x,y,F,A,T,W,D,R]);return O.default.createElement(Q.Provider,{value:q},O.default.createElement(ce,{launcher:o,broker:i},r))},H=(r,o,i)=>{const d=e.useContext(Q);if(d===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const R=e.useRef(i);e.useEffect(()=>{R.current=i},[i]),e.useEffect(()=>{if(!(!r||!o)){if(o.startsWith("key:")){const C=o.substring(4);return d.readyFrames[r]&&d.sendMessage(r,"subscribe-key",{keyChord:C}),d.addListener(r,`key-pressed:${C}`,(...v)=>R.current(...v))}return d.addListener(r,o,(...C)=>R.current(...C))}},[d,r,o])};de.propTypes={children:k.default.node.isRequired,ready:k.default.bool.isRequired,authorizationLauncher:k.default.func,credentialBroker:k.default.func};const ee=te.default.default||te.default,we=1e4,Te="credentials",_e=(r,o)=>`${r}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Te}`,Ie=ee.iframe`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),ge=require("prop-types"),me=require("styled-components"),V=r=>r&&r.__esModule?r:{default:r},O=V(e),k=V(ge),te=V(me),Q=e.createContext(null),Y=e.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),oe="access_token",J=r=>r?r.kind?r:r.accessToken?{kind:oe,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,Ee=60,Re=120,ke=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),G=r=>{try{return new URL(r).origin}catch{return null}},re=(r,o)=>{const i=o==null?void 0:o.origin;return!i||G(r==null?void 0:r.authUrl)!==i?null:i},ne=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const o=r.split(".");return o.length<=2?r:o.slice(-2).join(".")},N=(r,o)=>{try{const i=new URL(r),d=new URL(o);return i.protocol!==d.protocol?!0:ne(i.hostname)!==ne(d.hostname)}catch{return!0}},ue=(r,{onBlocked:o,onClosed:i})=>{const d=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!d)return o(),()=>{};const R=setInterval(()=>{d.closed&&(clearInterval(R),i())},1e3);return()=>clearInterval(R)},ce=({children:r,launcher:o,broker:i})=>{const d=e.useContext(Q),[R,C]=e.useState({}),[$,q]=e.useState({}),[D,W]=e.useState({}),[I,E]=e.useState({}),S=e.useRef(D);S.current=D;const B=e.useRef(R);B.current=R;const w=e.useRef(null),x=e.useRef({}),y=e.useRef({}),P=e.useRef(i);P.current=i;const U=e.useCallback(t=>{const s=x.current[t];if(!s)return;const n=c=>!c[t]||c[t].clientId?c:{...c,[t]:{...c[t],clientId:s}};C(n),E(n)},[]),F=e.useCallback((t,s)=>{t&&(E(n=>n[t]?n:{...n,[t]:{origin:t,reason:s,clientId:x.current[t]||null}}),U(t))},[U]),A=e.useCallback((t,{v2:s=!1,origin:n=null}={})=>{n&&(s&&S.current[n]||(C(c=>c[n]?c:{...c,[n]:{origin:n,authUrl:t.authUrl,status:s&&P.current?"broker":"interactive",v2:s,scope:t.scope||null,acceptsCredentials:y.current[n]||null,consent:null,error:null,clientId:t.clientId||x.current[n]||null,popupBlocked:!1}}),U(n)))},[U]),T=e.useRef({}),v=e.useCallback(t=>{T.current[t]&&(clearTimeout(T.current[t]),delete T.current[t])},[]),u=e.useCallback(t=>{v(t),C(s=>{if(!s[t])return s;const n={...s};return delete n[t],n})},[v]),l=e.useCallback(t=>{t&&(u(t),q(s=>({...s,[t]:(s[t]||0)+1})))},[u]),a=e.useCallback(t=>{u(t.origin)},[u]),p=e.useCallback((t,s)=>{const n=re(t,s);if(n){if(N(n,window.location.origin)){F(n,"cross-site-legacy");return}A(t,{origin:n})}},[A,F]);e.useEffect(()=>{if(!d)return;const t=[d.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(x.current[n.origin]=s.clientId,U(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?y.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&N(n.origin,window.location.origin)&&F(n.origin,"cross-site-legacy")}),d.addListener("*","authorize",p),d.addListener("*","login",p),d.addListener("*","credential-request",(s,n)=>A(s,{v2:!0,origin:re(s,n)}))];return()=>t.forEach(s=>s())},[d,p,A,U,F]),e.useEffect(()=>{const t=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const c=G(n.authUrl);if(!c||s.origin!==c)return;const b=B.current[c];if(!(!b||b.status!=="interactive")){if(n.accessToken){W(L=>({...L,[c]:J({accessToken:n.accessToken})})),u(c);return}l(c)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[u,l]);const h=e.useCallback((t,s)=>{const n=t==null?void 0:t.origin,c=J(s);!n||!c||(W(b=>({...b,[n]:c})),u(n))},[u]),g=e.useCallback((t,s)=>{C(n=>n[t]?{...n,[t]:{...n[t],...s}}:n)},[]),m=e.useRef({}),_=e.useCallback(async(t,{approve:s}={})=>{const n=P.current,{origin:c}=t;let b;try{b=await n({origin:c,clientId:t.clientId,scope:t.scope,authUrl:t.authUrl},{approve:s})}catch{s?g(c,{error:{reason:"broker_unavailable"}}):g(c,{status:"interactive"});return}const L=b==null?void 0:b.status,f=(b==null?void 0:b.body)||{};if(L===200&&f.credential){h(t,f.credential);return}if(L===409&&f.consentRequired){g(c,{status:"interactive",consent:{client:f.client||null,stepUp:!!f.stepUp,scope:f.scope||t.scope},error:null});return}const z=f.error||"broker_error";if(!s&&ke.has(z)){g(c,{status:"interactive"});return}if(s&&z==="consent_denied"){g(c,{error:null});return}if(z==="rate_limited"&&!t.rateLimitRetried){const X=Math.min(Number(f.retryAfter)>0?Number(f.retryAfter):Ee,Re),he={...t,rateLimitRetried:!0};v(c),T.current[c]=setTimeout(()=>{delete T.current[c],m.current[c]=!0,M.current(he,{approve:s}).finally(()=>{delete m.current[c]})},X*1e3),g(c,{rateLimitRetried:!0});return}u(c),E(X=>({...X,[c]:{origin:c,reason:`broker:${z}`,detail:{status:L!=null?L:null,reason:z},clientId:t.clientId||x.current[c]||null}}))},[h,g,u,v]),M=e.useRef(_);M.current=_,e.useEffect(()=>{Object.values(R).forEach(t=>{t.status!=="broker"||m.current[t.origin]||T.current[t.origin]||(m.current[t.origin]=!0,_(t).finally(()=>{delete m.current[t.origin]}))})},[R,_]);const K=e.useCallback(t=>!P.current||!(t!=null&&t.consent)||m.current[t.origin]?Promise.resolve():(m.current[t.origin]=!0,_(t,{approve:!0}).finally(()=>{delete m.current[t.origin]})),[_]);e.useEffect(()=>()=>{w.current&&w.current(),Object.values(T.current).forEach(clearTimeout)},[]);const Z=e.useCallback(t=>{w.current&&(w.current(),w.current=null);const s=o||ue;w.current=s(t,{onBlocked:()=>{C(n=>n[t.origin]?{...n,[t.origin]:{...n[t.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=B.current[t.origin];!n||n.v2||l(t.origin)}})},[o,l]),j={pending:Object.values(R).filter(t=>t.status==="interactive"),authorize:Z,approve:K,complete:h,dismiss:a,originEpochs:$,credentials:D,unsupported:I};return O.default.createElement(Y.Provider,{value:j},r)};ce.propTypes={children:k.default.node,launcher:k.default.func,broker:k.default.func};const Ce=()=>e.useContext(Y),ie=r=>{const{originEpochs:o}=e.useContext(Y),i=G(r);return i&&o[i]||0},ae=r=>{const{credentials:o}=e.useContext(Y),i=G(r);return i&&o[i]||null},le=r=>{const{unsupported:o}=e.useContext(Y),i=G(r);return i&&o[i]||null},se="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.",de=({children:r,authorizationLauncher:o,credentialBroker:i,ready:d})=>{const R=d===!0,C=e.useRef(!1);e.useEffect(()=>{d!==void 0||C.current||(C.current=!0,console.error(se),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(se))},[d]);const[$,q]=e.useState({}),[D,W]=e.useState({}),I=e.useRef({}),E=e.useRef({}),S=e.useRef({}),B=e.useCallback((u,l)=>{var a;return!!((a=S.current[u])!=null&&a.has(l))},[]),w=e.useCallback((u,l,a)=>{q(p=>({...p,[u]:{origin:l,frameRef:a}}))},[]),x=e.useCallback(u=>{q(l=>{const a={...l};return delete a[u],a}),W(l=>{const a={...l};return delete a[u],a}),delete S.current[u],Object.keys(E.current).forEach(l=>{E.current[l].instanceId===u&&delete E.current[l]})},[]);e.useEffect(()=>()=>{E.current={}},[]),e.useEffect(()=>{const u=(a=[],p,h)=>{a.forEach(g=>g(p,h))},l=a=>{var K,Z,j,t,s,n,c;if(!((K=a==null?void 0:a.data)!=null&&K.instanceId))return;const{instanceId:p,type:h}=a.data,g=$[p],m=(j=(Z=g==null?void 0:g.frameRef)==null?void 0:Z.current)==null?void 0:j.contentWindow;if(!m||a.source!==m||a.origin!==g.origin)return;const _={origin:a.origin},M=I.current;if(h==="response"){const{callbackId:b,response:L,error:f}=a.data,z=E.current[b];z&&z.instanceId===p&&(z.callback(L,f),delete E.current[b]);return}if(h==="mark-registered"){const{requestType:b}=a.data;S.current[p]||(S.current[p]=new Set),S.current[p].add(b);return}h==="ready"&&W(b=>({...b,[p]:!0})),u((t=M[p])==null?void 0:t[h],a.data,_),u((s=M["*"])==null?void 0:s[h],a.data,_),u((n=M[p])==null?void 0:n["*"],a.data,_),u((c=M["*"])==null?void 0:c["*"],a.data,_)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[$]);const y=e.useCallback((u,l,a,p)=>{var g,m;const h=$[u];if(!h){console.warn(`Origin not set for id: ${u}. Unable to send message.`);return}(m=(g=h==null?void 0:h.frameRef)==null?void 0:g.current)!=null&&m.contentWindow&&h.frameRef.current.contentWindow.postMessage({type:l,...a,instanceId:u},p||h.origin)},[$]),P=e.useRef(0),U=e.useCallback(()=>`${Date.now()}-${++P.current}`,[]),F=e.useCallback(async(u,l,a={})=>new Promise((p,h)=>{const g=U(),m=(_,M)=>{delete E.current[g],M?h(M):p(_)};E.current[g]={instanceId:u,callback:m},y(u,"request",{callbackId:g,requestType:l,data:a})}),[y]),A=e.useCallback((u,l)=>{y(u,"load-options",l)},[y]),T=e.useCallback((u,l)=>{y(u,"validate",l)},[y]),v=e.useMemo(()=>({registerFrame:w,unregisterFrame:x,sendMessage:y,sendRequest:F,loadOptions:A,validate:T,hasHandler:B,readyFrames:D,ready:R,addListener:(u,l,a)=>(I.current[u]||(I.current[u]={}),I.current[u][l]||(I.current[u][l]=[]),I.current[u][l].push(a),()=>{I.current[u][l]=I.current[u][l].filter(p=>p!==a)})}),[w,x,y,F,A,T,B,D,R]);return O.default.createElement(Q.Provider,{value:v},O.default.createElement(ce,{launcher:o,broker:i},r))},H=(r,o,i)=>{const d=e.useContext(Q);if(d===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const R=e.useRef(i);e.useEffect(()=>{R.current=i},[i]),e.useEffect(()=>{if(!(!r||!o)){if(o.startsWith("key:")){const C=o.substring(4);return d.readyFrames[r]&&d.sendMessage(r,"subscribe-key",{keyChord:C}),d.addListener(r,`key-pressed:${C}`,(...q)=>R.current(...q))}return d.addListener(r,o,(...C)=>R.current(...C))}},[d,r,o])};de.propTypes={children:k.default.node.isRequired,ready:k.default.bool.isRequired,authorizationLauncher:k.default.func,credentialBroker:k.default.func};const ee=te.default.default||te.default,we=1e4,Te="credentials",_e=(r,o)=>`${r}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Te}`,Ie=ee.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
@@ -22,4 +22,4 @@
22
22
  flex: 1;
23
23
  align-items: center;
24
24
  justify-content: center;
25
- `,Se=()=>O.default.createElement(ye,null,O.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),be=({id:r,src:o,path:i,onInit:d=()=>{},onTimeout:R,context:C={},params:$={},renderUnsupported:v,renderTimeout:D,...Z})=>{if("isConfiguring"in Z)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in C)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in C)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const I=e.useRef(),E=G(o),[S,W]=e.useState(),[w,x]=e.useState(0),[y,P]=e.useState(!1),[U,F]=e.useState(!1),A=ie(o),T=ae(o),q=le(o),[u,l]=e.useState(0),[a,p]=e.useState(null),{registerFrame:h,unregisterFrame:g,sendMessage:m,ready:_}=e.useContext(Q),[M,K]=e.useState(),B=e.useRef(),j=e.useRef(R),t=e.useRef(d),s=e.useRef(!1),n=e.useRef(),c=e.useCallback(()=>{s.current=!1,clearTimeout(B.current),clearTimeout(n.current),x(0),P(!1),F(!1),p(null)},[]);e.useEffect(()=>{(A>0||u>0)&&c()},[A,u,c]),e.useEffect(()=>{j.current=R},[R]),e.useEffect(()=>{t.current=d},[d]),e.useEffect(()=>{w&&m(r,"set-context",{context:{...C}},E)},[C,r,w,E]),e.useEffect(()=>{w&&m(r,"set-params",{params:$},E)},[$,r,w,E]),e.useEffect(()=>{i!==void 0&&K((i==null?void 0:i.indexOf("/"))===0?i:`/${i}`)},[i]),e.useEffect(()=>{M===void 0||!w||m(r,"navigate",{path:M},E)},[M,w,r,m,E]),e.useEffect(()=>{if(!o||!r||!I)return;if(!_){c(),W(void 0);return}c();const f=new URL(o);return h(r,f.origin,I),t.current(),W(_e(f.origin,r)),()=>{g(r)}},[o,r,_,h,I,c]),e.useEffect(()=>{if(!(!S||s.current))return B.current=setTimeout(()=>{P(!0),j.current&&j.current()},we),()=>clearTimeout(B.current)},[S,o,A,u]);const b=e.useCallback(()=>{s.current=!0,clearTimeout(B.current),P(!1)},[]);if(H(r,"init",f=>{b(),Array.isArray(f==null?void 0:f.acceptsCredentials)&&p(f.acceptsCredentials)}),H(r,"authorize",b),H(r,"login",b),H(r,"credential-request",()=>{b(),F(!0)}),e.useEffect(()=>{if(!U||!T)return;const f=a;if(Array.isArray(f)&&!f.includes(T.kind))return;const z=T.kind==="access_token"?{accessToken:T.accessToken}:{};m(r,"credential",{...z,credential:T},E)},[U,T,a,r,m,E]),H(r,"ready",()=>{b(),x(f=>f+1)}),H(r,"heartbeat",()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{l(f=>f+1)},6e3)}),e.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]),q)return v?v(q):O.default.createElement(pe,{entry:q});if(y&&!w)return D?D():O.default.createElement(Se,null);const L={...Z};return delete L.skipManifestCheck,O.default.createElement(Ie,{key:`auth-epoch-${A}-frame-${u}`,$isReady:w,ref:I,src:S,...L})};be.propTypes={id:k.default.string,src:k.default.string.isRequired,path:k.default.string,onInit:k.default.func,onTimeout:k.default.func,renderUnsupported:k.default.func,renderTimeout:k.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=oe;exports.EmbeddedAuthorizationContext=Y;exports.MMEmbeddableZone=be;exports.MMEmbeddableZoneContext=Q;exports.MMEmbeddableZoneProvider=de;exports.isCrossSite=N;exports.normalizeCredential=J;exports.popupAuthorizationLauncher=ue;exports.unsupportedCopy=fe;exports.useEmbeddedAuthorizations=Ce;exports.useEmbeddedCredential=ae;exports.useEmbeddedEffect=H;exports.useEmbeddedOriginEpoch=ie;exports.useEmbeddedUnsupported=le;
25
+ `,Se=()=>O.default.createElement(ye,null,O.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),be=({id:r,src:o,path:i,onInit:d=()=>{},onTimeout:R,context:C={},params:$={},renderUnsupported:q,renderTimeout:D,...W})=>{if("isConfiguring"in W)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in C)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in C)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const I=e.useRef(),E=G(o),[S,B]=e.useState(),[w,x]=e.useState(0),[y,P]=e.useState(!1),[U,F]=e.useState(!1),A=ie(o),T=ae(o),v=le(o),[u,l]=e.useState(0),[a,p]=e.useState(null),{registerFrame:h,unregisterFrame:g,sendMessage:m,ready:_}=e.useContext(Q),[M,K]=e.useState(),Z=e.useRef(),j=e.useRef(R),t=e.useRef(d),s=e.useRef(!1),n=e.useRef(),c=e.useCallback(()=>{s.current=!1,clearTimeout(Z.current),clearTimeout(n.current),x(0),P(!1),F(!1),p(null)},[]);e.useEffect(()=>{(A>0||u>0)&&c()},[A,u,c]),e.useEffect(()=>{j.current=R},[R]),e.useEffect(()=>{t.current=d},[d]),e.useEffect(()=>{w&&m(r,"set-context",{context:{...C}},E)},[C,r,w,E]),e.useEffect(()=>{w&&m(r,"set-params",{params:$},E)},[$,r,w,E]),e.useEffect(()=>{i!==void 0&&K((i==null?void 0:i.indexOf("/"))===0?i:`/${i}`)},[i]),e.useEffect(()=>{M===void 0||!w||m(r,"navigate",{path:M},E)},[M,w,r,m,E]),e.useEffect(()=>{if(!o||!r||!I)return;if(!_){c(),B(void 0);return}c();const f=new URL(o);return h(r,f.origin,I),t.current(),B(_e(f.origin,r)),()=>{g(r)}},[o,r,_,h,I,c]),e.useEffect(()=>{if(!(!S||s.current))return Z.current=setTimeout(()=>{P(!0),j.current&&j.current()},we),()=>clearTimeout(Z.current)},[S,o,A,u]);const b=e.useCallback(()=>{s.current=!0,clearTimeout(Z.current),P(!1)},[]);if(H(r,"init",f=>{b(),Array.isArray(f==null?void 0:f.acceptsCredentials)&&p(f.acceptsCredentials)}),H(r,"authorize",b),H(r,"login",b),H(r,"credential-request",()=>{b(),F(!0)}),e.useEffect(()=>{if(!U||!T)return;const f=a;if(Array.isArray(f)&&!f.includes(T.kind))return;const z=T.kind==="access_token"?{accessToken:T.accessToken}:{};m(r,"credential",{...z,credential:T},E)},[U,T,a,r,m,E]),H(r,"ready",()=>{b(),x(f=>f+1)}),H(r,"heartbeat",()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{l(f=>f+1)},6e3)}),e.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]),v)return q?q(v):O.default.createElement(pe,{entry:v});if(y&&!w)return D?D():O.default.createElement(Se,null);const L={...W};return delete L.skipManifestCheck,O.default.createElement(Ie,{key:`auth-epoch-${A}-frame-${u}`,$isReady:w,ref:I,src:S,...L})};be.propTypes={id:k.default.string,src:k.default.string.isRequired,path:k.default.string,onInit:k.default.func,onTimeout:k.default.func,renderUnsupported:k.default.func,renderTimeout:k.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=oe;exports.EmbeddedAuthorizationContext=Y;exports.MMEmbeddableZone=be;exports.MMEmbeddableZoneContext=Q;exports.MMEmbeddableZoneProvider=de;exports.isCrossSite=N;exports.normalizeCredential=J;exports.popupAuthorizationLauncher=ue;exports.unsupportedCopy=fe;exports.useEmbeddedAuthorizations=Ce;exports.useEmbeddedCredential=ae;exports.useEmbeddedEffect=H;exports.useEmbeddedOriginEpoch=ie;exports.useEmbeddedUnsupported=le;
@@ -14,39 +14,39 @@ const ee = ue(null), V = ue({
14
14
  originEpochs: {},
15
15
  credentials: {},
16
16
  unsupported: {}
17
- }), pe = "access_token", ne = (r) => r ? r.kind ? r : r.accessToken ? {
17
+ }), pe = "access_token", ne = (t) => t ? t.kind ? t : t.accessToken ? {
18
18
  kind: pe,
19
- accessToken: r.accessToken,
20
- expiresAt: r.expiresAt || null
21
- } : null : null, he = 60, ge = 120, me = /* @__PURE__ */ new Set([
19
+ accessToken: t.accessToken,
20
+ expiresAt: t.expiresAt || null
21
+ } : null : null, ge = 60, he = 120, me = /* @__PURE__ */ new Set([
22
22
  "host_not_allowed",
23
23
  "unbound_host_bound_guest",
24
24
  "invalid_token",
25
25
  "provider_unavailable"
26
- ]), J = (r) => {
26
+ ]), J = (t) => {
27
27
  try {
28
- return new URL(r).origin;
28
+ return new URL(t).origin;
29
29
  } catch {
30
30
  return null;
31
31
  }
32
- }, se = (r, s) => {
32
+ }, se = (t, s) => {
33
33
  const i = s == null ? void 0 : s.origin;
34
- return !i || J(r == null ? void 0 : r.authUrl) !== i ? null : i;
35
- }, oe = (r) => {
36
- if (!r || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(r) || r.includes(":"))
37
- return r;
38
- const s = r.split(".");
39
- return s.length <= 2 ? r : s.slice(-2).join(".");
40
- }, ce = (r, s) => {
34
+ return !i || J(t == null ? void 0 : t.authUrl) !== i ? null : i;
35
+ }, oe = (t) => {
36
+ if (!t || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(t) || t.includes(":"))
37
+ return t;
38
+ const s = t.split(".");
39
+ return s.length <= 2 ? t : s.slice(-2).join(".");
40
+ }, ce = (t, s) => {
41
41
  try {
42
- const i = new URL(r), l = new URL(s);
42
+ const i = new URL(t), l = new URL(s);
43
43
  return i.protocol !== l.protocol ? !0 : oe(i.hostname) !== oe(l.hostname);
44
44
  } catch {
45
45
  return !0;
46
46
  }
47
- }, be = (r, { onBlocked: s, onClosed: i }) => {
47
+ }, be = (t, { onBlocked: s, onClosed: i }) => {
48
48
  const l = window.open(
49
- r.authUrl,
49
+ t.authUrl,
50
50
  "mm-embed-auth",
51
51
  "popup,width=600,height=700"
52
52
  );
@@ -57,23 +57,23 @@ const ee = ue(null), V = ue({
57
57
  l.closed && (clearInterval(w), i());
58
58
  }, 1e3);
59
59
  return () => clearInterval(w);
60
- }, ae = ({ children: r, launcher: s, broker: i }) => {
61
- const l = G(ee), [w, I] = U({}), [v, D] = U({}), [j, H] = U({}), [y, E] = U({}), x = R(j);
60
+ }, ae = ({ children: t, launcher: s, broker: i }) => {
61
+ const l = G(ee), [w, I] = U({}), [v, D] = U({}), [j, K] = U({}), [y, E] = U({}), x = R(j);
62
62
  x.current = j;
63
- const K = R(w);
64
- K.current = w;
63
+ const Z = R(w);
64
+ Z.current = w;
65
65
  const _ = R(null), $ = R({}), A = R({}), q = R(i);
66
66
  q.current = i;
67
67
  const F = b((e) => {
68
68
  const n = $.current[e];
69
69
  if (!n)
70
70
  return;
71
- const t = (c) => !c[e] || c[e].clientId ? c : { ...c, [e]: { ...c[e], clientId: n } };
72
- I(t), E(t);
71
+ const r = (c) => !c[e] || c[e].clientId ? c : { ...c, [e]: { ...c[e], clientId: n } };
72
+ I(r), E(r);
73
73
  }, []), B = b(
74
74
  (e, n) => {
75
- e && (E((t) => t[e] ? t : {
76
- ...t,
75
+ e && (E((r) => r[e] ? r : {
76
+ ...r,
77
77
  [e]: {
78
78
  origin: e,
79
79
  reason: n,
@@ -83,22 +83,22 @@ const ee = ue(null), V = ue({
83
83
  },
84
84
  [F]
85
85
  ), z = b(
86
- (e, { v2: n = !1, origin: t = null } = {}) => {
87
- t && (n && x.current[t] || (I((c) => c[t] ? c : {
86
+ (e, { v2: n = !1, origin: r = null } = {}) => {
87
+ r && (n && x.current[r] || (I((c) => c[r] ? c : {
88
88
  ...c,
89
- [t]: {
90
- origin: t,
89
+ [r]: {
90
+ origin: r,
91
91
  authUrl: e.authUrl,
92
92
  status: n && q.current ? "broker" : "interactive",
93
93
  v2: n,
94
94
  scope: e.scope || null,
95
- acceptsCredentials: A.current[t] || null,
95
+ acceptsCredentials: A.current[r] || null,
96
96
  consent: null,
97
97
  error: null,
98
- clientId: e.clientId || $.current[t] || null,
98
+ clientId: e.clientId || $.current[r] || null,
99
99
  popupBlocked: !1
100
100
  }
101
- }), F(t)));
101
+ }), F(r)));
102
102
  },
103
103
  [F]
104
104
  ), M = R({}), W = b((e) => {
@@ -108,8 +108,8 @@ const ee = ue(null), V = ue({
108
108
  W(e), I((n) => {
109
109
  if (!n[e])
110
110
  return n;
111
- const t = { ...n };
112
- return delete t[e], t;
111
+ const r = { ...n };
112
+ return delete r[e], r;
113
113
  });
114
114
  },
115
115
  [W]
@@ -128,13 +128,13 @@ const ee = ue(null), V = ue({
128
128
  [o]
129
129
  ), f = b(
130
130
  (e, n) => {
131
- const t = se(e, n);
132
- if (t) {
133
- if (ce(t, window.location.origin)) {
134
- B(t, "cross-site-legacy");
131
+ const r = se(e, n);
132
+ if (r) {
133
+ if (ce(r, window.location.origin)) {
134
+ B(r, "cross-site-legacy");
135
135
  return;
136
136
  }
137
- z(e, { origin: t });
137
+ z(e, { origin: r });
138
138
  }
139
139
  },
140
140
  [z, B]
@@ -143,32 +143,32 @@ const ee = ue(null), V = ue({
143
143
  if (!l)
144
144
  return;
145
145
  const e = [
146
- l.addListener("*", "init", (n, t) => {
147
- t != null && t.origin && (n != null && n.clientId) && ($.current[t.origin] = n.clientId, F(t.origin)), t != null && t.origin && Array.isArray(n == null ? void 0 : n.acceptsCredentials) ? A.current[t.origin] = n.acceptsCredentials : t != null && t.origin && ce(t.origin, window.location.origin) && B(t.origin, "cross-site-legacy");
146
+ l.addListener("*", "init", (n, r) => {
147
+ r != null && r.origin && (n != null && n.clientId) && ($.current[r.origin] = n.clientId, F(r.origin)), r != null && r.origin && Array.isArray(n == null ? void 0 : n.acceptsCredentials) ? A.current[r.origin] = n.acceptsCredentials : r != null && r.origin && ce(r.origin, window.location.origin) && B(r.origin, "cross-site-legacy");
148
148
  }),
149
149
  l.addListener("*", "authorize", f),
150
150
  l.addListener("*", "login", f),
151
151
  l.addListener(
152
152
  "*",
153
153
  "credential-request",
154
- (n, t) => z(n, { v2: !0, origin: se(n, t) })
154
+ (n, r) => z(n, { v2: !0, origin: se(n, r) })
155
155
  )
156
156
  ];
157
157
  return () => e.forEach((n) => n());
158
158
  }, [l, f, z, F, B]), k(() => {
159
159
  const e = (n) => {
160
- const t = n == null ? void 0 : n.data;
161
- if (!t || t.type !== "authorized")
160
+ const r = n == null ? void 0 : n.data;
161
+ if (!r || r.type !== "authorized")
162
162
  return;
163
- const c = J(t.authUrl);
163
+ const c = J(r.authUrl);
164
164
  if (!c || n.origin !== c)
165
165
  return;
166
- const p = K.current[c];
166
+ const p = Z.current[c];
167
167
  if (!(!p || p.status !== "interactive")) {
168
- if (t.accessToken) {
169
- H((O) => ({
168
+ if (r.accessToken) {
169
+ K((O) => ({
170
170
  ...O,
171
- [c]: ne({ accessToken: t.accessToken })
171
+ [c]: ne({ accessToken: r.accessToken })
172
172
  })), o(c);
173
173
  return;
174
174
  }
@@ -177,20 +177,20 @@ const ee = ue(null), V = ue({
177
177
  };
178
178
  return window.addEventListener("message", e), () => window.removeEventListener("message", e);
179
179
  }, [o, a]);
180
- const h = b(
180
+ const g = b(
181
181
  (e, n) => {
182
- const t = e == null ? void 0 : e.origin, c = ne(n);
183
- !t || !c || (H((p) => ({ ...p, [t]: c })), o(t));
182
+ const r = e == null ? void 0 : e.origin, c = ne(n);
183
+ !r || !c || (K((p) => ({ ...p, [r]: c })), o(r));
184
184
  },
185
185
  [o]
186
- ), g = b((e, n) => {
187
- I((t) => t[e] ? { ...t, [e]: { ...t[e], ...n } } : t);
186
+ ), h = b((e, n) => {
187
+ I((r) => r[e] ? { ...r, [e]: { ...r[e], ...n } } : r);
188
188
  }, []), m = R({}), C = b(
189
189
  async (e, { approve: n } = {}) => {
190
- const t = q.current, { origin: c } = e;
190
+ const r = q.current, { origin: c } = e;
191
191
  let p;
192
192
  try {
193
- p = await t(
193
+ p = await r(
194
194
  {
195
195
  origin: c,
196
196
  clientId: e.clientId,
@@ -200,16 +200,16 @@ const ee = ue(null), V = ue({
200
200
  { approve: n }
201
201
  );
202
202
  } catch {
203
- n ? g(c, { error: { reason: "broker_unavailable" } }) : g(c, { status: "interactive" });
203
+ n ? h(c, { error: { reason: "broker_unavailable" } }) : h(c, { status: "interactive" });
204
204
  return;
205
205
  }
206
206
  const O = p == null ? void 0 : p.status, d = (p == null ? void 0 : p.body) || {};
207
207
  if (O === 200 && d.credential) {
208
- h(e, d.credential);
208
+ g(e, d.credential);
209
209
  return;
210
210
  }
211
211
  if (O === 409 && d.consentRequired) {
212
- g(c, {
212
+ h(c, {
213
213
  status: "interactive",
214
214
  consent: {
215
215
  client: d.client || null,
@@ -222,23 +222,23 @@ const ee = ue(null), V = ue({
222
222
  }
223
223
  const S = d.error || "broker_error";
224
224
  if (!n && me.has(S)) {
225
- g(c, { status: "interactive" });
225
+ h(c, { status: "interactive" });
226
226
  return;
227
227
  }
228
228
  if (n && S === "consent_denied") {
229
- g(c, { error: null });
229
+ h(c, { error: null });
230
230
  return;
231
231
  }
232
232
  if (S === "rate_limited" && !e.rateLimitRetried) {
233
233
  const N = Math.min(
234
- Number(d.retryAfter) > 0 ? Number(d.retryAfter) : he,
235
- ge
234
+ Number(d.retryAfter) > 0 ? Number(d.retryAfter) : ge,
235
+ he
236
236
  ), de = { ...e, rateLimitRetried: !0 };
237
237
  W(c), M.current[c] = setTimeout(() => {
238
238
  delete M.current[c], m.current[c] = !0, L.current(de, { approve: n }).finally(() => {
239
239
  delete m.current[c];
240
240
  });
241
- }, N * 1e3), g(c, { rateLimitRetried: !0 });
241
+ }, N * 1e3), h(c, { rateLimitRetried: !0 });
242
242
  return;
243
243
  }
244
244
  o(c), E((N) => ({
@@ -251,7 +251,7 @@ const ee = ue(null), V = ue({
251
251
  }
252
252
  }));
253
253
  },
254
- [h, g, o, W]
254
+ [g, h, o, W]
255
255
  ), L = R(C);
256
256
  L.current = C, k(() => {
257
257
  Object.values(w).forEach((e) => {
@@ -269,19 +269,23 @@ const ee = ue(null), V = ue({
269
269
  k(() => () => {
270
270
  _.current && _.current(), Object.values(M.current).forEach(clearTimeout);
271
271
  }, []);
272
- const Z = b(
272
+ const H = b(
273
273
  (e) => {
274
274
  _.current && (_.current(), _.current = null);
275
275
  const n = s || be;
276
276
  _.current = n(e, {
277
277
  onBlocked: () => {
278
- I((t) => t[e.origin] ? {
279
- ...t,
280
- [e.origin]: { ...t[e.origin], popupBlocked: !0 }
281
- } : t);
278
+ I((r) => r[e.origin] ? {
279
+ ...r,
280
+ [e.origin]: { ...r[e.origin], popupBlocked: !0 }
281
+ } : r);
282
282
  },
283
- // A popup closed without posting may still have completed login; the remounted guest re-requests.
284
- onClosed: () => a(e.origin)
283
+ // A completed login already removed the entry. A v2 entry stays pending so the prompt remains;
284
+ // a legacy guest is remounted because it only learns of a login by reloading.
285
+ onClosed: () => {
286
+ const r = Z.current[e.origin];
287
+ !r || r.v2 || a(e.origin);
288
+ }
285
289
  });
286
290
  },
287
291
  [s, a]
@@ -289,15 +293,15 @@ const ee = ue(null), V = ue({
289
293
  pending: Object.values(w).filter(
290
294
  (e) => e.status === "interactive"
291
295
  ),
292
- authorize: Z,
296
+ authorize: H,
293
297
  approve: Q,
294
- complete: h,
298
+ complete: g,
295
299
  dismiss: u,
296
300
  originEpochs: v,
297
301
  credentials: j,
298
302
  unsupported: y
299
303
  };
300
- return /* @__PURE__ */ P.createElement(V.Provider, { value: Y }, r);
304
+ return /* @__PURE__ */ P.createElement(V.Provider, { value: Y }, t);
301
305
  };
302
306
  ae.propTypes = {
303
307
  children: T.node,
@@ -312,17 +316,17 @@ ae.propTypes = {
312
316
  */
313
317
  broker: T.func
314
318
  };
315
- const $e = () => G(V), Ee = (r) => {
316
- const { originEpochs: s } = G(V), i = J(r);
319
+ const $e = () => G(V), Ee = (t) => {
320
+ const { originEpochs: s } = G(V), i = J(t);
317
321
  return i && s[i] || 0;
318
- }, Re = (r) => {
319
- const { credentials: s } = G(V), i = J(r);
322
+ }, Re = (t) => {
323
+ const { credentials: s } = G(V), i = J(t);
320
324
  return i && s[i] || null;
321
- }, ke = (r) => {
322
- const { unsupported: s } = G(V), i = J(r);
325
+ }, ke = (t) => {
326
+ const { unsupported: s } = G(V), i = J(t);
323
327
  return i && s[i] || null;
324
328
  }, 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 = ({
325
- children: r,
329
+ children: t,
326
330
  authorizationLauncher: s,
327
331
  credentialBroker: i,
328
332
  ready: l
@@ -331,7 +335,7 @@ const $e = () => G(V), Ee = (r) => {
331
335
  k(() => {
332
336
  l !== void 0 || I.current || (I.current = !0, console.error(ie), typeof window != "undefined" && typeof window.alert == "function" && window.alert(ie));
333
337
  }, [l]);
334
- const [v, D] = U({}), [j, H] = U({}), y = R({}), E = R({}), x = R({}), K = b((o, a) => {
338
+ const [v, D] = U({}), [j, K] = U({}), y = R({}), E = R({}), x = R({}), Z = b((o, a) => {
335
339
  var u;
336
340
  return !!((u = x.current[o]) != null && u.has(a));
337
341
  }, []), _ = b((o, a, u) => {
@@ -340,7 +344,7 @@ const $e = () => G(V), Ee = (r) => {
340
344
  D((a) => {
341
345
  const u = { ...a };
342
346
  return delete u[o], u;
343
- }), H((a) => {
347
+ }), K((a) => {
344
348
  const u = { ...a };
345
349
  return delete u[o], u;
346
350
  }), delete x.current[o], Object.keys(E.current).forEach((a) => {
@@ -350,27 +354,27 @@ const $e = () => G(V), Ee = (r) => {
350
354
  k(() => () => {
351
355
  E.current = {};
352
356
  }, []), k(() => {
353
- const o = (u = [], f, h) => {
354
- u.forEach((g) => g(f, h));
357
+ const o = (u = [], f, g) => {
358
+ u.forEach((h) => h(f, g));
355
359
  }, a = (u) => {
356
- var Q, Z, Y, e, n, t, c;
360
+ var Q, H, Y, e, n, r, c;
357
361
  if (!((Q = u == null ? void 0 : u.data) != null && Q.instanceId))
358
362
  return;
359
- const { instanceId: f, type: h } = u.data, g = v[f], m = (Y = (Z = g == null ? void 0 : g.frameRef) == null ? void 0 : Z.current) == null ? void 0 : Y.contentWindow;
360
- if (!m || u.source !== m || u.origin !== g.origin)
363
+ const { instanceId: f, type: g } = u.data, h = v[f], m = (Y = (H = h == null ? void 0 : h.frameRef) == null ? void 0 : H.current) == null ? void 0 : Y.contentWindow;
364
+ if (!m || u.source !== m || u.origin !== h.origin)
361
365
  return;
362
366
  const C = { origin: u.origin }, L = y.current;
363
- if (h === "response") {
367
+ if (g === "response") {
364
368
  const { callbackId: p, response: O, error: d } = u.data, S = E.current[p];
365
369
  S && S.instanceId === f && (S.callback(O, d), delete E.current[p]);
366
370
  return;
367
371
  }
368
- if (h === "mark-registered") {
372
+ if (g === "mark-registered") {
369
373
  const { requestType: p } = u.data;
370
374
  x.current[f] || (x.current[f] = /* @__PURE__ */ new Set()), x.current[f].add(p);
371
375
  return;
372
376
  }
373
- h === "ready" && H((p) => ({ ...p, [f]: !0 })), o((e = L[f]) == null ? void 0 : e[h], u.data, C), o((n = L["*"]) == null ? void 0 : n[h], u.data, C), o((t = L[f]) == null ? void 0 : t["*"], u.data, C), o((c = L["*"]) == null ? void 0 : c["*"], u.data, C);
377
+ g === "ready" && K((p) => ({ ...p, [f]: !0 })), o((e = L[f]) == null ? void 0 : e[g], u.data, C), o((n = L["*"]) == null ? void 0 : n[g], u.data, C), o((r = L[f]) == null ? void 0 : r["*"], u.data, C), o((c = L["*"]) == null ? void 0 : c["*"], u.data, C);
374
378
  };
375
379
  return window.addEventListener("message", a), () => {
376
380
  window.removeEventListener("message", a);
@@ -378,24 +382,24 @@ const $e = () => G(V), Ee = (r) => {
378
382
  }, [v]);
379
383
  const A = b(
380
384
  (o, a, u, f) => {
381
- var g, m;
382
- const h = v[o];
383
- if (!h) {
385
+ var h, m;
386
+ const g = v[o];
387
+ if (!g) {
384
388
  console.warn(`Origin not set for id: ${o}. Unable to send message.`);
385
389
  return;
386
390
  }
387
- (m = (g = h == null ? void 0 : h.frameRef) == null ? void 0 : g.current) != null && m.contentWindow && h.frameRef.current.contentWindow.postMessage(
391
+ (m = (h = g == null ? void 0 : g.frameRef) == null ? void 0 : h.current) != null && m.contentWindow && g.frameRef.current.contentWindow.postMessage(
388
392
  { type: a, ...u, instanceId: o },
389
- f || h.origin
393
+ f || g.origin
390
394
  );
391
395
  },
392
396
  [v]
393
397
  ), q = R(0), F = b(() => `${Date.now()}-${++q.current}`, []), B = b(
394
- async (o, a, u = {}) => new Promise((f, h) => {
395
- const g = F(), m = (C, L) => {
396
- delete E.current[g], L ? h(L) : f(C);
398
+ async (o, a, u = {}) => new Promise((f, g) => {
399
+ const h = F(), m = (C, L) => {
400
+ delete E.current[h], L ? g(L) : f(C);
397
401
  };
398
- E.current[g] = { instanceId: o, callback: m }, A(o, "request", { callbackId: g, requestType: a, data: u });
402
+ E.current[h] = { instanceId: o, callback: m }, A(o, "request", { callbackId: h, requestType: a, data: u });
399
403
  }),
400
404
  [A]
401
405
  ), z = b(
@@ -416,7 +420,7 @@ const $e = () => G(V), Ee = (r) => {
416
420
  sendRequest: B,
417
421
  loadOptions: z,
418
422
  validate: M,
419
- hasHandler: K,
423
+ hasHandler: Z,
420
424
  readyFrames: j,
421
425
  ready: w,
422
426
  addListener: (o, a, u) => (y.current[o] || (y.current[o] = {}), y.current[o][a] || (y.current[o][a] = []), y.current[o][a].push(u), () => {
@@ -430,7 +434,7 @@ const $e = () => G(V), Ee = (r) => {
430
434
  B,
431
435
  z,
432
436
  M,
433
- K,
437
+ Z,
434
438
  j,
435
439
  w
436
440
  ]
@@ -441,9 +445,9 @@ const $e = () => G(V), Ee = (r) => {
441
445
  launcher: s,
442
446
  broker: i
443
447
  },
444
- r
448
+ t
445
449
  ));
446
- }, X = (r, s, i) => {
450
+ }, X = (t, s, i) => {
447
451
  const l = G(ee);
448
452
  if (l === null)
449
453
  throw new Error(
@@ -453,22 +457,22 @@ const $e = () => G(V), Ee = (r) => {
453
457
  k(() => {
454
458
  w.current = i;
455
459
  }, [i]), k(() => {
456
- if (!(!r || !s)) {
460
+ if (!(!t || !s)) {
457
461
  if (s.startsWith("key:")) {
458
462
  const I = s.substring(4);
459
- return l.readyFrames[r] && l.sendMessage(r, "subscribe-key", { keyChord: I }), l.addListener(
460
- r,
463
+ return l.readyFrames[t] && l.sendMessage(t, "subscribe-key", { keyChord: I }), l.addListener(
464
+ t,
461
465
  `key-pressed:${I}`,
462
466
  (...D) => w.current(...D)
463
467
  );
464
468
  }
465
469
  return l.addListener(
466
- r,
470
+ t,
467
471
  s,
468
472
  (...I) => w.current(...I)
469
473
  );
470
474
  }
471
- }, [l, r, s]);
475
+ }, [l, t, s]);
472
476
  };
473
477
  we.propTypes = {
474
478
  children: T.node.isRequired,
@@ -487,18 +491,19 @@ we.propTypes = {
487
491
  /**
488
492
  * Optional credential broker for hosts that are first-party MachineMetrics clients
489
493
  * (`async (request, { approve }) => result`, see EmbeddedAuthorizationManager). When present,
490
- * v2 credential requests are brokered server-side (no popup) and consent is
491
- * rendered natively by the host from the broker's `client` identity.
494
+ * v2 credential requests are brokered server-side and consent is rendered natively by the host
495
+ * from the broker's `client` identity; a broker answer the host may not act on falls back to the
496
+ * interactive entry and its popup.
492
497
  */
493
498
  credentialBroker: T.func
494
499
  };
495
- const re = te.default || te, Te = 1e4, Ie = "credentials", _e = (r, s) => `${r}/mm-embedded-interop?id=${encodeURIComponent(s)}&origin=${encodeURIComponent(
500
+ const re = te.default || te, Te = 1e4, Ie = "credentials", _e = (t, s) => `${t}/mm-embedded-interop?id=${encodeURIComponent(s)}&origin=${encodeURIComponent(
496
501
  window.location.origin
497
502
  )}&caps=${Ie}`, Me = re.iframe`
498
503
  width: 100%;
499
504
  height: 100%;
500
505
  border: none;
501
- visibility: ${(r) => r.$isReady ? "visible" : "hidden"};
506
+ visibility: ${(t) => t.$isReady ? "visible" : "hidden"};
502
507
  `, Ce = re.div`
503
508
  width: 100%;
504
509
  height: 100%;
@@ -512,8 +517,8 @@ const re = te.default || te, Te = 1e4, Ie = "credentials", _e = (r, s) => `${r}/
512
517
  text-align: center;
513
518
  color: #555;
514
519
  font-size: 14px;
515
- `, ye = (r) => {
516
- const s = r && r.origin || "This app", i = r && r.reason || "";
520
+ `, ye = (t) => {
521
+ const s = t && t.origin || "This app", i = t && t.reason || "";
517
522
  switch (i) {
518
523
  case "broker:scope_above_ceiling":
519
524
  return {
@@ -540,9 +545,9 @@ const re = te.default || te, Te = 1e4, Ie = "credentials", _e = (r, s) => `${r}/
540
545
  detail: "It needs an update to support embedding from a different domain."
541
546
  };
542
547
  }
543
- }, le = ({ entry: r }) => {
544
- const s = ye(r);
545
- return /* @__PURE__ */ P.createElement(Ce, { "data-reason": r && r.reason || void 0 }, /* @__PURE__ */ P.createElement("div", { style: { fontWeight: 600 } }, s.title), /* @__PURE__ */ P.createElement("div", { style: { fontSize: 12, color: "#888" } }, s.detail));
548
+ }, le = ({ entry: t }) => {
549
+ const s = ye(t);
550
+ return /* @__PURE__ */ P.createElement(Ce, { "data-reason": t && t.reason || void 0 }, /* @__PURE__ */ P.createElement("div", { style: { fontWeight: 600 } }, s.title), /* @__PURE__ */ P.createElement("div", { style: { fontSize: 12, color: "#888" } }, s.detail));
546
551
  };
547
552
  le.propTypes = {
548
553
  entry: T.shape({
@@ -559,7 +564,7 @@ const Le = re.div`
559
564
  align-items: center;
560
565
  justify-content: center;
561
566
  `, Ae = () => /* @__PURE__ */ P.createElement(Le, null, /* @__PURE__ */ P.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), Ue = ({
562
- id: r,
567
+ id: t,
563
568
  src: s,
564
569
  path: i,
565
570
  onInit: l = () => {
@@ -569,9 +574,9 @@ const Le = re.div`
569
574
  params: v = {},
570
575
  renderUnsupported: D,
571
576
  renderTimeout: j,
572
- ...H
577
+ ...K
573
578
  }) => {
574
- if ("isConfiguring" in H)
579
+ if ("isConfiguring" in K)
575
580
  return console.error(
576
581
  "isConfiguring must be passed via the params prop to MMEmbeddableZone"
577
582
  ), null;
@@ -583,10 +588,10 @@ const Le = re.div`
583
588
  return console.error(
584
589
  "isFullScreen must be passed via the params prop to MMEmbeddableZone"
585
590
  ), null;
586
- const y = R(), E = J(s), [x, K] = U(), [_, $] = U(0), [A, q] = U(!1), [F, B] = U(!1), z = Ee(s), M = Re(s), W = ke(s), [o, a] = U(0), [u, f] = U(null), { registerFrame: h, unregisterFrame: g, sendMessage: m, ready: C } = G(
591
+ const y = R(), E = J(s), [x, Z] = U(), [_, $] = U(0), [A, q] = U(!1), [F, B] = U(!1), z = Ee(s), M = Re(s), W = ke(s), [o, a] = U(0), [u, f] = U(null), { registerFrame: g, unregisterFrame: h, sendMessage: m, ready: C } = G(
587
592
  ee
588
- ), [L, Q] = U(), Z = R(), Y = R(w), e = R(l), n = R(!1), t = R(), c = b(() => {
589
- n.current = !1, clearTimeout(Z.current), clearTimeout(t.current), $(0), q(!1), B(!1), f(null);
593
+ ), [L, Q] = U(), H = R(), Y = R(w), e = R(l), n = R(!1), r = R(), c = b(() => {
594
+ n.current = !1, clearTimeout(H.current), clearTimeout(r.current), $(0), q(!1), B(!1), f(null);
590
595
  }, []);
591
596
  k(() => {
592
597
  (z > 0 || o > 0) && c();
@@ -596,7 +601,7 @@ const Le = re.div`
596
601
  e.current = l;
597
602
  }, [l]), k(() => {
598
603
  _ && m(
599
- r,
604
+ t,
600
605
  "set-context",
601
606
  {
602
607
  context: {
@@ -605,36 +610,36 @@ const Le = re.div`
605
610
  },
606
611
  E
607
612
  );
608
- }, [I, r, _, E]), k(() => {
609
- _ && m(r, "set-params", { params: v }, E);
610
- }, [v, r, _, E]), k(() => {
613
+ }, [I, t, _, E]), k(() => {
614
+ _ && m(t, "set-params", { params: v }, E);
615
+ }, [v, t, _, E]), k(() => {
611
616
  i !== void 0 && Q((i == null ? void 0 : i.indexOf("/")) === 0 ? i : `/${i}`);
612
617
  }, [i]), k(() => {
613
- L === void 0 || !_ || m(r, "navigate", { path: L }, E);
614
- }, [L, _, r, m, E]), k(() => {
615
- if (!s || !r || !y)
618
+ L === void 0 || !_ || m(t, "navigate", { path: L }, E);
619
+ }, [L, _, t, m, E]), k(() => {
620
+ if (!s || !t || !y)
616
621
  return;
617
622
  if (!C) {
618
- c(), K(void 0);
623
+ c(), Z(void 0);
619
624
  return;
620
625
  }
621
626
  c();
622
627
  const d = new URL(s);
623
- return h(r, d.origin, y), e.current(), K(_e(d.origin, r)), () => {
624
- g(r);
628
+ return g(t, d.origin, y), e.current(), Z(_e(d.origin, t)), () => {
629
+ h(t);
625
630
  };
626
- }, [s, r, C, h, y, c]), k(() => {
631
+ }, [s, t, C, g, y, c]), k(() => {
627
632
  if (!(!x || n.current))
628
- return Z.current = setTimeout(() => {
633
+ return H.current = setTimeout(() => {
629
634
  q(!0), Y.current && Y.current();
630
- }, Te), () => clearTimeout(Z.current);
635
+ }, Te), () => clearTimeout(H.current);
631
636
  }, [x, s, z, o]);
632
637
  const p = b(() => {
633
- n.current = !0, clearTimeout(Z.current), q(!1);
638
+ n.current = !0, clearTimeout(H.current), q(!1);
634
639
  }, []);
635
- if (X(r, "init", (d) => {
640
+ if (X(t, "init", (d) => {
636
641
  p(), Array.isArray(d == null ? void 0 : d.acceptsCredentials) && f(d.acceptsCredentials);
637
- }), X(r, "authorize", p), X(r, "login", p), X(r, "credential-request", () => {
642
+ }), X(t, "authorize", p), X(t, "login", p), X(t, "credential-request", () => {
638
643
  p(), B(!0);
639
644
  }), k(() => {
640
645
  if (!F || !M)
@@ -643,27 +648,27 @@ const Le = re.div`
643
648
  if (Array.isArray(d) && !d.includes(M.kind))
644
649
  return;
645
650
  const S = M.kind === "access_token" ? { accessToken: M.accessToken } : {};
646
- m(r, "credential", { ...S, credential: M }, E);
651
+ m(t, "credential", { ...S, credential: M }, E);
647
652
  }, [
648
653
  F,
649
654
  M,
650
655
  u,
651
- r,
656
+ t,
652
657
  m,
653
658
  E
654
- ]), X(r, "ready", () => {
659
+ ]), X(t, "ready", () => {
655
660
  p(), $((d) => d + 1);
656
- }), X(r, "heartbeat", () => {
657
- t.current && clearTimeout(t.current), t.current = setTimeout(() => {
661
+ }), X(t, "heartbeat", () => {
662
+ r.current && clearTimeout(r.current), r.current = setTimeout(() => {
658
663
  a((d) => d + 1);
659
664
  }, 6e3);
660
665
  }), k(() => () => {
661
- t.current && clearTimeout(t.current);
666
+ r.current && clearTimeout(r.current);
662
667
  }, []), W)
663
668
  return D ? D(W) : /* @__PURE__ */ P.createElement(le, { entry: W });
664
669
  if (A && !_)
665
670
  return j ? j() : /* @__PURE__ */ P.createElement(Ae, null);
666
- const O = { ...H };
671
+ const O = { ...K };
667
672
  return delete O.skipManifestCheck, /* @__PURE__ */ P.createElement(
668
673
  Me,
669
674
  {
@@ -1,4 +1,4 @@
1
- (function(g,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],e):(g=typeof globalThis!="undefined"?globalThis:g||self,e(g["mm-react-embeddable"]={},g.React,g.PropTypes,g.styled))})(this,(function(g,e,me,Ee){"use strict";const R=t=>t&&t.__esModule?t:{default:t},O=R(e),C=R(me),te=R(Ee),J=e.createContext(null),G=e.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ne="access_token",V=t=>t?t.kind?t:t.accessToken?{kind:ne,accessToken:t.accessToken,expiresAt:t.expiresAt||null}:null:null,ge=60,ke=120,Ce=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),Q=t=>{try{return new URL(t).origin}catch{return null}},se=(t,o)=>{const c=o==null?void 0:o.origin;return!c||Q(t==null?void 0:t.authUrl)!==c?null:c},oe=t=>{if(!t||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(t)||t.includes(":"))return t;const o=t.split(".");return o.length<=2?t:o.slice(-2).join(".")},ee=(t,o)=>{try{const c=new URL(t),a=new URL(o);return c.protocol!==a.protocol?!0:oe(c.hostname)!==oe(a.hostname)}catch{return!0}},ue=(t,{onBlocked:o,onClosed:c})=>{const a=window.open(t.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!a)return o(),()=>{};const w=setInterval(()=>{a.closed&&(clearInterval(w),c())},1e3);return()=>clearInterval(w)},ie=({children:t,launcher:o,broker:c})=>{const a=e.useContext(J),[w,T]=e.useState({}),[F,B]=e.useState({}),[Z,W]=e.useState({}),[M,k]=e.useState({}),L=e.useRef(Z);L.current=Z;const H=e.useRef(w);H.current=w;const _=e.useRef(null),$=e.useRef({}),A=e.useRef({}),q=e.useRef(c);q.current=c;const x=e.useCallback(r=>{const s=$.current[r];if(!s)return;const n=i=>!i[r]||i[r].clientId?i:{...i,[r]:{...i[r],clientId:s}};T(n),k(n)},[]),v=e.useCallback((r,s)=>{r&&(k(n=>n[r]?n:{...n,[r]:{origin:r,reason:s,clientId:$.current[r]||null}}),x(r))},[x]),U=e.useCallback((r,{v2:s=!1,origin:n=null}={})=>{n&&(s&&L.current[n]||(T(i=>i[n]?i:{...i,[n]:{origin:n,authUrl:r.authUrl,status:s&&q.current?"broker":"interactive",v2:s,scope:r.scope||null,acceptsCredentials:A.current[n]||null,consent:null,error:null,clientId:r.clientId||$.current[n]||null,popupBlocked:!1}}),x(n)))},[x]),I=e.useRef({}),D=e.useCallback(r=>{I.current[r]&&(clearTimeout(I.current[r]),delete I.current[r])},[]),u=e.useCallback(r=>{D(r),T(s=>{if(!s[r])return s;const n={...s};return delete n[r],n})},[D]),d=e.useCallback(r=>{r&&(u(r),B(s=>({...s,[r]:(s[r]||0)+1})))},[u]),l=e.useCallback(r=>{u(r.origin)},[u]),p=e.useCallback((r,s)=>{const n=se(r,s);if(n){if(ee(n,window.location.origin)){v(n,"cross-site-legacy");return}U(r,{origin:n})}},[U,v]);e.useEffect(()=>{if(!a)return;const r=[a.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&($.current[n.origin]=s.clientId,x(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?A.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&ee(n.origin,window.location.origin)&&v(n.origin,"cross-site-legacy")}),a.addListener("*","authorize",p),a.addListener("*","login",p),a.addListener("*","credential-request",(s,n)=>U(s,{v2:!0,origin:se(s,n)}))];return()=>r.forEach(s=>s())},[a,p,U,x,v]),e.useEffect(()=>{const r=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const i=Q(n.authUrl);if(!i||s.origin!==i)return;const b=H.current[i];if(!(!b||b.status!=="interactive")){if(n.accessToken){W(z=>({...z,[i]:V({accessToken:n.accessToken})})),u(i);return}d(i)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[u,d]);const h=e.useCallback((r,s)=>{const n=r==null?void 0:r.origin,i=V(s);!n||!i||(W(b=>({...b,[n]:i})),u(n))},[u]),m=e.useCallback((r,s)=>{T(n=>n[r]?{...n,[r]:{...n[r],...s}}:n)},[]),E=e.useRef({}),y=e.useCallback(async(r,{approve:s}={})=>{const n=q.current,{origin:i}=r;let b;try{b=await n({origin:i,clientId:r.clientId,scope:r.scope,authUrl:r.authUrl},{approve:s})}catch{s?m(i,{error:{reason:"broker_unavailable"}}):m(i,{status:"interactive"});return}const z=b==null?void 0:b.status,f=(b==null?void 0:b.body)||{};if(z===200&&f.credential){h(r,f.credential);return}if(z===409&&f.consentRequired){m(i,{status:"interactive",consent:{client:f.client||null,stepUp:!!f.stepUp,scope:f.scope||r.scope},error:null});return}const P=f.error||"broker_error";if(!s&&Ce.has(P)){m(i,{status:"interactive"});return}if(s&&P==="consent_denied"){m(i,{error:null});return}if(P==="rate_limited"&&!r.rateLimitRetried){const N=Math.min(Number(f.retryAfter)>0?Number(f.retryAfter):ge,ke),Le={...r,rateLimitRetried:!0};D(i),I.current[i]=setTimeout(()=>{delete I.current[i],E.current[i]=!0,S.current(Le,{approve:s}).finally(()=>{delete E.current[i]})},N*1e3),m(i,{rateLimitRetried:!0});return}u(i),k(N=>({...N,[i]:{origin:i,reason:`broker:${P}`,detail:{status:z!=null?z:null,reason:P},clientId:r.clientId||$.current[i]||null}}))},[h,m,u,D]),S=e.useRef(y);S.current=y,e.useEffect(()=>{Object.values(w).forEach(r=>{r.status!=="broker"||E.current[r.origin]||I.current[r.origin]||(E.current[r.origin]=!0,y(r).finally(()=>{delete E.current[r.origin]}))})},[w,y]);const X=e.useCallback(r=>!q.current||!(r!=null&&r.consent)||E.current[r.origin]?Promise.resolve():(E.current[r.origin]=!0,y(r,{approve:!0}).finally(()=>{delete E.current[r.origin]})),[y]);e.useEffect(()=>()=>{_.current&&_.current(),Object.values(I.current).forEach(clearTimeout)},[]);const j=e.useCallback(r=>{_.current&&(_.current(),_.current=null);const s=o||ue;_.current=s(r,{onBlocked:()=>{T(n=>n[r.origin]?{...n,[r.origin]:{...n[r.origin],popupBlocked:!0}}:n)},onClosed:()=>d(r.origin)})},[o,d]),K={pending:Object.values(w).filter(r=>r.status==="interactive"),authorize:j,approve:X,complete:h,dismiss:l,originEpochs:F,credentials:Z,unsupported:M};return O.default.createElement(G.Provider,{value:K},t)};ie.propTypes={children:C.default.node,launcher:C.default.func,broker:C.default.func};const we=()=>e.useContext(G),ce=t=>{const{originEpochs:o}=e.useContext(G),c=Q(t);return c&&o[c]||0},le=t=>{const{credentials:o}=e.useContext(G),c=Q(t);return c&&o[c]||null},de=t=>{const{unsupported:o}=e.useContext(G),c=Q(t);return c&&o[c]||null},ae="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.",fe=({children:t,authorizationLauncher:o,credentialBroker:c,ready:a})=>{const w=a===!0,T=e.useRef(!1);e.useEffect(()=>{a!==void 0||T.current||(T.current=!0,console.error(ae),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ae))},[a]);const[F,B]=e.useState({}),[Z,W]=e.useState({}),M=e.useRef({}),k=e.useRef({}),L=e.useRef({}),H=e.useCallback((u,d)=>{var l;return!!((l=L.current[u])!=null&&l.has(d))},[]),_=e.useCallback((u,d,l)=>{B(p=>({...p,[u]:{origin:d,frameRef:l}}))},[]),$=e.useCallback(u=>{B(d=>{const l={...d};return delete l[u],l}),W(d=>{const l={...d};return delete l[u],l}),delete L.current[u],Object.keys(k.current).forEach(d=>{k.current[d].instanceId===u&&delete k.current[d]})},[]);e.useEffect(()=>()=>{k.current={}},[]),e.useEffect(()=>{const u=(l=[],p,h)=>{l.forEach(m=>m(p,h))},d=l=>{var X,j,K,r,s,n,i;if(!((X=l==null?void 0:l.data)!=null&&X.instanceId))return;const{instanceId:p,type:h}=l.data,m=F[p],E=(K=(j=m==null?void 0:m.frameRef)==null?void 0:j.current)==null?void 0:K.contentWindow;if(!E||l.source!==E||l.origin!==m.origin)return;const y={origin:l.origin},S=M.current;if(h==="response"){const{callbackId:b,response:z,error:f}=l.data,P=k.current[b];P&&P.instanceId===p&&(P.callback(z,f),delete k.current[b]);return}if(h==="mark-registered"){const{requestType:b}=l.data;L.current[p]||(L.current[p]=new Set),L.current[p].add(b);return}h==="ready"&&W(b=>({...b,[p]:!0})),u((r=S[p])==null?void 0:r[h],l.data,y),u((s=S["*"])==null?void 0:s[h],l.data,y),u((n=S[p])==null?void 0:n["*"],l.data,y),u((i=S["*"])==null?void 0:i["*"],l.data,y)};return window.addEventListener("message",d),()=>{window.removeEventListener("message",d)}},[F]);const A=e.useCallback((u,d,l,p)=>{var m,E;const h=F[u];if(!h){console.warn(`Origin not set for id: ${u}. Unable to send message.`);return}(E=(m=h==null?void 0:h.frameRef)==null?void 0:m.current)!=null&&E.contentWindow&&h.frameRef.current.contentWindow.postMessage({type:d,...l,instanceId:u},p||h.origin)},[F]),q=e.useRef(0),x=e.useCallback(()=>`${Date.now()}-${++q.current}`,[]),v=e.useCallback(async(u,d,l={})=>new Promise((p,h)=>{const m=x(),E=(y,S)=>{delete k.current[m],S?h(S):p(y)};k.current[m]={instanceId:u,callback:E},A(u,"request",{callbackId:m,requestType:d,data:l})}),[A]),U=e.useCallback((u,d)=>{A(u,"load-options",d)},[A]),I=e.useCallback((u,d)=>{A(u,"validate",d)},[A]),D=e.useMemo(()=>({registerFrame:_,unregisterFrame:$,sendMessage:A,sendRequest:v,loadOptions:U,validate:I,hasHandler:H,readyFrames:Z,ready:w,addListener:(u,d,l)=>(M.current[u]||(M.current[u]={}),M.current[u][d]||(M.current[u][d]=[]),M.current[u][d].push(l),()=>{M.current[u][d]=M.current[u][d].filter(p=>p!==l)})}),[_,$,A,v,U,I,H,Z,w]);return O.default.createElement(J.Provider,{value:D},O.default.createElement(ie,{launcher:o,broker:c},t))},Y=(t,o,c)=>{const a=e.useContext(J);if(a===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const w=e.useRef(c);e.useEffect(()=>{w.current=c},[c]),e.useEffect(()=>{if(!(!t||!o)){if(o.startsWith("key:")){const T=o.substring(4);return a.readyFrames[t]&&a.sendMessage(t,"subscribe-key",{keyChord:T}),a.addListener(t,`key-pressed:${T}`,(...B)=>w.current(...B))}return a.addListener(t,o,(...T)=>w.current(...T))}},[a,t,o])};fe.propTypes={children:C.default.node.isRequired,ready:C.default.bool.isRequired,authorizationLauncher:C.default.func,credentialBroker:C.default.func};const re=te.default.default||te.default,Te=1e4,_e="credentials",Ie=(t,o)=>`${t}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${_e}`,ye=re.iframe`
1
+ (function(g,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],e):(g=typeof globalThis!="undefined"?globalThis:g||self,e(g["mm-react-embeddable"]={},g.React,g.PropTypes,g.styled))})(this,(function(g,e,me,Ee){"use strict";const R=t=>t&&t.__esModule?t:{default:t},O=R(e),C=R(me),te=R(Ee),J=e.createContext(null),G=e.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ne="access_token",V=t=>t?t.kind?t:t.accessToken?{kind:ne,accessToken:t.accessToken,expiresAt:t.expiresAt||null}:null:null,ge=60,ke=120,Ce=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),Q=t=>{try{return new URL(t).origin}catch{return null}},se=(t,o)=>{const c=o==null?void 0:o.origin;return!c||Q(t==null?void 0:t.authUrl)!==c?null:c},oe=t=>{if(!t||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(t)||t.includes(":"))return t;const o=t.split(".");return o.length<=2?t:o.slice(-2).join(".")},ee=(t,o)=>{try{const c=new URL(t),a=new URL(o);return c.protocol!==a.protocol?!0:oe(c.hostname)!==oe(a.hostname)}catch{return!0}},ue=(t,{onBlocked:o,onClosed:c})=>{const a=window.open(t.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!a)return o(),()=>{};const w=setInterval(()=>{a.closed&&(clearInterval(w),c())},1e3);return()=>clearInterval(w)},ie=({children:t,launcher:o,broker:c})=>{const a=e.useContext(J),[w,T]=e.useState({}),[F,B]=e.useState({}),[Z,H]=e.useState({}),[M,k]=e.useState({}),L=e.useRef(Z);L.current=Z;const j=e.useRef(w);j.current=w;const _=e.useRef(null),$=e.useRef({}),A=e.useRef({}),v=e.useRef(c);v.current=c;const x=e.useCallback(r=>{const s=$.current[r];if(!s)return;const n=i=>!i[r]||i[r].clientId?i:{...i,[r]:{...i[r],clientId:s}};T(n),k(n)},[]),q=e.useCallback((r,s)=>{r&&(k(n=>n[r]?n:{...n,[r]:{origin:r,reason:s,clientId:$.current[r]||null}}),x(r))},[x]),U=e.useCallback((r,{v2:s=!1,origin:n=null}={})=>{n&&(s&&L.current[n]||(T(i=>i[n]?i:{...i,[n]:{origin:n,authUrl:r.authUrl,status:s&&v.current?"broker":"interactive",v2:s,scope:r.scope||null,acceptsCredentials:A.current[n]||null,consent:null,error:null,clientId:r.clientId||$.current[n]||null,popupBlocked:!1}}),x(n)))},[x]),I=e.useRef({}),D=e.useCallback(r=>{I.current[r]&&(clearTimeout(I.current[r]),delete I.current[r])},[]),u=e.useCallback(r=>{D(r),T(s=>{if(!s[r])return s;const n={...s};return delete n[r],n})},[D]),d=e.useCallback(r=>{r&&(u(r),B(s=>({...s,[r]:(s[r]||0)+1})))},[u]),l=e.useCallback(r=>{u(r.origin)},[u]),p=e.useCallback((r,s)=>{const n=se(r,s);if(n){if(ee(n,window.location.origin)){q(n,"cross-site-legacy");return}U(r,{origin:n})}},[U,q]);e.useEffect(()=>{if(!a)return;const r=[a.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&($.current[n.origin]=s.clientId,x(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?A.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&ee(n.origin,window.location.origin)&&q(n.origin,"cross-site-legacy")}),a.addListener("*","authorize",p),a.addListener("*","login",p),a.addListener("*","credential-request",(s,n)=>U(s,{v2:!0,origin:se(s,n)}))];return()=>r.forEach(s=>s())},[a,p,U,x,q]),e.useEffect(()=>{const r=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const i=Q(n.authUrl);if(!i||s.origin!==i)return;const b=j.current[i];if(!(!b||b.status!=="interactive")){if(n.accessToken){H(z=>({...z,[i]:V({accessToken:n.accessToken})})),u(i);return}d(i)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[u,d]);const h=e.useCallback((r,s)=>{const n=r==null?void 0:r.origin,i=V(s);!n||!i||(H(b=>({...b,[n]:i})),u(n))},[u]),m=e.useCallback((r,s)=>{T(n=>n[r]?{...n,[r]:{...n[r],...s}}:n)},[]),E=e.useRef({}),y=e.useCallback(async(r,{approve:s}={})=>{const n=v.current,{origin:i}=r;let b;try{b=await n({origin:i,clientId:r.clientId,scope:r.scope,authUrl:r.authUrl},{approve:s})}catch{s?m(i,{error:{reason:"broker_unavailable"}}):m(i,{status:"interactive"});return}const z=b==null?void 0:b.status,f=(b==null?void 0:b.body)||{};if(z===200&&f.credential){h(r,f.credential);return}if(z===409&&f.consentRequired){m(i,{status:"interactive",consent:{client:f.client||null,stepUp:!!f.stepUp,scope:f.scope||r.scope},error:null});return}const P=f.error||"broker_error";if(!s&&Ce.has(P)){m(i,{status:"interactive"});return}if(s&&P==="consent_denied"){m(i,{error:null});return}if(P==="rate_limited"&&!r.rateLimitRetried){const N=Math.min(Number(f.retryAfter)>0?Number(f.retryAfter):ge,ke),Le={...r,rateLimitRetried:!0};D(i),I.current[i]=setTimeout(()=>{delete I.current[i],E.current[i]=!0,S.current(Le,{approve:s}).finally(()=>{delete E.current[i]})},N*1e3),m(i,{rateLimitRetried:!0});return}u(i),k(N=>({...N,[i]:{origin:i,reason:`broker:${P}`,detail:{status:z!=null?z:null,reason:P},clientId:r.clientId||$.current[i]||null}}))},[h,m,u,D]),S=e.useRef(y);S.current=y,e.useEffect(()=>{Object.values(w).forEach(r=>{r.status!=="broker"||E.current[r.origin]||I.current[r.origin]||(E.current[r.origin]=!0,y(r).finally(()=>{delete E.current[r.origin]}))})},[w,y]);const X=e.useCallback(r=>!v.current||!(r!=null&&r.consent)||E.current[r.origin]?Promise.resolve():(E.current[r.origin]=!0,y(r,{approve:!0}).finally(()=>{delete E.current[r.origin]})),[y]);e.useEffect(()=>()=>{_.current&&_.current(),Object.values(I.current).forEach(clearTimeout)},[]);const W=e.useCallback(r=>{_.current&&(_.current(),_.current=null);const s=o||ue;_.current=s(r,{onBlocked:()=>{T(n=>n[r.origin]?{...n,[r.origin]:{...n[r.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=j.current[r.origin];!n||n.v2||d(r.origin)}})},[o,d]),K={pending:Object.values(w).filter(r=>r.status==="interactive"),authorize:W,approve:X,complete:h,dismiss:l,originEpochs:F,credentials:Z,unsupported:M};return O.default.createElement(G.Provider,{value:K},t)};ie.propTypes={children:C.default.node,launcher:C.default.func,broker:C.default.func};const we=()=>e.useContext(G),ce=t=>{const{originEpochs:o}=e.useContext(G),c=Q(t);return c&&o[c]||0},le=t=>{const{credentials:o}=e.useContext(G),c=Q(t);return c&&o[c]||null},de=t=>{const{unsupported:o}=e.useContext(G),c=Q(t);return c&&o[c]||null},ae="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.",fe=({children:t,authorizationLauncher:o,credentialBroker:c,ready:a})=>{const w=a===!0,T=e.useRef(!1);e.useEffect(()=>{a!==void 0||T.current||(T.current=!0,console.error(ae),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ae))},[a]);const[F,B]=e.useState({}),[Z,H]=e.useState({}),M=e.useRef({}),k=e.useRef({}),L=e.useRef({}),j=e.useCallback((u,d)=>{var l;return!!((l=L.current[u])!=null&&l.has(d))},[]),_=e.useCallback((u,d,l)=>{B(p=>({...p,[u]:{origin:d,frameRef:l}}))},[]),$=e.useCallback(u=>{B(d=>{const l={...d};return delete l[u],l}),H(d=>{const l={...d};return delete l[u],l}),delete L.current[u],Object.keys(k.current).forEach(d=>{k.current[d].instanceId===u&&delete k.current[d]})},[]);e.useEffect(()=>()=>{k.current={}},[]),e.useEffect(()=>{const u=(l=[],p,h)=>{l.forEach(m=>m(p,h))},d=l=>{var X,W,K,r,s,n,i;if(!((X=l==null?void 0:l.data)!=null&&X.instanceId))return;const{instanceId:p,type:h}=l.data,m=F[p],E=(K=(W=m==null?void 0:m.frameRef)==null?void 0:W.current)==null?void 0:K.contentWindow;if(!E||l.source!==E||l.origin!==m.origin)return;const y={origin:l.origin},S=M.current;if(h==="response"){const{callbackId:b,response:z,error:f}=l.data,P=k.current[b];P&&P.instanceId===p&&(P.callback(z,f),delete k.current[b]);return}if(h==="mark-registered"){const{requestType:b}=l.data;L.current[p]||(L.current[p]=new Set),L.current[p].add(b);return}h==="ready"&&H(b=>({...b,[p]:!0})),u((r=S[p])==null?void 0:r[h],l.data,y),u((s=S["*"])==null?void 0:s[h],l.data,y),u((n=S[p])==null?void 0:n["*"],l.data,y),u((i=S["*"])==null?void 0:i["*"],l.data,y)};return window.addEventListener("message",d),()=>{window.removeEventListener("message",d)}},[F]);const A=e.useCallback((u,d,l,p)=>{var m,E;const h=F[u];if(!h){console.warn(`Origin not set for id: ${u}. Unable to send message.`);return}(E=(m=h==null?void 0:h.frameRef)==null?void 0:m.current)!=null&&E.contentWindow&&h.frameRef.current.contentWindow.postMessage({type:d,...l,instanceId:u},p||h.origin)},[F]),v=e.useRef(0),x=e.useCallback(()=>`${Date.now()}-${++v.current}`,[]),q=e.useCallback(async(u,d,l={})=>new Promise((p,h)=>{const m=x(),E=(y,S)=>{delete k.current[m],S?h(S):p(y)};k.current[m]={instanceId:u,callback:E},A(u,"request",{callbackId:m,requestType:d,data:l})}),[A]),U=e.useCallback((u,d)=>{A(u,"load-options",d)},[A]),I=e.useCallback((u,d)=>{A(u,"validate",d)},[A]),D=e.useMemo(()=>({registerFrame:_,unregisterFrame:$,sendMessage:A,sendRequest:q,loadOptions:U,validate:I,hasHandler:j,readyFrames:Z,ready:w,addListener:(u,d,l)=>(M.current[u]||(M.current[u]={}),M.current[u][d]||(M.current[u][d]=[]),M.current[u][d].push(l),()=>{M.current[u][d]=M.current[u][d].filter(p=>p!==l)})}),[_,$,A,q,U,I,j,Z,w]);return O.default.createElement(J.Provider,{value:D},O.default.createElement(ie,{launcher:o,broker:c},t))},Y=(t,o,c)=>{const a=e.useContext(J);if(a===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const w=e.useRef(c);e.useEffect(()=>{w.current=c},[c]),e.useEffect(()=>{if(!(!t||!o)){if(o.startsWith("key:")){const T=o.substring(4);return a.readyFrames[t]&&a.sendMessage(t,"subscribe-key",{keyChord:T}),a.addListener(t,`key-pressed:${T}`,(...B)=>w.current(...B))}return a.addListener(t,o,(...T)=>w.current(...T))}},[a,t,o])};fe.propTypes={children:C.default.node.isRequired,ready:C.default.bool.isRequired,authorizationLauncher:C.default.func,credentialBroker:C.default.func};const re=te.default.default||te.default,Te=1e4,_e="credentials",Ie=(t,o)=>`${t}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${_e}`,ye=re.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
@@ -22,4 +22,4 @@
22
22
  flex: 1;
23
23
  align-items: center;
24
24
  justify-content: center;
25
- `,Ae=()=>O.default.createElement(Se,null,O.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),he=({id:t,src:o,path:c,onInit:a=()=>{},onTimeout:w,context:T={},params:F={},renderUnsupported:B,renderTimeout:Z,...W})=>{if("isConfiguring"in W)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in T)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in T)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const M=e.useRef(),k=Q(o),[L,H]=e.useState(),[_,$]=e.useState(0),[A,q]=e.useState(!1),[x,v]=e.useState(!1),U=ce(o),I=le(o),D=de(o),[u,d]=e.useState(0),[l,p]=e.useState(null),{registerFrame:h,unregisterFrame:m,sendMessage:E,ready:y}=e.useContext(J),[S,X]=e.useState(),j=e.useRef(),K=e.useRef(w),r=e.useRef(a),s=e.useRef(!1),n=e.useRef(),i=e.useCallback(()=>{s.current=!1,clearTimeout(j.current),clearTimeout(n.current),$(0),q(!1),v(!1),p(null)},[]);e.useEffect(()=>{(U>0||u>0)&&i()},[U,u,i]),e.useEffect(()=>{K.current=w},[w]),e.useEffect(()=>{r.current=a},[a]),e.useEffect(()=>{_&&E(t,"set-context",{context:{...T}},k)},[T,t,_,k]),e.useEffect(()=>{_&&E(t,"set-params",{params:F},k)},[F,t,_,k]),e.useEffect(()=>{c!==void 0&&X((c==null?void 0:c.indexOf("/"))===0?c:`/${c}`)},[c]),e.useEffect(()=>{S===void 0||!_||E(t,"navigate",{path:S},k)},[S,_,t,E,k]),e.useEffect(()=>{if(!o||!t||!M)return;if(!y){i(),H(void 0);return}i();const f=new URL(o);return h(t,f.origin,M),r.current(),H(Ie(f.origin,t)),()=>{m(t)}},[o,t,y,h,M,i]),e.useEffect(()=>{if(!(!L||s.current))return j.current=setTimeout(()=>{q(!0),K.current&&K.current()},Te),()=>clearTimeout(j.current)},[L,o,U,u]);const b=e.useCallback(()=>{s.current=!0,clearTimeout(j.current),q(!1)},[]);if(Y(t,"init",f=>{b(),Array.isArray(f==null?void 0:f.acceptsCredentials)&&p(f.acceptsCredentials)}),Y(t,"authorize",b),Y(t,"login",b),Y(t,"credential-request",()=>{b(),v(!0)}),e.useEffect(()=>{if(!x||!I)return;const f=l;if(Array.isArray(f)&&!f.includes(I.kind))return;const P=I.kind==="access_token"?{accessToken:I.accessToken}:{};E(t,"credential",{...P,credential:I},k)},[x,I,l,t,E,k]),Y(t,"ready",()=>{b(),$(f=>f+1)}),Y(t,"heartbeat",()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{d(f=>f+1)},6e3)}),e.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]),D)return B?B(D):O.default.createElement(be,{entry:D});if(A&&!_)return Z?Z():O.default.createElement(Ae,null);const z={...W};return delete z.skipManifestCheck,O.default.createElement(ye,{key:`auth-epoch-${U}-frame-${u}`,$isReady:_,ref:M,src:L,...z})};he.propTypes={id:C.default.string,src:C.default.string.isRequired,path:C.default.string,onInit:C.default.func,onTimeout:C.default.func,renderUnsupported:C.default.func,renderTimeout:C.default.func},g.CREDENTIAL_KIND_ACCESS_TOKEN=ne,g.EmbeddedAuthorizationContext=G,g.MMEmbeddableZone=he,g.MMEmbeddableZoneContext=J,g.MMEmbeddableZoneProvider=fe,g.isCrossSite=ee,g.normalizeCredential=V,g.popupAuthorizationLauncher=ue,g.unsupportedCopy=pe,g.useEmbeddedAuthorizations=we,g.useEmbeddedCredential=le,g.useEmbeddedEffect=Y,g.useEmbeddedOriginEpoch=ce,g.useEmbeddedUnsupported=de,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
25
+ `,Ae=()=>O.default.createElement(Se,null,O.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),he=({id:t,src:o,path:c,onInit:a=()=>{},onTimeout:w,context:T={},params:F={},renderUnsupported:B,renderTimeout:Z,...H})=>{if("isConfiguring"in H)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in T)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in T)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const M=e.useRef(),k=Q(o),[L,j]=e.useState(),[_,$]=e.useState(0),[A,v]=e.useState(!1),[x,q]=e.useState(!1),U=ce(o),I=le(o),D=de(o),[u,d]=e.useState(0),[l,p]=e.useState(null),{registerFrame:h,unregisterFrame:m,sendMessage:E,ready:y}=e.useContext(J),[S,X]=e.useState(),W=e.useRef(),K=e.useRef(w),r=e.useRef(a),s=e.useRef(!1),n=e.useRef(),i=e.useCallback(()=>{s.current=!1,clearTimeout(W.current),clearTimeout(n.current),$(0),v(!1),q(!1),p(null)},[]);e.useEffect(()=>{(U>0||u>0)&&i()},[U,u,i]),e.useEffect(()=>{K.current=w},[w]),e.useEffect(()=>{r.current=a},[a]),e.useEffect(()=>{_&&E(t,"set-context",{context:{...T}},k)},[T,t,_,k]),e.useEffect(()=>{_&&E(t,"set-params",{params:F},k)},[F,t,_,k]),e.useEffect(()=>{c!==void 0&&X((c==null?void 0:c.indexOf("/"))===0?c:`/${c}`)},[c]),e.useEffect(()=>{S===void 0||!_||E(t,"navigate",{path:S},k)},[S,_,t,E,k]),e.useEffect(()=>{if(!o||!t||!M)return;if(!y){i(),j(void 0);return}i();const f=new URL(o);return h(t,f.origin,M),r.current(),j(Ie(f.origin,t)),()=>{m(t)}},[o,t,y,h,M,i]),e.useEffect(()=>{if(!(!L||s.current))return W.current=setTimeout(()=>{v(!0),K.current&&K.current()},Te),()=>clearTimeout(W.current)},[L,o,U,u]);const b=e.useCallback(()=>{s.current=!0,clearTimeout(W.current),v(!1)},[]);if(Y(t,"init",f=>{b(),Array.isArray(f==null?void 0:f.acceptsCredentials)&&p(f.acceptsCredentials)}),Y(t,"authorize",b),Y(t,"login",b),Y(t,"credential-request",()=>{b(),q(!0)}),e.useEffect(()=>{if(!x||!I)return;const f=l;if(Array.isArray(f)&&!f.includes(I.kind))return;const P=I.kind==="access_token"?{accessToken:I.accessToken}:{};E(t,"credential",{...P,credential:I},k)},[x,I,l,t,E,k]),Y(t,"ready",()=>{b(),$(f=>f+1)}),Y(t,"heartbeat",()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{d(f=>f+1)},6e3)}),e.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]),D)return B?B(D):O.default.createElement(be,{entry:D});if(A&&!_)return Z?Z():O.default.createElement(Ae,null);const z={...H};return delete z.skipManifestCheck,O.default.createElement(ye,{key:`auth-epoch-${U}-frame-${u}`,$isReady:_,ref:M,src:L,...z})};he.propTypes={id:C.default.string,src:C.default.string.isRequired,path:C.default.string,onInit:C.default.func,onTimeout:C.default.func,renderUnsupported:C.default.func,renderTimeout:C.default.func},g.CREDENTIAL_KIND_ACCESS_TOKEN=ne,g.EmbeddedAuthorizationContext=G,g.MMEmbeddableZone=he,g.MMEmbeddableZoneContext=J,g.MMEmbeddableZoneProvider=fe,g.isCrossSite=ee,g.normalizeCredential=V,g.popupAuthorizationLauncher=ue,g.unsupportedCopy=pe,g.useEmbeddedAuthorizations=we,g.useEmbeddedCredential=le,g.useEmbeddedEffect=Y,g.useEmbeddedOriginEpoch=ce,g.useEmbeddedUnsupported=de,Object.defineProperty(g,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.1-1",
3
+ "version": "2.0.1-2",
4
4
  "license": "MIT",
5
5
  "module": "dist/mm-react-embeddable.es.js",
6
6
  "main": "dist/mm-react-embeddable.cjs.js",