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