@machinemetrics/mm-react-embeddable 1.4.0-7 → 2.0.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),k=require("prop-types"),B=require("styled-components"),H=t.createContext(null),D=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ee="access_token",N=r=>r?r.kind?r:r.accessToken?{kind:ee,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,fe=new Set(["host_not_allowed","invalid_token","provider_unavailable"]),G=typeof window!="undefined"&&window.location.protocol==="https:",pe=8e3,K=r=>{try{return new URL(r).origin}catch{return null}},Q=(r,o)=>{const i=o==null?void 0:o.origin;return!i||K(r==null?void 0:r.authUrl)!==i?null:i},X=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const o=r.split(".");return o.length<=2?r:o.slice(-2).join(".")},te=(r,o)=>{try{const i=new URL(r),f=new URL(o);return i.protocol!==f.protocol?!0:X(i.hostname)!==X(f.hostname)}catch{return!0}},ne=(r,{onBlocked:o,onClosed:i})=>{const f=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!f)return o(),()=>{};const h=setInterval(()=>{f.closed&&(clearInterval(h),i())},1e3);return()=>clearInterval(h)},re=({children:r,launcher:o,broker:i})=>{const f=t.useContext(H),[h,E]=t.useState({}),[L,w]=t.useState({}),[x,T]=t.useState({}),[z,M]=t.useState({}),P=t.useRef(x);P.current=x;const p=t.useRef(null),F=t.useRef({}),_=t.useRef({}),y=t.useRef({}),S=t.useRef(i);S.current=i;const I=t.useCallback(e=>{const n=_.current[e];if(!n)return;const s=l=>!l[e]||l[e].clientId?l:{...l,[e]:{...l[e],clientId:n}};E(s),M(s)},[]),$=t.useCallback((e,n)=>{e&&(M(s=>s[e]?s:{...s,[e]:{origin:e,reason:n,clientId:_.current[e]||null}}),I(e))},[I]),c=t.useCallback((e,{v2:n=!1,origin:s=null}={})=>{s&&(n&&P.current[s]||(E(l=>l[s]?l:{...l,[s]:{origin:s,authUrl:e.authUrl,silentUrl:e.silentUrl||null,status:n&&S.current?"broker":n&&e.silentUrl&&G?"silent":"interactive",v2:n,scope:e.scope||null,acceptsCredentials:y.current[s]||null,consent:null,error:null,clientId:e.clientId||_.current[s]||null,popupBlocked:!1}}),I(s)))},[I]),a=t.useCallback(e=>{E(n=>{if(!n[e])return n;const s={...n};return delete s[e],s})},[]),u=t.useCallback(e=>{e&&(a(e),w(n=>({...n,[e]:(n[e]||0)+1})))},[a]),d=t.useCallback(e=>{E(n=>!n[e]||n[e].status==="interactive"?n:{...n,[e]:{...n[e],status:"interactive"}})},[]),g=t.useCallback(e=>{a(e.origin)},[a]),m=t.useCallback((e,n)=>{const s=Q(e,n);if(s){if(te(s,window.location.origin)){$(s,"cross-site-legacy");return}c(e,{origin:s})}},[c,$]);t.useEffect(()=>{if(!f)return;const e=[f.addListener("*","init",(n,s)=>{s!=null&&s.origin&&(n!=null&&n.clientId)&&(_.current[s.origin]=n.clientId,I(s.origin)),s!=null&&s.origin&&Array.isArray(n==null?void 0:n.acceptsCredentials)&&(y.current[s.origin]=n.acceptsCredentials)}),f.addListener("*","authorize",m),f.addListener("*","login",m),f.addListener("*","credential-request",(n,s)=>c(n,{v2:!0,origin:Q(n,s)}))];return()=>e.forEach(n=>n())},[f,m,c,I]),t.useEffect(()=>{const e=n=>{const s=n==null?void 0:n.data;if(!s||s.type!=="authorized"&&s.type!=="authorize-failed")return;const l=K(s.authUrl);if(!(!l||n.origin!==l)){if(s.type==="authorized"){s.accessToken?(T(b=>({...b,[l]:N({accessToken:s.accessToken})})),a(l)):u(l);return}d(l)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[a,u,d]);const U=t.useCallback((e,n)=>{const s=e==null?void 0:e.origin,l=N(n);!s||!l||(T(b=>({...b,[s]:l})),a(s))},[a]),C=t.useCallback((e,n)=>{E(s=>s[e]?{...s,[e]:{...s[e],...n}}:s)},[]),R=t.useCallback(async(e,{approve:n}={})=>{const s=S.current,{origin:l}=e;let b;try{b=await s({origin:l,clientId:e.clientId,scope:e.scope,authUrl:e.authUrl},{approve:n})}catch{n?C(l,{error:{reason:"broker_unavailable"}}):C(l,{status:e.silentUrl&&G?"silent":"interactive"});return}if((b==null?void 0:b.status)===200&&b.credential){U(e,b.credential);return}if((b==null?void 0:b.status)===409&&b.consentRequired){C(l,{status:"interactive",consent:{client:b.client||null,stepUp:!!b.stepUp,scope:b.scope||e.scope},error:null});return}const Z=(b==null?void 0:b.error)||"broker_error";if(!n&&fe.has(Z)){C(l,{status:e.silentUrl&&G?"silent":"interactive"});return}if(n&&Z==="consent_denied"){C(l,{error:null});return}a(l),M(J=>({...J,[l]:{origin:l,reason:`broker:${Z}`,detail:b||null,clientId:e.clientId||_.current[l]||null}}))},[U,C,a]),O=t.useRef({});t.useEffect(()=>{Object.values(h).forEach(e=>{e.status!=="broker"||O.current[e.origin]||(O.current[e.origin]=!0,R(e).finally(()=>{delete O.current[e.origin]}))})},[h,R]);const v=t.useCallback(e=>!S.current||!(e!=null&&e.consent)?Promise.resolve():R(e,{approve:!0}),[R]);t.useEffect(()=>{const e=F.current;Object.values(h).forEach(n=>{n.status==="silent"&&!e[n.origin]&&(e[n.origin]=setTimeout(()=>{delete e[n.origin],d(n.origin)},pe))}),Object.keys(e).forEach(n=>{(!h[n]||h[n].status!=="silent")&&(clearTimeout(e[n]),delete e[n])})},[h,d]),t.useEffect(()=>()=>{p.current&&p.current(),Object.values(F.current).forEach(clearTimeout)},[]);const A=t.useCallback(e=>{p.current&&(p.current(),p.current=null);const n=o||ne;p.current=n(e,{onBlocked:()=>{E(s=>s[e.origin]?{...s,[e.origin]:{...s[e.origin],popupBlocked:!0}}:s)},onClosed:()=>{if(e.v2){G&&E(s=>!s[e.origin]||!s[e.origin].silentUrl?s:{...s,[e.origin]:{...s[e.origin],status:"silent"}});return}u(e.origin)}})},[o,u]),j={pending:Object.values(h).filter(e=>e.status==="interactive"),authorize:A,approve:v,complete:U,dismiss:g,originEpochs:L,credentials:x,unsupported:z},W=Object.values(h).filter(e=>e.status==="silent"&&e.silentUrl);return t.createElement(D.Provider,{value:j},r,W.map(e=>t.createElement("iframe",{key:`mm-silent-auth-${e.origin}`,src:e.silentUrl,title:`MachineMetrics silent authorization (${e.origin})`,"aria-hidden":"true",tabIndex:-1,style:{display:"none"}})))};re.propTypes={children:k.node,launcher:k.func,broker:k.func};const se=()=>t.useContext(D),oe=r=>{const{originEpochs:o}=t.useContext(D),i=K(r);return i&&o[i]||0},ie=r=>{const{credentials:o}=t.useContext(D),i=K(r);return i&&o[i]||null},ce=r=>{const{unsupported:o}=t.useContext(D),i=K(r);return i&&o[i]||null},ue=({children:r,authorizationLauncher:o,credentialBroker:i})=>{const[f,h]=t.useState({}),[E,L]=t.useState({}),w=t.useRef({}),x=t.useRef({}),T=t.useRef({}),z=t.useCallback((c,a)=>{var u;return!!((u=T.current[c])!=null&&u.has(a))},[]),M=t.useCallback((c,a,u)=>{h(d=>({...d,[c]:{origin:a,frameRef:u}}))},[]),P=t.useCallback(c=>{h(a=>{const u={...a};return delete u[c],u}),L(a=>{const u={...a};return delete u[c],u}),delete T.current[c]},[]);t.useEffect(()=>{const c=(u=[],d,g)=>{u.forEach(m=>m(d,g))},a=u=>{var O,v,A,j,W,e,n;if(!((O=u==null?void 0:u.data)!=null&&O.instanceId))return;const{instanceId:d,type:g}=u.data,m=f[d],U=(A=(v=m==null?void 0:m.frameRef)==null?void 0:v.current)==null?void 0:A.contentWindow;if(!U||u.source!==U||u.origin!==m.origin)return;const C={origin:u.origin},R=w.current;if(g==="response"){const{callbackId:s,response:l,error:b}=u.data,Z=x.current[s];Z&&(Z(l,b),delete x.current[s]);return}if(g==="mark-registered"){const{requestType:s}=u.data;T.current[d]||(T.current[d]=new Set),T.current[d].add(s);return}g==="ready"&&L(s=>({...s,[d]:!0})),c((j=R[d])==null?void 0:j[g],u.data,C),c((W=R["*"])==null?void 0:W[g],u.data,C),c((e=R[d])==null?void 0:e["*"],u.data,C),c((n=R["*"])==null?void 0:n["*"],u.data,C)};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[f]);const p=t.useCallback((c,a,u)=>{var g,m;const d=f[c];if(!d){console.warn(`Origin not set for id: ${c}. Unable to send message.`);return}(m=(g=d==null?void 0:d.frameRef)==null?void 0:g.current)!=null&&m.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:a,...u,instanceId:c},d.origin)},[f]),F=t.useRef(0),_=t.useCallback(()=>`${Date.now()}-${++F.current}`,[]),y=t.useCallback(async(c,a,u={})=>new Promise((d,g)=>{const m=_(),U=(C,R)=>{delete x.current[m],R?g(R):d(C)};x.current[m]=U,p(c,"request",{callbackId:m,requestType:a,data:u})}),[p]),S=t.useCallback((c,a)=>{p(c,"load-options",a)},[p]),I=t.useCallback((c,a)=>{p(c,"validate",a)},[p]),$=t.useMemo(()=>({registerFrame:M,unregisterFrame:P,sendMessage:p,sendRequest:y,loadOptions:S,validate:I,hasHandler:z,readyFrames:E,addListener:(c,a,u)=>(w.current[c]||(w.current[c]={}),w.current[c][a]||(w.current[c][a]=[]),w.current[c][a].push(u),()=>{w.current[c][a]=w.current[c][a].filter(d=>d!==u)})}),[M,P,p,y,S,I,z,E]);return t.createElement(H.Provider,{value:$},t.createElement(re,{launcher:o,broker:i},r))},q=(r,o,i)=>{const f=t.useContext(H);if(f===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const h=t.useRef(i);t.useEffect(()=>{h.current=i},[i]),t.useEffect(()=>{if(!(!r||!o)){if(o.startsWith("key:")){const E=o.substring(4);return f.readyFrames[r]&&f.sendMessage(r,"subscribe-key",{keyChord:E}),f.addListener(r,`key-pressed:${E}`,(...w)=>h.current(...w))}return f.addListener(r,o,(...E)=>h.current(...E))}},[f,r,o])};ue.propTypes={children:k.node.isRequired,authorizationLauncher:k.func,credentialBroker:k.func};const V=B.default||B,be=1e4,he="credentials",Y=(r,o)=>`${r}/mm-embedded-interop?id=${o}&origin=${window.location.origin}&caps=${he}`,ge=V.iframe`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),he=require("prop-types"),ge=require("styled-components"),Q=t=>t&&t.__esModule?t:{default:t},g=Q(n),C=Q(he),W=Q(ge),K=n.createContext(null),H=n.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),re="access_token",J=t=>t?t.kind?t:t.accessToken?{kind:re,accessToken:t.accessToken,expiresAt:t.expiresAt||null}:null:null,me=new Set(["host_not_allowed","invalid_token","provider_unavailable"]),N=typeof window!="undefined"&&window.location.protocol==="https:",Ee=8e3,G=t=>{try{return new URL(t).origin}catch{return null}},ee=(t,o)=>{const u=o==null?void 0:o.origin;return!u||G(t==null?void 0:t.authUrl)!==u?null:u},te=t=>{if(!t||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(t)||t.includes(":"))return t;const o=t.split(".");return o.length<=2?t:o.slice(-2).join(".")},se=(t,o)=>{try{const u=new URL(t),f=new URL(o);return u.protocol!==f.protocol?!0:te(u.hostname)!==te(f.hostname)}catch{return!0}},oe=(t,{onBlocked:o,onClosed:u})=>{const f=window.open(t.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!f)return o(),()=>{};const p=setInterval(()=>{f.closed&&(clearInterval(p),u())},1e3);return()=>clearInterval(p)},ie=({children:t,launcher:o,broker:u})=>{const f=n.useContext(K),[p,m]=n.useState({}),[F,w]=n.useState({}),[I,z]=n.useState({}),[_,S]=n.useState({}),j=n.useRef(I);j.current=I;const E=n.useRef(p);E.current=p;const M=n.useRef(null),Z=n.useRef({}),U=n.useRef({}),v=n.useRef({}),$=n.useRef(u);$.current=u;const T=n.useCallback(e=>{const r=U.current[e];if(!r)return;const s=l=>!l[e]||l[e].clientId?l:{...l,[e]:{...l[e],clientId:r}};m(s),S(s)},[]),c=n.useCallback((e,r)=>{e&&(S(s=>s[e]?s:{...s,[e]:{origin:e,reason:r,clientId:U.current[e]||null}}),T(e))},[T]),a=n.useCallback((e,{v2:r=!1,origin:s=null}={})=>{s&&(r&&j.current[s]||(m(l=>l[s]?l:{...l,[s]:{origin:s,authUrl:e.authUrl,silentUrl:e.silentUrl||null,status:r&&$.current?"broker":r&&e.silentUrl&&N?"silent":"interactive",v2:r,scope:e.scope||null,acceptsCredentials:v.current[s]||null,consent:null,error:null,clientId:e.clientId||U.current[s]||null,popupBlocked:!1}}),T(s)))},[T]),i=n.useCallback(e=>{m(r=>{if(!r[e])return r;const s={...r};return delete s[e],s})},[]),d=n.useCallback(e=>{e&&(i(e),w(r=>({...r,[e]:(r[e]||0)+1})))},[i]),b=n.useCallback(e=>{m(r=>!r[e]||r[e].status==="interactive"?r:{...r,[e]:{...r[e],status:"interactive"}})},[]),k=n.useCallback(e=>{i(e.origin)},[i]),A=n.useCallback((e,r)=>{const s=ee(e,r);if(s){if(se(s,window.location.origin)){c(s,"cross-site-legacy");return}a(e,{origin:s})}},[a,c]);n.useEffect(()=>{if(!f)return;const e=[f.addListener("*","init",(r,s)=>{s!=null&&s.origin&&(r!=null&&r.clientId)&&(U.current[s.origin]=r.clientId,T(s.origin)),s!=null&&s.origin&&Array.isArray(r==null?void 0:r.acceptsCredentials)&&(v.current[s.origin]=r.acceptsCredentials)}),f.addListener("*","authorize",A),f.addListener("*","login",A),f.addListener("*","credential-request",(r,s)=>a(r,{v2:!0,origin:ee(r,s)}))];return()=>e.forEach(r=>r())},[f,A,a,T]),n.useEffect(()=>{const e=r=>{const s=r==null?void 0:r.data;if(!s||s.type!=="authorized"&&s.type!=="authorize-failed")return;const l=G(s.authUrl);if(!(!l||r.origin!==l)){if(s.type==="authorized"){if(s.accessToken){if(!E.current[l])return;z(h=>({...h,[l]:J({accessToken:s.accessToken})})),i(l)}else d(l);return}b(l)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[i,d,b]);const x=n.useCallback((e,r)=>{const s=e==null?void 0:e.origin,l=J(r);!s||!l||(z(h=>({...h,[s]:l})),i(s))},[i]),R=n.useCallback((e,r)=>{m(s=>s[e]?{...s,[e]:{...s[e],...r}}:s)},[]),O=n.useCallback(async(e,{approve:r}={})=>{const s=$.current,{origin:l}=e;let h;try{h=await s({origin:l,clientId:e.clientId,scope:e.scope,authUrl:e.authUrl},{approve:r})}catch{r?R(l,{error:{reason:"broker_unavailable"}}):R(l,{status:e.silentUrl&&N?"silent":"interactive"});return}if((h==null?void 0:h.status)===200&&h.credential){x(e,h.credential);return}if((h==null?void 0:h.status)===409&&h.consentRequired){R(l,{status:"interactive",consent:{client:h.client||null,stepUp:!!h.stepUp,scope:h.scope||e.scope},error:null});return}const V=(h==null?void 0:h.error)||"broker_error";if(!r&&me.has(V)){R(l,{status:e.silentUrl&&N?"silent":"interactive"});return}if(r&&V==="consent_denied"){R(l,{error:null});return}i(l),S(Y=>({...Y,[l]:{origin:l,reason:`broker:${V}`,detail:h||null,clientId:e.clientId||U.current[l]||null}}))},[x,R,i]),P=n.useRef({});n.useEffect(()=>{Object.values(p).forEach(e=>{e.status!=="broker"||P.current[e.origin]||(P.current[e.origin]=!0,O(e).finally(()=>{delete P.current[e.origin]}))})},[p,O]);const y=n.useCallback(e=>!$.current||!(e!=null&&e.consent)?Promise.resolve():O(e,{approve:!0}),[O]);n.useEffect(()=>{const e=Z.current;Object.values(p).forEach(r=>{r.status==="silent"&&!e[r.origin]&&(e[r.origin]=setTimeout(()=>{delete e[r.origin],b(r.origin)},Ee))}),Object.keys(e).forEach(r=>{(!p[r]||p[r].status!=="silent")&&(clearTimeout(e[r]),delete e[r])})},[p,b]),n.useEffect(()=>()=>{M.current&&M.current(),Object.values(Z.current).forEach(clearTimeout)},[]);const q=n.useCallback(e=>{M.current&&(M.current(),M.current=null);const r=o||oe;M.current=r(e,{onBlocked:()=>{m(s=>s[e.origin]?{...s,[e.origin]:{...s[e.origin],popupBlocked:!0}}:s)},onClosed:()=>{if(e.v2){N&&m(s=>!s[e.origin]||!s[e.origin].silentUrl?s:{...s,[e.origin]:{...s[e.origin],status:"silent"}});return}d(e.origin)}})},[o,d]),D={pending:Object.values(p).filter(e=>e.status==="interactive"),authorize:q,approve:y,complete:x,dismiss:k,originEpochs:F,credentials:I,unsupported:_},L=Object.values(p).filter(e=>e.status==="silent"&&e.silentUrl);return g.default.createElement(H.Provider,{value:D},t,L.map(e=>g.default.createElement("iframe",{key:`mm-silent-auth-${e.origin}`,src:e.silentUrl,title:`MachineMetrics silent authorization (${e.origin})`,"aria-hidden":"true",tabIndex:-1,style:{display:"none"}})))};ie.propTypes={children:C.default.node,launcher:C.default.func,broker:C.default.func};const ue=()=>n.useContext(H),ce=t=>{const{originEpochs:o}=n.useContext(H),u=G(t);return u&&o[u]||0},ae=t=>{const{credentials:o}=n.useContext(H),u=G(t);return u&&o[u]||null},le=t=>{const{unsupported:o}=n.useContext(H),u=G(t);return u&&o[u]||null},de=({children:t,authorizationLauncher:o,credentialBroker:u})=>{const[f,p]=n.useState({}),[m,F]=n.useState({}),w=n.useRef({}),I=n.useRef({}),z=n.useRef({}),_=n.useCallback((c,a)=>{var i;return!!((i=z.current[c])!=null&&i.has(a))},[]),S=n.useCallback((c,a,i)=>{p(d=>({...d,[c]:{origin:a,frameRef:i}}))},[]),j=n.useCallback(c=>{p(a=>{const i={...a};return delete i[c],i}),F(a=>{const i={...a};return delete i[c],i}),delete z.current[c]},[]);n.useEffect(()=>{const c=(i=[],d,b)=>{i.forEach(k=>k(d,b))},a=i=>{var O,P,y,q,D,L,e;if(!((O=i==null?void 0:i.data)!=null&&O.instanceId))return;const{instanceId:d,type:b}=i.data,k=f[d],A=(y=(P=k==null?void 0:k.frameRef)==null?void 0:P.current)==null?void 0:y.contentWindow;if(!A||i.source!==A||i.origin!==k.origin)return;const x={origin:i.origin},R=w.current;if(b==="response"){const{callbackId:r,response:s,error:l}=i.data,h=I.current[r];h&&(h(s,l),delete I.current[r]);return}if(b==="mark-registered"){const{requestType:r}=i.data;z.current[d]||(z.current[d]=new Set),z.current[d].add(r);return}b==="ready"&&F(r=>({...r,[d]:!0})),c((q=R[d])==null?void 0:q[b],i.data,x),c((D=R["*"])==null?void 0:D[b],i.data,x),c((L=R[d])==null?void 0:L["*"],i.data,x),c((e=R["*"])==null?void 0:e["*"],i.data,x)};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[f]);const E=n.useCallback((c,a,i)=>{var b,k;const d=f[c];if(!d){console.warn(`Origin not set for id: ${c}. Unable to send message.`);return}(k=(b=d==null?void 0:d.frameRef)==null?void 0:b.current)!=null&&k.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:a,...i,instanceId:c},d.origin)},[f]),M=n.useRef(0),Z=n.useCallback(()=>`${Date.now()}-${++M.current}`,[]),U=n.useCallback(async(c,a,i={})=>new Promise((d,b)=>{const k=Z(),A=(x,R)=>{delete I.current[k],R?b(R):d(x)};I.current[k]=A,E(c,"request",{callbackId:k,requestType:a,data:i})}),[E]),v=n.useCallback((c,a)=>{E(c,"load-options",a)},[E]),$=n.useCallback((c,a)=>{E(c,"validate",a)},[E]),T=n.useMemo(()=>({registerFrame:S,unregisterFrame:j,sendMessage:E,sendRequest:U,loadOptions:v,validate:$,hasHandler:_,readyFrames:m,addListener:(c,a,i)=>(w.current[c]||(w.current[c]={}),w.current[c][a]||(w.current[c][a]=[]),w.current[c][a].push(i),()=>{w.current[c][a]=w.current[c][a].filter(d=>d!==i)})}),[S,j,E,U,v,$,_,m]);return g.default.createElement(K.Provider,{value:T},g.default.createElement(ie,{launcher:o,broker:u},t))},B=(t,o,u)=>{const f=n.useContext(K);if(f===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const p=n.useRef(u);n.useEffect(()=>{p.current=u},[u]),n.useEffect(()=>{if(!(!t||!o)){if(o.startsWith("key:")){const m=o.substring(4);return f.readyFrames[t]&&f.sendMessage(t,"subscribe-key",{keyChord:m}),f.addListener(t,`key-pressed:${m}`,(...w)=>p.current(...w))}return f.addListener(t,o,(...m)=>p.current(...m))}},[f,t,o])};de.propTypes={children:C.default.node.isRequired,authorizationLauncher:C.default.func,credentialBroker:C.default.func};const X=W.default.default||W.default,ke=1e4,Re="credentials",ne=(t,o)=>`${t}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Re}`,Ce=X.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
5
- visibility: ${r=>r.$isReady?"visible":"hidden"};
6
- `,me=V.div`
5
+ visibility: ${t=>t.$isReady?"visible":"hidden"};
6
+ `,we=X.div`
7
7
  width: 100%;
8
8
  height: 100%;
9
9
  display: flex;
@@ -16,13 +16,13 @@
16
16
  text-align: center;
17
17
  color: #555;
18
18
  font-size: 14px;
19
- `,ae=r=>{const o=r&&r.origin||"This app",i=r&&r.reason||"";switch(i){case"broker:scope_above_ceiling":return{title:`${o} can’t be authorized here`,detail:"It asks for permissions your role doesn’t have."};case"broker:origin_mismatch":case"broker:unknown_client":return{title:`${o} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${o} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return i.startsWith("broker:")?{title:`${o} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${o} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},le=({entry:r})=>{const o=ae(r);return t.createElement(me,{"data-reason":r&&r.reason||void 0},t.createElement("div",{style:{fontWeight:600}},o.title),t.createElement("div",{style:{fontSize:12,color:"#888"}},o.detail))};le.propTypes={entry:k.shape({origin:k.string,name:k.string,reason:k.string,detail:k.object})};const Ee=V.div`
19
+ `,fe=t=>{const o=t&&t.origin||"This app",u=t&&t.reason||"";switch(u){case"broker:scope_above_ceiling":return{title:`${o} can’t be authorized here`,detail:"It asks for permissions your role doesn’t have."};case"broker:origin_mismatch":case"broker:unknown_client":return{title:`${o} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${o} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return u.startsWith("broker:")?{title:`${o} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${o} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},pe=({entry:t})=>{const o=fe(t);return g.default.createElement(we,{"data-reason":t&&t.reason||void 0},g.default.createElement("div",{style:{fontWeight:600}},o.title),g.default.createElement("div",{style:{fontSize:12,color:"#888"}},o.detail))};pe.propTypes={entry:C.default.shape({origin:C.default.string,name:C.default.string,reason:C.default.string,detail:C.default.object})};const xe=X.div`
20
20
  height: 100%;
21
21
  display: flex;
22
22
  flex: 1;
23
23
  align-items: center;
24
24
  justify-content: center;
25
- `,ke=()=>t.createElement(Ee,null,t.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),de=({id:r,src:o,path:i,onInit:f=()=>{},onTimeout:h,context:E={},params:L={},renderUnsupported:w,renderTimeout:x,...T})=>{if("isConfiguring"in T)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in E)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in E)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const z=t.useRef(),[M,P]=t.useState(),[p,F]=t.useState(0),[_,y]=t.useState(!1),[S,I]=t.useState(!1),$=oe(o),c=ie(o),a=ce(o);t.useEffect(()=>{$>0&&F(0)},[$]);const{registerFrame:u,unregisterFrame:d,sendMessage:g}=t.useContext(H),[m,U]=t.useState(),C=t.useRef(),R=t.useRef(h),O=t.useRef(f),v=t.useRef(!1);t.useEffect(()=>{R.current=h},[h]),t.useEffect(()=>{O.current=f},[f]),t.useEffect(()=>{p&&g(r,"set-context",{context:{...E}})},[E,r,p]),t.useEffect(()=>{p&&g(r,"set-params",{params:L})},[L,r,p]),t.useEffect(()=>{i!==void 0&&U((i==null?void 0:i.indexOf("/"))===0?i:`/${i}`)},[i]),t.useEffect(()=>{m===void 0||!p||g(r,"navigate",{path:m})},[m,p,r,g]),t.useEffect(()=>{if(!o||!r||!z)return;const n=new URL(o);return u(r,n.origin,z),O.current(),P(Y(n.origin,r)),()=>{d(r)}},[o,r,u,z]),t.useEffect(()=>{if(!(!M||v.current))return C.current=setTimeout(()=>{y(!0),R.current&&R.current()},be),()=>clearTimeout(C.current)},[M]);const A=t.useCallback(()=>{v.current=!0,clearTimeout(C.current),y(!1)},[]),[j,W]=t.useState(null);q(r,"init",n=>{A(),Array.isArray(n==null?void 0:n.acceptsCredentials)&&W(n.acceptsCredentials)}),q(r,"authorize",A),q(r,"login",A),q(r,"credential-request",()=>{A(),I(!0)}),t.useEffect(()=>{if(!S||!c)return;const n=j;if(Array.isArray(n)&&!n.includes(c.kind))return;const s=c.kind==="access_token"?{accessToken:c.accessToken}:{};g(r,"credential",{...s,credential:c})},[S,c,j,r,g]),q(r,"ready",()=>{A(),F(n=>n+1)});const e=t.useRef();return q(r,"heartbeat",()=>{e.current&&clearTimeout(e.current),e.current=setTimeout(()=>{if(z.current){const n=new URL(o);z.current.src=Y(n.origin,r)}},6e3)}),t.useEffect(()=>()=>{e.current&&clearTimeout(e.current)},[]),a?w?w(a):t.createElement(le,{entry:a}):_&&!p?x?x():t.createElement(ke,null):t.createElement(ge,{key:`auth-epoch-${$}`,$isReady:p,ref:z,src:M,...T})};de.propTypes={id:k.string,src:k.string.isRequired,path:k.string,onInit:k.func,onTimeout:k.func,renderUnsupported:k.func,renderTimeout:k.func};const Ce=B.div`
25
+ `,Te=()=>g.default.createElement(xe,null,g.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),be=({id:t,src:o,path:u,onInit:f=()=>{},onTimeout:p,context:m={},params:F={},renderUnsupported:w,renderTimeout:I,...z})=>{if("isConfiguring"in z)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in m)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in m)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const _=n.useRef(),[S,j]=n.useState(),[E,M]=n.useState(0),[Z,U]=n.useState(!1),[v,$]=n.useState(!1),T=ce(o),c=ae(o),a=le(o);n.useEffect(()=>{T>0&&M(0)},[T]);const{registerFrame:i,unregisterFrame:d,sendMessage:b}=n.useContext(K),[k,A]=n.useState(),x=n.useRef(),R=n.useRef(p),O=n.useRef(f),P=n.useRef(!1);n.useEffect(()=>{R.current=p},[p]),n.useEffect(()=>{O.current=f},[f]),n.useEffect(()=>{E&&b(t,"set-context",{context:{...m}})},[m,t,E]),n.useEffect(()=>{E&&b(t,"set-params",{params:F})},[F,t,E]),n.useEffect(()=>{u!==void 0&&A((u==null?void 0:u.indexOf("/"))===0?u:`/${u}`)},[u]),n.useEffect(()=>{k===void 0||!E||b(t,"navigate",{path:k})},[k,E,t,b]),n.useEffect(()=>{if(!o||!t||!_)return;const e=new URL(o);return i(t,e.origin,_),O.current(),j(ne(e.origin,t)),()=>{d(t)}},[o,t,i,_]),n.useEffect(()=>{if(!(!S||P.current))return x.current=setTimeout(()=>{U(!0),R.current&&R.current()},ke),()=>clearTimeout(x.current)},[S]);const y=n.useCallback(()=>{P.current=!0,clearTimeout(x.current),U(!1)},[]),[q,D]=n.useState(null);B(t,"init",e=>{y(),Array.isArray(e==null?void 0:e.acceptsCredentials)&&D(e.acceptsCredentials)}),B(t,"authorize",y),B(t,"login",y),B(t,"credential-request",()=>{y(),$(!0)}),n.useEffect(()=>{if(!v||!c)return;const e=q;if(Array.isArray(e)&&!e.includes(c.kind))return;const r=c.kind==="access_token"?{accessToken:c.accessToken}:{};b(t,"credential",{...r,credential:c})},[v,c,q,t,b]),B(t,"ready",()=>{y(),M(e=>e+1)});const L=n.useRef();return B(t,"heartbeat",()=>{L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{if(_.current){const e=new URL(o);_.current.src=ne(e.origin,t)}},6e3)}),n.useEffect(()=>()=>{L.current&&clearTimeout(L.current)},[]),a?w?w(a):g.default.createElement(pe,{entry:a}):Z&&!E?I?I():g.default.createElement(Te,null):g.default.createElement(Ce,{key:`auth-epoch-${T}`,$isReady:E,ref:_,src:S,...z})};be.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};const Ie=W.default.div`
26
26
  position: fixed;
27
27
  inset: 0;
28
28
  background: rgba(0, 0, 0, 0.45);
@@ -30,7 +30,7 @@
30
30
  align-items: center;
31
31
  justify-content: center;
32
32
  z-index: 10000;
33
- `,Re=B.div`
33
+ `,ze=W.default.div`
34
34
  background: #fff;
35
35
  border-radius: 8px;
36
36
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
@@ -39,13 +39,13 @@
39
39
  max-width: calc(100vw - 32px);
40
40
  font-family: sans-serif;
41
41
  color: #222;
42
- `,we=B.div`
42
+ `,_e=W.default.div`
43
43
  display: flex;
44
44
  align-items: center;
45
45
  justify-content: space-between;
46
46
  padding: 10px 0;
47
47
  gap: 16px;
48
- `,xe=B.button`
48
+ `,Me=W.default.button`
49
49
  background: #16a500;
50
50
  color: #fff;
51
51
  border: none;
@@ -54,8 +54,8 @@
54
54
  font-size: 14px;
55
55
  cursor: pointer;
56
56
  white-space: nowrap;
57
- `,Te=B.p`
57
+ `,Ue=W.default.p`
58
58
  color: #b3261e;
59
59
  font-size: 13px;
60
60
  margin: 4px 0 0;
61
- `,ze=()=>{const{pending:r,authorize:o}=se();return r.length===0?null:t.createElement(Ce,null,t.createElement(Re,null,t.createElement("h3",{style:{margin:"0 0 8px"}},"Authorization Required"),t.createElement("p",{style:{margin:"0 0 12px",fontSize:14,color:"#555"}},"The following apps need you to sign in and authorize them before they can load."),r.map(i=>t.createElement("div",{key:i.origin},t.createElement(we,null,t.createElement("div",null,t.createElement("div",{style:{fontWeight:600}},i.origin)),t.createElement(xe,{onClick:()=>o(i)},"Authorize")),i.popupBlocked&&t.createElement(Te,null,"The sign-in window was blocked. Allow popups for this site, then try again.")))))};exports.CREDENTIAL_KIND_ACCESS_TOKEN=ee;exports.EmbeddedAuthorizationContext=D;exports.EmbeddedAuthorizationPrompt=ze;exports.MMEmbeddableZone=de;exports.MMEmbeddableZoneContext=H;exports.MMEmbeddableZoneProvider=ue;exports.isCrossSite=te;exports.normalizeCredential=N;exports.popupAuthorizationLauncher=ne;exports.unsupportedCopy=ae;exports.useEmbeddedAuthorizations=se;exports.useEmbeddedCredential=ie;exports.useEmbeddedEffect=q;exports.useEmbeddedOriginEpoch=oe;exports.useEmbeddedUnsupported=ce;
61
+ `,Se=()=>{const{pending:t,authorize:o}=ue();return t.length===0?null:g.default.createElement(Ie,null,g.default.createElement(ze,null,g.default.createElement("h3",{style:{margin:"0 0 8px"}},"Authorization Required"),g.default.createElement("p",{style:{margin:"0 0 12px",fontSize:14,color:"#555"}},"The following apps need you to sign in and authorize them before they can load."),t.map(u=>g.default.createElement("div",{key:u.origin},g.default.createElement(_e,null,g.default.createElement("div",null,g.default.createElement("div",{style:{fontWeight:600}},u.origin)),g.default.createElement(Me,{onClick:()=>o(u)},"Authorize")),u.popupBlocked&&g.default.createElement(Ue,null,"The sign-in window was blocked. Allow popups for this site, then try again.")))))};exports.CREDENTIAL_KIND_ACCESS_TOKEN=re;exports.EmbeddedAuthorizationContext=H;exports.EmbeddedAuthorizationPrompt=Se;exports.MMEmbeddableZone=be;exports.MMEmbeddableZoneContext=K;exports.MMEmbeddableZoneProvider=de;exports.isCrossSite=se;exports.normalizeCredential=J;exports.popupAuthorizationLauncher=oe;exports.unsupportedCopy=fe;exports.useEmbeddedAuthorizations=ue;exports.useEmbeddedCredential=ae;exports.useEmbeddedEffect=B;exports.useEmbeddedOriginEpoch=ce;exports.useEmbeddedUnsupported=le;