@machinemetrics/mm-react-embeddable 2.0.3-0 → 2.0.3-1

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