@machinemetrics/mm-react-embeddable 2.0.3-2 → 2.0.3-4
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,10 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),ze=require("prop-types"),$e=require("styled-components"),fe=e=>e&&e.__esModule?e:{default:e},z=fe(t),R=fe(ze),Ee=fe($e),ce=t.createContext(null),re=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),we="access_token",le=e=>e?e.kind?e:e.accessToken?{kind:we,accessToken:e.accessToken,expiresAt:e.expiresAt||null}:null:null,De=60,Fe=120,Pe=3e4,qe=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),ne=e=>{try{return new URL(e).origin}catch{return null}},Re=(e,c)=>{const a=c==null?void 0:c.origin;return!a||ne(e==null?void 0:e.authUrl)!==a?null:a},ge=e=>{if(!e||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(e)||e.includes(":"))return e;const c=e.split(".");return c.length<=2?e:c.slice(-2).join(".")},de=(e,c)=>{try{const a=new URL(e),b=new URL(c);return a.protocol!==b.protocol?!0:ge(a.hostname)!==ge(b.hostname)}catch{return!0}},Te=(e,{onBlocked:c,onClosed:a})=>{const b=window.open(e.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!b)return c(),()=>{};const m=setInterval(()=>{b.closed&&(clearInterval(m),a())},1e3);return()=>clearInterval(m)},_e=({children:e,launcher:c,broker:a,ready:b})=>{const m=t.useContext(ce),[T,_]=t.useState({}),[P,V]=t.useState({}),[B,I]=t.useState({}),[S,M]=t.useState({}),E=t.useRef(B);E.current=B;const q=t.useRef(T);q.current=T;const $=t.useRef(null),h=t.useRef({}),H=t.useRef({}),K=t.useRef(a);K.current=a;const A=t.useRef({}),W=t.useRef({}),N=t.useCallback((r,s,n)=>{!r||!s||(A.current[r]||(A.current[r]=new Set),n?A.current[r].add(s):A.current[r].delete(s))},[]),L=t.useCallback(r=>{const s=h.current[r];if(!s)return;const n=o=>!o[r]||o[r].clientId?o:{...o,[r]:{...o[r],clientId:s}};_(n),M(n)},[]),i=t.useCallback((r,s)=>{r&&(M(n=>n[r]?n:{...n,[r]:{origin:r,reason:s,clientId:h.current[r]||null}}),L(r))},[L]),l=t.useCallback((r,{v2:s=!1,origin:n=null}={})=>{var o;if(n){if(s&&E.current[n]){if(!((o=A.current[n])!=null&&o.has(r.instanceId)))return;const p=Date.now();if(p-(W.current[n]||0)<Pe)return;W.current[n]=p,A.current[n].clear();const C={...E.current};delete C[n],E.current=C,I(C)}_(p=>p[n]?p:{...p,[n]:{origin:n,authUrl:r.authUrl,status:s&&K.current?"broker":"interactive",v2:s,scope:r.scope||null,acceptsCredentials:H.current[n]||null,consent:null,error:null,clientId:r.clientId||h.current[n]||null,popupBlocked:!1}}),L(n)}},[L]),u=t.useRef({}),f=t.useCallback(r=>{u.current[r]&&(clearTimeout(u.current[r]),delete u.current[r])},[]),d=t.useCallback(r=>{f(r),_(s=>{if(!s[r])return s;const n={...s};return delete n[r],n})},[f]),g=t.useCallback(r=>{r&&(d(r),V(s=>({...s,[r]:(s[r]||0)+1})))},[d]),D=t.useCallback(r=>{d(r.origin)},[d]),v=t.useCallback((r,s)=>{const n=Re(r,s);if(n){if(de(n,window.location.origin)){i(n,"cross-site-legacy");return}l(r,{origin:n})}},[l,i]);t.useEffect(()=>{if(!m)return;const r=[m.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(h.current[n.origin]=s.clientId,L(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?H.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&de(n.origin,window.location.origin)&&i(n.origin,"cross-site-legacy")}),m.addListener("*","authorize",v),m.addListener("*","login",v),m.addListener("*","credential-request",(s,n)=>l(s,{v2:!0,origin:Re(s,n)}))];return()=>r.forEach(s=>s())},[m,v,l,L,i]),t.useEffect(()=>{const r=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const o=ne(n.authUrl);if(!o||s.origin!==o)return;const p=q.current[o];if(!(!p||p.status!=="interactive")){if(n.accessToken){I(C=>({...C,[o]:le({accessToken:n.accessToken})})),d(o);return}g(o)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[d,g]);const x=t.useCallback((r,s)=>{const n=r==null?void 0:r.origin,o=le(s);!n||!o||(I(p=>({...p,[n]:o})),d(n))},[d]),k=t.useCallback((r,s)=>{_(n=>n[r]?{...n,[r]:{...n[r],...s}}:n)},[]),y=t.useRef({}),U=t.useCallback(async(r,{approve:s}={})=>{const n=K.current,{origin:o}=r;let p;try{p=await n({origin:o,clientId:r.clientId,scope:r.scope,authUrl:r.authUrl},{approve:s})}catch{s?k(o,{error:{reason:"broker_unavailable"}}):k(o,{status:"interactive"});return}const C=p==null?void 0:p.status,O=(p==null?void 0:p.body)||{};if(C===200&&O.credential){x(r,O.credential);return}if(C===409&&O.consentRequired){k(o,{status:"interactive",consent:{client:O.client||null,stepUp:!!O.stepUp,scope:O.scope||r.scope},error:null});return}const Z=O.error||"broker_error";if(!s&&qe.has(Z)){k(o,{status:"interactive"});return}if(s&&Z==="consent_denied"){k(o,{error:null});return}if(Z==="rate_limited"&&!r.rateLimitRetried){const G=Math.min(Number(O.retryAfter)>0?Number(O.retryAfter):De,Fe),J={...r,rateLimitRetried:!0};f(o),u.current[o]=setTimeout(()=>{delete u.current[o],y.current[o]=!0,Q.current(J,{approve:s}).finally(()=>{delete y.current[o]})},G*1e3),k(o,{rateLimitRetried:!0});return}d(o),M(G=>({...G,[o]:{origin:o,reason:`broker:${Z}`,detail:{status:C!=null?C:null,reason:Z},clientId:r.clientId||h.current[o]||null}}))},[x,k,d,f]),Q=t.useRef(U);Q.current=U,t.useEffect(()=>{Object.values(T).forEach(r=>{r.status!=="broker"||y.current[r.origin]||u.current[r.origin]||(y.current[r.origin]=!0,U(r).finally(()=>{delete y.current[r.origin]}))})},[T,U]);const F=t.useCallback(r=>!K.current||!(r!=null&&r.consent)||y.current[r.origin]?Promise.resolve():(y.current[r.origin]=!0,U(r,{approve:!0}).finally(()=>{delete y.current[r.origin]})),[U]);t.useEffect(()=>()=>{$.current&&$.current(),Object.values(u.current).forEach(clearTimeout)},[]),t.useEffect(()=>{b===!1&&(Object.values(u.current).forEach(clearTimeout),u.current={},y.current={},h.current={},H.current={},A.current={},W.current={},E.current={},I({}),_({}),M({}))},[b]);const Y=t.useCallback(r=>{$.current&&($.current(),$.current=null);const s=c||Te;$.current=s(r,{onBlocked:()=>{_(n=>n[r.origin]?{...n,[r.origin]:{...n[r.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=q.current[r.origin];!n||n.v2||g(r.origin)}})},[c,g]),X={pending:Object.values(T).filter(r=>r.status==="interactive"),authorize:Y,approve:F,complete:x,dismiss:D,originEpochs:P,credentials:B,unsupported:S,setDelivered:N};return z.default.createElement(re.Provider,{value:X},e)};_e.propTypes={children:R.default.node,launcher:R.default.func,ready:R.default.bool,broker:R.default.func};const Ie=()=>t.useContext(re),Me=e=>{const{originEpochs:c}=t.useContext(re),a=ne(e);return a&&c[a]||0},ye=e=>{const{credentials:c}=t.useContext(re),a=ne(e);return a&&c[a]||null},Ae=e=>{const{unsupported:c}=t.useContext(re),a=ne(e);return a&&c[a]||null},ke="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.",Se=({children:e,authorizationLauncher:c,credentialBroker:a,ready:b})=>{const m=b===!0,T=t.useRef(!1);t.useEffect(()=>{b!==void 0||T.current||(T.current=!0,console.error(ke),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ke))},[b]);const[_,P]=t.useState({}),[V,B]=t.useState({}),I=t.useRef({}),S=t.useRef({}),M=t.useRef({}),E=t.useCallback((i,l)=>{var u;return!!((u=M.current[i])!=null&&u.has(l))},[]),q=t.useCallback((i,l,u)=>{P(f=>({...f,[i]:{origin:l,frameRef:u}}))},[]),$=t.useCallback(i=>{P(l=>{const u={...l};return delete u[i],u}),B(l=>{const u={...l};return delete u[i],u}),delete M.current[i],Object.keys(S.current).forEach(l=>{S.current[l].instanceId===i&&delete S.current[l]})},[]);t.useEffect(()=>()=>{S.current={}},[]),t.useEffect(()=>{const i=(u=[],f,d)=>{u.forEach(g=>g(f,d))},l=u=>{var k,y,U,Q,F,Y,X;if(!((k=u==null?void 0:u.data)!=null&&k.instanceId))return;const{instanceId:f,type:d}=u.data,g=_[f],D=(U=(y=g==null?void 0:g.frameRef)==null?void 0:y.current)==null?void 0:U.contentWindow;if(!D||u.source!==D||u.origin!==g.origin)return;const v={origin:u.origin},x=I.current;if(d==="response"){const{callbackId:r,response:s,error:n}=u.data,o=S.current[r];o&&o.instanceId===f&&(o.callback(s,n),delete S.current[r]);return}if(d==="mark-registered"){const{requestType:r}=u.data;M.current[f]||(M.current[f]=new Set),M.current[f].add(r);return}d==="ready"&&B(r=>({...r,[f]:!0})),i((Q=x[f])==null?void 0:Q[d],u.data,v),i((F=x["*"])==null?void 0:F[d],u.data,v),i((Y=x[f])==null?void 0:Y["*"],u.data,v),i((X=x["*"])==null?void 0:X["*"],u.data,v)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[_]);const h=t.useCallback((i,l,u,f)=>{var g,D;const d=_[i];if(!d){console.warn(`Origin not set for id: ${i}. Unable to send message.`);return}(D=(g=d==null?void 0:d.frameRef)==null?void 0:g.current)!=null&&D.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:l,...u,instanceId:i},f||d.origin)},[_]),H=t.useRef(0),K=t.useCallback(()=>`${Date.now()}-${++H.current}`,[]),A=t.useCallback(async(i,l,u={})=>new Promise((f,d)=>{const g=K(),D=(v,x)=>{delete S.current[g],x?d(x):f(v)};S.current[g]={instanceId:i,callback:D},h(i,"request",{callbackId:g,requestType:l,data:u})}),[h]),W=t.useCallback((i,l)=>{h(i,"load-options",l)},[h]),N=t.useCallback((i,l)=>{h(i,"validate",l)},[h]),L=t.useMemo(()=>({registerFrame:q,unregisterFrame:$,sendMessage:h,sendRequest:A,loadOptions:W,validate:N,hasHandler:E,readyFrames:V,ready:m,addListener:(i,l,u)=>(I.current[i]||(I.current[i]={}),I.current[i][l]||(I.current[i][l]=[]),I.current[i][l].push(u),()=>{I.current[i][l]=I.current[i][l].filter(f=>f!==u)})}),[q,$,h,A,W,N,E,V,m]);return z.default.createElement(ce.Provider,{value:L},z.default.createElement(_e,{launcher:c,broker:a,ready:m},e))},ee=(e,c,a)=>{const b=t.useContext(ce);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(!(!e||!c)){if(c.startsWith("key:")){const T=c.substring(4);return b.readyFrames[e]&&b.sendMessage(e,"subscribe-key",{keyChord:T}),b.addListener(e,`key-pressed:${T}`,(...P)=>m.current(...P))}return b.addListener(e,c,(...T)=>m.current(...T))}},[b,e,c])};Se.propTypes={children:R.default.node.isRequired,ready:R.default.bool.isRequired,authorizationLauncher:R.default.func,credentialBroker:R.default.func};const pe=Ee.default.default||Ee.default,Be=1e4,We=6e3,Ce=15e3,Ze=2e3,je=3e3,Le=()=>typeof document!="undefined"&&document.visibilityState==="hidden",te=(e,c,a)=>{if(e.current&&clearTimeout(e.current.handle),Le()){e.current={ms:c,fn:a,suspended:!0};return}const b=Date.now(),m=setTimeout(()=>{if(Date.now()-b-c>je){te(e,c,a);return}e.current=void 0,a()},c);e.current={handle:m,ms:c,fn:a}},j=e=>{e.current&&clearTimeout(e.current.handle),e.current=void 0},ie=e=>{e.current&&!e.current.suspended&&(clearTimeout(e.current.handle),e.current={ms:e.current.ms,fn:e.current.fn,suspended:!0})},ae=e=>{e.current&&e.current.suspended&&te(e,e.current.ms,e.current.fn)},He="credentials",Ke=(e,c)=>`${e}/mm-embedded-interop?id=${encodeURIComponent(c)}&origin=${encodeURIComponent(window.location.origin)}&caps=${He}`,Ye=pe.iframe`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),Oe=require("prop-types"),ze=require("styled-components"),fe=e=>e&&e.__esModule?e:{default:e},z=fe(t),R=fe(Oe),me=fe(ze),ce=t.createContext(null),re=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),Ce="access_token",le=e=>e?e.kind?e:e.accessToken?{kind:Ce,accessToken:e.accessToken,expiresAt:e.expiresAt||null}:null:null,$e=60,De=120,Fe=3e4,Pe=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),ne=e=>{try{return new URL(e).origin}catch{return null}},Re=(e,c)=>{const a=c==null?void 0:c.origin;return!a||ne(e==null?void 0:e.authUrl)!==a?null:a},ge=e=>{if(!e||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(e)||e.includes(":"))return e;const c=e.split(".");return c.length<=2?e:c.slice(-2).join(".")},de=(e,c)=>{try{const a=new URL(e),b=new URL(c);return a.protocol!==b.protocol?!0:ge(a.hostname)!==ge(b.hostname)}catch{return!0}},we=(e,{onBlocked:c,onClosed:a})=>{const b=window.open(e.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!b)return c(),()=>{};const E=setInterval(()=>{b.closed&&(clearInterval(E),a())},1e3);return()=>clearInterval(E)},_e=({children:e,launcher:c,broker:a,ready:b})=>{const E=t.useContext(ce),[C,_]=t.useState({}),[P,Y]=t.useState({}),[W,T]=t.useState({}),[y,I]=t.useState({}),m=t.useRef(W);m.current=W;const q=t.useRef(C);q.current=C;const $=t.useRef(null),h=t.useRef({}),H=t.useRef({}),K=t.useRef(a);K.current=a;const S=t.useRef({}),Z=t.useRef({}),N=t.useCallback((r,s,n)=>{!r||!s||(S.current[r]||(S.current[r]=new Set),n?S.current[r].add(s):S.current[r].delete(s))},[]),L=t.useCallback(r=>{const s=h.current[r];if(!s)return;const n=o=>!o[r]||o[r].clientId?o:{...o,[r]:{...o[r],clientId:s}};_(n),I(n)},[]),i=t.useCallback((r,s)=>{r&&(I(n=>n[r]?n:{...n,[r]:{origin:r,reason:s,clientId:h.current[r]||null}}),L(r))},[L]),l=t.useCallback((r,{v2:s=!1,origin:n=null}={})=>{var o;if(n){if(s&&m.current[n]){if(!((o=S.current[n])!=null&&o.has(r.instanceId)))return;const p=Date.now();if(p-(Z.current[n]||0)<Fe)return;Z.current[n]=p,S.current[n].clear();const M={...m.current};delete M[n],m.current=M,T(M)}_(p=>p[n]?p:{...p,[n]:{origin:n,authUrl:r.authUrl,status:s&&K.current?"broker":"interactive",v2:s,scope:r.scope||null,acceptsCredentials:H.current[n]||null,consent:null,error:null,clientId:r.clientId||h.current[n]||null,popupBlocked:!1}}),L(n)}},[L]),u=t.useRef({}),f=t.useCallback(r=>{u.current[r]&&(clearTimeout(u.current[r]),delete u.current[r])},[]),d=t.useCallback(r=>{f(r),_(s=>{if(!s[r])return s;const n={...s};return delete n[r],n})},[f]),g=t.useCallback(r=>{r&&(d(r),Y(s=>({...s,[r]:(s[r]||0)+1})))},[d]),D=t.useCallback(r=>{d(r.origin)},[d]),v=t.useCallback((r,s)=>{const n=Re(r,s);if(n){if(de(n,window.location.origin)){i(n,"cross-site-legacy");return}l(r,{origin:n})}},[l,i]);t.useEffect(()=>{if(!E)return;const r=[E.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(h.current[n.origin]=s.clientId,L(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?H.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&de(n.origin,window.location.origin)&&i(n.origin,"cross-site-legacy")}),E.addListener("*","authorize",v),E.addListener("*","login",v),E.addListener("*","credential-request",(s,n)=>l(s,{v2:!0,origin:Re(s,n)}))];return()=>r.forEach(s=>s())},[E,v,l,L,i]),t.useEffect(()=>{const r=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const o=ne(n.authUrl);if(!o||s.origin!==o)return;const p=q.current[o];if(!(!p||p.status!=="interactive")){if(n.accessToken){T(M=>({...M,[o]:le({accessToken:n.accessToken})})),d(o);return}g(o)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[d,g]);const x=t.useCallback((r,s)=>{const n=r==null?void 0:r.origin,o=le(s);!n||!o||(T(p=>({...p,[n]:o})),d(n))},[d]),k=t.useCallback((r,s)=>{_(n=>n[r]?{...n,[r]:{...n[r],...s}}:n)},[]),A=t.useRef({}),U=t.useCallback(async(r,{approve:s}={})=>{const n=K.current,{origin:o}=r;let p;try{p=await n({origin:o,clientId:r.clientId,scope:r.scope,authUrl:r.authUrl},{approve:s})}catch{s?k(o,{error:{reason:"broker_unavailable"}}):k(o,{status:"interactive"});return}const M=p==null?void 0:p.status,O=(p==null?void 0:p.body)||{};if(M===200&&O.credential){x(r,O.credential);return}if(M===409&&O.consentRequired){k(o,{status:"interactive",consent:{client:O.client||null,stepUp:!!O.stepUp,scope:O.scope||r.scope},error:null});return}const B=O.error||"broker_error";if(!s&&Pe.has(B)){k(o,{status:"interactive"});return}if(s&&B==="consent_denied"){k(o,{error:null});return}if(B==="rate_limited"&&!r.rateLimitRetried){const V=Math.min(Number(O.retryAfter)>0?Number(O.retryAfter):$e,De),J={...r,rateLimitRetried:!0};f(o),u.current[o]=setTimeout(()=>{delete u.current[o],A.current[o]=!0,Q.current(J,{approve:s}).finally(()=>{delete A.current[o]})},V*1e3),k(o,{rateLimitRetried:!0});return}d(o),I(V=>({...V,[o]:{origin:o,reason:`broker:${B}`,detail:{status:M!=null?M:null,reason:B},clientId:r.clientId||h.current[o]||null}}))},[x,k,d,f]),Q=t.useRef(U);Q.current=U,t.useEffect(()=>{Object.values(C).forEach(r=>{r.status!=="broker"||A.current[r.origin]||u.current[r.origin]||(A.current[r.origin]=!0,U(r).finally(()=>{delete A.current[r.origin]}))})},[C,U]);const F=t.useCallback(r=>!K.current||!(r!=null&&r.consent)||A.current[r.origin]?Promise.resolve():(A.current[r.origin]=!0,U(r,{approve:!0}).finally(()=>{delete A.current[r.origin]})),[U]);t.useEffect(()=>()=>{$.current&&$.current(),Object.values(u.current).forEach(clearTimeout)},[]),t.useEffect(()=>{b===!1&&(Object.values(u.current).forEach(clearTimeout),u.current={},A.current={},h.current={},H.current={},S.current={},Z.current={},m.current={},T({}),_({}),I({}))},[b]);const G=t.useCallback(r=>{$.current&&($.current(),$.current=null);const s=c||we;$.current=s(r,{onBlocked:()=>{_(n=>n[r.origin]?{...n,[r.origin]:{...n[r.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=q.current[r.origin];!n||n.v2||g(r.origin)}})},[c,g]),X={pending:Object.values(C).filter(r=>r.status==="interactive"),authorize:G,approve:F,complete:x,dismiss:D,originEpochs:P,credentials:W,unsupported:y,setDelivered:N};return z.default.createElement(re.Provider,{value:X},e)};_e.propTypes={children:R.default.node,launcher:R.default.func,ready:R.default.bool,broker:R.default.func};const Te=()=>t.useContext(re),Ie=e=>{const{originEpochs:c}=t.useContext(re),a=ne(e);return a&&c[a]||0},Ae=e=>{const{credentials:c}=t.useContext(re),a=ne(e);return a&&c[a]||null},Me=e=>{const{unsupported:c}=t.useContext(re),a=ne(e);return a&&c[a]||null},ke="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.",Se=({children:e,authorizationLauncher:c,credentialBroker:a,ready:b})=>{const E=b===!0,C=t.useRef(!1);t.useEffect(()=>{b!==void 0||C.current||(C.current=!0,console.error(ke),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ke))},[b]);const[_,P]=t.useState({}),[Y,W]=t.useState({}),T=t.useRef({}),y=t.useRef({}),I=t.useRef({}),m=t.useCallback((i,l)=>{var u;return!!((u=I.current[i])!=null&&u.has(l))},[]),q=t.useCallback((i,l,u)=>{P(f=>({...f,[i]:{origin:l,frameRef:u}}))},[]),$=t.useCallback(i=>{P(l=>{const u={...l};return delete u[i],u}),W(l=>{const u={...l};return delete u[i],u}),delete I.current[i],Object.keys(y.current).forEach(l=>{y.current[l].instanceId===i&&delete y.current[l]})},[]);t.useEffect(()=>()=>{y.current={}},[]),t.useEffect(()=>{const i=(u=[],f,d)=>{u.forEach(g=>g(f,d))},l=u=>{var k,A,U,Q,F,G,X;if(!((k=u==null?void 0:u.data)!=null&&k.instanceId))return;const{instanceId:f,type:d}=u.data,g=_[f],D=(U=(A=g==null?void 0:g.frameRef)==null?void 0:A.current)==null?void 0:U.contentWindow;if(!D||u.source!==D||u.origin!==g.origin)return;const v={origin:u.origin},x=T.current;if(d==="response"){const{callbackId:r,response:s,error:n}=u.data,o=y.current[r];o&&o.instanceId===f&&(o.callback(s,n),delete y.current[r]);return}if(d==="mark-registered"){const{requestType:r}=u.data;I.current[f]||(I.current[f]=new Set),I.current[f].add(r);return}d==="ready"&&W(r=>({...r,[f]:!0})),i((Q=x[f])==null?void 0:Q[d],u.data,v),i((F=x["*"])==null?void 0:F[d],u.data,v),i((G=x[f])==null?void 0:G["*"],u.data,v),i((X=x["*"])==null?void 0:X["*"],u.data,v)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[_]);const h=t.useCallback((i,l,u,f)=>{var g,D;const d=_[i];if(!d){console.warn(`Origin not set for id: ${i}. Unable to send message.`);return}(D=(g=d==null?void 0:d.frameRef)==null?void 0:g.current)!=null&&D.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:l,...u,instanceId:i},f||d.origin)},[_]),H=t.useRef(0),K=t.useCallback(()=>`${Date.now()}-${++H.current}`,[]),S=t.useCallback(async(i,l,u={})=>new Promise((f,d)=>{const g=K(),D=(v,x)=>{delete y.current[g],x?d(x):f(v)};y.current[g]={instanceId:i,callback:D},h(i,"request",{callbackId:g,requestType:l,data:u})}),[h]),Z=t.useCallback((i,l)=>{h(i,"load-options",l)},[h]),N=t.useCallback((i,l)=>{h(i,"validate",l)},[h]),L=t.useMemo(()=>({registerFrame:q,unregisterFrame:$,sendMessage:h,sendRequest:S,loadOptions:Z,validate:N,hasHandler:m,readyFrames:Y,ready:E,addListener:(i,l,u)=>(T.current[i]||(T.current[i]={}),T.current[i][l]||(T.current[i][l]=[]),T.current[i][l].push(u),()=>{T.current[i][l]=T.current[i][l].filter(f=>f!==u)})}),[q,$,h,S,Z,N,m,Y,E]);return z.default.createElement(ce.Provider,{value:L},z.default.createElement(_e,{launcher:c,broker:a,ready:E},e))},ee=(e,c,a)=>{const b=t.useContext(ce);if(b===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const E=t.useRef(a);t.useEffect(()=>{E.current=a},[a]),t.useEffect(()=>{if(!(!e||!c)){if(c.startsWith("key:")){const C=c.substring(4);return b.readyFrames[e]&&b.sendMessage(e,"subscribe-key",{keyChord:C}),b.addListener(e,`key-pressed:${C}`,(...P)=>E.current(...P))}return b.addListener(e,c,(...C)=>E.current(...C))}},[b,e,c])};Se.propTypes={children:R.default.node.isRequired,ready:R.default.bool.isRequired,authorizationLauncher:R.default.func,credentialBroker:R.default.func};const pe=me.default.default||me.default,qe=1e4,Be=6e3,We=5e3,Ze=2e4,je=3e3,ye=()=>typeof document!="undefined"&&document.visibilityState==="hidden",te=(e,c,a)=>{if(e.current&&clearTimeout(e.current.handle),ye()){e.current={ms:c,fn:a,suspended:!0};return}const b=Date.now(),E=setTimeout(()=>{if(Date.now()-b-c>je){te(e,c,a);return}e.current=void 0,a()},c);e.current={handle:E,ms:c,fn:a}},j=e=>{e.current&&clearTimeout(e.current.handle),e.current=void 0},ie=e=>{e.current&&!e.current.suspended&&(clearTimeout(e.current.handle),e.current={ms:e.current.ms,fn:e.current.fn,suspended:!0})},ae=e=>{e.current&&e.current.suspended&&te(e,e.current.ms,e.current.fn)},He="credentials",Ke=(e,c)=>`${e}/mm-embedded-interop?id=${encodeURIComponent(c)}&origin=${encodeURIComponent(window.location.origin)}&caps=${He}`,Ge=pe.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
5
5
|
visibility: ${e=>e.$isReady?"visible":"hidden"};
|
|
6
6
|
${e=>e.$collapsed?"position: absolute; width: 1px; height: 1px; overflow: hidden;":""}
|
|
7
|
-
`,
|
|
7
|
+
`,Ve=pe.div`
|
|
8
8
|
width: 100%;
|
|
9
9
|
height: 100%;
|
|
10
10
|
display: flex;
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
text-align: center;
|
|
18
18
|
color: #555;
|
|
19
19
|
font-size: 14px;
|
|
20
|
-
`,
|
|
20
|
+
`,Le=e=>{const c=e&&e.origin||"This app",a=e&&e.reason||"";switch(a){case"broker:scope_above_ceiling":return{title:`${c} 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:`${c} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${c} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return a.startsWith("broker:")?{title:`${c} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${c} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},ve=({entry:e})=>{const c=Le(e);return z.default.createElement(Ve,{"data-reason":e&&e.reason||void 0},z.default.createElement("div",{style:{fontWeight:600}},c.title),z.default.createElement("div",{style:{fontSize:12,color:"#888"}},c.detail))};ve.propTypes={entry:R.default.shape({origin:R.default.string,name:R.default.string,reason:R.default.string,detail:R.default.object})};const Ye=pe.div`
|
|
21
21
|
height: 100%;
|
|
22
22
|
display: flex;
|
|
23
23
|
flex: 1;
|
|
24
24
|
align-items: center;
|
|
25
25
|
justify-content: center;
|
|
26
|
-
`,Ne=()=>z.default.createElement(
|
|
26
|
+
`,Ne=()=>z.default.createElement(Ye,null,z.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),xe=({id:e,src:c,path:a,onInit:b=()=>{},onTimeout:E,onRemount:C,onStall:_,context:P={},params:Y={},renderUnsupported:W,renderTimeout:T,...y})=>{if("isConfiguring"in y)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in P)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in P)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const I=t.useRef(),m=ne(c),[q,$]=t.useState(),[h,H]=t.useState(0),[K,S]=t.useState(!1),[Z,N]=t.useState(!1),L=Ie(c),i=Ae(c),l=Me(c),{setDelivered:u}=Te(),[f,d]=t.useState(0),[g,D]=t.useState(null),{registerFrame:v,unregisterFrame:x,sendMessage:k,ready:A}=t.useContext(ce),[U,Q]=t.useState(),F=t.useRef(),G=t.useRef(E),X=t.useRef(b),r=t.useRef(C),s=t.useRef(_),n=t.useRef(!1),o=t.useRef(),p=t.useRef(),M=t.useRef(!1),O=t.useRef(!1),B=t.useRef(!1),V=t.useRef(null),J=t.useCallback(()=>{n.current=!1,M.current=!1,O.current=!1,B.current=!1,V.current=null,j(F),j(o),j(p),H(0),S(!1),N(!1),D(null),u(m,e,!1)},[u,m,e]);t.useEffect(()=>{(L>0||f>0)&&J()},[L,f,J]),t.useEffect(()=>{G.current=E},[E]),t.useEffect(()=>{X.current=b},[b]),t.useEffect(()=>{r.current=C},[C]),t.useEffect(()=>{s.current=_},[_]),t.useEffect(()=>{const w=()=>{if(ye()){ie(F),ie(o),ie(p);return}ae(F),ae(p),M.current&&ae(o)};return document.addEventListener("visibilitychange",w),()=>document.removeEventListener("visibilitychange",w)},[]),t.useEffect(()=>{h&&k(e,"set-context",{context:{...P}},m)},[P,e,h,m]),t.useEffect(()=>{h&&k(e,"set-params",{params:Y},m)},[Y,e,h,m]),t.useEffect(()=>{a!==void 0&&Q((a==null?void 0:a.indexOf("/"))===0?a:`/${a}`)},[a]),t.useEffect(()=>{U===void 0||!h||k(e,"navigate",{path:U},m)},[U,h,e,k,m]),t.useEffect(()=>{if(!c||!e||!I)return;if(!A){J(),$(void 0);return}J();const w=new URL(c);return v(e,w.origin,I),X.current(),$(Ke(w.origin,e)),()=>{x(e)}},[c,e,A,v,I,J]);const ue=t.useCallback(()=>{S(!0),G.current&&G.current()},[]);t.useEffect(()=>{if(!(!q||n.current))return te(F,qe,ue),()=>j(F)},[q,c,L,f,ue]);const se=t.useCallback(()=>{n.current=!0,j(F),S(!1)},[]),oe=t.useCallback(()=>{if(!B.current){B.current=!0,k(e,"credential",V.current,m),s.current&&s.current("redelivered"),te(p,Ze,oe);return}s.current&&s.current("ready"),ue()},[e,k,m,ue]);ee(e,"init",w=>{se(),Array.isArray(w==null?void 0:w.acceptsCredentials)&&D(w.acceptsCredentials)}),ee(e,"authorize",se),ee(e,"login",se),ee(e,"credential-request",()=>{se(),N(!0)}),t.useEffect(()=>{if(!Z||!i||O.current)return;const w=g;if(Array.isArray(w)&&!w.includes(i.kind))return;const Ee={...i.kind==="access_token"?{accessToken:i.accessToken}:{},credential:i};V.current=Ee,B.current=!1,k(e,"credential",Ee,m),u(m,e,!0),te(p,We,oe)},[oe,Z,i,g,e,k,m,u]),ee(e,"ready",()=>{se(),j(p),O.current=!0,H(w=>w+1)});const Ue=t.useCallback(()=>{r.current&&r.current("heartbeat"),d(w=>w+1)},[]);if(ee(e,"heartbeat",()=>{M.current=!0,te(o,Be,Ue)}),t.useEffect(()=>()=>{j(o),j(p),j(F)},[]),l)return W?W(l):z.default.createElement(ve,{entry:l});const be=!!(K&&!h),he={...y};return delete he.skipManifestCheck,z.default.createElement(z.default.Fragment,null,be&&(T?T():z.default.createElement(Ne,null)),z.default.createElement(Ge,{key:`auth-epoch-${L}-frame-${f}`,$isReady:h,$collapsed:be,ref:I,src:q,...he}))};xe.propTypes={id:R.default.string,src:R.default.string.isRequired,path:R.default.string,onInit:R.default.func,onTimeout:R.default.func,onRemount:R.default.func,onStall:R.default.func,renderUnsupported:R.default.func,renderTimeout:R.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=Ce;exports.EmbeddedAuthorizationContext=re;exports.MMEmbeddableZone=xe;exports.MMEmbeddableZoneContext=ce;exports.MMEmbeddableZoneProvider=Se;exports.isCrossSite=de;exports.normalizeCredential=le;exports.popupAuthorizationLauncher=we;exports.unsupportedCopy=Le;exports.useEmbeddedAuthorizations=Te;exports.useEmbeddedCredential=Ae;exports.useEmbeddedEffect=ee;exports.useEmbeddedOriginEpoch=Ie;exports.useEmbeddedUnsupported=Me;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import D, { createContext as _e, useContext as ne, useState as F, useRef as l, useCallback as h, useEffect as g, useMemo as Ce } from "react";
|
|
2
2
|
import w from "prop-types";
|
|
3
3
|
import Re from "styled-components";
|
|
4
|
-
const le =
|
|
4
|
+
const le = _e(null), ue = _e({
|
|
5
5
|
pending: [],
|
|
6
6
|
authorize: () => {
|
|
7
7
|
},
|
|
@@ -16,11 +16,11 @@ const le = ye(null), ue = ye({
|
|
|
16
16
|
unsupported: {},
|
|
17
17
|
setDelivered: () => {
|
|
18
18
|
}
|
|
19
|
-
}),
|
|
20
|
-
kind:
|
|
19
|
+
}), ve = "access_token", Ee = (e) => e ? e.kind ? e : e.accessToken ? {
|
|
20
|
+
kind: ve,
|
|
21
21
|
accessToken: e.accessToken,
|
|
22
22
|
expiresAt: e.expiresAt || null
|
|
23
|
-
} : null : null, Se = 60,
|
|
23
|
+
} : null : null, Se = 60, Ue = 120, xe = 3e4, Oe = /* @__PURE__ */ new Set([
|
|
24
24
|
"host_not_allowed",
|
|
25
25
|
"unbound_host_bound_guest",
|
|
26
26
|
"invalid_token",
|
|
@@ -34,19 +34,19 @@ const le = ye(null), ue = ye({
|
|
|
34
34
|
}, we = (e, s) => {
|
|
35
35
|
const u = s == null ? void 0 : s.origin;
|
|
36
36
|
return !u || oe(e == null ? void 0 : e.authUrl) !== u ? null : u;
|
|
37
|
-
},
|
|
37
|
+
}, ke = (e) => {
|
|
38
38
|
if (!e || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(e) || e.includes(":"))
|
|
39
39
|
return e;
|
|
40
40
|
const s = e.split(".");
|
|
41
41
|
return s.length <= 2 ? e : s.slice(-2).join(".");
|
|
42
|
-
},
|
|
42
|
+
}, Te = (e, s) => {
|
|
43
43
|
try {
|
|
44
44
|
const u = new URL(e), m = new URL(s);
|
|
45
|
-
return u.protocol !== m.protocol ? !0 :
|
|
45
|
+
return u.protocol !== m.protocol ? !0 : ke(u.hostname) !== ke(m.hostname);
|
|
46
46
|
} catch {
|
|
47
47
|
return !0;
|
|
48
48
|
}
|
|
49
|
-
},
|
|
49
|
+
}, $e = (e, { onBlocked: s, onClosed: u }) => {
|
|
50
50
|
const m = window.open(
|
|
51
51
|
e.authUrl,
|
|
52
52
|
"mm-embed-auth",
|
|
@@ -60,64 +60,64 @@ const le = ye(null), ue = ye({
|
|
|
60
60
|
}, 1e3);
|
|
61
61
|
return () => clearInterval(R);
|
|
62
62
|
}, Ae = ({ children: e, launcher: s, broker: u, ready: m }) => {
|
|
63
|
-
const R = ne(le), [
|
|
64
|
-
E.current =
|
|
65
|
-
const j = l(
|
|
66
|
-
j.current =
|
|
67
|
-
const P = l(null), b = l({}),
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
!r || !n || (
|
|
71
|
-
}, []),
|
|
63
|
+
const R = ne(le), [I, A] = F({}), [q, J] = F({}), [Z, L] = F({}), [S, y] = F({}), E = l(Z);
|
|
64
|
+
E.current = Z;
|
|
65
|
+
const j = l(I);
|
|
66
|
+
j.current = I;
|
|
67
|
+
const P = l(null), b = l({}), V = l({}), Y = l(u);
|
|
68
|
+
Y.current = u;
|
|
69
|
+
const v = l({}), K = l({}), N = h((r, n, t) => {
|
|
70
|
+
!r || !n || (v.current[r] || (v.current[r] = /* @__PURE__ */ new Set()), t ? v.current[r].add(n) : v.current[r].delete(n));
|
|
71
|
+
}, []), U = h((r) => {
|
|
72
72
|
const n = b.current[r];
|
|
73
73
|
if (!n)
|
|
74
74
|
return;
|
|
75
75
|
const t = (o) => !o[r] || o[r].clientId ? o : { ...o, [r]: { ...o[r], clientId: n } };
|
|
76
|
-
A(t),
|
|
76
|
+
A(t), y(t);
|
|
77
77
|
}, []), i = h(
|
|
78
78
|
(r, n) => {
|
|
79
|
-
r && (
|
|
79
|
+
r && (y((t) => t[r] ? t : {
|
|
80
80
|
...t,
|
|
81
81
|
[r]: {
|
|
82
82
|
origin: r,
|
|
83
83
|
reason: n,
|
|
84
84
|
clientId: b.current[r] || null
|
|
85
85
|
}
|
|
86
|
-
}),
|
|
86
|
+
}), U(r));
|
|
87
87
|
},
|
|
88
|
-
[
|
|
88
|
+
[U]
|
|
89
89
|
), a = h(
|
|
90
90
|
(r, { v2: n = !1, origin: t = null } = {}) => {
|
|
91
91
|
var o;
|
|
92
92
|
if (t) {
|
|
93
93
|
if (n && E.current[t]) {
|
|
94
|
-
if (!((o =
|
|
94
|
+
if (!((o = v.current[t]) != null && o.has(r.instanceId)))
|
|
95
95
|
return;
|
|
96
96
|
const p = Date.now();
|
|
97
|
-
if (p - (
|
|
97
|
+
if (p - (K.current[t] || 0) < xe)
|
|
98
98
|
return;
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
delete
|
|
99
|
+
K.current[t] = p, v.current[t].clear();
|
|
100
|
+
const C = { ...E.current };
|
|
101
|
+
delete C[t], E.current = C, L(C);
|
|
102
102
|
}
|
|
103
103
|
A((p) => p[t] ? p : {
|
|
104
104
|
...p,
|
|
105
105
|
[t]: {
|
|
106
106
|
origin: t,
|
|
107
107
|
authUrl: r.authUrl,
|
|
108
|
-
status: n &&
|
|
108
|
+
status: n && Y.current ? "broker" : "interactive",
|
|
109
109
|
v2: n,
|
|
110
110
|
scope: r.scope || null,
|
|
111
|
-
acceptsCredentials:
|
|
111
|
+
acceptsCredentials: V.current[t] || null,
|
|
112
112
|
consent: null,
|
|
113
113
|
error: null,
|
|
114
114
|
clientId: r.clientId || b.current[t] || null,
|
|
115
115
|
popupBlocked: !1
|
|
116
116
|
}
|
|
117
|
-
}),
|
|
117
|
+
}), U(t);
|
|
118
118
|
}
|
|
119
119
|
},
|
|
120
|
-
[
|
|
120
|
+
[U]
|
|
121
121
|
), c = l({}), f = h((r) => {
|
|
122
122
|
c.current[r] && (clearTimeout(c.current[r]), delete c.current[r]);
|
|
123
123
|
}, []), d = h(
|
|
@@ -130,7 +130,7 @@ const le = ye(null), ue = ye({
|
|
|
130
130
|
});
|
|
131
131
|
},
|
|
132
132
|
[f]
|
|
133
|
-
),
|
|
133
|
+
), k = h(
|
|
134
134
|
(r) => {
|
|
135
135
|
r && (d(r), J((n) => ({
|
|
136
136
|
...n,
|
|
@@ -147,7 +147,7 @@ const le = ye(null), ue = ye({
|
|
|
147
147
|
(r, n) => {
|
|
148
148
|
const t = we(r, n);
|
|
149
149
|
if (t) {
|
|
150
|
-
if (
|
|
150
|
+
if (Te(t, window.location.origin)) {
|
|
151
151
|
i(t, "cross-site-legacy");
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
@@ -161,7 +161,7 @@ const le = ye(null), ue = ye({
|
|
|
161
161
|
return;
|
|
162
162
|
const r = [
|
|
163
163
|
R.addListener("*", "init", (n, t) => {
|
|
164
|
-
t != null && t.origin && (n != null && n.clientId) && (b.current[t.origin] = n.clientId,
|
|
164
|
+
t != null && t.origin && (n != null && n.clientId) && (b.current[t.origin] = n.clientId, U(t.origin)), t != null && t.origin && Array.isArray(n == null ? void 0 : n.acceptsCredentials) ? V.current[t.origin] = n.acceptsCredentials : t != null && t.origin && Te(t.origin, window.location.origin) && i(t.origin, "cross-site-legacy");
|
|
165
165
|
}),
|
|
166
166
|
R.addListener("*", "authorize", x),
|
|
167
167
|
R.addListener("*", "login", x),
|
|
@@ -172,7 +172,7 @@ const le = ye(null), ue = ye({
|
|
|
172
172
|
)
|
|
173
173
|
];
|
|
174
174
|
return () => r.forEach((n) => n());
|
|
175
|
-
}, [R, x, a,
|
|
175
|
+
}, [R, x, a, U, i]), g(() => {
|
|
176
176
|
const r = (n) => {
|
|
177
177
|
const t = n == null ? void 0 : n.data;
|
|
178
178
|
if (!t || t.type !== "authorized")
|
|
@@ -183,28 +183,28 @@ const le = ye(null), ue = ye({
|
|
|
183
183
|
const p = j.current[o];
|
|
184
184
|
if (!(!p || p.status !== "interactive")) {
|
|
185
185
|
if (t.accessToken) {
|
|
186
|
-
L((
|
|
187
|
-
...
|
|
186
|
+
L((C) => ({
|
|
187
|
+
...C,
|
|
188
188
|
[o]: Ee({ accessToken: t.accessToken })
|
|
189
189
|
})), d(o);
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
|
-
|
|
192
|
+
k(o);
|
|
193
193
|
}
|
|
194
194
|
};
|
|
195
195
|
return window.addEventListener("message", r), () => window.removeEventListener("message", r);
|
|
196
|
-
}, [d,
|
|
196
|
+
}, [d, k]);
|
|
197
197
|
const O = h(
|
|
198
198
|
(r, n) => {
|
|
199
199
|
const t = r == null ? void 0 : r.origin, o = Ee(n);
|
|
200
200
|
!t || !o || (L((p) => ({ ...p, [t]: o })), d(t));
|
|
201
201
|
},
|
|
202
202
|
[d]
|
|
203
|
-
),
|
|
203
|
+
), T = h((r, n) => {
|
|
204
204
|
A((t) => t[r] ? { ...t, [r]: { ...t[r], ...n } } : t);
|
|
205
|
-
}, []),
|
|
205
|
+
}, []), M = l({}), $ = h(
|
|
206
206
|
async (r, { approve: n } = {}) => {
|
|
207
|
-
const t =
|
|
207
|
+
const t = Y.current, { origin: o } = r;
|
|
208
208
|
let p;
|
|
209
209
|
try {
|
|
210
210
|
p = await t(
|
|
@@ -217,16 +217,16 @@ const le = ye(null), ue = ye({
|
|
|
217
217
|
{ approve: n }
|
|
218
218
|
);
|
|
219
219
|
} catch {
|
|
220
|
-
n ?
|
|
220
|
+
n ? T(o, { error: { reason: "broker_unavailable" } }) : T(o, { status: "interactive" });
|
|
221
221
|
return;
|
|
222
222
|
}
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
223
|
+
const C = p == null ? void 0 : p.status, z = (p == null ? void 0 : p.body) || {};
|
|
224
|
+
if (C === 200 && z.credential) {
|
|
225
225
|
O(r, z.credential);
|
|
226
226
|
return;
|
|
227
227
|
}
|
|
228
|
-
if (
|
|
229
|
-
|
|
228
|
+
if (C === 409 && z.consentRequired) {
|
|
229
|
+
T(o, {
|
|
230
230
|
status: "interactive",
|
|
231
231
|
consent: {
|
|
232
232
|
client: z.client || null,
|
|
@@ -237,61 +237,61 @@ const le = ye(null), ue = ye({
|
|
|
237
237
|
});
|
|
238
238
|
return;
|
|
239
239
|
}
|
|
240
|
-
const
|
|
241
|
-
if (!n &&
|
|
242
|
-
|
|
240
|
+
const H = z.error || "broker_error";
|
|
241
|
+
if (!n && Oe.has(H)) {
|
|
242
|
+
T(o, { status: "interactive" });
|
|
243
243
|
return;
|
|
244
244
|
}
|
|
245
|
-
if (n &&
|
|
246
|
-
|
|
245
|
+
if (n && H === "consent_denied") {
|
|
246
|
+
T(o, { error: null });
|
|
247
247
|
return;
|
|
248
248
|
}
|
|
249
|
-
if (
|
|
249
|
+
if (H === "rate_limited" && !r.rateLimitRetried) {
|
|
250
250
|
const X = Math.min(
|
|
251
251
|
Number(z.retryAfter) > 0 ? Number(z.retryAfter) : Se,
|
|
252
|
-
|
|
252
|
+
Ue
|
|
253
253
|
), te = { ...r, rateLimitRetried: !0 };
|
|
254
254
|
f(o), c.current[o] = setTimeout(() => {
|
|
255
|
-
delete c.current[o],
|
|
256
|
-
delete
|
|
255
|
+
delete c.current[o], M.current[o] = !0, ee.current(te, { approve: n }).finally(() => {
|
|
256
|
+
delete M.current[o];
|
|
257
257
|
});
|
|
258
|
-
}, X * 1e3),
|
|
258
|
+
}, X * 1e3), T(o, { rateLimitRetried: !0 });
|
|
259
259
|
return;
|
|
260
260
|
}
|
|
261
|
-
d(o),
|
|
261
|
+
d(o), y((X) => ({
|
|
262
262
|
...X,
|
|
263
263
|
[o]: {
|
|
264
264
|
origin: o,
|
|
265
|
-
reason: `broker:${
|
|
266
|
-
detail: { status:
|
|
265
|
+
reason: `broker:${H}`,
|
|
266
|
+
detail: { status: C != null ? C : null, reason: H },
|
|
267
267
|
clientId: r.clientId || b.current[o] || null
|
|
268
268
|
}
|
|
269
269
|
}));
|
|
270
270
|
},
|
|
271
|
-
[O,
|
|
271
|
+
[O, T, d, f]
|
|
272
272
|
), ee = l($);
|
|
273
273
|
ee.current = $, g(() => {
|
|
274
|
-
Object.values(
|
|
275
|
-
r.status !== "broker" ||
|
|
276
|
-
delete
|
|
274
|
+
Object.values(I).forEach((r) => {
|
|
275
|
+
r.status !== "broker" || M.current[r.origin] || c.current[r.origin] || (M.current[r.origin] = !0, $(r).finally(() => {
|
|
276
|
+
delete M.current[r.origin];
|
|
277
277
|
}));
|
|
278
278
|
});
|
|
279
|
-
}, [
|
|
279
|
+
}, [I, $]);
|
|
280
280
|
const W = h(
|
|
281
|
-
(r) => !
|
|
282
|
-
delete
|
|
281
|
+
(r) => !Y.current || !(r != null && r.consent) || M.current[r.origin] ? Promise.resolve() : (M.current[r.origin] = !0, $(r, { approve: !0 }).finally(() => {
|
|
282
|
+
delete M.current[r.origin];
|
|
283
283
|
})),
|
|
284
284
|
[$]
|
|
285
285
|
);
|
|
286
286
|
g(() => () => {
|
|
287
287
|
P.current && P.current(), Object.values(c.current).forEach(clearTimeout);
|
|
288
288
|
}, []), g(() => {
|
|
289
|
-
m === !1 && (Object.values(c.current).forEach(clearTimeout), c.current = {},
|
|
289
|
+
m === !1 && (Object.values(c.current).forEach(clearTimeout), c.current = {}, M.current = {}, b.current = {}, V.current = {}, v.current = {}, K.current = {}, E.current = {}, L({}), A({}), y({}));
|
|
290
290
|
}, [m]);
|
|
291
291
|
const Q = h(
|
|
292
292
|
(r) => {
|
|
293
293
|
P.current && (P.current(), P.current = null);
|
|
294
|
-
const n = s ||
|
|
294
|
+
const n = s || $e;
|
|
295
295
|
P.current = n(r, {
|
|
296
296
|
onBlocked: () => {
|
|
297
297
|
A((t) => t[r.origin] ? {
|
|
@@ -303,13 +303,13 @@ const le = ye(null), ue = ye({
|
|
|
303
303
|
// a legacy guest is remounted because it only learns of a login by reloading.
|
|
304
304
|
onClosed: () => {
|
|
305
305
|
const t = j.current[r.origin];
|
|
306
|
-
!t || t.v2 ||
|
|
306
|
+
!t || t.v2 || k(r.origin);
|
|
307
307
|
}
|
|
308
308
|
});
|
|
309
309
|
},
|
|
310
|
-
[s,
|
|
310
|
+
[s, k]
|
|
311
311
|
), re = {
|
|
312
|
-
pending: Object.values(
|
|
312
|
+
pending: Object.values(I).filter(
|
|
313
313
|
(r) => r.status === "interactive"
|
|
314
314
|
),
|
|
315
315
|
authorize: Q,
|
|
@@ -317,11 +317,11 @@ const le = ye(null), ue = ye({
|
|
|
317
317
|
complete: O,
|
|
318
318
|
dismiss: B,
|
|
319
319
|
originEpochs: q,
|
|
320
|
-
credentials:
|
|
321
|
-
unsupported:
|
|
320
|
+
credentials: Z,
|
|
321
|
+
unsupported: S,
|
|
322
322
|
setDelivered: N
|
|
323
323
|
};
|
|
324
|
-
return /* @__PURE__ */
|
|
324
|
+
return /* @__PURE__ */ D.createElement(ue.Provider, { value: re }, e);
|
|
325
325
|
};
|
|
326
326
|
Ae.propTypes = {
|
|
327
327
|
children: w.node,
|
|
@@ -337,65 +337,65 @@ Ae.propTypes = {
|
|
|
337
337
|
*/
|
|
338
338
|
broker: w.func
|
|
339
339
|
};
|
|
340
|
-
const
|
|
340
|
+
const ze = () => ne(ue), Fe = (e) => {
|
|
341
341
|
const { originEpochs: s } = ne(ue), u = oe(e);
|
|
342
342
|
return u && s[u] || 0;
|
|
343
|
-
},
|
|
343
|
+
}, De = (e) => {
|
|
344
344
|
const { credentials: s } = ne(ue), u = oe(e);
|
|
345
345
|
return u && s[u] || null;
|
|
346
|
-
},
|
|
346
|
+
}, Pe = (e) => {
|
|
347
347
|
const { unsupported: s } = ne(ue), u = oe(e);
|
|
348
348
|
return u && s[u] || null;
|
|
349
|
-
}, 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.",
|
|
349
|
+
}, 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.", Be = ({
|
|
350
350
|
children: e,
|
|
351
351
|
authorizationLauncher: s,
|
|
352
352
|
credentialBroker: u,
|
|
353
353
|
ready: m
|
|
354
354
|
}) => {
|
|
355
|
-
const R = m === !0,
|
|
355
|
+
const R = m === !0, I = l(!1);
|
|
356
356
|
g(() => {
|
|
357
|
-
m !== void 0 ||
|
|
357
|
+
m !== void 0 || I.current || (I.current = !0, console.error(Ie), typeof window != "undefined" && typeof window.alert == "function" && window.alert(Ie));
|
|
358
358
|
}, [m]);
|
|
359
|
-
const [A, q] =
|
|
359
|
+
const [A, q] = F({}), [J, Z] = F({}), L = l({}), S = l({}), y = l({}), E = h((i, a) => {
|
|
360
360
|
var c;
|
|
361
|
-
return !!((c =
|
|
361
|
+
return !!((c = y.current[i]) != null && c.has(a));
|
|
362
362
|
}, []), j = h((i, a, c) => {
|
|
363
363
|
q((f) => ({ ...f, [i]: { origin: a, frameRef: c } }));
|
|
364
364
|
}, []), P = h((i) => {
|
|
365
365
|
q((a) => {
|
|
366
366
|
const c = { ...a };
|
|
367
367
|
return delete c[i], c;
|
|
368
|
-
}),
|
|
368
|
+
}), Z((a) => {
|
|
369
369
|
const c = { ...a };
|
|
370
370
|
return delete c[i], c;
|
|
371
|
-
}), delete
|
|
372
|
-
|
|
371
|
+
}), delete y.current[i], Object.keys(S.current).forEach((a) => {
|
|
372
|
+
S.current[a].instanceId === i && delete S.current[a];
|
|
373
373
|
});
|
|
374
374
|
}, []);
|
|
375
375
|
g(() => () => {
|
|
376
|
-
|
|
376
|
+
S.current = {};
|
|
377
377
|
}, []), g(() => {
|
|
378
378
|
const i = (c = [], f, d) => {
|
|
379
|
-
c.forEach((
|
|
379
|
+
c.forEach((k) => k(f, d));
|
|
380
380
|
}, a = (c) => {
|
|
381
|
-
var
|
|
382
|
-
if (!((
|
|
381
|
+
var T, M, $, ee, W, Q, re;
|
|
382
|
+
if (!((T = c == null ? void 0 : c.data) != null && T.instanceId))
|
|
383
383
|
return;
|
|
384
|
-
const { instanceId: f, type: d } = c.data,
|
|
385
|
-
if (!B || c.source !== B || c.origin !==
|
|
384
|
+
const { instanceId: f, type: d } = c.data, k = A[f], B = ($ = (M = k == null ? void 0 : k.frameRef) == null ? void 0 : M.current) == null ? void 0 : $.contentWindow;
|
|
385
|
+
if (!B || c.source !== B || c.origin !== k.origin)
|
|
386
386
|
return;
|
|
387
387
|
const x = { origin: c.origin }, O = L.current;
|
|
388
388
|
if (d === "response") {
|
|
389
|
-
const { callbackId: r, response: n, error: t } = c.data, o =
|
|
390
|
-
o && o.instanceId === f && (o.callback(n, t), delete
|
|
389
|
+
const { callbackId: r, response: n, error: t } = c.data, o = S.current[r];
|
|
390
|
+
o && o.instanceId === f && (o.callback(n, t), delete S.current[r]);
|
|
391
391
|
return;
|
|
392
392
|
}
|
|
393
393
|
if (d === "mark-registered") {
|
|
394
394
|
const { requestType: r } = c.data;
|
|
395
|
-
|
|
395
|
+
y.current[f] || (y.current[f] = /* @__PURE__ */ new Set()), y.current[f].add(r);
|
|
396
396
|
return;
|
|
397
397
|
}
|
|
398
|
-
d === "ready" &&
|
|
398
|
+
d === "ready" && Z((r) => ({ ...r, [f]: !0 })), i((ee = O[f]) == null ? void 0 : ee[d], c.data, x), i((W = O["*"]) == null ? void 0 : W[d], c.data, x), i((Q = O[f]) == null ? void 0 : Q["*"], c.data, x), i((re = O["*"]) == null ? void 0 : re["*"], c.data, x);
|
|
399
399
|
};
|
|
400
400
|
return window.addEventListener("message", a), () => {
|
|
401
401
|
window.removeEventListener("message", a);
|
|
@@ -403,27 +403,27 @@ const De = () => ne(ue), Fe = (e) => {
|
|
|
403
403
|
}, [A]);
|
|
404
404
|
const b = h(
|
|
405
405
|
(i, a, c, f) => {
|
|
406
|
-
var
|
|
406
|
+
var k, B;
|
|
407
407
|
const d = A[i];
|
|
408
408
|
if (!d) {
|
|
409
409
|
console.warn(`Origin not set for id: ${i}. Unable to send message.`);
|
|
410
410
|
return;
|
|
411
411
|
}
|
|
412
|
-
(B = (
|
|
412
|
+
(B = (k = d == null ? void 0 : d.frameRef) == null ? void 0 : k.current) != null && B.contentWindow && d.frameRef.current.contentWindow.postMessage(
|
|
413
413
|
{ type: a, ...c, instanceId: i },
|
|
414
414
|
f || d.origin
|
|
415
415
|
);
|
|
416
416
|
},
|
|
417
417
|
[A]
|
|
418
|
-
),
|
|
418
|
+
), V = l(0), Y = h(() => `${Date.now()}-${++V.current}`, []), v = h(
|
|
419
419
|
async (i, a, c = {}) => new Promise((f, d) => {
|
|
420
|
-
const
|
|
421
|
-
delete
|
|
420
|
+
const k = Y(), B = (x, O) => {
|
|
421
|
+
delete S.current[k], O ? d(O) : f(x);
|
|
422
422
|
};
|
|
423
|
-
|
|
423
|
+
S.current[k] = { instanceId: i, callback: B }, b(i, "request", { callbackId: k, requestType: a, data: c });
|
|
424
424
|
}),
|
|
425
425
|
[b]
|
|
426
|
-
),
|
|
426
|
+
), K = h(
|
|
427
427
|
(i, a) => {
|
|
428
428
|
b(i, "load-options", a);
|
|
429
429
|
},
|
|
@@ -433,13 +433,13 @@ const De = () => ne(ue), Fe = (e) => {
|
|
|
433
433
|
b(i, "validate", a);
|
|
434
434
|
},
|
|
435
435
|
[b]
|
|
436
|
-
),
|
|
436
|
+
), U = Ce(
|
|
437
437
|
() => ({
|
|
438
438
|
registerFrame: j,
|
|
439
439
|
unregisterFrame: P,
|
|
440
440
|
sendMessage: b,
|
|
441
|
-
sendRequest:
|
|
442
|
-
loadOptions:
|
|
441
|
+
sendRequest: v,
|
|
442
|
+
loadOptions: K,
|
|
443
443
|
validate: N,
|
|
444
444
|
hasHandler: E,
|
|
445
445
|
readyFrames: J,
|
|
@@ -452,15 +452,15 @@ const De = () => ne(ue), Fe = (e) => {
|
|
|
452
452
|
j,
|
|
453
453
|
P,
|
|
454
454
|
b,
|
|
455
|
-
|
|
456
|
-
|
|
455
|
+
v,
|
|
456
|
+
K,
|
|
457
457
|
N,
|
|
458
458
|
E,
|
|
459
459
|
J,
|
|
460
460
|
R
|
|
461
461
|
]
|
|
462
462
|
);
|
|
463
|
-
return /* @__PURE__ */
|
|
463
|
+
return /* @__PURE__ */ D.createElement(le.Provider, { value: U }, /* @__PURE__ */ D.createElement(
|
|
464
464
|
Ae,
|
|
465
465
|
{
|
|
466
466
|
launcher: s,
|
|
@@ -481,22 +481,22 @@ const De = () => ne(ue), Fe = (e) => {
|
|
|
481
481
|
}, [u]), g(() => {
|
|
482
482
|
if (!(!e || !s)) {
|
|
483
483
|
if (s.startsWith("key:")) {
|
|
484
|
-
const
|
|
485
|
-
return m.readyFrames[e] && m.sendMessage(e, "subscribe-key", { keyChord:
|
|
484
|
+
const I = s.substring(4);
|
|
485
|
+
return m.readyFrames[e] && m.sendMessage(e, "subscribe-key", { keyChord: I }), m.addListener(
|
|
486
486
|
e,
|
|
487
|
-
`key-pressed:${
|
|
487
|
+
`key-pressed:${I}`,
|
|
488
488
|
(...q) => R.current(...q)
|
|
489
489
|
);
|
|
490
490
|
}
|
|
491
491
|
return m.addListener(
|
|
492
492
|
e,
|
|
493
493
|
s,
|
|
494
|
-
(...
|
|
494
|
+
(...I) => R.current(...I)
|
|
495
495
|
);
|
|
496
496
|
}
|
|
497
497
|
}, [m, e, s]);
|
|
498
498
|
};
|
|
499
|
-
|
|
499
|
+
Be.propTypes = {
|
|
500
500
|
children: w.node.isRequired,
|
|
501
501
|
/**
|
|
502
502
|
* Required. True once the host holds its bearer; zones mount no iframe until then. Missing =
|
|
@@ -519,7 +519,7 @@ We.propTypes = {
|
|
|
519
519
|
*/
|
|
520
520
|
credentialBroker: w.func
|
|
521
521
|
};
|
|
522
|
-
const he = Re.default || Re,
|
|
522
|
+
const he = Re.default || Re, We = 1e4, qe = 6e3, je = 5e3, He = 2e4, Ze = 3e3, Le = () => typeof document != "undefined" && document.visibilityState === "hidden", ce = (e, s, u) => {
|
|
523
523
|
if (e.current && clearTimeout(e.current.handle), Le()) {
|
|
524
524
|
e.current = { ms: s, fn: u, suspended: !0 };
|
|
525
525
|
return;
|
|
@@ -532,21 +532,21 @@ const he = Re.default || Re, qe = 1e4, je = 6e3, _e = 15e3, He = 2e3, Ze = 3e3,
|
|
|
532
532
|
e.current = void 0, u();
|
|
533
533
|
}, s);
|
|
534
534
|
e.current = { handle: R, ms: s, fn: u };
|
|
535
|
-
},
|
|
535
|
+
}, G = (e) => {
|
|
536
536
|
e.current && clearTimeout(e.current.handle), e.current = void 0;
|
|
537
537
|
}, fe = (e) => {
|
|
538
538
|
e.current && !e.current.suspended && (clearTimeout(e.current.handle), e.current = { ms: e.current.ms, fn: e.current.fn, suspended: !0 });
|
|
539
539
|
}, pe = (e) => {
|
|
540
540
|
e.current && e.current.suspended && ce(e, e.current.ms, e.current.fn);
|
|
541
|
-
}, Ke = "credentials",
|
|
541
|
+
}, Ke = "credentials", Ge = (e, s) => `${e}/mm-embedded-interop?id=${encodeURIComponent(s)}&origin=${encodeURIComponent(
|
|
542
542
|
window.location.origin
|
|
543
|
-
)}&caps=${Ke}`,
|
|
543
|
+
)}&caps=${Ke}`, Ve = he.iframe`
|
|
544
544
|
width: 100%;
|
|
545
545
|
height: 100%;
|
|
546
546
|
border: none;
|
|
547
547
|
visibility: ${(e) => e.$isReady ? "visible" : "hidden"};
|
|
548
548
|
${(e) => e.$collapsed ? "position: absolute; width: 1px; height: 1px; overflow: hidden;" : ""}
|
|
549
|
-
`,
|
|
549
|
+
`, Ye = he.div`
|
|
550
550
|
width: 100%;
|
|
551
551
|
height: 100%;
|
|
552
552
|
display: flex;
|
|
@@ -587,11 +587,11 @@ const he = Re.default || Re, qe = 1e4, je = 6e3, _e = 15e3, He = 2e3, Ze = 3e3,
|
|
|
587
587
|
detail: "It needs an update to support embedding from a different domain."
|
|
588
588
|
};
|
|
589
589
|
}
|
|
590
|
-
},
|
|
590
|
+
}, ye = ({ entry: e }) => {
|
|
591
591
|
const s = Qe(e);
|
|
592
|
-
return /* @__PURE__ */
|
|
592
|
+
return /* @__PURE__ */ D.createElement(Ye, { "data-reason": e && e.reason || void 0 }, /* @__PURE__ */ D.createElement("div", { style: { fontWeight: 600 } }, s.title), /* @__PURE__ */ D.createElement("div", { style: { fontSize: 12, color: "#888" } }, s.detail));
|
|
593
593
|
};
|
|
594
|
-
|
|
594
|
+
ye.propTypes = {
|
|
595
595
|
entry: w.shape({
|
|
596
596
|
origin: w.string,
|
|
597
597
|
name: w.string,
|
|
@@ -605,22 +605,22 @@ const Xe = he.div`
|
|
|
605
605
|
flex: 1;
|
|
606
606
|
align-items: center;
|
|
607
607
|
justify-content: center;
|
|
608
|
-
`, Je = () => /* @__PURE__ */
|
|
608
|
+
`, Je = () => /* @__PURE__ */ D.createElement(Xe, null, /* @__PURE__ */ D.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), Ne = ({
|
|
609
609
|
id: e,
|
|
610
610
|
src: s,
|
|
611
611
|
path: u,
|
|
612
612
|
onInit: m = () => {
|
|
613
613
|
},
|
|
614
614
|
onTimeout: R,
|
|
615
|
-
onRemount:
|
|
615
|
+
onRemount: I,
|
|
616
616
|
onStall: A,
|
|
617
617
|
context: q = {},
|
|
618
618
|
params: J = {},
|
|
619
|
-
renderUnsupported:
|
|
619
|
+
renderUnsupported: Z,
|
|
620
620
|
renderTimeout: L,
|
|
621
|
-
...
|
|
621
|
+
...S
|
|
622
622
|
}) => {
|
|
623
|
-
if ("isConfiguring" in
|
|
623
|
+
if ("isConfiguring" in S)
|
|
624
624
|
return console.error(
|
|
625
625
|
"isConfiguring must be passed via the params prop to MMEmbeddableZone"
|
|
626
626
|
), null;
|
|
@@ -632,20 +632,20 @@ const Xe = he.div`
|
|
|
632
632
|
return console.error(
|
|
633
633
|
"isFullScreen must be passed via the params prop to MMEmbeddableZone"
|
|
634
634
|
), null;
|
|
635
|
-
const
|
|
635
|
+
const y = l(), E = oe(s), [j, P] = F(), [b, V] = F(0), [Y, v] = F(!1), [K, N] = F(!1), U = Fe(s), i = De(s), a = Pe(s), { setDelivered: c } = ze(), [f, d] = F(0), [k, B] = F(null), { registerFrame: x, unregisterFrame: O, sendMessage: T, ready: M } = ne(
|
|
636
636
|
le
|
|
637
|
-
), [$, ee] =
|
|
638
|
-
t.current = !1, z.current = !1,
|
|
637
|
+
), [$, ee] = F(), W = l(), Q = l(R), re = l(m), r = l(I), n = l(A), t = l(!1), o = l(), p = l(), C = l(!1), z = l(!1), H = l(!1), X = l(null), te = h(() => {
|
|
638
|
+
t.current = !1, C.current = !1, z.current = !1, H.current = !1, X.current = null, G(W), G(o), G(p), V(0), v(!1), N(!1), B(null), c(E, e, !1);
|
|
639
639
|
}, [c, E, e]);
|
|
640
640
|
g(() => {
|
|
641
|
-
(
|
|
642
|
-
}, [
|
|
641
|
+
(U > 0 || f > 0) && te();
|
|
642
|
+
}, [U, f, te]), g(() => {
|
|
643
643
|
Q.current = R;
|
|
644
644
|
}, [R]), g(() => {
|
|
645
645
|
re.current = m;
|
|
646
646
|
}, [m]), g(() => {
|
|
647
|
-
r.current =
|
|
648
|
-
}, [
|
|
647
|
+
r.current = I;
|
|
648
|
+
}, [I]), g(() => {
|
|
649
649
|
n.current = A;
|
|
650
650
|
}, [A]), g(() => {
|
|
651
651
|
const _ = () => {
|
|
@@ -653,11 +653,11 @@ const Xe = he.div`
|
|
|
653
653
|
fe(W), fe(o), fe(p);
|
|
654
654
|
return;
|
|
655
655
|
}
|
|
656
|
-
pe(W), pe(p),
|
|
656
|
+
pe(W), pe(p), C.current && pe(o);
|
|
657
657
|
};
|
|
658
658
|
return document.addEventListener("visibilitychange", _), () => document.removeEventListener("visibilitychange", _);
|
|
659
659
|
}, []), g(() => {
|
|
660
|
-
b &&
|
|
660
|
+
b && T(
|
|
661
661
|
e,
|
|
662
662
|
"set-context",
|
|
663
663
|
{
|
|
@@ -668,85 +668,83 @@ const Xe = he.div`
|
|
|
668
668
|
E
|
|
669
669
|
);
|
|
670
670
|
}, [q, e, b, E]), g(() => {
|
|
671
|
-
b &&
|
|
671
|
+
b && T(e, "set-params", { params: J }, E);
|
|
672
672
|
}, [J, e, b, E]), g(() => {
|
|
673
673
|
u !== void 0 && ee((u == null ? void 0 : u.indexOf("/")) === 0 ? u : `/${u}`);
|
|
674
674
|
}, [u]), g(() => {
|
|
675
|
-
$ === void 0 || !b ||
|
|
676
|
-
}, [$, b, e,
|
|
677
|
-
if (!s || !e || !
|
|
675
|
+
$ === void 0 || !b || T(e, "navigate", { path: $ }, E);
|
|
676
|
+
}, [$, b, e, T, E]), g(() => {
|
|
677
|
+
if (!s || !e || !y)
|
|
678
678
|
return;
|
|
679
|
-
if (!
|
|
679
|
+
if (!M) {
|
|
680
680
|
te(), P(void 0);
|
|
681
681
|
return;
|
|
682
682
|
}
|
|
683
683
|
te();
|
|
684
684
|
const _ = new URL(s);
|
|
685
|
-
return x(e, _.origin,
|
|
685
|
+
return x(e, _.origin, y), re.current(), P(Ge(_.origin, e)), () => {
|
|
686
686
|
O(e);
|
|
687
687
|
};
|
|
688
|
-
}, [s, e,
|
|
688
|
+
}, [s, e, M, x, y, te]);
|
|
689
689
|
const ae = h(() => {
|
|
690
|
-
|
|
690
|
+
v(!0), Q.current && Q.current();
|
|
691
691
|
}, []);
|
|
692
692
|
g(() => {
|
|
693
693
|
if (!(!j || t.current))
|
|
694
|
-
return ce(W,
|
|
695
|
-
}, [j, s,
|
|
694
|
+
return ce(W, We, ae), () => G(W);
|
|
695
|
+
}, [j, s, U, f, ae]);
|
|
696
696
|
const ie = h(() => {
|
|
697
|
-
t.current = !0,
|
|
698
|
-
}, []),
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
K.current = !0, k(e, "credential", _, E), n.current && n.current("redelivered"), ce(p, _e, me);
|
|
697
|
+
t.current = !0, G(W), v(!1);
|
|
698
|
+
}, []), de = h(() => {
|
|
699
|
+
if (!H.current) {
|
|
700
|
+
H.current = !0, T(e, "credential", X.current, E), n.current && n.current("redelivered"), ce(p, He, de);
|
|
702
701
|
return;
|
|
703
702
|
}
|
|
704
703
|
n.current && n.current("ready"), ae();
|
|
705
|
-
}, [e,
|
|
704
|
+
}, [e, T, E, ae]);
|
|
706
705
|
se(e, "init", (_) => {
|
|
707
|
-
ie(),
|
|
706
|
+
ie(), Array.isArray(_ == null ? void 0 : _.acceptsCredentials) && B(_.acceptsCredentials);
|
|
708
707
|
}), se(e, "authorize", ie), se(e, "login", ie), se(e, "credential-request", () => {
|
|
709
708
|
ie(), N(!0);
|
|
710
709
|
}), g(() => {
|
|
711
|
-
if (!
|
|
710
|
+
if (!K || !i || z.current)
|
|
712
711
|
return;
|
|
713
|
-
const _ =
|
|
712
|
+
const _ = k;
|
|
714
713
|
if (Array.isArray(_) && !_.includes(i.kind))
|
|
715
714
|
return;
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
I.current = void 0, k(e, "credential", de, E);
|
|
719
|
-
}, He), () => clearTimeout(I.current);
|
|
715
|
+
const ge = { ...i.kind === "access_token" ? { accessToken: i.accessToken } : {}, credential: i };
|
|
716
|
+
X.current = ge, H.current = !1, T(e, "credential", ge, E), c(E, e, !0), ce(p, je, de);
|
|
720
717
|
}, [
|
|
721
|
-
|
|
718
|
+
de,
|
|
719
|
+
K,
|
|
722
720
|
i,
|
|
723
|
-
T,
|
|
724
|
-
e,
|
|
725
721
|
k,
|
|
722
|
+
e,
|
|
723
|
+
T,
|
|
726
724
|
E,
|
|
727
725
|
c
|
|
728
726
|
]), se(e, "ready", () => {
|
|
729
|
-
ie(),
|
|
727
|
+
ie(), G(p), z.current = !0, V((_) => _ + 1);
|
|
730
728
|
});
|
|
731
|
-
const
|
|
729
|
+
const Me = h(() => {
|
|
732
730
|
r.current && r.current("heartbeat"), d((_) => _ + 1);
|
|
733
731
|
}, []);
|
|
734
732
|
if (se(e, "heartbeat", () => {
|
|
735
|
-
|
|
733
|
+
C.current = !0, ce(o, qe, Me);
|
|
736
734
|
}), g(() => () => {
|
|
737
|
-
|
|
735
|
+
G(o), G(p), G(W);
|
|
738
736
|
}, []), a)
|
|
739
|
-
return
|
|
740
|
-
const
|
|
741
|
-
return delete
|
|
742
|
-
|
|
737
|
+
return Z ? Z(a) : /* @__PURE__ */ D.createElement(ye, { entry: a });
|
|
738
|
+
const me = !!(Y && !b), be = { ...S };
|
|
739
|
+
return delete be.skipManifestCheck, /* @__PURE__ */ D.createElement(D.Fragment, null, me && (L ? L() : /* @__PURE__ */ D.createElement(Je, null)), /* @__PURE__ */ D.createElement(
|
|
740
|
+
Ve,
|
|
743
741
|
{
|
|
744
|
-
key: `auth-epoch-${
|
|
742
|
+
key: `auth-epoch-${U}-frame-${f}`,
|
|
745
743
|
$isReady: b,
|
|
746
|
-
$collapsed:
|
|
747
|
-
ref:
|
|
744
|
+
$collapsed: me,
|
|
745
|
+
ref: y,
|
|
748
746
|
src: j,
|
|
749
|
-
...
|
|
747
|
+
...be
|
|
750
748
|
}
|
|
751
749
|
));
|
|
752
750
|
};
|
|
@@ -777,18 +775,18 @@ Ne.propTypes = {
|
|
|
777
775
|
renderTimeout: w.func
|
|
778
776
|
};
|
|
779
777
|
export {
|
|
780
|
-
|
|
778
|
+
ve as CREDENTIAL_KIND_ACCESS_TOKEN,
|
|
781
779
|
ue as EmbeddedAuthorizationContext,
|
|
782
780
|
Ne as MMEmbeddableZone,
|
|
783
781
|
le as MMEmbeddableZoneContext,
|
|
784
|
-
|
|
785
|
-
|
|
782
|
+
Be as MMEmbeddableZoneProvider,
|
|
783
|
+
Te as isCrossSite,
|
|
786
784
|
Ee as normalizeCredential,
|
|
787
|
-
|
|
785
|
+
$e as popupAuthorizationLauncher,
|
|
788
786
|
Qe as unsupportedCopy,
|
|
789
|
-
|
|
790
|
-
|
|
787
|
+
ze as useEmbeddedAuthorizations,
|
|
788
|
+
De as useEmbeddedCredential,
|
|
791
789
|
se as useEmbeddedEffect,
|
|
792
790
|
Fe as useEmbeddedOriginEpoch,
|
|
793
|
-
|
|
791
|
+
Pe as useEmbeddedUnsupported
|
|
794
792
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(g,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):(g=typeof globalThis!="undefined"?globalThis:g||self,r(g["mm-react-embeddable"]={},g.React,g.PropTypes,g.styled))})(this,(function(g,r,xe,De){"use strict";const ce=e=>e&&e.__esModule?e:{default:e},v=ce(r),k=ce(xe),me=ce(De),ue=r.createContext(null),te=r.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),he="access_token",le=e=>e?e.kind?e:e.accessToken?{kind:he,accessToken:e.accessToken,expiresAt:e.expiresAt||null}:null:null,Fe=60,Pe=120,qe=3e4,Be=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),ne=e=>{try{return new URL(e).origin}catch{return null}},Ee=(e,u)=>{const l=u==null?void 0:u.origin;return!l||ne(e==null?void 0:e.authUrl)!==l?null:l},ge=e=>{if(!e||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(e)||e.includes(":"))return e;const u=e.split(".");return u.length<=2?e:u.slice(-2).join(".")},de=(e,u)=>{try{const l=new URL(e),b=new URL(u);return l.protocol!==b.protocol?!0:ge(l.hostname)!==ge(b.hostname)}catch{return!0}},ke=(e,{onBlocked:u,onClosed:l})=>{const b=window.open(e.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!b)return u(),()=>{};const h=setInterval(()=>{b.closed&&(clearInterval(h),l())},1e3);return()=>clearInterval(h)},Ce=({children:e,launcher:u,broker:l,ready:b})=>{const h=r.useContext(ue),[y,I]=r.useState({}),[B,Q]=r.useState({}),[Z,M]=r.useState({}),[U,A]=r.useState({}),E=r.useRef(Z);E.current=Z;const W=r.useRef(y);W.current=y;const F=r.useRef(null),m=r.useRef({}),R=r.useRef({}),Y=r.useRef(l);Y.current=l;const L=r.useRef({}),H=r.useRef({}),X=r.useCallback((t,s,n)=>{!t||!s||(L.current[t]||(L.current[t]=new Set),n?L.current[t].add(s):L.current[t].delete(s))},[]),O=r.useCallback(t=>{const s=m.current[t];if(!s)return;const n=i=>!i[t]||i[t].clientId?i:{...i,[t]:{...i[t],clientId:s}};I(n),A(n)},[]),c=r.useCallback((t,s)=>{t&&(A(n=>n[t]?n:{...n,[t]:{origin:t,reason:s,clientId:m.current[t]||null}}),O(t))},[O]),d=r.useCallback((t,{v2:s=!1,origin:n=null}={})=>{var i;if(n){if(s&&E.current[n]){if(!((i=L.current[n])!=null&&i.has(t.instanceId)))return;const p=Date.now();if(p-(H.current[n]||0)<qe)return;H.current[n]=p,L.current[n].clear();const w={...E.current};delete w[n],E.current=w,M(w)}I(p=>p[n]?p:{...p,[n]:{origin:n,authUrl:t.authUrl,status:s&&Y.current?"broker":"interactive",v2:s,scope:t.scope||null,acceptsCredentials:R.current[n]||null,consent:null,error:null,clientId:t.clientId||m.current[n]||null,popupBlocked:!1}}),O(n)}},[O]),o=r.useRef({}),f=r.useCallback(t=>{o.current[t]&&(clearTimeout(o.current[t]),delete o.current[t])},[]),a=r.useCallback(t=>{f(t),I(s=>{if(!s[t])return s;const n={...s};return delete n[t],n})},[f]),C=r.useCallback(t=>{t&&(a(t),Q(s=>({...s,[t]:(s[t]||0)+1})))},[a]),P=r.useCallback(t=>{a(t.origin)},[a]),z=r.useCallback((t,s)=>{const n=Ee(t,s);if(n){if(de(n,window.location.origin)){c(n,"cross-site-legacy");return}d(t,{origin:n})}},[d,c]);r.useEffect(()=>{if(!h)return;const t=[h.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(m.current[n.origin]=s.clientId,O(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?R.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&de(n.origin,window.location.origin)&&c(n.origin,"cross-site-legacy")}),h.addListener("*","authorize",z),h.addListener("*","login",z),h.addListener("*","credential-request",(s,n)=>d(s,{v2:!0,origin:Ee(s,n)}))];return()=>t.forEach(s=>s())},[h,z,d,O,c]),r.useEffect(()=>{const t=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const i=ne(n.authUrl);if(!i||s.origin!==i)return;const p=W.current[i];if(!(!p||p.status!=="interactive")){if(n.accessToken){M(w=>({...w,[i]:le({accessToken:n.accessToken})})),a(i);return}C(i)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[a,C]);const $=r.useCallback((t,s)=>{const n=t==null?void 0:t.origin,i=le(s);!n||!i||(M(p=>({...p,[n]:i})),a(n))},[a]),T=r.useCallback((t,s)=>{I(n=>n[t]?{...n,[t]:{...n[t],...s}}:n)},[]),S=r.useRef({}),x=r.useCallback(async(t,{approve:s}={})=>{const n=Y.current,{origin:i}=t;let p;try{p=await n({origin:i,clientId:t.clientId,scope:t.scope,authUrl:t.authUrl},{approve:s})}catch{s?T(i,{error:{reason:"broker_unavailable"}}):T(i,{status:"interactive"});return}const w=p==null?void 0:p.status,D=(p==null?void 0:p.body)||{};if(w===200&&D.credential){$(t,D.credential);return}if(w===409&&D.consentRequired){T(i,{status:"interactive",consent:{client:D.client||null,stepUp:!!D.stepUp,scope:D.scope||t.scope},error:null});return}const K=D.error||"broker_error";if(!s&&Be.has(K)){T(i,{status:"interactive"});return}if(s&&K==="consent_denied"){T(i,{error:null});return}if(K==="rate_limited"&&!t.rateLimitRetried){const V=Math.min(Number(D.retryAfter)>0?Number(D.retryAfter):Fe,Pe),re={...t,rateLimitRetried:!0};f(i),o.current[i]=setTimeout(()=>{delete o.current[i],S.current[i]=!0,J.current(re,{approve:s}).finally(()=>{delete S.current[i]})},V*1e3),T(i,{rateLimitRetried:!0});return}a(i),A(V=>({...V,[i]:{origin:i,reason:`broker:${K}`,detail:{status:w!=null?w:null,reason:K},clientId:t.clientId||m.current[i]||null}}))},[$,T,a,f]),J=r.useRef(x);J.current=x,r.useEffect(()=>{Object.values(y).forEach(t=>{t.status!=="broker"||S.current[t.origin]||o.current[t.origin]||(S.current[t.origin]=!0,x(t).finally(()=>{delete S.current[t.origin]}))})},[y,x]);const q=r.useCallback(t=>!Y.current||!(t!=null&&t.consent)||S.current[t.origin]?Promise.resolve():(S.current[t.origin]=!0,x(t,{approve:!0}).finally(()=>{delete S.current[t.origin]})),[x]);r.useEffect(()=>()=>{F.current&&F.current(),Object.values(o.current).forEach(clearTimeout)},[]),r.useEffect(()=>{b===!1&&(Object.values(o.current).forEach(clearTimeout),o.current={},S.current={},m.current={},R.current={},L.current={},H.current={},E.current={},M({}),I({}),A({}))},[b]);const G=r.useCallback(t=>{F.current&&(F.current(),F.current=null);const s=u||ke;F.current=s(t,{onBlocked:()=>{I(n=>n[t.origin]?{...n,[t.origin]:{...n[t.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=W.current[t.origin];!n||n.v2||C(t.origin)}})},[u,C]),ee={pending:Object.values(y).filter(t=>t.status==="interactive"),authorize:G,approve:q,complete:$,dismiss:P,originEpochs:B,credentials:Z,unsupported:U,setDelivered:X};return v.default.createElement(te.Provider,{value:ee},e)};Ce.propTypes={children:k.default.node,launcher:k.default.func,ready:k.default.bool,broker:k.default.func};const Te=()=>r.useContext(te),we=e=>{const{originEpochs:u}=r.useContext(te),l=ne(e);return l&&u[l]||0},_e=e=>{const{credentials:u}=r.useContext(te),l=ne(e);return l&&u[l]||null},ye=e=>{const{unsupported:u}=r.useContext(te),l=ne(e);return l&&u[l]||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.",Me=({children:e,authorizationLauncher:u,credentialBroker:l,ready:b})=>{const h=b===!0,y=r.useRef(!1);r.useEffect(()=>{b!==void 0||y.current||(y.current=!0,console.error(Ie),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(Ie))},[b]);const[I,B]=r.useState({}),[Q,Z]=r.useState({}),M=r.useRef({}),U=r.useRef({}),A=r.useRef({}),E=r.useCallback((c,d)=>{var o;return!!((o=A.current[c])!=null&&o.has(d))},[]),W=r.useCallback((c,d,o)=>{B(f=>({...f,[c]:{origin:d,frameRef:o}}))},[]),F=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(U.current).forEach(d=>{U.current[d].instanceId===c&&delete U.current[d]})},[]);r.useEffect(()=>()=>{U.current={}},[]),r.useEffect(()=>{const c=(o=[],f,a)=>{o.forEach(C=>C(f,a))},d=o=>{var T,S,x,J,q,G,ee;if(!((T=o==null?void 0:o.data)!=null&&T.instanceId))return;const{instanceId:f,type:a}=o.data,C=I[f],P=(x=(S=C==null?void 0:C.frameRef)==null?void 0:S.current)==null?void 0:x.contentWindow;if(!P||o.source!==P||o.origin!==C.origin)return;const z={origin:o.origin},$=M.current;if(a==="response"){const{callbackId:t,response:s,error:n}=o.data,i=U.current[t];i&&i.instanceId===f&&(i.callback(s,n),delete U.current[t]);return}if(a==="mark-registered"){const{requestType:t}=o.data;A.current[f]||(A.current[f]=new Set),A.current[f].add(t);return}a==="ready"&&Z(t=>({...t,[f]:!0})),c((J=$[f])==null?void 0:J[a],o.data,z),c((q=$["*"])==null?void 0:q[a],o.data,z),c((G=$[f])==null?void 0:G["*"],o.data,z),c((ee=$["*"])==null?void 0:ee["*"],o.data,z)};return window.addEventListener("message",d),()=>{window.removeEventListener("message",d)}},[I]);const m=r.useCallback((c,d,o,f)=>{var C,P;const a=I[c];if(!a){console.warn(`Origin not set for id: ${c}. Unable to send message.`);return}(P=(C=a==null?void 0:a.frameRef)==null?void 0:C.current)!=null&&P.contentWindow&&a.frameRef.current.contentWindow.postMessage({type:d,...o,instanceId:c},f||a.origin)},[I]),R=r.useRef(0),Y=r.useCallback(()=>`${Date.now()}-${++R.current}`,[]),L=r.useCallback(async(c,d,o={})=>new Promise((f,a)=>{const C=Y(),P=(z,$)=>{delete U.current[C],$?a($):f(z)};U.current[C]={instanceId:c,callback:P},m(c,"request",{callbackId:C,requestType:d,data:o})}),[m]),H=r.useCallback((c,d)=>{m(c,"load-options",d)},[m]),X=r.useCallback((c,d)=>{m(c,"validate",d)},[m]),O=r.useMemo(()=>({registerFrame:W,unregisterFrame:F,sendMessage:m,sendRequest:L,loadOptions:H,validate:X,hasHandler:E,readyFrames:Q,ready:h,addListener:(c,d,o)=>(M.current[c]||(M.current[c]={}),M.current[c][d]||(M.current[c][d]=[]),M.current[c][d].push(o),()=>{M.current[c][d]=M.current[c][d].filter(f=>f!==o)})}),[W,F,m,L,H,X,E,Q,h]);return v.default.createElement(ue.Provider,{value:O},v.default.createElement(Ce,{launcher:u,broker:l,ready:h},e))},N=(e,u,l)=>{const b=r.useContext(ue);if(b===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const h=r.useRef(l);r.useEffect(()=>{h.current=l},[l]),r.useEffect(()=>{if(!(!e||!u)){if(u.startsWith("key:")){const y=u.substring(4);return b.readyFrames[e]&&b.sendMessage(e,"subscribe-key",{keyChord:y}),b.addListener(e,`key-pressed:${y}`,(...B)=>h.current(...B))}return b.addListener(e,u,(...y)=>h.current(...y))}},[b,e,u])};Me.propTypes={children:k.default.node.isRequired,ready:k.default.bool.isRequired,authorizationLauncher:k.default.func,credentialBroker:k.default.func};const ae=me.default.default||me.default,We=1e4,je=6e3,Ae=15e3,Ze=2e3,He=3e3,Se=()=>typeof document!="undefined"&&document.visibilityState==="hidden",se=(e,u,l)=>{if(e.current&&clearTimeout(e.current.handle),Se()){e.current={ms:u,fn:l,suspended:!0};return}const b=Date.now(),h=setTimeout(()=>{if(Date.now()-b-u>He){se(e,u,l);return}e.current=void 0,l()},u);e.current={handle:h,ms:u,fn:l}},j=e=>{e.current&&clearTimeout(e.current.handle),e.current=void 0},fe=e=>{e.current&&!e.current.suspended&&(clearTimeout(e.current.handle),e.current={ms:e.current.ms,fn:e.current.fn,suspended:!0})},pe=e=>{e.current&&e.current.suspended&&se(e,e.current.ms,e.current.fn)},Ke="credentials",Re=(e,u)=>`${e}/mm-embedded-interop?id=${encodeURIComponent(u)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Ke}`,Ye=ae.iframe`
|
|
1
|
+
(function(E,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):(E=typeof globalThis!="undefined"?globalThis:E||self,r(E["mm-react-embeddable"]={},E.React,E.PropTypes,E.styled))})(this,(function(E,r,$e,xe){"use strict";const ce=e=>e&&e.__esModule?e:{default:e},v=ce(r),g=ce($e),he=ce(xe),ue=r.createContext(null),te=r.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{},setDelivered:()=>{}}),me="access_token",le=e=>e?e.kind?e:e.accessToken?{kind:me,accessToken:e.accessToken,expiresAt:e.expiresAt||null}:null:null,De=60,Fe=120,Pe=3e4,qe=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),ne=e=>{try{return new URL(e).origin}catch{return null}},Ee=(e,u)=>{const l=u==null?void 0:u.origin;return!l||ne(e==null?void 0:e.authUrl)!==l?null:l},ge=e=>{if(!e||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(e)||e.includes(":"))return e;const u=e.split(".");return u.length<=2?e:u.slice(-2).join(".")},de=(e,u)=>{try{const l=new URL(e),b=new URL(u);return l.protocol!==b.protocol?!0:ge(l.hostname)!==ge(b.hostname)}catch{return!0}},ke=(e,{onBlocked:u,onClosed:l})=>{const b=window.open(e.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!b)return u(),()=>{};const m=setInterval(()=>{b.closed&&(clearInterval(m),l())},1e3);return()=>clearInterval(m)},Ce=({children:e,launcher:u,broker:l,ready:b})=>{const m=r.useContext(ue),[T,y]=r.useState({}),[B,Q]=r.useState({}),[H,I]=r.useState({}),[U,A]=r.useState({}),k=r.useRef(H);k.current=H;const W=r.useRef(T);W.current=T;const F=r.useRef(null),h=r.useRef({}),R=r.useRef({}),G=r.useRef(l);G.current=l;const L=r.useRef({}),K=r.useRef({}),X=r.useCallback((t,s,n)=>{!t||!s||(L.current[t]||(L.current[t]=new Set),n?L.current[t].add(s):L.current[t].delete(s))},[]),O=r.useCallback(t=>{const s=h.current[t];if(!s)return;const n=i=>!i[t]||i[t].clientId?i:{...i,[t]:{...i[t],clientId:s}};y(n),A(n)},[]),c=r.useCallback((t,s)=>{t&&(A(n=>n[t]?n:{...n,[t]:{origin:t,reason:s,clientId:h.current[t]||null}}),O(t))},[O]),d=r.useCallback((t,{v2:s=!1,origin:n=null}={})=>{var i;if(n){if(s&&k.current[n]){if(!((i=L.current[n])!=null&&i.has(t.instanceId)))return;const p=Date.now();if(p-(K.current[n]||0)<Pe)return;K.current[n]=p,L.current[n].clear();const S={...k.current};delete S[n],k.current=S,I(S)}y(p=>p[n]?p:{...p,[n]:{origin:n,authUrl:t.authUrl,status:s&&G.current?"broker":"interactive",v2:s,scope:t.scope||null,acceptsCredentials:R.current[n]||null,consent:null,error:null,clientId:t.clientId||h.current[n]||null,popupBlocked:!1}}),O(n)}},[O]),o=r.useRef({}),f=r.useCallback(t=>{o.current[t]&&(clearTimeout(o.current[t]),delete o.current[t])},[]),a=r.useCallback(t=>{f(t),y(s=>{if(!s[t])return s;const n={...s};return delete n[t],n})},[f]),C=r.useCallback(t=>{t&&(a(t),Q(s=>({...s,[t]:(s[t]||0)+1})))},[a]),P=r.useCallback(t=>{a(t.origin)},[a]),z=r.useCallback((t,s)=>{const n=Ee(t,s);if(n){if(de(n,window.location.origin)){c(n,"cross-site-legacy");return}d(t,{origin:n})}},[d,c]);r.useEffect(()=>{if(!m)return;const t=[m.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(h.current[n.origin]=s.clientId,O(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?R.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&de(n.origin,window.location.origin)&&c(n.origin,"cross-site-legacy")}),m.addListener("*","authorize",z),m.addListener("*","login",z),m.addListener("*","credential-request",(s,n)=>d(s,{v2:!0,origin:Ee(s,n)}))];return()=>t.forEach(s=>s())},[m,z,d,O,c]),r.useEffect(()=>{const t=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const i=ne(n.authUrl);if(!i||s.origin!==i)return;const p=W.current[i];if(!(!p||p.status!=="interactive")){if(n.accessToken){I(S=>({...S,[i]:le({accessToken:n.accessToken})})),a(i);return}C(i)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[a,C]);const $=r.useCallback((t,s)=>{const n=t==null?void 0:t.origin,i=le(s);!n||!i||(I(p=>({...p,[n]:i})),a(n))},[a]),w=r.useCallback((t,s)=>{y(n=>n[t]?{...n,[t]:{...n[t],...s}}:n)},[]),M=r.useRef({}),x=r.useCallback(async(t,{approve:s}={})=>{const n=G.current,{origin:i}=t;let p;try{p=await n({origin:i,clientId:t.clientId,scope:t.scope,authUrl:t.authUrl},{approve:s})}catch{s?w(i,{error:{reason:"broker_unavailable"}}):w(i,{status:"interactive"});return}const S=p==null?void 0:p.status,D=(p==null?void 0:p.body)||{};if(S===200&&D.credential){$(t,D.credential);return}if(S===409&&D.consentRequired){w(i,{status:"interactive",consent:{client:D.client||null,stepUp:!!D.stepUp,scope:D.scope||t.scope},error:null});return}const j=D.error||"broker_error";if(!s&&qe.has(j)){w(i,{status:"interactive"});return}if(s&&j==="consent_denied"){w(i,{error:null});return}if(j==="rate_limited"&&!t.rateLimitRetried){const Y=Math.min(Number(D.retryAfter)>0?Number(D.retryAfter):De,Fe),re={...t,rateLimitRetried:!0};f(i),o.current[i]=setTimeout(()=>{delete o.current[i],M.current[i]=!0,J.current(re,{approve:s}).finally(()=>{delete M.current[i]})},Y*1e3),w(i,{rateLimitRetried:!0});return}a(i),A(Y=>({...Y,[i]:{origin:i,reason:`broker:${j}`,detail:{status:S!=null?S:null,reason:j},clientId:t.clientId||h.current[i]||null}}))},[$,w,a,f]),J=r.useRef(x);J.current=x,r.useEffect(()=>{Object.values(T).forEach(t=>{t.status!=="broker"||M.current[t.origin]||o.current[t.origin]||(M.current[t.origin]=!0,x(t).finally(()=>{delete M.current[t.origin]}))})},[T,x]);const q=r.useCallback(t=>!G.current||!(t!=null&&t.consent)||M.current[t.origin]?Promise.resolve():(M.current[t.origin]=!0,x(t,{approve:!0}).finally(()=>{delete M.current[t.origin]})),[x]);r.useEffect(()=>()=>{F.current&&F.current(),Object.values(o.current).forEach(clearTimeout)},[]),r.useEffect(()=>{b===!1&&(Object.values(o.current).forEach(clearTimeout),o.current={},M.current={},h.current={},R.current={},L.current={},K.current={},k.current={},I({}),y({}),A({}))},[b]);const V=r.useCallback(t=>{F.current&&(F.current(),F.current=null);const s=u||ke;F.current=s(t,{onBlocked:()=>{y(n=>n[t.origin]?{...n,[t.origin]:{...n[t.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=W.current[t.origin];!n||n.v2||C(t.origin)}})},[u,C]),ee={pending:Object.values(T).filter(t=>t.status==="interactive"),authorize:V,approve:q,complete:$,dismiss:P,originEpochs:B,credentials:H,unsupported:U,setDelivered:X};return v.default.createElement(te.Provider,{value:ee},e)};Ce.propTypes={children:g.default.node,launcher:g.default.func,ready:g.default.bool,broker:g.default.func};const we=()=>r.useContext(te),Te=e=>{const{originEpochs:u}=r.useContext(te),l=ne(e);return l&&u[l]||0},_e=e=>{const{credentials:u}=r.useContext(te),l=ne(e);return l&&u[l]||null},ye=e=>{const{unsupported:u}=r.useContext(te),l=ne(e);return l&&u[l]||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.",Ae=({children:e,authorizationLauncher:u,credentialBroker:l,ready:b})=>{const m=b===!0,T=r.useRef(!1);r.useEffect(()=>{b!==void 0||T.current||(T.current=!0,console.error(Ie),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(Ie))},[b]);const[y,B]=r.useState({}),[Q,H]=r.useState({}),I=r.useRef({}),U=r.useRef({}),A=r.useRef({}),k=r.useCallback((c,d)=>{var o;return!!((o=A.current[c])!=null&&o.has(d))},[]),W=r.useCallback((c,d,o)=>{B(f=>({...f,[c]:{origin:d,frameRef:o}}))},[]),F=r.useCallback(c=>{B(d=>{const o={...d};return delete o[c],o}),H(d=>{const o={...d};return delete o[c],o}),delete A.current[c],Object.keys(U.current).forEach(d=>{U.current[d].instanceId===c&&delete U.current[d]})},[]);r.useEffect(()=>()=>{U.current={}},[]),r.useEffect(()=>{const c=(o=[],f,a)=>{o.forEach(C=>C(f,a))},d=o=>{var w,M,x,J,q,V,ee;if(!((w=o==null?void 0:o.data)!=null&&w.instanceId))return;const{instanceId:f,type:a}=o.data,C=y[f],P=(x=(M=C==null?void 0:C.frameRef)==null?void 0:M.current)==null?void 0:x.contentWindow;if(!P||o.source!==P||o.origin!==C.origin)return;const z={origin:o.origin},$=I.current;if(a==="response"){const{callbackId:t,response:s,error:n}=o.data,i=U.current[t];i&&i.instanceId===f&&(i.callback(s,n),delete U.current[t]);return}if(a==="mark-registered"){const{requestType:t}=o.data;A.current[f]||(A.current[f]=new Set),A.current[f].add(t);return}a==="ready"&&H(t=>({...t,[f]:!0})),c((J=$[f])==null?void 0:J[a],o.data,z),c((q=$["*"])==null?void 0:q[a],o.data,z),c((V=$[f])==null?void 0:V["*"],o.data,z),c((ee=$["*"])==null?void 0:ee["*"],o.data,z)};return window.addEventListener("message",d),()=>{window.removeEventListener("message",d)}},[y]);const h=r.useCallback((c,d,o,f)=>{var C,P;const a=y[c];if(!a){console.warn(`Origin not set for id: ${c}. Unable to send message.`);return}(P=(C=a==null?void 0:a.frameRef)==null?void 0:C.current)!=null&&P.contentWindow&&a.frameRef.current.contentWindow.postMessage({type:d,...o,instanceId:c},f||a.origin)},[y]),R=r.useRef(0),G=r.useCallback(()=>`${Date.now()}-${++R.current}`,[]),L=r.useCallback(async(c,d,o={})=>new Promise((f,a)=>{const C=G(),P=(z,$)=>{delete U.current[C],$?a($):f(z)};U.current[C]={instanceId:c,callback:P},h(c,"request",{callbackId:C,requestType:d,data:o})}),[h]),K=r.useCallback((c,d)=>{h(c,"load-options",d)},[h]),X=r.useCallback((c,d)=>{h(c,"validate",d)},[h]),O=r.useMemo(()=>({registerFrame:W,unregisterFrame:F,sendMessage:h,sendRequest:L,loadOptions:K,validate:X,hasHandler:k,readyFrames:Q,ready:m,addListener:(c,d,o)=>(I.current[c]||(I.current[c]={}),I.current[c][d]||(I.current[c][d]=[]),I.current[c][d].push(o),()=>{I.current[c][d]=I.current[c][d].filter(f=>f!==o)})}),[W,F,h,L,K,X,k,Q,m]);return v.default.createElement(ue.Provider,{value:O},v.default.createElement(Ce,{launcher:u,broker:l,ready:m},e))},N=(e,u,l)=>{const b=r.useContext(ue);if(b===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const m=r.useRef(l);r.useEffect(()=>{m.current=l},[l]),r.useEffect(()=>{if(!(!e||!u)){if(u.startsWith("key:")){const T=u.substring(4);return b.readyFrames[e]&&b.sendMessage(e,"subscribe-key",{keyChord:T}),b.addListener(e,`key-pressed:${T}`,(...B)=>m.current(...B))}return b.addListener(e,u,(...T)=>m.current(...T))}},[b,e,u])};Ae.propTypes={children:g.default.node.isRequired,ready:g.default.bool.isRequired,authorizationLauncher:g.default.func,credentialBroker:g.default.func};const ae=he.default.default||he.default,Be=1e4,We=6e3,je=5e3,Ze=2e4,He=3e3,Me=()=>typeof document!="undefined"&&document.visibilityState==="hidden",se=(e,u,l)=>{if(e.current&&clearTimeout(e.current.handle),Me()){e.current={ms:u,fn:l,suspended:!0};return}const b=Date.now(),m=setTimeout(()=>{if(Date.now()-b-u>He){se(e,u,l);return}e.current=void 0,l()},u);e.current={handle:m,ms:u,fn:l}},Z=e=>{e.current&&clearTimeout(e.current.handle),e.current=void 0},fe=e=>{e.current&&!e.current.suspended&&(clearTimeout(e.current.handle),e.current={ms:e.current.ms,fn:e.current.fn,suspended:!0})},pe=e=>{e.current&&e.current.suspended&&se(e,e.current.ms,e.current.fn)},Ke="credentials",Re=(e,u)=>`${e}/mm-embedded-interop?id=${encodeURIComponent(u)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Ke}`,Ge=ae.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
5
5
|
visibility: ${e=>e.$isReady?"visible":"hidden"};
|
|
6
6
|
${e=>e.$collapsed?"position: absolute; width: 1px; height: 1px; overflow: hidden;":""}
|
|
7
|
-
`,
|
|
7
|
+
`,Ve=ae.div`
|
|
8
8
|
width: 100%;
|
|
9
9
|
height: 100%;
|
|
10
10
|
display: flex;
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
text-align: center;
|
|
18
18
|
color: #555;
|
|
19
19
|
font-size: 14px;
|
|
20
|
-
`,
|
|
20
|
+
`,Se=e=>{const u=e&&e.origin||"This app",l=e&&e.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."}}},Le=({entry:e})=>{const u=Se(e);return v.default.createElement(Ve,{"data-reason":e&&e.reason||void 0},v.default.createElement("div",{style:{fontWeight:600}},u.title),v.default.createElement("div",{style:{fontSize:12,color:"#888"}},u.detail))};Le.propTypes={entry:g.default.shape({origin:g.default.string,name:g.default.string,reason:g.default.string,detail:g.default.object})};const Ye=ae.div`
|
|
21
21
|
height: 100%;
|
|
22
22
|
display: flex;
|
|
23
23
|
flex: 1;
|
|
24
24
|
align-items: center;
|
|
25
25
|
justify-content: center;
|
|
26
|
-
`,Ne=()=>v.default.createElement(
|
|
26
|
+
`,Ne=()=>v.default.createElement(Ye,null,v.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),ve=({id:e,src:u,path:l,onInit:b=()=>{},onTimeout:m,onRemount:T,onStall:y,context:B={},params:Q={},renderUnsupported:H,renderTimeout:I,...U})=>{if("isConfiguring"in U)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in B)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in B)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const A=r.useRef(),k=ne(u),[W,F]=r.useState(),[h,R]=r.useState(0),[G,L]=r.useState(!1),[K,X]=r.useState(!1),O=Te(u),c=_e(u),d=ye(u),{setDelivered:o}=we(),[f,a]=r.useState(0),[C,P]=r.useState(null),{registerFrame:z,unregisterFrame:$,sendMessage:w,ready:M}=r.useContext(ue),[x,J]=r.useState(),q=r.useRef(),V=r.useRef(m),ee=r.useRef(b),t=r.useRef(T),s=r.useRef(y),n=r.useRef(!1),i=r.useRef(),p=r.useRef(),S=r.useRef(!1),D=r.useRef(!1),j=r.useRef(!1),Y=r.useRef(null),re=r.useCallback(()=>{n.current=!1,S.current=!1,D.current=!1,j.current=!1,Y.current=null,Z(q),Z(i),Z(p),R(0),L(!1),X(!1),P(null),o(k,e,!1)},[o,k,e]);r.useEffect(()=>{(O>0||f>0)&&re()},[O,f,re]),r.useEffect(()=>{V.current=m},[m]),r.useEffect(()=>{ee.current=b},[b]),r.useEffect(()=>{t.current=T},[T]),r.useEffect(()=>{s.current=y},[y]),r.useEffect(()=>{const _=()=>{if(Me()){fe(q),fe(i),fe(p);return}pe(q),pe(p),S.current&&pe(i)};return document.addEventListener("visibilitychange",_),()=>document.removeEventListener("visibilitychange",_)},[]),r.useEffect(()=>{h&&w(e,"set-context",{context:{...B}},k)},[B,e,h,k]),r.useEffect(()=>{h&&w(e,"set-params",{params:Q},k)},[Q,e,h,k]),r.useEffect(()=>{l!==void 0&&J((l==null?void 0:l.indexOf("/"))===0?l:`/${l}`)},[l]),r.useEffect(()=>{x===void 0||!h||w(e,"navigate",{path:x},k)},[x,h,e,w,k]),r.useEffect(()=>{if(!u||!e||!A)return;if(!M){re(),F(void 0);return}re();const _=new URL(u);return z(e,_.origin,A),ee.current(),F(Re(_.origin,e)),()=>{$(e)}},[u,e,M,z,A,re]);const ie=r.useCallback(()=>{L(!0),V.current&&V.current()},[]);r.useEffect(()=>{if(!(!W||n.current))return se(q,Be,ie),()=>Z(q)},[W,u,O,f,ie]);const oe=r.useCallback(()=>{n.current=!0,Z(q),L(!1)},[]),be=r.useCallback(()=>{if(!j.current){j.current=!0,w(e,"credential",Y.current,k),s.current&&s.current("redelivered"),se(p,Ze,be);return}s.current&&s.current("ready"),ie()},[e,w,k,ie]);N(e,"init",_=>{oe(),Array.isArray(_==null?void 0:_.acceptsCredentials)&&P(_.acceptsCredentials)}),N(e,"authorize",oe),N(e,"login",oe),N(e,"credential-request",()=>{oe(),X(!0)}),r.useEffect(()=>{if(!K||!c||D.current)return;const _=C;if(Array.isArray(_)&&!_.includes(c.kind))return;const ze={...c.kind==="access_token"?{accessToken:c.accessToken}:{},credential:c};Y.current=ze,j.current=!1,w(e,"credential",ze,k),o(k,e,!0),se(p,je,be)},[be,K,c,C,e,w,k,o]),N(e,"ready",()=>{oe(),Z(p),D.current=!0,R(_=>_+1)});const Qe=r.useCallback(()=>{t.current&&t.current("heartbeat"),a(_=>_+1)},[]);if(N(e,"heartbeat",()=>{S.current=!0,se(i,We,Qe)}),r.useEffect(()=>()=>{Z(i),Z(p),Z(q)},[]),d)return H?H(d):v.default.createElement(Le,{entry:d});const Ue=!!(G&&!h),Oe={...U};return delete Oe.skipManifestCheck,v.default.createElement(v.default.Fragment,null,Ue&&(I?I():v.default.createElement(Ne,null)),v.default.createElement(Ge,{key:`auth-epoch-${O}-frame-${f}`,$isReady:h,$collapsed:Ue,ref:A,src:W,...Oe}))};ve.propTypes={id:g.default.string,src:g.default.string.isRequired,path:g.default.string,onInit:g.default.func,onTimeout:g.default.func,onRemount:g.default.func,onStall:g.default.func,renderUnsupported:g.default.func,renderTimeout:g.default.func},E.CREDENTIAL_KIND_ACCESS_TOKEN=me,E.EmbeddedAuthorizationContext=te,E.MMEmbeddableZone=ve,E.MMEmbeddableZoneContext=ue,E.MMEmbeddableZoneProvider=Ae,E.isCrossSite=de,E.normalizeCredential=le,E.popupAuthorizationLauncher=ke,E.unsupportedCopy=Se,E.useEmbeddedAuthorizations=we,E.useEmbeddedCredential=_e,E.useEmbeddedEffect=N,E.useEmbeddedOriginEpoch=Te,E.useEmbeddedUnsupported=ye,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|