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

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