@machinemetrics/mm-react-embeddable 1.4.0-5 → 1.4.0-7

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