@machinemetrics/mm-react-embeddable 2.0.0-4 → 2.0.0-5
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"),Ee=require("prop-types"),ge=require("styled-components"),ee=r=>r&&r.__esModule?r:{default:r},L=ee(t),k=ee(Ee),re=ee(ge),Y=t.createContext(null),N=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ue="access_token",Q=r=>r?r.kind?r:r.accessToken?{kind:ue,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,Re=60,ke=120,Ce=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),J=typeof window!="undefined"&&window.location.protocol==="https:",Te=8e3,G=r=>{try{return new URL(r).origin}catch{return null}},ne=(r,u)=>{const i=u==null?void 0:u.origin;return!i||G(r==null?void 0:r.authUrl)!==i?null:i},se=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const u=r.split(".");return u.length<=2?r:u.slice(-2).join(".")},oe=(r,u)=>{try{const i=new URL(r),f=new URL(u);return i.protocol!==f.protocol?!0:se(i.hostname)!==se(f.hostname)}catch{return!0}},ce=(r,{onBlocked:u,onClosed:i})=>{const f=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!f)return u(),()=>{};const m=setInterval(()=>{f.closed&&(clearInterval(m),i())},1e3);return()=>clearInterval(m)},ie=({children:r,launcher:u,broker:i})=>{const f=t.useContext(Y),[m,E]=t.useState({}),[B,C]=t.useState({}),[x,A]=t.useState({}),[P,O]=t.useState({}),v=t.useRef(x);v.current=x;const g=t.useRef(m);g.current=m;const z=t.useRef(null),K=t.useRef({}),M=t.useRef({}),D=t.useRef({}),$=t.useRef(i);$.current=i;const _=t.useCallback(e=>{const n=M.current[e];if(!n)return;const s=a=>!a[e]||a[e].clientId?a:{...a,[e]:{...a[e],clientId:n}};E(s),O(s)},[]),c=t.useCallback((e,n)=>{e&&(O(s=>s[e]?s:{...s,[e]:{origin:e,reason:n,clientId:M.current[e]||null}}),_(e))},[_]),l=t.useCallback((e,{v2:n=!1,origin:s=null}={})=>{s&&(n&&v.current[s]||(E(a=>a[s]?a:{...a,[s]:{origin:s,authUrl:e.authUrl,silentUrl:e.silentUrl||null,status:n&&$.current?"broker":n&&e.silentUrl&&J?"silent":"interactive",v2:n,scope:e.scope||null,acceptsCredentials:D.current[s]||null,consent:null,error:null,clientId:e.clientId||M.current[s]||null,popupBlocked:!1}}),_(s)))},[_]),o=t.useRef({}),d=t.useCallback(e=>{o.current[e]&&(clearTimeout(o.current[e]),delete o.current[e])},[]),p=t.useCallback(e=>{d(e),E(n=>{if(!n[e])return n;const s={...n};return delete s[e],s})},[d]),h=t.useCallback(e=>{e&&(p(e),C(n=>({...n,[e]:(n[e]||0)+1})))},[p]),S=t.useCallback(e=>{E(n=>!n[e]||n[e].status==="interactive"?n:{...n,[e]:{...n[e],status:"interactive"}})},[]),y=t.useCallback(e=>{p(e.origin)},[p]),R=t.useCallback((e,n)=>{const s=ne(e,n);if(s){if(oe(s,window.location.origin)){c(s,"cross-site-legacy");return}l(e,{origin:s})}},[l,c]);t.useEffect(()=>{if(!f)return;const e=[f.addListener("*","init",(n,s)=>{s!=null&&s.origin&&(n!=null&&n.clientId)&&(M.current[s.origin]=n.clientId,_(s.origin)),s!=null&&s.origin&&Array.isArray(n==null?void 0:n.acceptsCredentials)&&(D.current[s.origin]=n.acceptsCredentials)}),f.addListener("*","authorize",R),f.addListener("*","login",R),f.addListener("*","credential-request",(n,s)=>l(n,{v2:!0,origin:ne(n,s)}))];return()=>e.forEach(n=>n())},[f,R,l,_]),t.useEffect(()=>{const e=n=>{const s=n==null?void 0:n.data;if(!s||s.type!=="authorized"&&s.type!=="authorize-failed")return;const a=G(s.authUrl);if(!(!a||n.origin!==a)){if(s.type==="authorized"){if(s.accessToken){if(!g.current[a])return;A(b=>({...b,[a]:Q({accessToken:s.accessToken})})),p(a)}else h(a);return}S(a)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[p,h,S]);const F=t.useCallback((e,n)=>{const s=e==null?void 0:e.origin,a=Q(n);!s||!a||(A(b=>({...b,[s]:a})),p(s))},[p]),U=t.useCallback((e,n)=>{E(s=>s[e]?{...s,[e]:{...s[e],...n}}:s)},[]),w=t.useRef({}),I=t.useCallback(async(e,{approve:n}={})=>{const s=$.current,{origin:a}=e;let b;try{b=await s({origin:a,clientId:e.clientId,scope:e.scope,authUrl:e.authUrl},{approve:n})}catch{n?U(a,{error:{reason:"broker_unavailable"}}):U(a,{status:e.silentUrl&&J?"silent":"interactive"});return}if((b==null?void 0:b.status)===200&&b.credential){F(e,b.credential);return}if((b==null?void 0:b.status)===409&&b.consentRequired){U(a,{status:"interactive",consent:{client:b.client||null,stepUp:!!b.stepUp,scope:b.scope||e.scope},error:null});return}const V=(b==null?void 0:b.error)||"broker_error";if(!n&&Ce.has(V)){U(a,{status:e.silentUrl&&J?"silent":"interactive"});return}if(n&&V==="consent_denied"){U(a,{error:null});return}if(V==="rate_limited"&&!e.rateLimitRetried){const X=Math.min(Number(b==null?void 0:b.retryAfter)>0?Number(b.retryAfter):Re,ke),he={...e,rateLimitRetried:!0};d(a),o.current[a]=setTimeout(()=>{delete o.current[a],w.current[a]=!0,Z.current(he,{approve:n}).finally(()=>{delete w.current[a]})},X*1e3),U(a,{rateLimitRetried:!0});return}p(a),O(X=>({...X,[a]:{origin:a,reason:`broker:${V}`,detail:b||null,clientId:e.clientId||M.current[a]||null}}))},[F,U,p,d]),Z=t.useRef(I);Z.current=I,t.useEffect(()=>{Object.values(m).forEach(e=>{e.status!=="broker"||w.current[e.origin]||o.current[e.origin]||(w.current[e.origin]=!0,I(e).finally(()=>{delete w.current[e.origin]}))})},[m,I]);const W=t.useCallback(e=>!$.current||!(e!=null&&e.consent)?Promise.resolve():I(e,{approve:!0}),[I]);t.useEffect(()=>{const e=K.current;Object.values(m).forEach(n=>{n.status==="silent"&&!e[n.origin]&&(e[n.origin]=setTimeout(()=>{delete e[n.origin],S(n.origin)},Te))}),Object.keys(e).forEach(n=>{(!m[n]||m[n].status!=="silent")&&(clearTimeout(e[n]),delete e[n])})},[m,S]),t.useEffect(()=>()=>{z.current&&z.current(),Object.values(K.current).forEach(clearTimeout),Object.values(o.current).forEach(clearTimeout)},[]);const j=t.useCallback(e=>{z.current&&(z.current(),z.current=null);const n=u||ce;z.current=n(e,{onBlocked:()=>{E(s=>s[e.origin]?{...s,[e.origin]:{...s[e.origin],popupBlocked:!0}}:s)},onClosed:()=>{if(e.v2){J&&E(s=>!s[e.origin]||!s[e.origin].silentUrl?s:{...s,[e.origin]:{...s[e.origin],status:"silent"}});return}h(e.origin)}})},[u,h]),T={pending:Object.values(m).filter(e=>e.status==="interactive"),authorize:j,approve:W,complete:F,dismiss:y,originEpochs:B,credentials:x,unsupported:P},q=Object.values(m).filter(e=>e.status==="silent"&&e.silentUrl);return L.default.createElement(N.Provider,{value:T},r,q.map(e=>L.default.createElement("iframe",{key:`mm-silent-auth-${e.origin}`,src:e.silentUrl,title:`MachineMetrics silent authorization (${e.origin})`,"aria-hidden":"true",tabIndex:-1,style:{display:"none"}})))};ie.propTypes={children:k.default.node,launcher:k.default.func,broker:k.default.func};const _e=()=>t.useContext(N),ae=r=>{const{originEpochs:u}=t.useContext(N),i=G(r);return i&&u[i]||0},le=r=>{const{credentials:u}=t.useContext(N),i=G(r);return i&&u[i]||null},de=r=>{const{unsupported:u}=t.useContext(N),i=G(r);return i&&u[i]||null},fe=({children:r,authorizationLauncher:u,credentialBroker:i})=>{const[f,m]=t.useState({}),[E,B]=t.useState({}),C=t.useRef({}),x=t.useRef({}),A=t.useRef({}),P=t.useCallback((c,l)=>{var o;return!!((o=A.current[c])!=null&&o.has(l))},[]),O=t.useCallback((c,l,o)=>{m(d=>({...d,[c]:{origin:l,frameRef:o}}))},[]),v=t.useCallback(c=>{m(l=>{const o={...l};return delete o[c],o}),B(l=>{const o={...l};return delete o[c],o}),delete A.current[c]},[]);t.useEffect(()=>{const c=(o=[],d,p)=>{o.forEach(h=>h(d,p))},l=o=>{var F,U,w,I,Z,W,j;if(!((F=o==null?void 0:o.data)!=null&&F.instanceId))return;const{instanceId:d,type:p}=o.data,h=f[d],S=(w=(U=h==null?void 0:h.frameRef)==null?void 0:U.current)==null?void 0:w.contentWindow;if(!S||o.source!==S||o.origin!==h.origin)return;const y={origin:o.origin},R=C.current;if(p==="response"){const{callbackId:T,response:q,error:e}=o.data,n=x.current[T];n&&(n(q,e),delete x.current[T]);return}if(p==="mark-registered"){const{requestType:T}=o.data;A.current[d]||(A.current[d]=new Set),A.current[d].add(T);return}p==="ready"&&B(T=>({...T,[d]:!0})),c((I=R[d])==null?void 0:I[p],o.data,y),c((Z=R["*"])==null?void 0:Z[p],o.data,y),c((W=R[d])==null?void 0:W["*"],o.data,y),c((j=R["*"])==null?void 0:j["*"],o.data,y)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[f]);const g=t.useCallback((c,l,o)=>{var p,h;const d=f[c];if(!d){console.warn(`Origin not set for id: ${c}. Unable to send message.`);return}(h=(p=d==null?void 0:d.frameRef)==null?void 0:p.current)!=null&&h.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:l,...o,instanceId:c},d.origin)},[f]),z=t.useRef(0),K=t.useCallback(()=>`${Date.now()}-${++z.current}`,[]),M=t.useCallback(async(c,l,o={})=>new Promise((d,p)=>{const h=K(),S=(y,R)=>{delete x.current[h],R?p(R):d(y)};x.current[h]=S,g(c,"request",{callbackId:h,requestType:l,data:o})}),[g]),D=t.useCallback((c,l)=>{g(c,"load-options",l)},[g]),$=t.useCallback((c,l)=>{g(c,"validate",l)},[g]),_=t.useMemo(()=>({registerFrame:O,unregisterFrame:v,sendMessage:g,sendRequest:M,loadOptions:D,validate:$,hasHandler:P,readyFrames:E,addListener:(c,l,o)=>(C.current[c]||(C.current[c]={}),C.current[c][l]||(C.current[c][l]=[]),C.current[c][l].push(o),()=>{C.current[c][l]=C.current[c][l].filter(d=>d!==o)})}),[O,v,g,M,D,$,P,E]);return L.default.createElement(Y.Provider,{value:_},L.default.createElement(ie,{launcher:u,broker:i},r))},H=(r,u,i)=>{const f=t.useContext(Y);if(f===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const m=t.useRef(i);t.useEffect(()=>{m.current=i},[i]),t.useEffect(()=>{if(!(!r||!u)){if(u.startsWith("key:")){const E=u.substring(4);return f.readyFrames[r]&&f.sendMessage(r,"subscribe-key",{keyChord:E}),f.addListener(r,`key-pressed:${E}`,(...C)=>m.current(...C))}return f.addListener(r,u,(...E)=>m.current(...E))}},[f,r,u])};fe.propTypes={children:k.default.node.isRequired,authorizationLauncher:k.default.func,credentialBroker:k.default.func};const te=re.default.default||re.default,we=1e4,Ie="credentials",Me=(r,u)=>`${r}/mm-embedded-interop?id=${encodeURIComponent(u)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Ie}`,Se=te.iframe`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),Ee=require("prop-types"),ge=require("styled-components"),te=r=>r&&r.__esModule?r:{default:r},L=te(t),k=te(Ee),ne=te(ge),Y=t.createContext(null),N=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ue="access_token",Q=r=>r?r.kind?r:r.accessToken?{kind:ue,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,Re=60,ke=120,Ce=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),J=typeof window!="undefined"&&window.location.protocol==="https:",Te=8e3,G=r=>{try{return new URL(r).origin}catch{return null}},se=(r,o)=>{const i=o==null?void 0:o.origin;return!i||G(r==null?void 0:r.authUrl)!==i?null:i},oe=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(".")},ee=(r,o)=>{try{const i=new URL(r),f=new URL(o);return i.protocol!==f.protocol?!0:oe(i.hostname)!==oe(f.hostname)}catch{return!0}},ce=(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)},ie=({children:r,launcher:o,broker:i})=>{const f=t.useContext(Y),[h,E]=t.useState({}),[B,C]=t.useState({}),[x,A]=t.useState({}),[P,O]=t.useState({}),v=t.useRef(x);v.current=x;const g=t.useRef(h);g.current=h;const z=t.useRef(null),K=t.useRef({}),M=t.useRef({}),D=t.useRef({}),$=t.useRef(i);$.current=i;const _=t.useCallback(e=>{const n=M.current[e];if(!n)return;const s=a=>!a[e]||a[e].clientId?a:{...a,[e]:{...a[e],clientId:n}};E(s),O(s)},[]),c=t.useCallback((e,n)=>{e&&(O(s=>s[e]?s:{...s,[e]:{origin:e,reason:n,clientId:M.current[e]||null}}),_(e))},[_]),l=t.useCallback((e,{v2:n=!1,origin:s=null}={})=>{s&&(n&&v.current[s]||(E(a=>a[s]?a:{...a,[s]:{origin:s,authUrl:e.authUrl,silentUrl:e.silentUrl||null,status:n&&$.current?"broker":n&&e.silentUrl&&J?"silent":"interactive",v2:n,scope:e.scope||null,acceptsCredentials:D.current[s]||null,consent:null,error:null,clientId:e.clientId||M.current[s]||null,popupBlocked:!1}}),_(s)))},[_]),u=t.useRef({}),d=t.useCallback(e=>{u.current[e]&&(clearTimeout(u.current[e]),delete u.current[e])},[]),p=t.useCallback(e=>{d(e),E(n=>{if(!n[e])return n;const s={...n};return delete s[e],s})},[d]),m=t.useCallback(e=>{e&&(p(e),C(n=>({...n,[e]:(n[e]||0)+1})))},[p]),S=t.useCallback(e=>{E(n=>!n[e]||n[e].status==="interactive"?n:{...n,[e]:{...n[e],status:"interactive"}})},[]),y=t.useCallback(e=>{p(e.origin)},[p]),R=t.useCallback((e,n)=>{const s=se(e,n);if(s){if(ee(s,window.location.origin)){c(s,"cross-site-legacy");return}l(e,{origin:s})}},[l,c]);t.useEffect(()=>{if(!f)return;const e=[f.addListener("*","init",(n,s)=>{s!=null&&s.origin&&(n!=null&&n.clientId)&&(M.current[s.origin]=n.clientId,_(s.origin)),s!=null&&s.origin&&Array.isArray(n==null?void 0:n.acceptsCredentials)?D.current[s.origin]=n.acceptsCredentials:s!=null&&s.origin&&ee(s.origin,window.location.origin)&&c(s.origin,"cross-site-legacy")}),f.addListener("*","authorize",R),f.addListener("*","login",R),f.addListener("*","credential-request",(n,s)=>l(n,{v2:!0,origin:se(n,s)}))];return()=>e.forEach(n=>n())},[f,R,l,_,c]),t.useEffect(()=>{const e=n=>{const s=n==null?void 0:n.data;if(!s||s.type!=="authorized"&&s.type!=="authorize-failed")return;const a=G(s.authUrl);if(!(!a||n.origin!==a)){if(s.type==="authorized"){if(s.accessToken){if(!g.current[a])return;A(b=>({...b,[a]:Q({accessToken:s.accessToken})})),p(a)}else m(a);return}S(a)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[p,m,S]);const F=t.useCallback((e,n)=>{const s=e==null?void 0:e.origin,a=Q(n);!s||!a||(A(b=>({...b,[s]:a})),p(s))},[p]),U=t.useCallback((e,n)=>{E(s=>s[e]?{...s,[e]:{...s[e],...n}}:s)},[]),w=t.useRef({}),I=t.useCallback(async(e,{approve:n}={})=>{const s=$.current,{origin:a}=e;let b;try{b=await s({origin:a,clientId:e.clientId,scope:e.scope,authUrl:e.authUrl},{approve:n})}catch{n?U(a,{error:{reason:"broker_unavailable"}}):U(a,{status:e.silentUrl&&J?"silent":"interactive"});return}if((b==null?void 0:b.status)===200&&b.credential){F(e,b.credential);return}if((b==null?void 0:b.status)===409&&b.consentRequired){U(a,{status:"interactive",consent:{client:b.client||null,stepUp:!!b.stepUp,scope:b.scope||e.scope},error:null});return}const V=(b==null?void 0:b.error)||"broker_error";if(!n&&Ce.has(V)){U(a,{status:e.silentUrl&&J?"silent":"interactive"});return}if(n&&V==="consent_denied"){U(a,{error:null});return}if(V==="rate_limited"&&!e.rateLimitRetried){const X=Math.min(Number(b==null?void 0:b.retryAfter)>0?Number(b.retryAfter):Re,ke),me={...e,rateLimitRetried:!0};d(a),u.current[a]=setTimeout(()=>{delete u.current[a],w.current[a]=!0,Z.current(me,{approve:n}).finally(()=>{delete w.current[a]})},X*1e3),U(a,{rateLimitRetried:!0});return}p(a),O(X=>({...X,[a]:{origin:a,reason:`broker:${V}`,detail:b||null,clientId:e.clientId||M.current[a]||null}}))},[F,U,p,d]),Z=t.useRef(I);Z.current=I,t.useEffect(()=>{Object.values(h).forEach(e=>{e.status!=="broker"||w.current[e.origin]||u.current[e.origin]||(w.current[e.origin]=!0,I(e).finally(()=>{delete w.current[e.origin]}))})},[h,I]);const W=t.useCallback(e=>!$.current||!(e!=null&&e.consent)?Promise.resolve():I(e,{approve:!0}),[I]);t.useEffect(()=>{const e=K.current;Object.values(h).forEach(n=>{n.status==="silent"&&!e[n.origin]&&(e[n.origin]=setTimeout(()=>{delete e[n.origin],S(n.origin)},Te))}),Object.keys(e).forEach(n=>{(!h[n]||h[n].status!=="silent")&&(clearTimeout(e[n]),delete e[n])})},[h,S]),t.useEffect(()=>()=>{z.current&&z.current(),Object.values(K.current).forEach(clearTimeout),Object.values(u.current).forEach(clearTimeout)},[]);const j=t.useCallback(e=>{z.current&&(z.current(),z.current=null);const n=o||ce;z.current=n(e,{onBlocked:()=>{E(s=>s[e.origin]?{...s,[e.origin]:{...s[e.origin],popupBlocked:!0}}:s)},onClosed:()=>{if(e.v2){J&&E(s=>!s[e.origin]||!s[e.origin].silentUrl?s:{...s,[e.origin]:{...s[e.origin],status:"silent"}});return}m(e.origin)}})},[o,m]),T={pending:Object.values(h).filter(e=>e.status==="interactive"),authorize:j,approve:W,complete:F,dismiss:y,originEpochs:B,credentials:x,unsupported:P},q=Object.values(h).filter(e=>e.status==="silent"&&e.silentUrl);return L.default.createElement(N.Provider,{value:T},r,q.map(e=>L.default.createElement("iframe",{key:`mm-silent-auth-${e.origin}`,src:e.silentUrl,title:`MachineMetrics silent authorization (${e.origin})`,"aria-hidden":"true",tabIndex:-1,style:{display:"none"}})))};ie.propTypes={children:k.default.node,launcher:k.default.func,broker:k.default.func};const _e=()=>t.useContext(N),ae=r=>{const{originEpochs:o}=t.useContext(N),i=G(r);return i&&o[i]||0},le=r=>{const{credentials:o}=t.useContext(N),i=G(r);return i&&o[i]||null},de=r=>{const{unsupported:o}=t.useContext(N),i=G(r);return i&&o[i]||null},fe=({children:r,authorizationLauncher:o,credentialBroker:i})=>{const[f,h]=t.useState({}),[E,B]=t.useState({}),C=t.useRef({}),x=t.useRef({}),A=t.useRef({}),P=t.useCallback((c,l)=>{var u;return!!((u=A.current[c])!=null&&u.has(l))},[]),O=t.useCallback((c,l,u)=>{h(d=>({...d,[c]:{origin:l,frameRef:u}}))},[]),v=t.useCallback(c=>{h(l=>{const u={...l};return delete u[c],u}),B(l=>{const u={...l};return delete u[c],u}),delete A.current[c]},[]);t.useEffect(()=>{const c=(u=[],d,p)=>{u.forEach(m=>m(d,p))},l=u=>{var F,U,w,I,Z,W,j;if(!((F=u==null?void 0:u.data)!=null&&F.instanceId))return;const{instanceId:d,type:p}=u.data,m=f[d],S=(w=(U=m==null?void 0:m.frameRef)==null?void 0:U.current)==null?void 0:w.contentWindow;if(!S||u.source!==S||u.origin!==m.origin)return;const y={origin:u.origin},R=C.current;if(p==="response"){const{callbackId:T,response:q,error:e}=u.data,n=x.current[T];n&&(n(q,e),delete x.current[T]);return}if(p==="mark-registered"){const{requestType:T}=u.data;A.current[d]||(A.current[d]=new Set),A.current[d].add(T);return}p==="ready"&&B(T=>({...T,[d]:!0})),c((I=R[d])==null?void 0:I[p],u.data,y),c((Z=R["*"])==null?void 0:Z[p],u.data,y),c((W=R[d])==null?void 0:W["*"],u.data,y),c((j=R["*"])==null?void 0:j["*"],u.data,y)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[f]);const g=t.useCallback((c,l,u)=>{var p,m;const d=f[c];if(!d){console.warn(`Origin not set for id: ${c}. Unable to send message.`);return}(m=(p=d==null?void 0:d.frameRef)==null?void 0:p.current)!=null&&m.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:l,...u,instanceId:c},d.origin)},[f]),z=t.useRef(0),K=t.useCallback(()=>`${Date.now()}-${++z.current}`,[]),M=t.useCallback(async(c,l,u={})=>new Promise((d,p)=>{const m=K(),S=(y,R)=>{delete x.current[m],R?p(R):d(y)};x.current[m]=S,g(c,"request",{callbackId:m,requestType:l,data:u})}),[g]),D=t.useCallback((c,l)=>{g(c,"load-options",l)},[g]),$=t.useCallback((c,l)=>{g(c,"validate",l)},[g]),_=t.useMemo(()=>({registerFrame:O,unregisterFrame:v,sendMessage:g,sendRequest:M,loadOptions:D,validate:$,hasHandler:P,readyFrames:E,addListener:(c,l,u)=>(C.current[c]||(C.current[c]={}),C.current[c][l]||(C.current[c][l]=[]),C.current[c][l].push(u),()=>{C.current[c][l]=C.current[c][l].filter(d=>d!==u)})}),[O,v,g,M,D,$,P,E]);return L.default.createElement(Y.Provider,{value:_},L.default.createElement(ie,{launcher:o,broker:i},r))},H=(r,o,i)=>{const f=t.useContext(Y);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}`,(...C)=>h.current(...C))}return f.addListener(r,o,(...E)=>h.current(...E))}},[f,r,o])};fe.propTypes={children:k.default.node.isRequired,authorizationLauncher:k.default.func,credentialBroker:k.default.func};const re=ne.default.default||ne.default,we=1e4,Ie="credentials",Me=(r,o)=>`${r}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Ie}`,Se=re.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
5
5
|
visibility: ${r=>r.$isReady?"visible":"hidden"};
|
|
6
|
-
`,Ue=
|
|
6
|
+
`,Ue=re.div`
|
|
7
7
|
width: 100%;
|
|
8
8
|
height: 100%;
|
|
9
9
|
display: flex;
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
text-align: center;
|
|
17
17
|
color: #555;
|
|
18
18
|
font-size: 14px;
|
|
19
|
-
`,pe=r=>{const
|
|
19
|
+
`,pe=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."}}},be=({entry:r})=>{const o=pe(r);return L.default.createElement(Ue,{"data-reason":r&&r.reason||void 0},L.default.createElement("div",{style:{fontWeight:600}},o.title),L.default.createElement("div",{style:{fontSize:12,color:"#888"}},o.detail))};be.propTypes={entry:k.default.shape({origin:k.default.string,name:k.default.string,reason:k.default.string,detail:k.default.object})};const Le=re.div`
|
|
20
20
|
height: 100%;
|
|
21
21
|
display: flex;
|
|
22
22
|
flex: 1;
|
|
23
23
|
align-items: center;
|
|
24
24
|
justify-content: center;
|
|
25
|
-
`,xe=()=>L.default.createElement(Le,null,L.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),
|
|
25
|
+
`,xe=()=>L.default.createElement(Le,null,L.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),he=({id:r,src:o,path:i,onInit:f=()=>{},onTimeout:h,context:E={},params:B={},renderUnsupported:C,renderTimeout:x,...A})=>{if("isConfiguring"in A)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 P=t.useRef(),[O,v]=t.useState(),[g,z]=t.useState(0),[K,M]=t.useState(!1),[D,$]=t.useState(!1),_=ae(o),c=le(o),l=de(o),[u,d]=t.useState(0),[p,m]=t.useState(null),{registerFrame:S,unregisterFrame:y,sendMessage:R}=t.useContext(Y),[F,U]=t.useState(),w=t.useRef(),I=t.useRef(h),Z=t.useRef(f),W=t.useRef(!1),j=t.useCallback(()=>{W.current=!1,clearTimeout(w.current),z(0),M(!1),$(!1),m(null)},[]);t.useEffect(()=>{(_>0||u>0)&&j()},[_,u,j]),t.useEffect(()=>{I.current=h},[h]),t.useEffect(()=>{Z.current=f},[f]),t.useEffect(()=>{g&&R(r,"set-context",{context:{...E}})},[E,r,g]),t.useEffect(()=>{g&&R(r,"set-params",{params:B})},[B,r,g]),t.useEffect(()=>{i!==void 0&&U((i==null?void 0:i.indexOf("/"))===0?i:`/${i}`)},[i]),t.useEffect(()=>{F===void 0||!g||R(r,"navigate",{path:F})},[F,g,r,R]),t.useEffect(()=>{if(!o||!r||!P)return;j();const e=new URL(o);return S(r,e.origin,P),Z.current(),v(Me(e.origin,r)),()=>{y(r)}},[o,r,S,P,j]),t.useEffect(()=>{if(!(!O||W.current))return w.current=setTimeout(()=>{M(!0),I.current&&I.current()},we),()=>clearTimeout(w.current)},[O,o,_,u]);const T=t.useCallback(()=>{W.current=!0,clearTimeout(w.current),M(!1)},[]);H(r,"init",e=>{T(),Array.isArray(e==null?void 0:e.acceptsCredentials)&&m(e.acceptsCredentials)}),H(r,"authorize",T),H(r,"login",T),H(r,"credential-request",()=>{T(),$(!0)}),t.useEffect(()=>{if(!D||!c)return;const e=p;if(Array.isArray(e)&&!e.includes(c.kind))return;const n=c.kind==="access_token"?{accessToken:c.accessToken}:{};R(r,"credential",{...n,credential:c})},[D,c,p,r,R]),H(r,"ready",()=>{T(),z(e=>e+1)});const q=t.useRef();return H(r,"heartbeat",()=>{q.current&&clearTimeout(q.current),q.current=setTimeout(()=>{d(e=>e+1)},6e3)}),t.useEffect(()=>()=>{q.current&&clearTimeout(q.current)},[]),l?C?C(l):L.default.createElement(be,{entry:l}):K&&!g?x?x():L.default.createElement(xe,null):L.default.createElement(Se,{key:`auth-epoch-${_}-frame-${u}`,$isReady:g,ref:P,src:O,...A})};he.propTypes={id:k.default.string,src:k.default.string.isRequired,path:k.default.string,onInit:k.default.func,onTimeout:k.default.func,renderUnsupported:k.default.func,renderTimeout:k.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=ue;exports.EmbeddedAuthorizationContext=N;exports.MMEmbeddableZone=he;exports.MMEmbeddableZoneContext=Y;exports.MMEmbeddableZoneProvider=fe;exports.isCrossSite=ee;exports.normalizeCredential=Q;exports.popupAuthorizationLauncher=ce;exports.unsupportedCopy=pe;exports.useEmbeddedAuthorizations=_e;exports.useEmbeddedCredential=le;exports.useEmbeddedEffect=H;exports.useEmbeddedOriginEpoch=ae;exports.useEmbeddedUnsupported=de;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import x, { createContext as
|
|
1
|
+
import x, { createContext as le, useContext as G, useState as C, useRef as b, useCallback as m, useEffect as T, useMemo as pe } from "react";
|
|
2
2
|
import w from "prop-types";
|
|
3
3
|
import se from "styled-components";
|
|
4
|
-
const re =
|
|
4
|
+
const re = le(null), J = le({
|
|
5
5
|
pending: [],
|
|
6
6
|
authorize: () => {
|
|
7
7
|
},
|
|
@@ -14,16 +14,16 @@ const re = ue(null), J = ue({
|
|
|
14
14
|
originEpochs: {},
|
|
15
15
|
credentials: {},
|
|
16
16
|
unsupported: {}
|
|
17
|
-
}),
|
|
18
|
-
kind:
|
|
17
|
+
}), he = "access_token", oe = (t) => t ? t.kind ? t : t.accessToken ? {
|
|
18
|
+
kind: he,
|
|
19
19
|
accessToken: t.accessToken,
|
|
20
20
|
expiresAt: t.expiresAt || null
|
|
21
|
-
} : null : null, me = 60,
|
|
21
|
+
} : null : null, me = 60, ge = 120, be = /* @__PURE__ */ new Set([
|
|
22
22
|
"host_not_allowed",
|
|
23
23
|
"unbound_host_bound_guest",
|
|
24
24
|
"invalid_token",
|
|
25
25
|
"provider_unavailable"
|
|
26
|
-
]), te = typeof window != "undefined" && window.location.protocol === "https:",
|
|
26
|
+
]), te = typeof window != "undefined" && window.location.protocol === "https:", Ee = 8e3, N = (t) => {
|
|
27
27
|
try {
|
|
28
28
|
return new URL(t).origin;
|
|
29
29
|
} catch {
|
|
@@ -37,7 +37,7 @@ const re = ue(null), J = ue({
|
|
|
37
37
|
return t;
|
|
38
38
|
const s = t.split(".");
|
|
39
39
|
return s.length <= 2 ? t : s.slice(-2).join(".");
|
|
40
|
-
},
|
|
40
|
+
}, ue = (t, s) => {
|
|
41
41
|
try {
|
|
42
42
|
const c = new URL(t), d = new URL(s);
|
|
43
43
|
return c.protocol !== d.protocol ? !0 : ce(c.hostname) !== ce(d.hostname);
|
|
@@ -53,32 +53,32 @@ const re = ue(null), J = ue({
|
|
|
53
53
|
if (!d)
|
|
54
54
|
return s(), () => {
|
|
55
55
|
};
|
|
56
|
-
const
|
|
57
|
-
d.closed && (clearInterval(
|
|
56
|
+
const h = setInterval(() => {
|
|
57
|
+
d.closed && (clearInterval(h), c());
|
|
58
58
|
}, 1e3);
|
|
59
|
-
return () => clearInterval(
|
|
59
|
+
return () => clearInterval(h);
|
|
60
60
|
}, ae = ({ children: t, launcher: s, broker: c }) => {
|
|
61
|
-
const d = G(re), [
|
|
61
|
+
const d = G(re), [h, E] = C({}), [H, I] = C({}), [$, S] = C({}), [q, y] = C({}), Y = b($);
|
|
62
62
|
Y.current = $;
|
|
63
|
-
const R = b(
|
|
64
|
-
R.current =
|
|
65
|
-
const F = b(null), V = b({}), A = b({}), Z = b({}),
|
|
66
|
-
|
|
67
|
-
const U =
|
|
63
|
+
const R = b(h);
|
|
64
|
+
R.current = h;
|
|
65
|
+
const F = b(null), V = b({}), A = b({}), Z = b({}), P = b(c);
|
|
66
|
+
P.current = c;
|
|
67
|
+
const U = m((e) => {
|
|
68
68
|
const r = A.current[e];
|
|
69
69
|
if (!r)
|
|
70
70
|
return;
|
|
71
71
|
const n = (u) => !u[e] || u[e].clientId ? u : { ...u, [e]: { ...u[e], clientId: r } };
|
|
72
|
-
E(n),
|
|
73
|
-
}, []), i =
|
|
72
|
+
E(n), y(n);
|
|
73
|
+
}, []), i = m(
|
|
74
74
|
(e, r) => {
|
|
75
|
-
e && (
|
|
75
|
+
e && (y((n) => n[e] ? n : {
|
|
76
76
|
...n,
|
|
77
77
|
[e]: { origin: e, reason: r, clientId: A.current[e] || null }
|
|
78
78
|
}), U(e));
|
|
79
79
|
},
|
|
80
80
|
[U]
|
|
81
|
-
),
|
|
81
|
+
), l = m(
|
|
82
82
|
(e, { v2: r = !1, origin: n = null } = {}) => {
|
|
83
83
|
n && (r && Y.current[n] || (E((u) => u[n] ? u : {
|
|
84
84
|
...u,
|
|
@@ -89,7 +89,7 @@ const re = ue(null), J = ue({
|
|
|
89
89
|
// v2 entries try the invisible silent resolver first — but only on a host that can
|
|
90
90
|
// frame login (https). Otherwise (and for legacy signals) go straight to interactive,
|
|
91
91
|
// so an http host doesn't wait out a silent frame that can never load login.
|
|
92
|
-
status: r &&
|
|
92
|
+
status: r && P.current ? "broker" : r && e.silentUrl && te ? "silent" : "interactive",
|
|
93
93
|
v2: r,
|
|
94
94
|
// v1.9: the scope the guest asked for; forwarded verbatim to the broker.
|
|
95
95
|
scope: e.scope || null,
|
|
@@ -104,16 +104,16 @@ const re = ue(null), J = ue({
|
|
|
104
104
|
}), U(n)));
|
|
105
105
|
},
|
|
106
106
|
[U]
|
|
107
|
-
), o = b({}),
|
|
107
|
+
), o = b({}), a = m((e) => {
|
|
108
108
|
o.current[e] && (clearTimeout(o.current[e]), delete o.current[e]);
|
|
109
|
-
}, []), f =
|
|
110
|
-
|
|
109
|
+
}, []), f = m((e) => {
|
|
110
|
+
a(e), E((r) => {
|
|
111
111
|
if (!r[e])
|
|
112
112
|
return r;
|
|
113
113
|
const n = { ...r };
|
|
114
114
|
return delete n[e], n;
|
|
115
115
|
});
|
|
116
|
-
}, [
|
|
116
|
+
}, [a]), g = m(
|
|
117
117
|
(e) => {
|
|
118
118
|
e && (f(e), I((r) => ({
|
|
119
119
|
...r,
|
|
@@ -121,28 +121,28 @@ const re = ue(null), J = ue({
|
|
|
121
121
|
})));
|
|
122
122
|
},
|
|
123
123
|
[f]
|
|
124
|
-
), O =
|
|
124
|
+
), O = m((e) => {
|
|
125
125
|
E((r) => !r[e] || r[e].status === "interactive" ? r : {
|
|
126
126
|
...r,
|
|
127
127
|
[e]: { ...r[e], status: "interactive" }
|
|
128
128
|
});
|
|
129
|
-
}, []), j =
|
|
129
|
+
}, []), j = m(
|
|
130
130
|
(e) => {
|
|
131
131
|
f(e.origin);
|
|
132
132
|
},
|
|
133
133
|
[f]
|
|
134
|
-
), k =
|
|
134
|
+
), k = m(
|
|
135
135
|
(e, r) => {
|
|
136
136
|
const n = ie(e, r);
|
|
137
137
|
if (n) {
|
|
138
|
-
if (
|
|
138
|
+
if (ue(n, window.location.origin)) {
|
|
139
139
|
i(n, "cross-site-legacy");
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
l(e, { origin: n });
|
|
143
143
|
}
|
|
144
144
|
},
|
|
145
|
-
[
|
|
145
|
+
[l, i]
|
|
146
146
|
);
|
|
147
147
|
T(() => {
|
|
148
148
|
if (!d)
|
|
@@ -155,18 +155,18 @@ const re = ue(null), J = ue({
|
|
|
155
155
|
// clientId is only a lookup key: the host resolves the display name from
|
|
156
156
|
// it, and a broker binds it to the attested origin server-side.
|
|
157
157
|
d.addListener("*", "init", (r, n) => {
|
|
158
|
-
n != null && n.origin && (r != null && r.clientId) && (A.current[n.origin] = r.clientId, U(n.origin)), n != null && n.origin && Array.isArray(r == null ? void 0 : r.acceptsCredentials)
|
|
158
|
+
n != null && n.origin && (r != null && r.clientId) && (A.current[n.origin] = r.clientId, U(n.origin)), n != null && n.origin && Array.isArray(r == null ? void 0 : r.acceptsCredentials) ? Z.current[n.origin] = r.acceptsCredentials : n != null && n.origin && ue(n.origin, window.location.origin) && i(n.origin, "cross-site-legacy");
|
|
159
159
|
}),
|
|
160
160
|
d.addListener("*", "authorize", k),
|
|
161
161
|
d.addListener("*", "login", k),
|
|
162
162
|
d.addListener(
|
|
163
163
|
"*",
|
|
164
164
|
"credential-request",
|
|
165
|
-
(r, n) =>
|
|
165
|
+
(r, n) => l(r, { v2: !0, origin: ie(r, n) })
|
|
166
166
|
)
|
|
167
167
|
];
|
|
168
168
|
return () => e.forEach((r) => r());
|
|
169
|
-
}, [d, k,
|
|
169
|
+
}, [d, k, l, U, i]), T(() => {
|
|
170
170
|
const e = (r) => {
|
|
171
171
|
const n = r == null ? void 0 : r.data;
|
|
172
172
|
if (!n || n.type !== "authorized" && n.type !== "authorize-failed")
|
|
@@ -190,17 +190,17 @@ const re = ue(null), J = ue({
|
|
|
190
190
|
};
|
|
191
191
|
return window.addEventListener("message", e), () => window.removeEventListener("message", e);
|
|
192
192
|
}, [f, g, O]);
|
|
193
|
-
const B =
|
|
193
|
+
const B = m(
|
|
194
194
|
(e, r) => {
|
|
195
195
|
const n = e == null ? void 0 : e.origin, u = oe(r);
|
|
196
196
|
!n || !u || (S((p) => ({ ...p, [n]: u })), f(n));
|
|
197
197
|
},
|
|
198
198
|
[f]
|
|
199
|
-
), z =
|
|
199
|
+
), z = m((e, r) => {
|
|
200
200
|
E((n) => n[e] ? { ...n, [e]: { ...n[e], ...r } } : n);
|
|
201
|
-
}, []), L = b({}), M =
|
|
201
|
+
}, []), L = b({}), M = m(
|
|
202
202
|
async (e, { approve: r } = {}) => {
|
|
203
|
-
const n =
|
|
203
|
+
const n = P.current, { origin: u } = e;
|
|
204
204
|
let p;
|
|
205
205
|
try {
|
|
206
206
|
p = await n(
|
|
@@ -230,7 +230,7 @@ const re = ue(null), J = ue({
|
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
232
|
const Q = (p == null ? void 0 : p.error) || "broker_error";
|
|
233
|
-
if (!r &&
|
|
233
|
+
if (!r && be.has(Q)) {
|
|
234
234
|
z(u, {
|
|
235
235
|
status: e.silentUrl && te ? "silent" : "interactive"
|
|
236
236
|
});
|
|
@@ -243,16 +243,16 @@ const re = ue(null), J = ue({
|
|
|
243
243
|
if (Q === "rate_limited" && !e.rateLimitRetried) {
|
|
244
244
|
const ee = Math.min(
|
|
245
245
|
Number(p == null ? void 0 : p.retryAfter) > 0 ? Number(p.retryAfter) : me,
|
|
246
|
-
|
|
247
|
-
),
|
|
248
|
-
|
|
249
|
-
delete o.current[u], L.current[u] = !0, v.current(
|
|
246
|
+
ge
|
|
247
|
+
), fe = { ...e, rateLimitRetried: !0 };
|
|
248
|
+
a(u), o.current[u] = setTimeout(() => {
|
|
249
|
+
delete o.current[u], L.current[u] = !0, v.current(fe, { approve: r }).finally(() => {
|
|
250
250
|
delete L.current[u];
|
|
251
251
|
});
|
|
252
252
|
}, ee * 1e3), z(u, { rateLimitRetried: !0 });
|
|
253
253
|
return;
|
|
254
254
|
}
|
|
255
|
-
f(u),
|
|
255
|
+
f(u), y((ee) => ({
|
|
256
256
|
...ee,
|
|
257
257
|
[u]: {
|
|
258
258
|
origin: u,
|
|
@@ -262,32 +262,32 @@ const re = ue(null), J = ue({
|
|
|
262
262
|
}
|
|
263
263
|
}));
|
|
264
264
|
},
|
|
265
|
-
[B, z, f,
|
|
265
|
+
[B, z, f, a]
|
|
266
266
|
), v = b(M);
|
|
267
267
|
v.current = M, T(() => {
|
|
268
|
-
Object.values(
|
|
268
|
+
Object.values(h).forEach((e) => {
|
|
269
269
|
e.status !== "broker" || L.current[e.origin] || o.current[e.origin] || (L.current[e.origin] = !0, M(e).finally(() => {
|
|
270
270
|
delete L.current[e.origin];
|
|
271
271
|
}));
|
|
272
272
|
});
|
|
273
|
-
}, [
|
|
274
|
-
const K =
|
|
275
|
-
(e) => !
|
|
273
|
+
}, [h, M]);
|
|
274
|
+
const K = m(
|
|
275
|
+
(e) => !P.current || !(e != null && e.consent) ? Promise.resolve() : M(e, { approve: !0 }),
|
|
276
276
|
[M]
|
|
277
277
|
);
|
|
278
278
|
T(() => {
|
|
279
279
|
const e = V.current;
|
|
280
|
-
Object.values(
|
|
280
|
+
Object.values(h).forEach((r) => {
|
|
281
281
|
r.status === "silent" && !e[r.origin] && (e[r.origin] = setTimeout(() => {
|
|
282
282
|
delete e[r.origin], O(r.origin);
|
|
283
|
-
},
|
|
283
|
+
}, Ee));
|
|
284
284
|
}), Object.keys(e).forEach((r) => {
|
|
285
|
-
(!
|
|
285
|
+
(!h[r] || h[r].status !== "silent") && (clearTimeout(e[r]), delete e[r]);
|
|
286
286
|
});
|
|
287
|
-
}, [
|
|
287
|
+
}, [h, O]), T(() => () => {
|
|
288
288
|
F.current && F.current(), Object.values(V.current).forEach(clearTimeout), Object.values(o.current).forEach(clearTimeout);
|
|
289
289
|
}, []);
|
|
290
|
-
const W =
|
|
290
|
+
const W = m(
|
|
291
291
|
(e) => {
|
|
292
292
|
F.current && (F.current(), F.current = null);
|
|
293
293
|
const r = s || Re;
|
|
@@ -314,7 +314,7 @@ const re = ue(null), J = ue({
|
|
|
314
314
|
), _ = {
|
|
315
315
|
// Hosts render UI for interactive entries only; silent resolution is
|
|
316
316
|
// invisible by design.
|
|
317
|
-
pending: Object.values(
|
|
317
|
+
pending: Object.values(h).filter(
|
|
318
318
|
(e) => e.status === "interactive"
|
|
319
319
|
),
|
|
320
320
|
authorize: W,
|
|
@@ -324,7 +324,7 @@ const re = ue(null), J = ue({
|
|
|
324
324
|
originEpochs: H,
|
|
325
325
|
credentials: $,
|
|
326
326
|
unsupported: q
|
|
327
|
-
}, D = Object.values(
|
|
327
|
+
}, D = Object.values(h).filter(
|
|
328
328
|
(e) => e.status === "silent" && e.silentUrl
|
|
329
329
|
);
|
|
330
330
|
return /* @__PURE__ */ x.createElement(J.Provider, { value: _ }, t, D.map((e) => /* @__PURE__ */ x.createElement(
|
|
@@ -351,7 +351,7 @@ ae.propTypes = {
|
|
|
351
351
|
*/
|
|
352
352
|
broker: w.func
|
|
353
353
|
};
|
|
354
|
-
const
|
|
354
|
+
const ye = () => G(J), Te = (t) => {
|
|
355
355
|
const { originEpochs: s } = G(J), c = N(t);
|
|
356
356
|
return c && s[c] || 0;
|
|
357
357
|
}, ke = (t) => {
|
|
@@ -361,28 +361,28 @@ const Pe = () => G(J), Te = (t) => {
|
|
|
361
361
|
const { unsupported: s } = G(J), c = N(t);
|
|
362
362
|
return c && s[c] || null;
|
|
363
363
|
}, Ie = ({ children: t, authorizationLauncher: s, credentialBroker: c }) => {
|
|
364
|
-
const [d,
|
|
364
|
+
const [d, h] = C({}), [E, H] = C({}), I = b({}), $ = b({}), S = b({}), q = m((i, l) => {
|
|
365
365
|
var o;
|
|
366
|
-
return !!((o = S.current[i]) != null && o.has(
|
|
367
|
-
}, []),
|
|
368
|
-
|
|
369
|
-
}, []), Y =
|
|
370
|
-
|
|
371
|
-
const o = { ...
|
|
366
|
+
return !!((o = S.current[i]) != null && o.has(l));
|
|
367
|
+
}, []), y = m((i, l, o) => {
|
|
368
|
+
h((a) => ({ ...a, [i]: { origin: l, frameRef: o } }));
|
|
369
|
+
}, []), Y = m((i) => {
|
|
370
|
+
h((l) => {
|
|
371
|
+
const o = { ...l };
|
|
372
372
|
return delete o[i], o;
|
|
373
|
-
}), H((
|
|
374
|
-
const o = { ...
|
|
373
|
+
}), H((l) => {
|
|
374
|
+
const o = { ...l };
|
|
375
375
|
return delete o[i], o;
|
|
376
376
|
}), delete S.current[i];
|
|
377
377
|
}, []);
|
|
378
378
|
T(() => {
|
|
379
|
-
const i = (o = [],
|
|
380
|
-
o.forEach((g) => g(
|
|
381
|
-
},
|
|
379
|
+
const i = (o = [], a, f) => {
|
|
380
|
+
o.forEach((g) => g(a, f));
|
|
381
|
+
}, l = (o) => {
|
|
382
382
|
var B, z, L, M, v, K, W;
|
|
383
383
|
if (!((B = o == null ? void 0 : o.data) != null && B.instanceId))
|
|
384
384
|
return;
|
|
385
|
-
const { instanceId:
|
|
385
|
+
const { instanceId: a, type: f } = o.data, g = d[a], O = (L = (z = g == null ? void 0 : g.frameRef) == null ? void 0 : z.current) == null ? void 0 : L.contentWindow;
|
|
386
386
|
if (!O || o.source !== O || o.origin !== g.origin)
|
|
387
387
|
return;
|
|
388
388
|
const j = { origin: o.origin }, k = I.current;
|
|
@@ -393,68 +393,68 @@ const Pe = () => G(J), Te = (t) => {
|
|
|
393
393
|
}
|
|
394
394
|
if (f === "mark-registered") {
|
|
395
395
|
const { requestType: _ } = o.data;
|
|
396
|
-
S.current[
|
|
396
|
+
S.current[a] || (S.current[a] = /* @__PURE__ */ new Set()), S.current[a].add(_);
|
|
397
397
|
return;
|
|
398
398
|
}
|
|
399
|
-
f === "ready" && H((_) => ({ ..._, [
|
|
399
|
+
f === "ready" && H((_) => ({ ..._, [a]: !0 })), i((M = k[a]) == null ? void 0 : M[f], o.data, j), i((v = k["*"]) == null ? void 0 : v[f], o.data, j), i((K = k[a]) == null ? void 0 : K["*"], o.data, j), i((W = k["*"]) == null ? void 0 : W["*"], o.data, j);
|
|
400
400
|
};
|
|
401
|
-
return window.addEventListener("message",
|
|
402
|
-
window.removeEventListener("message",
|
|
401
|
+
return window.addEventListener("message", l), () => {
|
|
402
|
+
window.removeEventListener("message", l);
|
|
403
403
|
};
|
|
404
404
|
}, [d]);
|
|
405
|
-
const R =
|
|
406
|
-
(i,
|
|
405
|
+
const R = m(
|
|
406
|
+
(i, l, o) => {
|
|
407
407
|
var f, g;
|
|
408
|
-
const
|
|
409
|
-
if (!
|
|
408
|
+
const a = d[i];
|
|
409
|
+
if (!a) {
|
|
410
410
|
console.warn(`Origin not set for id: ${i}. Unable to send message.`);
|
|
411
411
|
return;
|
|
412
412
|
}
|
|
413
|
-
(g = (f =
|
|
414
|
-
{ type:
|
|
415
|
-
|
|
413
|
+
(g = (f = a == null ? void 0 : a.frameRef) == null ? void 0 : f.current) != null && g.contentWindow && a.frameRef.current.contentWindow.postMessage(
|
|
414
|
+
{ type: l, ...o, instanceId: i },
|
|
415
|
+
a.origin
|
|
416
416
|
);
|
|
417
417
|
},
|
|
418
418
|
[d]
|
|
419
|
-
), F = b(0), V =
|
|
420
|
-
async (i,
|
|
419
|
+
), F = b(0), V = m(() => `${Date.now()}-${++F.current}`, []), A = m(
|
|
420
|
+
async (i, l, o = {}) => new Promise((a, f) => {
|
|
421
421
|
const g = V(), O = (j, k) => {
|
|
422
|
-
delete $.current[g], k ? f(k) :
|
|
422
|
+
delete $.current[g], k ? f(k) : a(j);
|
|
423
423
|
};
|
|
424
|
-
$.current[g] = O, R(i, "request", { callbackId: g, requestType:
|
|
424
|
+
$.current[g] = O, R(i, "request", { callbackId: g, requestType: l, data: o });
|
|
425
425
|
}),
|
|
426
426
|
[R]
|
|
427
|
-
), Z =
|
|
428
|
-
(i,
|
|
429
|
-
R(i, "load-options",
|
|
427
|
+
), Z = m(
|
|
428
|
+
(i, l) => {
|
|
429
|
+
R(i, "load-options", l);
|
|
430
430
|
},
|
|
431
431
|
[R]
|
|
432
|
-
),
|
|
433
|
-
(i,
|
|
434
|
-
R(i, "validate",
|
|
432
|
+
), P = m(
|
|
433
|
+
(i, l) => {
|
|
434
|
+
R(i, "validate", l);
|
|
435
435
|
},
|
|
436
436
|
[R]
|
|
437
|
-
), U =
|
|
437
|
+
), U = pe(
|
|
438
438
|
() => ({
|
|
439
|
-
registerFrame:
|
|
439
|
+
registerFrame: y,
|
|
440
440
|
unregisterFrame: Y,
|
|
441
441
|
sendMessage: R,
|
|
442
442
|
sendRequest: A,
|
|
443
443
|
loadOptions: Z,
|
|
444
|
-
validate:
|
|
444
|
+
validate: P,
|
|
445
445
|
hasHandler: q,
|
|
446
446
|
readyFrames: E,
|
|
447
|
-
addListener: (i,
|
|
448
|
-
I.current[i][
|
|
447
|
+
addListener: (i, l, o) => (I.current[i] || (I.current[i] = {}), I.current[i][l] || (I.current[i][l] = []), I.current[i][l].push(o), () => {
|
|
448
|
+
I.current[i][l] = I.current[i][l].filter((a) => a !== o);
|
|
449
449
|
})
|
|
450
450
|
}),
|
|
451
451
|
[
|
|
452
|
-
|
|
452
|
+
y,
|
|
453
453
|
Y,
|
|
454
454
|
R,
|
|
455
455
|
A,
|
|
456
456
|
Z,
|
|
457
|
-
|
|
457
|
+
P,
|
|
458
458
|
q,
|
|
459
459
|
E
|
|
460
460
|
]
|
|
@@ -466,9 +466,9 @@ const Pe = () => G(J), Te = (t) => {
|
|
|
466
466
|
throw new Error(
|
|
467
467
|
"useEmbeddedEffect must be used within a MMEmbeddableZoneProvider"
|
|
468
468
|
);
|
|
469
|
-
const
|
|
469
|
+
const h = b(c);
|
|
470
470
|
T(() => {
|
|
471
|
-
|
|
471
|
+
h.current = c;
|
|
472
472
|
}, [c]), T(() => {
|
|
473
473
|
if (!(!t || !s)) {
|
|
474
474
|
if (s.startsWith("key:")) {
|
|
@@ -476,13 +476,13 @@ const Pe = () => G(J), Te = (t) => {
|
|
|
476
476
|
return d.readyFrames[t] && d.sendMessage(t, "subscribe-key", { keyChord: E }), d.addListener(
|
|
477
477
|
t,
|
|
478
478
|
`key-pressed:${E}`,
|
|
479
|
-
(...I) =>
|
|
479
|
+
(...I) => h.current(...I)
|
|
480
480
|
);
|
|
481
481
|
}
|
|
482
482
|
return d.addListener(
|
|
483
483
|
t,
|
|
484
484
|
s,
|
|
485
|
-
(...E) =>
|
|
485
|
+
(...E) => h.current(...E)
|
|
486
486
|
);
|
|
487
487
|
}
|
|
488
488
|
}, [d, t, s]);
|
|
@@ -552,11 +552,11 @@ const ne = se.default || se, _e = 1e4, Ue = "credentials", Le = (t, s) => `${t}/
|
|
|
552
552
|
detail: "It needs an update to support embedding from a different domain."
|
|
553
553
|
};
|
|
554
554
|
}
|
|
555
|
-
},
|
|
555
|
+
}, de = ({ entry: t }) => {
|
|
556
556
|
const s = Ae(t);
|
|
557
557
|
return /* @__PURE__ */ x.createElement(Ce, { "data-reason": t && t.reason || void 0 }, /* @__PURE__ */ x.createElement("div", { style: { fontWeight: 600 } }, s.title), /* @__PURE__ */ x.createElement("div", { style: { fontSize: 12, color: "#888" } }, s.detail));
|
|
558
558
|
};
|
|
559
|
-
|
|
559
|
+
de.propTypes = {
|
|
560
560
|
entry: w.shape({
|
|
561
561
|
origin: w.string,
|
|
562
562
|
name: w.string,
|
|
@@ -576,7 +576,7 @@ const Oe = ne.div`
|
|
|
576
576
|
path: c,
|
|
577
577
|
onInit: d = () => {
|
|
578
578
|
},
|
|
579
|
-
onTimeout:
|
|
579
|
+
onTimeout: h,
|
|
580
580
|
context: E = {},
|
|
581
581
|
params: H = {},
|
|
582
582
|
renderUnsupported: I,
|
|
@@ -595,16 +595,16 @@ const Oe = ne.div`
|
|
|
595
595
|
return console.error(
|
|
596
596
|
"isFullScreen must be passed via the params prop to MMEmbeddableZone"
|
|
597
597
|
), null;
|
|
598
|
-
const q = b(), [
|
|
598
|
+
const q = b(), [y, Y] = C(), [R, F] = C(0), [V, A] = C(!1), [Z, P] = C(!1), U = Te(s), i = ke(s), l = we(s), [o, a] = C(0), [f, g] = C(null), { registerFrame: O, unregisterFrame: j, sendMessage: k } = G(
|
|
599
599
|
re
|
|
600
|
-
), [B, z] = C(), L = b(), M = b(
|
|
601
|
-
K.current = !1, clearTimeout(L.current), F(0), A(!1),
|
|
600
|
+
), [B, z] = C(), L = b(), M = b(h), v = b(d), K = b(!1), W = m(() => {
|
|
601
|
+
K.current = !1, clearTimeout(L.current), F(0), A(!1), P(!1), g(null);
|
|
602
602
|
}, []);
|
|
603
603
|
T(() => {
|
|
604
604
|
(U > 0 || o > 0) && W();
|
|
605
605
|
}, [U, o, W]), T(() => {
|
|
606
|
-
M.current =
|
|
607
|
-
}, [
|
|
606
|
+
M.current = h;
|
|
607
|
+
}, [h]), T(() => {
|
|
608
608
|
v.current = d;
|
|
609
609
|
}, [d]), T(() => {
|
|
610
610
|
R && k(t, "set-context", {
|
|
@@ -627,18 +627,18 @@ const Oe = ne.div`
|
|
|
627
627
|
j(t);
|
|
628
628
|
};
|
|
629
629
|
}, [s, t, O, q, W]), T(() => {
|
|
630
|
-
if (!(!
|
|
630
|
+
if (!(!y || K.current))
|
|
631
631
|
return L.current = setTimeout(() => {
|
|
632
632
|
A(!0), M.current && M.current();
|
|
633
633
|
}, _e), () => clearTimeout(L.current);
|
|
634
|
-
}, [
|
|
635
|
-
const _ =
|
|
634
|
+
}, [y, s, U, o]);
|
|
635
|
+
const _ = m(() => {
|
|
636
636
|
K.current = !0, clearTimeout(L.current), A(!1);
|
|
637
637
|
}, []);
|
|
638
638
|
X(t, "init", (e) => {
|
|
639
639
|
_(), Array.isArray(e == null ? void 0 : e.acceptsCredentials) && g(e.acceptsCredentials);
|
|
640
640
|
}), X(t, "authorize", _), X(t, "login", _), X(t, "credential-request", () => {
|
|
641
|
-
_(),
|
|
641
|
+
_(), P(!0);
|
|
642
642
|
}), T(() => {
|
|
643
643
|
if (!Z || !i)
|
|
644
644
|
return;
|
|
@@ -653,17 +653,17 @@ const Oe = ne.div`
|
|
|
653
653
|
const D = b();
|
|
654
654
|
return X(t, "heartbeat", () => {
|
|
655
655
|
D.current && clearTimeout(D.current), D.current = setTimeout(() => {
|
|
656
|
-
|
|
656
|
+
a((e) => e + 1);
|
|
657
657
|
}, 6e3);
|
|
658
658
|
}), T(() => () => {
|
|
659
659
|
D.current && clearTimeout(D.current);
|
|
660
|
-
}, []),
|
|
660
|
+
}, []), l ? I ? I(l) : /* @__PURE__ */ x.createElement(de, { entry: l }) : V && !R ? $ ? $() : /* @__PURE__ */ x.createElement(ze, null) : /* @__PURE__ */ x.createElement(
|
|
661
661
|
Me,
|
|
662
662
|
{
|
|
663
663
|
key: `auth-epoch-${U}-frame-${o}`,
|
|
664
664
|
$isReady: R,
|
|
665
665
|
ref: q,
|
|
666
|
-
src:
|
|
666
|
+
src: y,
|
|
667
667
|
...S
|
|
668
668
|
}
|
|
669
669
|
);
|
|
@@ -688,16 +688,16 @@ xe.propTypes = {
|
|
|
688
688
|
renderTimeout: w.func
|
|
689
689
|
};
|
|
690
690
|
export {
|
|
691
|
-
|
|
691
|
+
he as CREDENTIAL_KIND_ACCESS_TOKEN,
|
|
692
692
|
J as EmbeddedAuthorizationContext,
|
|
693
693
|
xe as MMEmbeddableZone,
|
|
694
694
|
re as MMEmbeddableZoneContext,
|
|
695
695
|
Ie as MMEmbeddableZoneProvider,
|
|
696
|
-
|
|
696
|
+
ue as isCrossSite,
|
|
697
697
|
oe as normalizeCredential,
|
|
698
698
|
Re as popupAuthorizationLauncher,
|
|
699
699
|
Ae as unsupportedCopy,
|
|
700
|
-
|
|
700
|
+
ye as useEmbeddedAuthorizations,
|
|
701
701
|
ke as useEmbeddedCredential,
|
|
702
702
|
X as useEmbeddedEffect,
|
|
703
703
|
Te as useEmbeddedOriginEpoch,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
(function(h,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):(h=typeof globalThis!="undefined"?globalThis:h||self,t(h["mm-react-embeddable"]={},h.React,h.PropTypes,h.styled))})(this,(function(h,t,Ee,ge){"use strict";const ee=r=>r&&r.__esModule?r:{default:r},U=ee(t),C=ee(Ee),ne=ee(ge),V=t.createContext(null),Y=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),se="access_token",te=r=>r?r.kind?r:r.accessToken?{kind:se,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,ke=60,Ce=120,Te=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),J=typeof window!="undefined"&&window.location.protocol==="https:",_e=8e3,X=r=>{try{return new URL(r).origin}catch{return null}},ue=(r,u)=>{const c=u==null?void 0:u.origin;return!c||X(r==null?void 0:r.authUrl)!==c?null:c},oe=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const u=r.split(".");return u.length<=2?r:u.slice(-2).join(".")},ie=(r,u)=>{try{const c=new URL(r),f=new URL(u);return c.protocol!==f.protocol?!0:oe(c.hostname)!==oe(f.hostname)}catch{return!0}},ce=(r,{onBlocked:u,onClosed:c})=>{const f=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!f)return u(),()=>{};const m=setInterval(()=>{f.closed&&(clearInterval(m),c())},1e3);return()=>clearInterval(m)},le=({children:r,launcher:u,broker:c})=>{const f=t.useContext(V),[m,g]=t.useState({}),[Z,_]=t.useState({}),[O,y]=t.useState({}),[q,x]=t.useState({}),N=t.useRef(O);N.current=O;const k=t.useRef(m);k.current=m;const $=t.useRef(null),G=t.useRef({}),L=t.useRef({}),W=t.useRef({}),F=t.useRef(c);F.current=c;const I=t.useCallback(e=>{const n=L.current[e];if(!n)return;const s=l=>!l[e]||l[e].clientId?l:{...l,[e]:{...l[e],clientId:n}};g(s),x(s)},[]),i=t.useCallback((e,n)=>{e&&(x(s=>s[e]?s:{...s,[e]:{origin:e,reason:n,clientId:L.current[e]||null}}),I(e))},[I]),a=t.useCallback((e,{v2:n=!1,origin:s=null}={})=>{s&&(n&&N.current[s]||(g(l=>l[s]?l:{...l,[s]:{origin:s,authUrl:e.authUrl,silentUrl:e.silentUrl||null,status:n&&F.current?"broker":n&&e.silentUrl&&J?"silent":"interactive",v2:n,scope:e.scope||null,acceptsCredentials:W.current[s]||null,consent:null,error:null,clientId:e.clientId||L.current[s]||null,popupBlocked:!1}}),I(s)))},[I]),o=t.useRef({}),d=t.useCallback(e=>{o.current[e]&&(clearTimeout(o.current[e]),delete o.current[e])},[]),p=t.useCallback(e=>{d(e),g(n=>{if(!n[e])return n;const s={...n};return delete s[e],s})},[d]),E=t.useCallback(e=>{e&&(p(e),_(n=>({...n,[e]:(n[e]||0)+1})))},[p]),A=t.useCallback(e=>{g(n=>!n[e]||n[e].status==="interactive"?n:{...n,[e]:{...n[e],status:"interactive"}})},[]),P=t.useCallback(e=>{p(e.origin)},[p]),T=t.useCallback((e,n)=>{const s=ue(e,n);if(s){if(ie(s,window.location.origin)){i(s,"cross-site-legacy");return}a(e,{origin:s})}},[a,i]);t.useEffect(()=>{if(!f)return;const e=[f.addListener("*","init",(n,s)=>{s!=null&&s.origin&&(n!=null&&n.clientId)&&(L.current[s.origin]=n.clientId,I(s.origin)),s!=null&&s.origin&&Array.isArray(n==null?void 0:n.acceptsCredentials)&&(W.current[s.origin]=n.acceptsCredentials)}),f.addListener("*","authorize",T),f.addListener("*","login",T),f.addListener("*","credential-request",(n,s)=>a(n,{v2:!0,origin:ue(n,s)}))];return()=>e.forEach(n=>n())},[f,T,a,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=X(s.authUrl);if(!(!l||n.origin!==l)){if(s.type==="authorized"){if(s.accessToken){if(!k.current[l])return;y(b=>({...b,[l]:te({accessToken:s.accessToken})})),p(l)}else E(l);return}A(l)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[p,E,A]);const j=t.useCallback((e,n)=>{const s=e==null?void 0:e.origin,l=te(n);!s||!l||(y(b=>({...b,[s]:l})),p(s))},[p]),z=t.useCallback((e,n)=>{g(s=>s[e]?{...s,[e]:{...s[e],...n}}:s)},[]),M=t.useRef({}),S=t.useCallback(async(e,{approve:n}={})=>{const s=F.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?z(l,{error:{reason:"broker_unavailable"}}):z(l,{status:e.silentUrl&&J?"silent":"interactive"});return}if((b==null?void 0:b.status)===200&&b.credential){j(e,b.credential);return}if((b==null?void 0:b.status)===409&&b.consentRequired){z(l,{status:"interactive",consent:{client:b.client||null,stepUp:!!b.stepUp,scope:b.scope||e.scope},error:null});return}const Q=(b==null?void 0:b.error)||"broker_error";if(!n&&Te.has(Q)){z(l,{status:e.silentUrl&&J?"silent":"interactive"});return}if(n&&Q==="consent_denied"){z(l,{error:null});return}if(Q==="rate_limited"&&!e.rateLimitRetried){const R=Math.min(Number(b==null?void 0:b.retryAfter)>0?Number(b.retryAfter):ke,Ce),Oe={...e,rateLimitRetried:!0};d(l),o.current[l]=setTimeout(()=>{delete o.current[l],M.current[l]=!0,v.current(Oe,{approve:n}).finally(()=>{delete M.current[l]})},R*1e3),z(l,{rateLimitRetried:!0});return}p(l),x(R=>({...R,[l]:{origin:l,reason:`broker:${Q}`,detail:b||null,clientId:e.clientId||L.current[l]||null}}))},[j,z,p,d]),v=t.useRef(S);v.current=S,t.useEffect(()=>{Object.values(m).forEach(e=>{e.status!=="broker"||M.current[e.origin]||o.current[e.origin]||(M.current[e.origin]=!0,S(e).finally(()=>{delete M.current[e.origin]}))})},[m,S]);const H=t.useCallback(e=>!F.current||!(e!=null&&e.consent)?Promise.resolve():S(e,{approve:!0}),[S]);t.useEffect(()=>{const e=G.current;Object.values(m).forEach(n=>{n.status==="silent"&&!e[n.origin]&&(e[n.origin]=setTimeout(()=>{delete e[n.origin],A(n.origin)},_e))}),Object.keys(e).forEach(n=>{(!m[n]||m[n].status!=="silent")&&(clearTimeout(e[n]),delete e[n])})},[m,A]),t.useEffect(()=>()=>{$.current&&$.current(),Object.values(G.current).forEach(clearTimeout),Object.values(o.current).forEach(clearTimeout)},[]);const B=t.useCallback(e=>{$.current&&($.current(),$.current=null);const n=u||ce;$.current=n(e,{onBlocked:()=>{g(s=>s[e.origin]?{...s,[e.origin]:{...s[e.origin],popupBlocked:!0}}:s)},onClosed:()=>{if(e.v2){J&&g(s=>!s[e.origin]||!s[e.origin].silentUrl?s:{...s,[e.origin]:{...s[e.origin],status:"silent"}});return}E(e.origin)}})},[u,E]),w={pending:Object.values(m).filter(e=>e.status==="interactive"),authorize:B,approve:H,complete:j,dismiss:P,originEpochs:Z,credentials:O,unsupported:q},D=Object.values(m).filter(e=>e.status==="silent"&&e.silentUrl);return U.default.createElement(Y.Provider,{value:w},r,D.map(e=>U.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"}})))};le.propTypes={children:C.default.node,launcher:C.default.func,broker:C.default.func};const we=()=>t.useContext(Y),ae=r=>{const{originEpochs:u}=t.useContext(Y),c=X(r);return c&&u[c]||0},de=r=>{const{credentials:u}=t.useContext(Y),c=X(r);return c&&u[c]||null},fe=r=>{const{unsupported:u}=t.useContext(Y),c=X(r);return c&&u[c]||null},pe=({children:r,authorizationLauncher:u,credentialBroker:c})=>{const[f,m]=t.useState({}),[g,Z]=t.useState({}),_=t.useRef({}),O=t.useRef({}),y=t.useRef({}),q=t.useCallback((i,a)=>{var o;return!!((o=y.current[i])!=null&&o.has(a))},[]),x=t.useCallback((i,a,o)=>{m(d=>({...d,[i]:{origin:a,frameRef:o}}))},[]),N=t.useCallback(i=>{m(a=>{const o={...a};return delete o[i],o}),Z(a=>{const o={...a};return delete o[i],o}),delete y.current[i]},[]);t.useEffect(()=>{const i=(o=[],d,p)=>{o.forEach(E=>E(d,p))},a=o=>{var j,z,M,S,v,H,B;if(!((j=o==null?void 0:o.data)!=null&&j.instanceId))return;const{instanceId:d,type:p}=o.data,E=f[d],A=(M=(z=E==null?void 0:E.frameRef)==null?void 0:z.current)==null?void 0:M.contentWindow;if(!A||o.source!==A||o.origin!==E.origin)return;const P={origin:o.origin},T=_.current;if(p==="response"){const{callbackId:w,response:D,error:e}=o.data,n=O.current[w];n&&(n(D,e),delete O.current[w]);return}if(p==="mark-registered"){const{requestType:w}=o.data;y.current[d]||(y.current[d]=new Set),y.current[d].add(w);return}p==="ready"&&Z(w=>({...w,[d]:!0})),i((S=T[d])==null?void 0:S[p],o.data,P),i((v=T["*"])==null?void 0:v[p],o.data,P),i((H=T[d])==null?void 0:H["*"],o.data,P),i((B=T["*"])==null?void 0:B["*"],o.data,P)};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[f]);const k=t.useCallback((i,a,o)=>{var p,E;const d=f[i];if(!d){console.warn(`Origin not set for id: ${i}. Unable to send message.`);return}(E=(p=d==null?void 0:d.frameRef)==null?void 0:p.current)!=null&&E.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:a,...o,instanceId:i},d.origin)},[f]),$=t.useRef(0),G=t.useCallback(()=>`${Date.now()}-${++$.current}`,[]),L=t.useCallback(async(i,a,o={})=>new Promise((d,p)=>{const E=G(),A=(P,T)=>{delete O.current[E],T?p(T):d(P)};O.current[E]=A,k(i,"request",{callbackId:E,requestType:a,data:o})}),[k]),W=t.useCallback((i,a)=>{k(i,"load-options",a)},[k]),F=t.useCallback((i,a)=>{k(i,"validate",a)},[k]),I=t.useMemo(()=>({registerFrame:x,unregisterFrame:N,sendMessage:k,sendRequest:L,loadOptions:W,validate:F,hasHandler:q,readyFrames:g,addListener:(i,a,o)=>(_.current[i]||(_.current[i]={}),_.current[i][a]||(_.current[i][a]=[]),_.current[i][a].push(o),()=>{_.current[i][a]=_.current[i][a].filter(d=>d!==o)})}),[x,N,k,L,W,F,q,g]);return U.default.createElement(V.Provider,{value:I},U.default.createElement(le,{launcher:u,broker:c},r))},K=(r,u,c)=>{const f=t.useContext(V);if(f===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const m=t.useRef(c);t.useEffect(()=>{m.current=c},[c]),t.useEffect(()=>{if(!(!r||!u)){if(u.startsWith("key:")){const g=u.substring(4);return f.readyFrames[r]&&f.sendMessage(r,"subscribe-key",{keyChord:g}),f.addListener(r,`key-pressed:${g}`,(..._)=>m.current(..._))}return f.addListener(r,u,(...g)=>m.current(...g))}},[f,r,u])};pe.propTypes={children:C.default.node.isRequired,authorizationLauncher:C.default.func,credentialBroker:C.default.func};const re=ne.default.default||ne.default,Ie=1e4,Me="credentials",Se=(r,u)=>`${r}/mm-embedded-interop?id=${encodeURIComponent(u)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Me}`,Ue=re.iframe`
|
|
1
|
+
(function(h,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):(h=typeof globalThis!="undefined"?globalThis:h||self,t(h["mm-react-embeddable"]={},h.React,h.PropTypes,h.styled))})(this,(function(h,t,Ee,ge){"use strict";const ee=r=>r&&r.__esModule?r:{default:r},U=ee(t),C=ee(Ee),se=ee(ge),V=t.createContext(null),Y=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ue="access_token",te=r=>r?r.kind?r:r.accessToken?{kind:ue,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,ke=60,Ce=120,Te=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),J=typeof window!="undefined"&&window.location.protocol==="https:",_e=8e3,X=r=>{try{return new URL(r).origin}catch{return null}},oe=(r,u)=>{const c=u==null?void 0:u.origin;return!c||X(r==null?void 0:r.authUrl)!==c?null:c},ie=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const u=r.split(".");return u.length<=2?r:u.slice(-2).join(".")},re=(r,u)=>{try{const c=new URL(r),f=new URL(u);return c.protocol!==f.protocol?!0:ie(c.hostname)!==ie(f.hostname)}catch{return!0}},ce=(r,{onBlocked:u,onClosed:c})=>{const f=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!f)return u(),()=>{};const m=setInterval(()=>{f.closed&&(clearInterval(m),c())},1e3);return()=>clearInterval(m)},le=({children:r,launcher:u,broker:c})=>{const f=t.useContext(V),[m,g]=t.useState({}),[Z,_]=t.useState({}),[O,y]=t.useState({}),[q,x]=t.useState({}),N=t.useRef(O);N.current=O;const k=t.useRef(m);k.current=m;const $=t.useRef(null),G=t.useRef({}),L=t.useRef({}),W=t.useRef({}),F=t.useRef(c);F.current=c;const I=t.useCallback(e=>{const n=L.current[e];if(!n)return;const s=l=>!l[e]||l[e].clientId?l:{...l,[e]:{...l[e],clientId:n}};g(s),x(s)},[]),i=t.useCallback((e,n)=>{e&&(x(s=>s[e]?s:{...s,[e]:{origin:e,reason:n,clientId:L.current[e]||null}}),I(e))},[I]),a=t.useCallback((e,{v2:n=!1,origin:s=null}={})=>{s&&(n&&N.current[s]||(g(l=>l[s]?l:{...l,[s]:{origin:s,authUrl:e.authUrl,silentUrl:e.silentUrl||null,status:n&&F.current?"broker":n&&e.silentUrl&&J?"silent":"interactive",v2:n,scope:e.scope||null,acceptsCredentials:W.current[s]||null,consent:null,error:null,clientId:e.clientId||L.current[s]||null,popupBlocked:!1}}),I(s)))},[I]),o=t.useRef({}),d=t.useCallback(e=>{o.current[e]&&(clearTimeout(o.current[e]),delete o.current[e])},[]),p=t.useCallback(e=>{d(e),g(n=>{if(!n[e])return n;const s={...n};return delete s[e],s})},[d]),E=t.useCallback(e=>{e&&(p(e),_(n=>({...n,[e]:(n[e]||0)+1})))},[p]),A=t.useCallback(e=>{g(n=>!n[e]||n[e].status==="interactive"?n:{...n,[e]:{...n[e],status:"interactive"}})},[]),P=t.useCallback(e=>{p(e.origin)},[p]),T=t.useCallback((e,n)=>{const s=oe(e,n);if(s){if(re(s,window.location.origin)){i(s,"cross-site-legacy");return}a(e,{origin:s})}},[a,i]);t.useEffect(()=>{if(!f)return;const e=[f.addListener("*","init",(n,s)=>{s!=null&&s.origin&&(n!=null&&n.clientId)&&(L.current[s.origin]=n.clientId,I(s.origin)),s!=null&&s.origin&&Array.isArray(n==null?void 0:n.acceptsCredentials)?W.current[s.origin]=n.acceptsCredentials:s!=null&&s.origin&&re(s.origin,window.location.origin)&&i(s.origin,"cross-site-legacy")}),f.addListener("*","authorize",T),f.addListener("*","login",T),f.addListener("*","credential-request",(n,s)=>a(n,{v2:!0,origin:oe(n,s)}))];return()=>e.forEach(n=>n())},[f,T,a,I,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=X(s.authUrl);if(!(!l||n.origin!==l)){if(s.type==="authorized"){if(s.accessToken){if(!k.current[l])return;y(b=>({...b,[l]:te({accessToken:s.accessToken})})),p(l)}else E(l);return}A(l)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[p,E,A]);const j=t.useCallback((e,n)=>{const s=e==null?void 0:e.origin,l=te(n);!s||!l||(y(b=>({...b,[s]:l})),p(s))},[p]),z=t.useCallback((e,n)=>{g(s=>s[e]?{...s,[e]:{...s[e],...n}}:s)},[]),M=t.useRef({}),S=t.useCallback(async(e,{approve:n}={})=>{const s=F.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?z(l,{error:{reason:"broker_unavailable"}}):z(l,{status:e.silentUrl&&J?"silent":"interactive"});return}if((b==null?void 0:b.status)===200&&b.credential){j(e,b.credential);return}if((b==null?void 0:b.status)===409&&b.consentRequired){z(l,{status:"interactive",consent:{client:b.client||null,stepUp:!!b.stepUp,scope:b.scope||e.scope},error:null});return}const Q=(b==null?void 0:b.error)||"broker_error";if(!n&&Te.has(Q)){z(l,{status:e.silentUrl&&J?"silent":"interactive"});return}if(n&&Q==="consent_denied"){z(l,{error:null});return}if(Q==="rate_limited"&&!e.rateLimitRetried){const R=Math.min(Number(b==null?void 0:b.retryAfter)>0?Number(b.retryAfter):ke,Ce),Oe={...e,rateLimitRetried:!0};d(l),o.current[l]=setTimeout(()=>{delete o.current[l],M.current[l]=!0,v.current(Oe,{approve:n}).finally(()=>{delete M.current[l]})},R*1e3),z(l,{rateLimitRetried:!0});return}p(l),x(R=>({...R,[l]:{origin:l,reason:`broker:${Q}`,detail:b||null,clientId:e.clientId||L.current[l]||null}}))},[j,z,p,d]),v=t.useRef(S);v.current=S,t.useEffect(()=>{Object.values(m).forEach(e=>{e.status!=="broker"||M.current[e.origin]||o.current[e.origin]||(M.current[e.origin]=!0,S(e).finally(()=>{delete M.current[e.origin]}))})},[m,S]);const H=t.useCallback(e=>!F.current||!(e!=null&&e.consent)?Promise.resolve():S(e,{approve:!0}),[S]);t.useEffect(()=>{const e=G.current;Object.values(m).forEach(n=>{n.status==="silent"&&!e[n.origin]&&(e[n.origin]=setTimeout(()=>{delete e[n.origin],A(n.origin)},_e))}),Object.keys(e).forEach(n=>{(!m[n]||m[n].status!=="silent")&&(clearTimeout(e[n]),delete e[n])})},[m,A]),t.useEffect(()=>()=>{$.current&&$.current(),Object.values(G.current).forEach(clearTimeout),Object.values(o.current).forEach(clearTimeout)},[]);const B=t.useCallback(e=>{$.current&&($.current(),$.current=null);const n=u||ce;$.current=n(e,{onBlocked:()=>{g(s=>s[e.origin]?{...s,[e.origin]:{...s[e.origin],popupBlocked:!0}}:s)},onClosed:()=>{if(e.v2){J&&g(s=>!s[e.origin]||!s[e.origin].silentUrl?s:{...s,[e.origin]:{...s[e.origin],status:"silent"}});return}E(e.origin)}})},[u,E]),w={pending:Object.values(m).filter(e=>e.status==="interactive"),authorize:B,approve:H,complete:j,dismiss:P,originEpochs:Z,credentials:O,unsupported:q},D=Object.values(m).filter(e=>e.status==="silent"&&e.silentUrl);return U.default.createElement(Y.Provider,{value:w},r,D.map(e=>U.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"}})))};le.propTypes={children:C.default.node,launcher:C.default.func,broker:C.default.func};const we=()=>t.useContext(Y),ae=r=>{const{originEpochs:u}=t.useContext(Y),c=X(r);return c&&u[c]||0},de=r=>{const{credentials:u}=t.useContext(Y),c=X(r);return c&&u[c]||null},fe=r=>{const{unsupported:u}=t.useContext(Y),c=X(r);return c&&u[c]||null},pe=({children:r,authorizationLauncher:u,credentialBroker:c})=>{const[f,m]=t.useState({}),[g,Z]=t.useState({}),_=t.useRef({}),O=t.useRef({}),y=t.useRef({}),q=t.useCallback((i,a)=>{var o;return!!((o=y.current[i])!=null&&o.has(a))},[]),x=t.useCallback((i,a,o)=>{m(d=>({...d,[i]:{origin:a,frameRef:o}}))},[]),N=t.useCallback(i=>{m(a=>{const o={...a};return delete o[i],o}),Z(a=>{const o={...a};return delete o[i],o}),delete y.current[i]},[]);t.useEffect(()=>{const i=(o=[],d,p)=>{o.forEach(E=>E(d,p))},a=o=>{var j,z,M,S,v,H,B;if(!((j=o==null?void 0:o.data)!=null&&j.instanceId))return;const{instanceId:d,type:p}=o.data,E=f[d],A=(M=(z=E==null?void 0:E.frameRef)==null?void 0:z.current)==null?void 0:M.contentWindow;if(!A||o.source!==A||o.origin!==E.origin)return;const P={origin:o.origin},T=_.current;if(p==="response"){const{callbackId:w,response:D,error:e}=o.data,n=O.current[w];n&&(n(D,e),delete O.current[w]);return}if(p==="mark-registered"){const{requestType:w}=o.data;y.current[d]||(y.current[d]=new Set),y.current[d].add(w);return}p==="ready"&&Z(w=>({...w,[d]:!0})),i((S=T[d])==null?void 0:S[p],o.data,P),i((v=T["*"])==null?void 0:v[p],o.data,P),i((H=T[d])==null?void 0:H["*"],o.data,P),i((B=T["*"])==null?void 0:B["*"],o.data,P)};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[f]);const k=t.useCallback((i,a,o)=>{var p,E;const d=f[i];if(!d){console.warn(`Origin not set for id: ${i}. Unable to send message.`);return}(E=(p=d==null?void 0:d.frameRef)==null?void 0:p.current)!=null&&E.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:a,...o,instanceId:i},d.origin)},[f]),$=t.useRef(0),G=t.useCallback(()=>`${Date.now()}-${++$.current}`,[]),L=t.useCallback(async(i,a,o={})=>new Promise((d,p)=>{const E=G(),A=(P,T)=>{delete O.current[E],T?p(T):d(P)};O.current[E]=A,k(i,"request",{callbackId:E,requestType:a,data:o})}),[k]),W=t.useCallback((i,a)=>{k(i,"load-options",a)},[k]),F=t.useCallback((i,a)=>{k(i,"validate",a)},[k]),I=t.useMemo(()=>({registerFrame:x,unregisterFrame:N,sendMessage:k,sendRequest:L,loadOptions:W,validate:F,hasHandler:q,readyFrames:g,addListener:(i,a,o)=>(_.current[i]||(_.current[i]={}),_.current[i][a]||(_.current[i][a]=[]),_.current[i][a].push(o),()=>{_.current[i][a]=_.current[i][a].filter(d=>d!==o)})}),[x,N,k,L,W,F,q,g]);return U.default.createElement(V.Provider,{value:I},U.default.createElement(le,{launcher:u,broker:c},r))},K=(r,u,c)=>{const f=t.useContext(V);if(f===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const m=t.useRef(c);t.useEffect(()=>{m.current=c},[c]),t.useEffect(()=>{if(!(!r||!u)){if(u.startsWith("key:")){const g=u.substring(4);return f.readyFrames[r]&&f.sendMessage(r,"subscribe-key",{keyChord:g}),f.addListener(r,`key-pressed:${g}`,(..._)=>m.current(..._))}return f.addListener(r,u,(...g)=>m.current(...g))}},[f,r,u])};pe.propTypes={children:C.default.node.isRequired,authorizationLauncher:C.default.func,credentialBroker:C.default.func};const ne=se.default.default||se.default,Ie=1e4,Me="credentials",Se=(r,u)=>`${r}/mm-embedded-interop?id=${encodeURIComponent(u)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Me}`,Ue=ne.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
5
5
|
visibility: ${r=>r.$isReady?"visible":"hidden"};
|
|
6
|
-
`,Le=
|
|
6
|
+
`,Le=ne.div`
|
|
7
7
|
width: 100%;
|
|
8
8
|
height: 100%;
|
|
9
9
|
display: flex;
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
text-align: center;
|
|
17
17
|
color: #555;
|
|
18
18
|
font-size: 14px;
|
|
19
|
-
`,be=r=>{const u=r&&r.origin||"This app",c=r&&r.reason||"";switch(c){case"broker:scope_above_ceiling":return{title:`${u} can’t be authorized here`,detail:"It asks for permissions your role doesn’t have."};case"broker:origin_mismatch":case"broker:unknown_client":return{title:`${u} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${u} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return c.startsWith("broker:")?{title:`${u} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${u} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},me=({entry:r})=>{const u=be(r);return U.default.createElement(Le,{"data-reason":r&&r.reason||void 0},U.default.createElement("div",{style:{fontWeight:600}},u.title),U.default.createElement("div",{style:{fontSize:12,color:"#888"}},u.detail))};me.propTypes={entry:C.default.shape({origin:C.default.string,name:C.default.string,reason:C.default.string,detail:C.default.object})};const Ae=
|
|
19
|
+
`,be=r=>{const u=r&&r.origin||"This app",c=r&&r.reason||"";switch(c){case"broker:scope_above_ceiling":return{title:`${u} can’t be authorized here`,detail:"It asks for permissions your role doesn’t have."};case"broker:origin_mismatch":case"broker:unknown_client":return{title:`${u} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${u} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return c.startsWith("broker:")?{title:`${u} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${u} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},me=({entry:r})=>{const u=be(r);return U.default.createElement(Le,{"data-reason":r&&r.reason||void 0},U.default.createElement("div",{style:{fontWeight:600}},u.title),U.default.createElement("div",{style:{fontSize:12,color:"#888"}},u.detail))};me.propTypes={entry:C.default.shape({origin:C.default.string,name:C.default.string,reason:C.default.string,detail:C.default.object})};const Ae=ne.div`
|
|
20
20
|
height: 100%;
|
|
21
21
|
display: flex;
|
|
22
22
|
flex: 1;
|
|
23
23
|
align-items: center;
|
|
24
24
|
justify-content: center;
|
|
25
|
-
`,ze=()=>U.default.createElement(Ae,null,U.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),he=({id:r,src:u,path:c,onInit:f=()=>{},onTimeout:m,context:g={},params:Z={},renderUnsupported:_,renderTimeout:O,...y})=>{if("isConfiguring"in y)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in g)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in g)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const q=t.useRef(),[x,N]=t.useState(),[k,$]=t.useState(0),[G,L]=t.useState(!1),[W,F]=t.useState(!1),I=ae(u),i=de(u),a=fe(u),[o,d]=t.useState(0),[p,E]=t.useState(null),{registerFrame:A,unregisterFrame:P,sendMessage:T}=t.useContext(V),[j,z]=t.useState(),M=t.useRef(),S=t.useRef(m),v=t.useRef(f),H=t.useRef(!1),B=t.useCallback(()=>{H.current=!1,clearTimeout(M.current),$(0),L(!1),F(!1),E(null)},[]);t.useEffect(()=>{(I>0||o>0)&&B()},[I,o,B]),t.useEffect(()=>{S.current=m},[m]),t.useEffect(()=>{v.current=f},[f]),t.useEffect(()=>{k&&T(r,"set-context",{context:{...g}})},[g,r,k]),t.useEffect(()=>{k&&T(r,"set-params",{params:Z})},[Z,r,k]),t.useEffect(()=>{c!==void 0&&z((c==null?void 0:c.indexOf("/"))===0?c:`/${c}`)},[c]),t.useEffect(()=>{j===void 0||!k||T(r,"navigate",{path:j})},[j,k,r,T]),t.useEffect(()=>{if(!u||!r||!q)return;B();const e=new URL(u);return A(r,e.origin,q),v.current(),N(Se(e.origin,r)),()=>{P(r)}},[u,r,A,q,B]),t.useEffect(()=>{if(!(!x||H.current))return M.current=setTimeout(()=>{L(!0),S.current&&S.current()},Ie),()=>clearTimeout(M.current)},[x,u,I,o]);const w=t.useCallback(()=>{H.current=!0,clearTimeout(M.current),L(!1)},[]);K(r,"init",e=>{w(),Array.isArray(e==null?void 0:e.acceptsCredentials)&&E(e.acceptsCredentials)}),K(r,"authorize",w),K(r,"login",w),K(r,"credential-request",()=>{w(),F(!0)}),t.useEffect(()=>{if(!W||!i)return;const e=p;if(Array.isArray(e)&&!e.includes(i.kind))return;const n=i.kind==="access_token"?{accessToken:i.accessToken}:{};T(r,"credential",{...n,credential:i})},[W,i,p,r,T]),K(r,"ready",()=>{w(),$(e=>e+1)});const D=t.useRef();return K(r,"heartbeat",()=>{D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{d(e=>e+1)},6e3)}),t.useEffect(()=>()=>{D.current&&clearTimeout(D.current)},[]),a?_?_(a):U.default.createElement(me,{entry:a}):G&&!k?O?O():U.default.createElement(ze,null):U.default.createElement(Ue,{key:`auth-epoch-${I}-frame-${o}`,$isReady:k,ref:q,src:x,...y})};he.propTypes={id:C.default.string,src:C.default.string.isRequired,path:C.default.string,onInit:C.default.func,onTimeout:C.default.func,renderUnsupported:C.default.func,renderTimeout:C.default.func},h.CREDENTIAL_KIND_ACCESS_TOKEN=
|
|
25
|
+
`,ze=()=>U.default.createElement(Ae,null,U.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),he=({id:r,src:u,path:c,onInit:f=()=>{},onTimeout:m,context:g={},params:Z={},renderUnsupported:_,renderTimeout:O,...y})=>{if("isConfiguring"in y)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in g)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in g)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const q=t.useRef(),[x,N]=t.useState(),[k,$]=t.useState(0),[G,L]=t.useState(!1),[W,F]=t.useState(!1),I=ae(u),i=de(u),a=fe(u),[o,d]=t.useState(0),[p,E]=t.useState(null),{registerFrame:A,unregisterFrame:P,sendMessage:T}=t.useContext(V),[j,z]=t.useState(),M=t.useRef(),S=t.useRef(m),v=t.useRef(f),H=t.useRef(!1),B=t.useCallback(()=>{H.current=!1,clearTimeout(M.current),$(0),L(!1),F(!1),E(null)},[]);t.useEffect(()=>{(I>0||o>0)&&B()},[I,o,B]),t.useEffect(()=>{S.current=m},[m]),t.useEffect(()=>{v.current=f},[f]),t.useEffect(()=>{k&&T(r,"set-context",{context:{...g}})},[g,r,k]),t.useEffect(()=>{k&&T(r,"set-params",{params:Z})},[Z,r,k]),t.useEffect(()=>{c!==void 0&&z((c==null?void 0:c.indexOf("/"))===0?c:`/${c}`)},[c]),t.useEffect(()=>{j===void 0||!k||T(r,"navigate",{path:j})},[j,k,r,T]),t.useEffect(()=>{if(!u||!r||!q)return;B();const e=new URL(u);return A(r,e.origin,q),v.current(),N(Se(e.origin,r)),()=>{P(r)}},[u,r,A,q,B]),t.useEffect(()=>{if(!(!x||H.current))return M.current=setTimeout(()=>{L(!0),S.current&&S.current()},Ie),()=>clearTimeout(M.current)},[x,u,I,o]);const w=t.useCallback(()=>{H.current=!0,clearTimeout(M.current),L(!1)},[]);K(r,"init",e=>{w(),Array.isArray(e==null?void 0:e.acceptsCredentials)&&E(e.acceptsCredentials)}),K(r,"authorize",w),K(r,"login",w),K(r,"credential-request",()=>{w(),F(!0)}),t.useEffect(()=>{if(!W||!i)return;const e=p;if(Array.isArray(e)&&!e.includes(i.kind))return;const n=i.kind==="access_token"?{accessToken:i.accessToken}:{};T(r,"credential",{...n,credential:i})},[W,i,p,r,T]),K(r,"ready",()=>{w(),$(e=>e+1)});const D=t.useRef();return K(r,"heartbeat",()=>{D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{d(e=>e+1)},6e3)}),t.useEffect(()=>()=>{D.current&&clearTimeout(D.current)},[]),a?_?_(a):U.default.createElement(me,{entry:a}):G&&!k?O?O():U.default.createElement(ze,null):U.default.createElement(Ue,{key:`auth-epoch-${I}-frame-${o}`,$isReady:k,ref:q,src:x,...y})};he.propTypes={id:C.default.string,src:C.default.string.isRequired,path:C.default.string,onInit:C.default.func,onTimeout:C.default.func,renderUnsupported:C.default.func,renderTimeout:C.default.func},h.CREDENTIAL_KIND_ACCESS_TOKEN=ue,h.EmbeddedAuthorizationContext=Y,h.MMEmbeddableZone=he,h.MMEmbeddableZoneContext=V,h.MMEmbeddableZoneProvider=pe,h.isCrossSite=re,h.normalizeCredential=te,h.popupAuthorizationLauncher=ce,h.unsupportedCopy=be,h.useEmbeddedAuthorizations=we,h.useEmbeddedCredential=de,h.useEmbeddedEffect=K,h.useEmbeddedOriginEpoch=ae,h.useEmbeddedUnsupported=fe,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@machinemetrics/mm-react-embeddable",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"module": "dist/mm-react-embeddable.es.js",
|
|
6
6
|
"main": "dist/mm-react-embeddable.cjs.js",
|
|
@@ -44,4 +44,4 @@
|
|
|
44
44
|
"vite": "^7.2.2",
|
|
45
45
|
"vitest": "^4.0.10"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|