@machinemetrics/mm-react-embeddable 2.0.1-1 → 2.0.1-2
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.
package/README.md
CHANGED
|
@@ -23,5 +23,5 @@ the app and where it runs; footer Cancel/Approve; checkbox rows when several app
|
|
|
23
23
|
pending; legacy rows keep their own Authorize button because a popup must open from
|
|
24
24
|
the user's click on that row).
|
|
25
25
|
|
|
26
|
-
A host
|
|
27
|
-
interactive entry, and the host's UI opens the popup for it.
|
|
26
|
+
A host with no `credentialBroker`, or one whose broker returns an answer it may not act on, gets
|
|
27
|
+
an interactive entry, and the host's UI opens the popup for it.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),ge=require("prop-types"),me=require("styled-components"),V=r=>r&&r.__esModule?r:{default:r},O=V(e),k=V(ge),te=V(me),Q=e.createContext(null),Y=e.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),oe="access_token",J=r=>r?r.kind?r:r.accessToken?{kind:oe,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,Ee=60,Re=120,ke=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),G=r=>{try{return new URL(r).origin}catch{return null}},re=(r,o)=>{const i=o==null?void 0:o.origin;return!i||G(r==null?void 0:r.authUrl)!==i?null:i},ne=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const o=r.split(".");return o.length<=2?r:o.slice(-2).join(".")},N=(r,o)=>{try{const i=new URL(r),d=new URL(o);return i.protocol!==d.protocol?!0:ne(i.hostname)!==ne(d.hostname)}catch{return!0}},ue=(r,{onBlocked:o,onClosed:i})=>{const d=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!d)return o(),()=>{};const R=setInterval(()=>{d.closed&&(clearInterval(R),i())},1e3);return()=>clearInterval(R)},ce=({children:r,launcher:o,broker:i})=>{const d=e.useContext(Q),[R,C]=e.useState({}),[$,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),ge=require("prop-types"),me=require("styled-components"),V=r=>r&&r.__esModule?r:{default:r},O=V(e),k=V(ge),te=V(me),Q=e.createContext(null),Y=e.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),oe="access_token",J=r=>r?r.kind?r:r.accessToken?{kind:oe,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,Ee=60,Re=120,ke=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),G=r=>{try{return new URL(r).origin}catch{return null}},re=(r,o)=>{const i=o==null?void 0:o.origin;return!i||G(r==null?void 0:r.authUrl)!==i?null:i},ne=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const o=r.split(".");return o.length<=2?r:o.slice(-2).join(".")},N=(r,o)=>{try{const i=new URL(r),d=new URL(o);return i.protocol!==d.protocol?!0:ne(i.hostname)!==ne(d.hostname)}catch{return!0}},ue=(r,{onBlocked:o,onClosed:i})=>{const d=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!d)return o(),()=>{};const R=setInterval(()=>{d.closed&&(clearInterval(R),i())},1e3);return()=>clearInterval(R)},ce=({children:r,launcher:o,broker:i})=>{const d=e.useContext(Q),[R,C]=e.useState({}),[$,q]=e.useState({}),[D,W]=e.useState({}),[I,E]=e.useState({}),S=e.useRef(D);S.current=D;const B=e.useRef(R);B.current=R;const w=e.useRef(null),x=e.useRef({}),y=e.useRef({}),P=e.useRef(i);P.current=i;const U=e.useCallback(t=>{const s=x.current[t];if(!s)return;const n=c=>!c[t]||c[t].clientId?c:{...c,[t]:{...c[t],clientId:s}};C(n),E(n)},[]),F=e.useCallback((t,s)=>{t&&(E(n=>n[t]?n:{...n,[t]:{origin:t,reason:s,clientId:x.current[t]||null}}),U(t))},[U]),A=e.useCallback((t,{v2:s=!1,origin:n=null}={})=>{n&&(s&&S.current[n]||(C(c=>c[n]?c:{...c,[n]:{origin:n,authUrl:t.authUrl,status:s&&P.current?"broker":"interactive",v2:s,scope:t.scope||null,acceptsCredentials:y.current[n]||null,consent:null,error:null,clientId:t.clientId||x.current[n]||null,popupBlocked:!1}}),U(n)))},[U]),T=e.useRef({}),v=e.useCallback(t=>{T.current[t]&&(clearTimeout(T.current[t]),delete T.current[t])},[]),u=e.useCallback(t=>{v(t),C(s=>{if(!s[t])return s;const n={...s};return delete n[t],n})},[v]),l=e.useCallback(t=>{t&&(u(t),q(s=>({...s,[t]:(s[t]||0)+1})))},[u]),a=e.useCallback(t=>{u(t.origin)},[u]),p=e.useCallback((t,s)=>{const n=re(t,s);if(n){if(N(n,window.location.origin)){F(n,"cross-site-legacy");return}A(t,{origin:n})}},[A,F]);e.useEffect(()=>{if(!d)return;const t=[d.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(x.current[n.origin]=s.clientId,U(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?y.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&N(n.origin,window.location.origin)&&F(n.origin,"cross-site-legacy")}),d.addListener("*","authorize",p),d.addListener("*","login",p),d.addListener("*","credential-request",(s,n)=>A(s,{v2:!0,origin:re(s,n)}))];return()=>t.forEach(s=>s())},[d,p,A,U,F]),e.useEffect(()=>{const t=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const c=G(n.authUrl);if(!c||s.origin!==c)return;const b=B.current[c];if(!(!b||b.status!=="interactive")){if(n.accessToken){W(L=>({...L,[c]:J({accessToken:n.accessToken})})),u(c);return}l(c)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[u,l]);const h=e.useCallback((t,s)=>{const n=t==null?void 0:t.origin,c=J(s);!n||!c||(W(b=>({...b,[n]:c})),u(n))},[u]),g=e.useCallback((t,s)=>{C(n=>n[t]?{...n,[t]:{...n[t],...s}}:n)},[]),m=e.useRef({}),_=e.useCallback(async(t,{approve:s}={})=>{const n=P.current,{origin:c}=t;let b;try{b=await n({origin:c,clientId:t.clientId,scope:t.scope,authUrl:t.authUrl},{approve:s})}catch{s?g(c,{error:{reason:"broker_unavailable"}}):g(c,{status:"interactive"});return}const L=b==null?void 0:b.status,f=(b==null?void 0:b.body)||{};if(L===200&&f.credential){h(t,f.credential);return}if(L===409&&f.consentRequired){g(c,{status:"interactive",consent:{client:f.client||null,stepUp:!!f.stepUp,scope:f.scope||t.scope},error:null});return}const z=f.error||"broker_error";if(!s&&ke.has(z)){g(c,{status:"interactive"});return}if(s&&z==="consent_denied"){g(c,{error:null});return}if(z==="rate_limited"&&!t.rateLimitRetried){const X=Math.min(Number(f.retryAfter)>0?Number(f.retryAfter):Ee,Re),he={...t,rateLimitRetried:!0};v(c),T.current[c]=setTimeout(()=>{delete T.current[c],m.current[c]=!0,M.current(he,{approve:s}).finally(()=>{delete m.current[c]})},X*1e3),g(c,{rateLimitRetried:!0});return}u(c),E(X=>({...X,[c]:{origin:c,reason:`broker:${z}`,detail:{status:L!=null?L:null,reason:z},clientId:t.clientId||x.current[c]||null}}))},[h,g,u,v]),M=e.useRef(_);M.current=_,e.useEffect(()=>{Object.values(R).forEach(t=>{t.status!=="broker"||m.current[t.origin]||T.current[t.origin]||(m.current[t.origin]=!0,_(t).finally(()=>{delete m.current[t.origin]}))})},[R,_]);const K=e.useCallback(t=>!P.current||!(t!=null&&t.consent)||m.current[t.origin]?Promise.resolve():(m.current[t.origin]=!0,_(t,{approve:!0}).finally(()=>{delete m.current[t.origin]})),[_]);e.useEffect(()=>()=>{w.current&&w.current(),Object.values(T.current).forEach(clearTimeout)},[]);const Z=e.useCallback(t=>{w.current&&(w.current(),w.current=null);const s=o||ue;w.current=s(t,{onBlocked:()=>{C(n=>n[t.origin]?{...n,[t.origin]:{...n[t.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=B.current[t.origin];!n||n.v2||l(t.origin)}})},[o,l]),j={pending:Object.values(R).filter(t=>t.status==="interactive"),authorize:Z,approve:K,complete:h,dismiss:a,originEpochs:$,credentials:D,unsupported:I};return O.default.createElement(Y.Provider,{value:j},r)};ce.propTypes={children:k.default.node,launcher:k.default.func,broker:k.default.func};const Ce=()=>e.useContext(Y),ie=r=>{const{originEpochs:o}=e.useContext(Y),i=G(r);return i&&o[i]||0},ae=r=>{const{credentials:o}=e.useContext(Y),i=G(r);return i&&o[i]||null},le=r=>{const{unsupported:o}=e.useContext(Y),i=G(r);return i&&o[i]||null},se="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.",de=({children:r,authorizationLauncher:o,credentialBroker:i,ready:d})=>{const R=d===!0,C=e.useRef(!1);e.useEffect(()=>{d!==void 0||C.current||(C.current=!0,console.error(se),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(se))},[d]);const[$,q]=e.useState({}),[D,W]=e.useState({}),I=e.useRef({}),E=e.useRef({}),S=e.useRef({}),B=e.useCallback((u,l)=>{var a;return!!((a=S.current[u])!=null&&a.has(l))},[]),w=e.useCallback((u,l,a)=>{q(p=>({...p,[u]:{origin:l,frameRef:a}}))},[]),x=e.useCallback(u=>{q(l=>{const a={...l};return delete a[u],a}),W(l=>{const a={...l};return delete a[u],a}),delete S.current[u],Object.keys(E.current).forEach(l=>{E.current[l].instanceId===u&&delete E.current[l]})},[]);e.useEffect(()=>()=>{E.current={}},[]),e.useEffect(()=>{const u=(a=[],p,h)=>{a.forEach(g=>g(p,h))},l=a=>{var K,Z,j,t,s,n,c;if(!((K=a==null?void 0:a.data)!=null&&K.instanceId))return;const{instanceId:p,type:h}=a.data,g=$[p],m=(j=(Z=g==null?void 0:g.frameRef)==null?void 0:Z.current)==null?void 0:j.contentWindow;if(!m||a.source!==m||a.origin!==g.origin)return;const _={origin:a.origin},M=I.current;if(h==="response"){const{callbackId:b,response:L,error:f}=a.data,z=E.current[b];z&&z.instanceId===p&&(z.callback(L,f),delete E.current[b]);return}if(h==="mark-registered"){const{requestType:b}=a.data;S.current[p]||(S.current[p]=new Set),S.current[p].add(b);return}h==="ready"&&W(b=>({...b,[p]:!0})),u((t=M[p])==null?void 0:t[h],a.data,_),u((s=M["*"])==null?void 0:s[h],a.data,_),u((n=M[p])==null?void 0:n["*"],a.data,_),u((c=M["*"])==null?void 0:c["*"],a.data,_)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[$]);const y=e.useCallback((u,l,a,p)=>{var g,m;const h=$[u];if(!h){console.warn(`Origin not set for id: ${u}. Unable to send message.`);return}(m=(g=h==null?void 0:h.frameRef)==null?void 0:g.current)!=null&&m.contentWindow&&h.frameRef.current.contentWindow.postMessage({type:l,...a,instanceId:u},p||h.origin)},[$]),P=e.useRef(0),U=e.useCallback(()=>`${Date.now()}-${++P.current}`,[]),F=e.useCallback(async(u,l,a={})=>new Promise((p,h)=>{const g=U(),m=(_,M)=>{delete E.current[g],M?h(M):p(_)};E.current[g]={instanceId:u,callback:m},y(u,"request",{callbackId:g,requestType:l,data:a})}),[y]),A=e.useCallback((u,l)=>{y(u,"load-options",l)},[y]),T=e.useCallback((u,l)=>{y(u,"validate",l)},[y]),v=e.useMemo(()=>({registerFrame:w,unregisterFrame:x,sendMessage:y,sendRequest:F,loadOptions:A,validate:T,hasHandler:B,readyFrames:D,ready:R,addListener:(u,l,a)=>(I.current[u]||(I.current[u]={}),I.current[u][l]||(I.current[u][l]=[]),I.current[u][l].push(a),()=>{I.current[u][l]=I.current[u][l].filter(p=>p!==a)})}),[w,x,y,F,A,T,B,D,R]);return O.default.createElement(Q.Provider,{value:v},O.default.createElement(ce,{launcher:o,broker:i},r))},H=(r,o,i)=>{const d=e.useContext(Q);if(d===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const R=e.useRef(i);e.useEffect(()=>{R.current=i},[i]),e.useEffect(()=>{if(!(!r||!o)){if(o.startsWith("key:")){const C=o.substring(4);return d.readyFrames[r]&&d.sendMessage(r,"subscribe-key",{keyChord:C}),d.addListener(r,`key-pressed:${C}`,(...q)=>R.current(...q))}return d.addListener(r,o,(...C)=>R.current(...C))}},[d,r,o])};de.propTypes={children:k.default.node.isRequired,ready:k.default.bool.isRequired,authorizationLauncher:k.default.func,credentialBroker:k.default.func};const ee=te.default.default||te.default,we=1e4,Te="credentials",_e=(r,o)=>`${r}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Te}`,Ie=ee.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
@@ -22,4 +22,4 @@
|
|
|
22
22
|
flex: 1;
|
|
23
23
|
align-items: center;
|
|
24
24
|
justify-content: center;
|
|
25
|
-
`,Se=()=>O.default.createElement(ye,null,O.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),be=({id:r,src:o,path:i,onInit:d=()=>{},onTimeout:R,context:C={},params:$={},renderUnsupported:
|
|
25
|
+
`,Se=()=>O.default.createElement(ye,null,O.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),be=({id:r,src:o,path:i,onInit:d=()=>{},onTimeout:R,context:C={},params:$={},renderUnsupported:q,renderTimeout:D,...W})=>{if("isConfiguring"in W)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 I=e.useRef(),E=G(o),[S,B]=e.useState(),[w,x]=e.useState(0),[y,P]=e.useState(!1),[U,F]=e.useState(!1),A=ie(o),T=ae(o),v=le(o),[u,l]=e.useState(0),[a,p]=e.useState(null),{registerFrame:h,unregisterFrame:g,sendMessage:m,ready:_}=e.useContext(Q),[M,K]=e.useState(),Z=e.useRef(),j=e.useRef(R),t=e.useRef(d),s=e.useRef(!1),n=e.useRef(),c=e.useCallback(()=>{s.current=!1,clearTimeout(Z.current),clearTimeout(n.current),x(0),P(!1),F(!1),p(null)},[]);e.useEffect(()=>{(A>0||u>0)&&c()},[A,u,c]),e.useEffect(()=>{j.current=R},[R]),e.useEffect(()=>{t.current=d},[d]),e.useEffect(()=>{w&&m(r,"set-context",{context:{...C}},E)},[C,r,w,E]),e.useEffect(()=>{w&&m(r,"set-params",{params:$},E)},[$,r,w,E]),e.useEffect(()=>{i!==void 0&&K((i==null?void 0:i.indexOf("/"))===0?i:`/${i}`)},[i]),e.useEffect(()=>{M===void 0||!w||m(r,"navigate",{path:M},E)},[M,w,r,m,E]),e.useEffect(()=>{if(!o||!r||!I)return;if(!_){c(),B(void 0);return}c();const f=new URL(o);return h(r,f.origin,I),t.current(),B(_e(f.origin,r)),()=>{g(r)}},[o,r,_,h,I,c]),e.useEffect(()=>{if(!(!S||s.current))return Z.current=setTimeout(()=>{P(!0),j.current&&j.current()},we),()=>clearTimeout(Z.current)},[S,o,A,u]);const b=e.useCallback(()=>{s.current=!0,clearTimeout(Z.current),P(!1)},[]);if(H(r,"init",f=>{b(),Array.isArray(f==null?void 0:f.acceptsCredentials)&&p(f.acceptsCredentials)}),H(r,"authorize",b),H(r,"login",b),H(r,"credential-request",()=>{b(),F(!0)}),e.useEffect(()=>{if(!U||!T)return;const f=a;if(Array.isArray(f)&&!f.includes(T.kind))return;const z=T.kind==="access_token"?{accessToken:T.accessToken}:{};m(r,"credential",{...z,credential:T},E)},[U,T,a,r,m,E]),H(r,"ready",()=>{b(),x(f=>f+1)}),H(r,"heartbeat",()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{l(f=>f+1)},6e3)}),e.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]),v)return q?q(v):O.default.createElement(pe,{entry:v});if(y&&!w)return D?D():O.default.createElement(Se,null);const L={...W};return delete L.skipManifestCheck,O.default.createElement(Ie,{key:`auth-epoch-${A}-frame-${u}`,$isReady:w,ref:I,src:S,...L})};be.propTypes={id:k.default.string,src:k.default.string.isRequired,path:k.default.string,onInit:k.default.func,onTimeout:k.default.func,renderUnsupported:k.default.func,renderTimeout:k.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=oe;exports.EmbeddedAuthorizationContext=Y;exports.MMEmbeddableZone=be;exports.MMEmbeddableZoneContext=Q;exports.MMEmbeddableZoneProvider=de;exports.isCrossSite=N;exports.normalizeCredential=J;exports.popupAuthorizationLauncher=ue;exports.unsupportedCopy=fe;exports.useEmbeddedAuthorizations=Ce;exports.useEmbeddedCredential=ae;exports.useEmbeddedEffect=H;exports.useEmbeddedOriginEpoch=ie;exports.useEmbeddedUnsupported=le;
|
|
@@ -14,39 +14,39 @@ const ee = ue(null), V = ue({
|
|
|
14
14
|
originEpochs: {},
|
|
15
15
|
credentials: {},
|
|
16
16
|
unsupported: {}
|
|
17
|
-
}), pe = "access_token", ne = (
|
|
17
|
+
}), pe = "access_token", ne = (t) => t ? t.kind ? t : t.accessToken ? {
|
|
18
18
|
kind: pe,
|
|
19
|
-
accessToken:
|
|
20
|
-
expiresAt:
|
|
21
|
-
} : null : null,
|
|
19
|
+
accessToken: t.accessToken,
|
|
20
|
+
expiresAt: t.expiresAt || null
|
|
21
|
+
} : null : null, ge = 60, he = 120, me = /* @__PURE__ */ new Set([
|
|
22
22
|
"host_not_allowed",
|
|
23
23
|
"unbound_host_bound_guest",
|
|
24
24
|
"invalid_token",
|
|
25
25
|
"provider_unavailable"
|
|
26
|
-
]), J = (
|
|
26
|
+
]), J = (t) => {
|
|
27
27
|
try {
|
|
28
|
-
return new URL(
|
|
28
|
+
return new URL(t).origin;
|
|
29
29
|
} catch {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
|
-
}, se = (
|
|
32
|
+
}, se = (t, s) => {
|
|
33
33
|
const i = s == null ? void 0 : s.origin;
|
|
34
|
-
return !i || J(
|
|
35
|
-
}, oe = (
|
|
36
|
-
if (!
|
|
37
|
-
return
|
|
38
|
-
const s =
|
|
39
|
-
return s.length <= 2 ?
|
|
40
|
-
}, ce = (
|
|
34
|
+
return !i || J(t == null ? void 0 : t.authUrl) !== i ? null : i;
|
|
35
|
+
}, oe = (t) => {
|
|
36
|
+
if (!t || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(t) || t.includes(":"))
|
|
37
|
+
return t;
|
|
38
|
+
const s = t.split(".");
|
|
39
|
+
return s.length <= 2 ? t : s.slice(-2).join(".");
|
|
40
|
+
}, ce = (t, s) => {
|
|
41
41
|
try {
|
|
42
|
-
const i = new URL(
|
|
42
|
+
const i = new URL(t), l = new URL(s);
|
|
43
43
|
return i.protocol !== l.protocol ? !0 : oe(i.hostname) !== oe(l.hostname);
|
|
44
44
|
} catch {
|
|
45
45
|
return !0;
|
|
46
46
|
}
|
|
47
|
-
}, be = (
|
|
47
|
+
}, be = (t, { onBlocked: s, onClosed: i }) => {
|
|
48
48
|
const l = window.open(
|
|
49
|
-
|
|
49
|
+
t.authUrl,
|
|
50
50
|
"mm-embed-auth",
|
|
51
51
|
"popup,width=600,height=700"
|
|
52
52
|
);
|
|
@@ -57,23 +57,23 @@ const ee = ue(null), V = ue({
|
|
|
57
57
|
l.closed && (clearInterval(w), i());
|
|
58
58
|
}, 1e3);
|
|
59
59
|
return () => clearInterval(w);
|
|
60
|
-
}, ae = ({ children:
|
|
61
|
-
const l = G(ee), [w, I] = U({}), [v, D] = U({}), [j,
|
|
60
|
+
}, ae = ({ children: t, launcher: s, broker: i }) => {
|
|
61
|
+
const l = G(ee), [w, I] = U({}), [v, D] = U({}), [j, K] = U({}), [y, E] = U({}), x = R(j);
|
|
62
62
|
x.current = j;
|
|
63
|
-
const
|
|
64
|
-
|
|
63
|
+
const Z = R(w);
|
|
64
|
+
Z.current = w;
|
|
65
65
|
const _ = R(null), $ = R({}), A = R({}), q = R(i);
|
|
66
66
|
q.current = i;
|
|
67
67
|
const F = b((e) => {
|
|
68
68
|
const n = $.current[e];
|
|
69
69
|
if (!n)
|
|
70
70
|
return;
|
|
71
|
-
const
|
|
72
|
-
I(
|
|
71
|
+
const r = (c) => !c[e] || c[e].clientId ? c : { ...c, [e]: { ...c[e], clientId: n } };
|
|
72
|
+
I(r), E(r);
|
|
73
73
|
}, []), B = b(
|
|
74
74
|
(e, n) => {
|
|
75
|
-
e && (E((
|
|
76
|
-
...
|
|
75
|
+
e && (E((r) => r[e] ? r : {
|
|
76
|
+
...r,
|
|
77
77
|
[e]: {
|
|
78
78
|
origin: e,
|
|
79
79
|
reason: n,
|
|
@@ -83,22 +83,22 @@ const ee = ue(null), V = ue({
|
|
|
83
83
|
},
|
|
84
84
|
[F]
|
|
85
85
|
), z = b(
|
|
86
|
-
(e, { v2: n = !1, origin:
|
|
87
|
-
|
|
86
|
+
(e, { v2: n = !1, origin: r = null } = {}) => {
|
|
87
|
+
r && (n && x.current[r] || (I((c) => c[r] ? c : {
|
|
88
88
|
...c,
|
|
89
|
-
[
|
|
90
|
-
origin:
|
|
89
|
+
[r]: {
|
|
90
|
+
origin: r,
|
|
91
91
|
authUrl: e.authUrl,
|
|
92
92
|
status: n && q.current ? "broker" : "interactive",
|
|
93
93
|
v2: n,
|
|
94
94
|
scope: e.scope || null,
|
|
95
|
-
acceptsCredentials: A.current[
|
|
95
|
+
acceptsCredentials: A.current[r] || null,
|
|
96
96
|
consent: null,
|
|
97
97
|
error: null,
|
|
98
|
-
clientId: e.clientId || $.current[
|
|
98
|
+
clientId: e.clientId || $.current[r] || null,
|
|
99
99
|
popupBlocked: !1
|
|
100
100
|
}
|
|
101
|
-
}), F(
|
|
101
|
+
}), F(r)));
|
|
102
102
|
},
|
|
103
103
|
[F]
|
|
104
104
|
), M = R({}), W = b((e) => {
|
|
@@ -108,8 +108,8 @@ const ee = ue(null), V = ue({
|
|
|
108
108
|
W(e), I((n) => {
|
|
109
109
|
if (!n[e])
|
|
110
110
|
return n;
|
|
111
|
-
const
|
|
112
|
-
return delete
|
|
111
|
+
const r = { ...n };
|
|
112
|
+
return delete r[e], r;
|
|
113
113
|
});
|
|
114
114
|
},
|
|
115
115
|
[W]
|
|
@@ -128,13 +128,13 @@ const ee = ue(null), V = ue({
|
|
|
128
128
|
[o]
|
|
129
129
|
), f = b(
|
|
130
130
|
(e, n) => {
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
133
|
-
if (ce(
|
|
134
|
-
B(
|
|
131
|
+
const r = se(e, n);
|
|
132
|
+
if (r) {
|
|
133
|
+
if (ce(r, window.location.origin)) {
|
|
134
|
+
B(r, "cross-site-legacy");
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
|
-
z(e, { origin:
|
|
137
|
+
z(e, { origin: r });
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
[z, B]
|
|
@@ -143,32 +143,32 @@ const ee = ue(null), V = ue({
|
|
|
143
143
|
if (!l)
|
|
144
144
|
return;
|
|
145
145
|
const e = [
|
|
146
|
-
l.addListener("*", "init", (n,
|
|
147
|
-
|
|
146
|
+
l.addListener("*", "init", (n, r) => {
|
|
147
|
+
r != null && r.origin && (n != null && n.clientId) && ($.current[r.origin] = n.clientId, F(r.origin)), r != null && r.origin && Array.isArray(n == null ? void 0 : n.acceptsCredentials) ? A.current[r.origin] = n.acceptsCredentials : r != null && r.origin && ce(r.origin, window.location.origin) && B(r.origin, "cross-site-legacy");
|
|
148
148
|
}),
|
|
149
149
|
l.addListener("*", "authorize", f),
|
|
150
150
|
l.addListener("*", "login", f),
|
|
151
151
|
l.addListener(
|
|
152
152
|
"*",
|
|
153
153
|
"credential-request",
|
|
154
|
-
(n,
|
|
154
|
+
(n, r) => z(n, { v2: !0, origin: se(n, r) })
|
|
155
155
|
)
|
|
156
156
|
];
|
|
157
157
|
return () => e.forEach((n) => n());
|
|
158
158
|
}, [l, f, z, F, B]), k(() => {
|
|
159
159
|
const e = (n) => {
|
|
160
|
-
const
|
|
161
|
-
if (!
|
|
160
|
+
const r = n == null ? void 0 : n.data;
|
|
161
|
+
if (!r || r.type !== "authorized")
|
|
162
162
|
return;
|
|
163
|
-
const c = J(
|
|
163
|
+
const c = J(r.authUrl);
|
|
164
164
|
if (!c || n.origin !== c)
|
|
165
165
|
return;
|
|
166
|
-
const p =
|
|
166
|
+
const p = Z.current[c];
|
|
167
167
|
if (!(!p || p.status !== "interactive")) {
|
|
168
|
-
if (
|
|
169
|
-
|
|
168
|
+
if (r.accessToken) {
|
|
169
|
+
K((O) => ({
|
|
170
170
|
...O,
|
|
171
|
-
[c]: ne({ accessToken:
|
|
171
|
+
[c]: ne({ accessToken: r.accessToken })
|
|
172
172
|
})), o(c);
|
|
173
173
|
return;
|
|
174
174
|
}
|
|
@@ -177,20 +177,20 @@ const ee = ue(null), V = ue({
|
|
|
177
177
|
};
|
|
178
178
|
return window.addEventListener("message", e), () => window.removeEventListener("message", e);
|
|
179
179
|
}, [o, a]);
|
|
180
|
-
const
|
|
180
|
+
const g = b(
|
|
181
181
|
(e, n) => {
|
|
182
|
-
const
|
|
183
|
-
!
|
|
182
|
+
const r = e == null ? void 0 : e.origin, c = ne(n);
|
|
183
|
+
!r || !c || (K((p) => ({ ...p, [r]: c })), o(r));
|
|
184
184
|
},
|
|
185
185
|
[o]
|
|
186
|
-
),
|
|
187
|
-
I((
|
|
186
|
+
), h = b((e, n) => {
|
|
187
|
+
I((r) => r[e] ? { ...r, [e]: { ...r[e], ...n } } : r);
|
|
188
188
|
}, []), m = R({}), C = b(
|
|
189
189
|
async (e, { approve: n } = {}) => {
|
|
190
|
-
const
|
|
190
|
+
const r = q.current, { origin: c } = e;
|
|
191
191
|
let p;
|
|
192
192
|
try {
|
|
193
|
-
p = await
|
|
193
|
+
p = await r(
|
|
194
194
|
{
|
|
195
195
|
origin: c,
|
|
196
196
|
clientId: e.clientId,
|
|
@@ -200,16 +200,16 @@ const ee = ue(null), V = ue({
|
|
|
200
200
|
{ approve: n }
|
|
201
201
|
);
|
|
202
202
|
} catch {
|
|
203
|
-
n ?
|
|
203
|
+
n ? h(c, { error: { reason: "broker_unavailable" } }) : h(c, { status: "interactive" });
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
206
206
|
const O = p == null ? void 0 : p.status, d = (p == null ? void 0 : p.body) || {};
|
|
207
207
|
if (O === 200 && d.credential) {
|
|
208
|
-
|
|
208
|
+
g(e, d.credential);
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
211
211
|
if (O === 409 && d.consentRequired) {
|
|
212
|
-
|
|
212
|
+
h(c, {
|
|
213
213
|
status: "interactive",
|
|
214
214
|
consent: {
|
|
215
215
|
client: d.client || null,
|
|
@@ -222,23 +222,23 @@ const ee = ue(null), V = ue({
|
|
|
222
222
|
}
|
|
223
223
|
const S = d.error || "broker_error";
|
|
224
224
|
if (!n && me.has(S)) {
|
|
225
|
-
|
|
225
|
+
h(c, { status: "interactive" });
|
|
226
226
|
return;
|
|
227
227
|
}
|
|
228
228
|
if (n && S === "consent_denied") {
|
|
229
|
-
|
|
229
|
+
h(c, { error: null });
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
232
|
if (S === "rate_limited" && !e.rateLimitRetried) {
|
|
233
233
|
const N = Math.min(
|
|
234
|
-
Number(d.retryAfter) > 0 ? Number(d.retryAfter) :
|
|
235
|
-
|
|
234
|
+
Number(d.retryAfter) > 0 ? Number(d.retryAfter) : ge,
|
|
235
|
+
he
|
|
236
236
|
), de = { ...e, rateLimitRetried: !0 };
|
|
237
237
|
W(c), M.current[c] = setTimeout(() => {
|
|
238
238
|
delete M.current[c], m.current[c] = !0, L.current(de, { approve: n }).finally(() => {
|
|
239
239
|
delete m.current[c];
|
|
240
240
|
});
|
|
241
|
-
}, N * 1e3),
|
|
241
|
+
}, N * 1e3), h(c, { rateLimitRetried: !0 });
|
|
242
242
|
return;
|
|
243
243
|
}
|
|
244
244
|
o(c), E((N) => ({
|
|
@@ -251,7 +251,7 @@ const ee = ue(null), V = ue({
|
|
|
251
251
|
}
|
|
252
252
|
}));
|
|
253
253
|
},
|
|
254
|
-
[
|
|
254
|
+
[g, h, o, W]
|
|
255
255
|
), L = R(C);
|
|
256
256
|
L.current = C, k(() => {
|
|
257
257
|
Object.values(w).forEach((e) => {
|
|
@@ -269,19 +269,23 @@ const ee = ue(null), V = ue({
|
|
|
269
269
|
k(() => () => {
|
|
270
270
|
_.current && _.current(), Object.values(M.current).forEach(clearTimeout);
|
|
271
271
|
}, []);
|
|
272
|
-
const
|
|
272
|
+
const H = b(
|
|
273
273
|
(e) => {
|
|
274
274
|
_.current && (_.current(), _.current = null);
|
|
275
275
|
const n = s || be;
|
|
276
276
|
_.current = n(e, {
|
|
277
277
|
onBlocked: () => {
|
|
278
|
-
I((
|
|
279
|
-
...
|
|
280
|
-
[e.origin]: { ...
|
|
281
|
-
} :
|
|
278
|
+
I((r) => r[e.origin] ? {
|
|
279
|
+
...r,
|
|
280
|
+
[e.origin]: { ...r[e.origin], popupBlocked: !0 }
|
|
281
|
+
} : r);
|
|
282
282
|
},
|
|
283
|
-
// A
|
|
284
|
-
|
|
283
|
+
// A completed login already removed the entry. A v2 entry stays pending so the prompt remains;
|
|
284
|
+
// a legacy guest is remounted because it only learns of a login by reloading.
|
|
285
|
+
onClosed: () => {
|
|
286
|
+
const r = Z.current[e.origin];
|
|
287
|
+
!r || r.v2 || a(e.origin);
|
|
288
|
+
}
|
|
285
289
|
});
|
|
286
290
|
},
|
|
287
291
|
[s, a]
|
|
@@ -289,15 +293,15 @@ const ee = ue(null), V = ue({
|
|
|
289
293
|
pending: Object.values(w).filter(
|
|
290
294
|
(e) => e.status === "interactive"
|
|
291
295
|
),
|
|
292
|
-
authorize:
|
|
296
|
+
authorize: H,
|
|
293
297
|
approve: Q,
|
|
294
|
-
complete:
|
|
298
|
+
complete: g,
|
|
295
299
|
dismiss: u,
|
|
296
300
|
originEpochs: v,
|
|
297
301
|
credentials: j,
|
|
298
302
|
unsupported: y
|
|
299
303
|
};
|
|
300
|
-
return /* @__PURE__ */ P.createElement(V.Provider, { value: Y },
|
|
304
|
+
return /* @__PURE__ */ P.createElement(V.Provider, { value: Y }, t);
|
|
301
305
|
};
|
|
302
306
|
ae.propTypes = {
|
|
303
307
|
children: T.node,
|
|
@@ -312,17 +316,17 @@ ae.propTypes = {
|
|
|
312
316
|
*/
|
|
313
317
|
broker: T.func
|
|
314
318
|
};
|
|
315
|
-
const $e = () => G(V), Ee = (
|
|
316
|
-
const { originEpochs: s } = G(V), i = J(
|
|
319
|
+
const $e = () => G(V), Ee = (t) => {
|
|
320
|
+
const { originEpochs: s } = G(V), i = J(t);
|
|
317
321
|
return i && s[i] || 0;
|
|
318
|
-
}, Re = (
|
|
319
|
-
const { credentials: s } = G(V), i = J(
|
|
322
|
+
}, Re = (t) => {
|
|
323
|
+
const { credentials: s } = G(V), i = J(t);
|
|
320
324
|
return i && s[i] || null;
|
|
321
|
-
}, ke = (
|
|
322
|
-
const { unsupported: s } = G(V), i = J(
|
|
325
|
+
}, ke = (t) => {
|
|
326
|
+
const { unsupported: s } = G(V), i = J(t);
|
|
323
327
|
return i && s[i] || null;
|
|
324
328
|
}, 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.", we = ({
|
|
325
|
-
children:
|
|
329
|
+
children: t,
|
|
326
330
|
authorizationLauncher: s,
|
|
327
331
|
credentialBroker: i,
|
|
328
332
|
ready: l
|
|
@@ -331,7 +335,7 @@ const $e = () => G(V), Ee = (r) => {
|
|
|
331
335
|
k(() => {
|
|
332
336
|
l !== void 0 || I.current || (I.current = !0, console.error(ie), typeof window != "undefined" && typeof window.alert == "function" && window.alert(ie));
|
|
333
337
|
}, [l]);
|
|
334
|
-
const [v, D] = U({}), [j,
|
|
338
|
+
const [v, D] = U({}), [j, K] = U({}), y = R({}), E = R({}), x = R({}), Z = b((o, a) => {
|
|
335
339
|
var u;
|
|
336
340
|
return !!((u = x.current[o]) != null && u.has(a));
|
|
337
341
|
}, []), _ = b((o, a, u) => {
|
|
@@ -340,7 +344,7 @@ const $e = () => G(V), Ee = (r) => {
|
|
|
340
344
|
D((a) => {
|
|
341
345
|
const u = { ...a };
|
|
342
346
|
return delete u[o], u;
|
|
343
|
-
}),
|
|
347
|
+
}), K((a) => {
|
|
344
348
|
const u = { ...a };
|
|
345
349
|
return delete u[o], u;
|
|
346
350
|
}), delete x.current[o], Object.keys(E.current).forEach((a) => {
|
|
@@ -350,27 +354,27 @@ const $e = () => G(V), Ee = (r) => {
|
|
|
350
354
|
k(() => () => {
|
|
351
355
|
E.current = {};
|
|
352
356
|
}, []), k(() => {
|
|
353
|
-
const o = (u = [], f,
|
|
354
|
-
u.forEach((
|
|
357
|
+
const o = (u = [], f, g) => {
|
|
358
|
+
u.forEach((h) => h(f, g));
|
|
355
359
|
}, a = (u) => {
|
|
356
|
-
var Q,
|
|
360
|
+
var Q, H, Y, e, n, r, c;
|
|
357
361
|
if (!((Q = u == null ? void 0 : u.data) != null && Q.instanceId))
|
|
358
362
|
return;
|
|
359
|
-
const { instanceId: f, type:
|
|
360
|
-
if (!m || u.source !== m || u.origin !==
|
|
363
|
+
const { instanceId: f, type: g } = u.data, h = v[f], m = (Y = (H = h == null ? void 0 : h.frameRef) == null ? void 0 : H.current) == null ? void 0 : Y.contentWindow;
|
|
364
|
+
if (!m || u.source !== m || u.origin !== h.origin)
|
|
361
365
|
return;
|
|
362
366
|
const C = { origin: u.origin }, L = y.current;
|
|
363
|
-
if (
|
|
367
|
+
if (g === "response") {
|
|
364
368
|
const { callbackId: p, response: O, error: d } = u.data, S = E.current[p];
|
|
365
369
|
S && S.instanceId === f && (S.callback(O, d), delete E.current[p]);
|
|
366
370
|
return;
|
|
367
371
|
}
|
|
368
|
-
if (
|
|
372
|
+
if (g === "mark-registered") {
|
|
369
373
|
const { requestType: p } = u.data;
|
|
370
374
|
x.current[f] || (x.current[f] = /* @__PURE__ */ new Set()), x.current[f].add(p);
|
|
371
375
|
return;
|
|
372
376
|
}
|
|
373
|
-
|
|
377
|
+
g === "ready" && K((p) => ({ ...p, [f]: !0 })), o((e = L[f]) == null ? void 0 : e[g], u.data, C), o((n = L["*"]) == null ? void 0 : n[g], u.data, C), o((r = L[f]) == null ? void 0 : r["*"], u.data, C), o((c = L["*"]) == null ? void 0 : c["*"], u.data, C);
|
|
374
378
|
};
|
|
375
379
|
return window.addEventListener("message", a), () => {
|
|
376
380
|
window.removeEventListener("message", a);
|
|
@@ -378,24 +382,24 @@ const $e = () => G(V), Ee = (r) => {
|
|
|
378
382
|
}, [v]);
|
|
379
383
|
const A = b(
|
|
380
384
|
(o, a, u, f) => {
|
|
381
|
-
var
|
|
382
|
-
const
|
|
383
|
-
if (!
|
|
385
|
+
var h, m;
|
|
386
|
+
const g = v[o];
|
|
387
|
+
if (!g) {
|
|
384
388
|
console.warn(`Origin not set for id: ${o}. Unable to send message.`);
|
|
385
389
|
return;
|
|
386
390
|
}
|
|
387
|
-
(m = (
|
|
391
|
+
(m = (h = g == null ? void 0 : g.frameRef) == null ? void 0 : h.current) != null && m.contentWindow && g.frameRef.current.contentWindow.postMessage(
|
|
388
392
|
{ type: a, ...u, instanceId: o },
|
|
389
|
-
f ||
|
|
393
|
+
f || g.origin
|
|
390
394
|
);
|
|
391
395
|
},
|
|
392
396
|
[v]
|
|
393
397
|
), q = R(0), F = b(() => `${Date.now()}-${++q.current}`, []), B = b(
|
|
394
|
-
async (o, a, u = {}) => new Promise((f,
|
|
395
|
-
const
|
|
396
|
-
delete E.current[
|
|
398
|
+
async (o, a, u = {}) => new Promise((f, g) => {
|
|
399
|
+
const h = F(), m = (C, L) => {
|
|
400
|
+
delete E.current[h], L ? g(L) : f(C);
|
|
397
401
|
};
|
|
398
|
-
E.current[
|
|
402
|
+
E.current[h] = { instanceId: o, callback: m }, A(o, "request", { callbackId: h, requestType: a, data: u });
|
|
399
403
|
}),
|
|
400
404
|
[A]
|
|
401
405
|
), z = b(
|
|
@@ -416,7 +420,7 @@ const $e = () => G(V), Ee = (r) => {
|
|
|
416
420
|
sendRequest: B,
|
|
417
421
|
loadOptions: z,
|
|
418
422
|
validate: M,
|
|
419
|
-
hasHandler:
|
|
423
|
+
hasHandler: Z,
|
|
420
424
|
readyFrames: j,
|
|
421
425
|
ready: w,
|
|
422
426
|
addListener: (o, a, u) => (y.current[o] || (y.current[o] = {}), y.current[o][a] || (y.current[o][a] = []), y.current[o][a].push(u), () => {
|
|
@@ -430,7 +434,7 @@ const $e = () => G(V), Ee = (r) => {
|
|
|
430
434
|
B,
|
|
431
435
|
z,
|
|
432
436
|
M,
|
|
433
|
-
|
|
437
|
+
Z,
|
|
434
438
|
j,
|
|
435
439
|
w
|
|
436
440
|
]
|
|
@@ -441,9 +445,9 @@ const $e = () => G(V), Ee = (r) => {
|
|
|
441
445
|
launcher: s,
|
|
442
446
|
broker: i
|
|
443
447
|
},
|
|
444
|
-
|
|
448
|
+
t
|
|
445
449
|
));
|
|
446
|
-
}, X = (
|
|
450
|
+
}, X = (t, s, i) => {
|
|
447
451
|
const l = G(ee);
|
|
448
452
|
if (l === null)
|
|
449
453
|
throw new Error(
|
|
@@ -453,22 +457,22 @@ const $e = () => G(V), Ee = (r) => {
|
|
|
453
457
|
k(() => {
|
|
454
458
|
w.current = i;
|
|
455
459
|
}, [i]), k(() => {
|
|
456
|
-
if (!(!
|
|
460
|
+
if (!(!t || !s)) {
|
|
457
461
|
if (s.startsWith("key:")) {
|
|
458
462
|
const I = s.substring(4);
|
|
459
|
-
return l.readyFrames[
|
|
460
|
-
|
|
463
|
+
return l.readyFrames[t] && l.sendMessage(t, "subscribe-key", { keyChord: I }), l.addListener(
|
|
464
|
+
t,
|
|
461
465
|
`key-pressed:${I}`,
|
|
462
466
|
(...D) => w.current(...D)
|
|
463
467
|
);
|
|
464
468
|
}
|
|
465
469
|
return l.addListener(
|
|
466
|
-
|
|
470
|
+
t,
|
|
467
471
|
s,
|
|
468
472
|
(...I) => w.current(...I)
|
|
469
473
|
);
|
|
470
474
|
}
|
|
471
|
-
}, [l,
|
|
475
|
+
}, [l, t, s]);
|
|
472
476
|
};
|
|
473
477
|
we.propTypes = {
|
|
474
478
|
children: T.node.isRequired,
|
|
@@ -487,18 +491,19 @@ we.propTypes = {
|
|
|
487
491
|
/**
|
|
488
492
|
* Optional credential broker for hosts that are first-party MachineMetrics clients
|
|
489
493
|
* (`async (request, { approve }) => result`, see EmbeddedAuthorizationManager). When present,
|
|
490
|
-
* v2 credential requests are brokered server-side
|
|
491
|
-
*
|
|
494
|
+
* v2 credential requests are brokered server-side and consent is rendered natively by the host
|
|
495
|
+
* from the broker's `client` identity; a broker answer the host may not act on falls back to the
|
|
496
|
+
* interactive entry and its popup.
|
|
492
497
|
*/
|
|
493
498
|
credentialBroker: T.func
|
|
494
499
|
};
|
|
495
|
-
const re = te.default || te, Te = 1e4, Ie = "credentials", _e = (
|
|
500
|
+
const re = te.default || te, Te = 1e4, Ie = "credentials", _e = (t, s) => `${t}/mm-embedded-interop?id=${encodeURIComponent(s)}&origin=${encodeURIComponent(
|
|
496
501
|
window.location.origin
|
|
497
502
|
)}&caps=${Ie}`, Me = re.iframe`
|
|
498
503
|
width: 100%;
|
|
499
504
|
height: 100%;
|
|
500
505
|
border: none;
|
|
501
|
-
visibility: ${(
|
|
506
|
+
visibility: ${(t) => t.$isReady ? "visible" : "hidden"};
|
|
502
507
|
`, Ce = re.div`
|
|
503
508
|
width: 100%;
|
|
504
509
|
height: 100%;
|
|
@@ -512,8 +517,8 @@ const re = te.default || te, Te = 1e4, Ie = "credentials", _e = (r, s) => `${r}/
|
|
|
512
517
|
text-align: center;
|
|
513
518
|
color: #555;
|
|
514
519
|
font-size: 14px;
|
|
515
|
-
`, ye = (
|
|
516
|
-
const s =
|
|
520
|
+
`, ye = (t) => {
|
|
521
|
+
const s = t && t.origin || "This app", i = t && t.reason || "";
|
|
517
522
|
switch (i) {
|
|
518
523
|
case "broker:scope_above_ceiling":
|
|
519
524
|
return {
|
|
@@ -540,9 +545,9 @@ const re = te.default || te, Te = 1e4, Ie = "credentials", _e = (r, s) => `${r}/
|
|
|
540
545
|
detail: "It needs an update to support embedding from a different domain."
|
|
541
546
|
};
|
|
542
547
|
}
|
|
543
|
-
}, le = ({ entry:
|
|
544
|
-
const s = ye(
|
|
545
|
-
return /* @__PURE__ */ P.createElement(Ce, { "data-reason":
|
|
548
|
+
}, le = ({ entry: t }) => {
|
|
549
|
+
const s = ye(t);
|
|
550
|
+
return /* @__PURE__ */ P.createElement(Ce, { "data-reason": t && t.reason || void 0 }, /* @__PURE__ */ P.createElement("div", { style: { fontWeight: 600 } }, s.title), /* @__PURE__ */ P.createElement("div", { style: { fontSize: 12, color: "#888" } }, s.detail));
|
|
546
551
|
};
|
|
547
552
|
le.propTypes = {
|
|
548
553
|
entry: T.shape({
|
|
@@ -559,7 +564,7 @@ const Le = re.div`
|
|
|
559
564
|
align-items: center;
|
|
560
565
|
justify-content: center;
|
|
561
566
|
`, Ae = () => /* @__PURE__ */ P.createElement(Le, null, /* @__PURE__ */ P.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), Ue = ({
|
|
562
|
-
id:
|
|
567
|
+
id: t,
|
|
563
568
|
src: s,
|
|
564
569
|
path: i,
|
|
565
570
|
onInit: l = () => {
|
|
@@ -569,9 +574,9 @@ const Le = re.div`
|
|
|
569
574
|
params: v = {},
|
|
570
575
|
renderUnsupported: D,
|
|
571
576
|
renderTimeout: j,
|
|
572
|
-
...
|
|
577
|
+
...K
|
|
573
578
|
}) => {
|
|
574
|
-
if ("isConfiguring" in
|
|
579
|
+
if ("isConfiguring" in K)
|
|
575
580
|
return console.error(
|
|
576
581
|
"isConfiguring must be passed via the params prop to MMEmbeddableZone"
|
|
577
582
|
), null;
|
|
@@ -583,10 +588,10 @@ const Le = re.div`
|
|
|
583
588
|
return console.error(
|
|
584
589
|
"isFullScreen must be passed via the params prop to MMEmbeddableZone"
|
|
585
590
|
), null;
|
|
586
|
-
const y = R(), E = J(s), [x,
|
|
591
|
+
const y = R(), E = J(s), [x, Z] = U(), [_, $] = U(0), [A, q] = U(!1), [F, B] = U(!1), z = Ee(s), M = Re(s), W = ke(s), [o, a] = U(0), [u, f] = U(null), { registerFrame: g, unregisterFrame: h, sendMessage: m, ready: C } = G(
|
|
587
592
|
ee
|
|
588
|
-
), [L, Q] = U(),
|
|
589
|
-
n.current = !1, clearTimeout(
|
|
593
|
+
), [L, Q] = U(), H = R(), Y = R(w), e = R(l), n = R(!1), r = R(), c = b(() => {
|
|
594
|
+
n.current = !1, clearTimeout(H.current), clearTimeout(r.current), $(0), q(!1), B(!1), f(null);
|
|
590
595
|
}, []);
|
|
591
596
|
k(() => {
|
|
592
597
|
(z > 0 || o > 0) && c();
|
|
@@ -596,7 +601,7 @@ const Le = re.div`
|
|
|
596
601
|
e.current = l;
|
|
597
602
|
}, [l]), k(() => {
|
|
598
603
|
_ && m(
|
|
599
|
-
|
|
604
|
+
t,
|
|
600
605
|
"set-context",
|
|
601
606
|
{
|
|
602
607
|
context: {
|
|
@@ -605,36 +610,36 @@ const Le = re.div`
|
|
|
605
610
|
},
|
|
606
611
|
E
|
|
607
612
|
);
|
|
608
|
-
}, [I,
|
|
609
|
-
_ && m(
|
|
610
|
-
}, [v,
|
|
613
|
+
}, [I, t, _, E]), k(() => {
|
|
614
|
+
_ && m(t, "set-params", { params: v }, E);
|
|
615
|
+
}, [v, t, _, E]), k(() => {
|
|
611
616
|
i !== void 0 && Q((i == null ? void 0 : i.indexOf("/")) === 0 ? i : `/${i}`);
|
|
612
617
|
}, [i]), k(() => {
|
|
613
|
-
L === void 0 || !_ || m(
|
|
614
|
-
}, [L, _,
|
|
615
|
-
if (!s || !
|
|
618
|
+
L === void 0 || !_ || m(t, "navigate", { path: L }, E);
|
|
619
|
+
}, [L, _, t, m, E]), k(() => {
|
|
620
|
+
if (!s || !t || !y)
|
|
616
621
|
return;
|
|
617
622
|
if (!C) {
|
|
618
|
-
c(),
|
|
623
|
+
c(), Z(void 0);
|
|
619
624
|
return;
|
|
620
625
|
}
|
|
621
626
|
c();
|
|
622
627
|
const d = new URL(s);
|
|
623
|
-
return
|
|
624
|
-
|
|
628
|
+
return g(t, d.origin, y), e.current(), Z(_e(d.origin, t)), () => {
|
|
629
|
+
h(t);
|
|
625
630
|
};
|
|
626
|
-
}, [s,
|
|
631
|
+
}, [s, t, C, g, y, c]), k(() => {
|
|
627
632
|
if (!(!x || n.current))
|
|
628
|
-
return
|
|
633
|
+
return H.current = setTimeout(() => {
|
|
629
634
|
q(!0), Y.current && Y.current();
|
|
630
|
-
}, Te), () => clearTimeout(
|
|
635
|
+
}, Te), () => clearTimeout(H.current);
|
|
631
636
|
}, [x, s, z, o]);
|
|
632
637
|
const p = b(() => {
|
|
633
|
-
n.current = !0, clearTimeout(
|
|
638
|
+
n.current = !0, clearTimeout(H.current), q(!1);
|
|
634
639
|
}, []);
|
|
635
|
-
if (X(
|
|
640
|
+
if (X(t, "init", (d) => {
|
|
636
641
|
p(), Array.isArray(d == null ? void 0 : d.acceptsCredentials) && f(d.acceptsCredentials);
|
|
637
|
-
}), X(
|
|
642
|
+
}), X(t, "authorize", p), X(t, "login", p), X(t, "credential-request", () => {
|
|
638
643
|
p(), B(!0);
|
|
639
644
|
}), k(() => {
|
|
640
645
|
if (!F || !M)
|
|
@@ -643,27 +648,27 @@ const Le = re.div`
|
|
|
643
648
|
if (Array.isArray(d) && !d.includes(M.kind))
|
|
644
649
|
return;
|
|
645
650
|
const S = M.kind === "access_token" ? { accessToken: M.accessToken } : {};
|
|
646
|
-
m(
|
|
651
|
+
m(t, "credential", { ...S, credential: M }, E);
|
|
647
652
|
}, [
|
|
648
653
|
F,
|
|
649
654
|
M,
|
|
650
655
|
u,
|
|
651
|
-
|
|
656
|
+
t,
|
|
652
657
|
m,
|
|
653
658
|
E
|
|
654
|
-
]), X(
|
|
659
|
+
]), X(t, "ready", () => {
|
|
655
660
|
p(), $((d) => d + 1);
|
|
656
|
-
}), X(
|
|
657
|
-
|
|
661
|
+
}), X(t, "heartbeat", () => {
|
|
662
|
+
r.current && clearTimeout(r.current), r.current = setTimeout(() => {
|
|
658
663
|
a((d) => d + 1);
|
|
659
664
|
}, 6e3);
|
|
660
665
|
}), k(() => () => {
|
|
661
|
-
|
|
666
|
+
r.current && clearTimeout(r.current);
|
|
662
667
|
}, []), W)
|
|
663
668
|
return D ? D(W) : /* @__PURE__ */ P.createElement(le, { entry: W });
|
|
664
669
|
if (A && !_)
|
|
665
670
|
return j ? j() : /* @__PURE__ */ P.createElement(Ae, null);
|
|
666
|
-
const O = { ...
|
|
671
|
+
const O = { ...K };
|
|
667
672
|
return delete O.skipManifestCheck, /* @__PURE__ */ P.createElement(
|
|
668
673
|
Me,
|
|
669
674
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(g,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],e):(g=typeof globalThis!="undefined"?globalThis:g||self,e(g["mm-react-embeddable"]={},g.React,g.PropTypes,g.styled))})(this,(function(g,e,me,Ee){"use strict";const R=t=>t&&t.__esModule?t:{default:t},O=R(e),C=R(me),te=R(Ee),J=e.createContext(null),G=e.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ne="access_token",V=t=>t?t.kind?t:t.accessToken?{kind:ne,accessToken:t.accessToken,expiresAt:t.expiresAt||null}:null:null,ge=60,ke=120,Ce=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),Q=t=>{try{return new URL(t).origin}catch{return null}},se=(t,o)=>{const c=o==null?void 0:o.origin;return!c||Q(t==null?void 0:t.authUrl)!==c?null:c},oe=t=>{if(!t||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(t)||t.includes(":"))return t;const o=t.split(".");return o.length<=2?t:o.slice(-2).join(".")},ee=(t,o)=>{try{const c=new URL(t),a=new URL(o);return c.protocol!==a.protocol?!0:oe(c.hostname)!==oe(a.hostname)}catch{return!0}},ue=(t,{onBlocked:o,onClosed:c})=>{const a=window.open(t.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!a)return o(),()=>{};const w=setInterval(()=>{a.closed&&(clearInterval(w),c())},1e3);return()=>clearInterval(w)},ie=({children:t,launcher:o,broker:c})=>{const a=e.useContext(J),[w,T]=e.useState({}),[F,B]=e.useState({}),[Z,W]=e.useState({}),[M,k]=e.useState({}),L=e.useRef(Z);L.current=Z;const H=e.useRef(w);H.current=w;const _=e.useRef(null),$=e.useRef({}),A=e.useRef({}),q=e.useRef(c);q.current=c;const x=e.useCallback(r=>{const s=$.current[r];if(!s)return;const n=i=>!i[r]||i[r].clientId?i:{...i,[r]:{...i[r],clientId:s}};T(n),k(n)},[]),v=e.useCallback((r,s)=>{r&&(k(n=>n[r]?n:{...n,[r]:{origin:r,reason:s,clientId:$.current[r]||null}}),x(r))},[x]),U=e.useCallback((r,{v2:s=!1,origin:n=null}={})=>{n&&(s&&L.current[n]||(T(i=>i[n]?i:{...i,[n]:{origin:n,authUrl:r.authUrl,status:s&&q.current?"broker":"interactive",v2:s,scope:r.scope||null,acceptsCredentials:A.current[n]||null,consent:null,error:null,clientId:r.clientId||$.current[n]||null,popupBlocked:!1}}),x(n)))},[x]),I=e.useRef({}),D=e.useCallback(r=>{I.current[r]&&(clearTimeout(I.current[r]),delete I.current[r])},[]),u=e.useCallback(r=>{D(r),T(s=>{if(!s[r])return s;const n={...s};return delete n[r],n})},[D]),d=e.useCallback(r=>{r&&(u(r),B(s=>({...s,[r]:(s[r]||0)+1})))},[u]),l=e.useCallback(r=>{u(r.origin)},[u]),p=e.useCallback((r,s)=>{const n=se(r,s);if(n){if(ee(n,window.location.origin)){v(n,"cross-site-legacy");return}U(r,{origin:n})}},[U,v]);e.useEffect(()=>{if(!a)return;const r=[a.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&($.current[n.origin]=s.clientId,x(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?A.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&ee(n.origin,window.location.origin)&&v(n.origin,"cross-site-legacy")}),a.addListener("*","authorize",p),a.addListener("*","login",p),a.addListener("*","credential-request",(s,n)=>U(s,{v2:!0,origin:se(s,n)}))];return()=>r.forEach(s=>s())},[a,p,U,x,v]),e.useEffect(()=>{const r=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const i=Q(n.authUrl);if(!i||s.origin!==i)return;const b=H.current[i];if(!(!b||b.status!=="interactive")){if(n.accessToken){W(z=>({...z,[i]:V({accessToken:n.accessToken})})),u(i);return}d(i)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[u,d]);const h=e.useCallback((r,s)=>{const n=r==null?void 0:r.origin,i=V(s);!n||!i||(W(b=>({...b,[n]:i})),u(n))},[u]),m=e.useCallback((r,s)=>{T(n=>n[r]?{...n,[r]:{...n[r],...s}}:n)},[]),E=e.useRef({}),y=e.useCallback(async(r,{approve:s}={})=>{const n=q.current,{origin:i}=r;let b;try{b=await n({origin:i,clientId:r.clientId,scope:r.scope,authUrl:r.authUrl},{approve:s})}catch{s?m(i,{error:{reason:"broker_unavailable"}}):m(i,{status:"interactive"});return}const z=b==null?void 0:b.status,f=(b==null?void 0:b.body)||{};if(z===200&&f.credential){h(r,f.credential);return}if(z===409&&f.consentRequired){m(i,{status:"interactive",consent:{client:f.client||null,stepUp:!!f.stepUp,scope:f.scope||r.scope},error:null});return}const P=f.error||"broker_error";if(!s&&Ce.has(P)){m(i,{status:"interactive"});return}if(s&&P==="consent_denied"){m(i,{error:null});return}if(P==="rate_limited"&&!r.rateLimitRetried){const N=Math.min(Number(f.retryAfter)>0?Number(f.retryAfter):ge,ke),Le={...r,rateLimitRetried:!0};D(i),I.current[i]=setTimeout(()=>{delete I.current[i],E.current[i]=!0,S.current(Le,{approve:s}).finally(()=>{delete E.current[i]})},N*1e3),m(i,{rateLimitRetried:!0});return}u(i),k(N=>({...N,[i]:{origin:i,reason:`broker:${P}`,detail:{status:z!=null?z:null,reason:P},clientId:r.clientId||$.current[i]||null}}))},[h,m,u,D]),S=e.useRef(y);S.current=y,e.useEffect(()=>{Object.values(w).forEach(r=>{r.status!=="broker"||E.current[r.origin]||I.current[r.origin]||(E.current[r.origin]=!0,y(r).finally(()=>{delete E.current[r.origin]}))})},[w,y]);const X=e.useCallback(r=>!q.current||!(r!=null&&r.consent)||E.current[r.origin]?Promise.resolve():(E.current[r.origin]=!0,y(r,{approve:!0}).finally(()=>{delete E.current[r.origin]})),[y]);e.useEffect(()=>()=>{_.current&&_.current(),Object.values(I.current).forEach(clearTimeout)},[]);const j=e.useCallback(r=>{_.current&&(_.current(),_.current=null);const s=o||ue;_.current=s(r,{onBlocked:()=>{T(n=>n[r.origin]?{...n,[r.origin]:{...n[r.origin],popupBlocked:!0}}:n)},onClosed:()=>d(r.origin)})},[o,d]),K={pending:Object.values(w).filter(r=>r.status==="interactive"),authorize:j,approve:X,complete:h,dismiss:l,originEpochs:F,credentials:Z,unsupported:M};return O.default.createElement(G.Provider,{value:K},t)};ie.propTypes={children:C.default.node,launcher:C.default.func,broker:C.default.func};const we=()=>e.useContext(G),ce=t=>{const{originEpochs:o}=e.useContext(G),c=Q(t);return c&&o[c]||0},le=t=>{const{credentials:o}=e.useContext(G),c=Q(t);return c&&o[c]||null},de=t=>{const{unsupported:o}=e.useContext(G),c=Q(t);return c&&o[c]||null},ae="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.",fe=({children:t,authorizationLauncher:o,credentialBroker:c,ready:a})=>{const w=a===!0,T=e.useRef(!1);e.useEffect(()=>{a!==void 0||T.current||(T.current=!0,console.error(ae),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ae))},[a]);const[F,B]=e.useState({}),[Z,W]=e.useState({}),M=e.useRef({}),k=e.useRef({}),L=e.useRef({}),H=e.useCallback((u,d)=>{var l;return!!((l=L.current[u])!=null&&l.has(d))},[]),_=e.useCallback((u,d,l)=>{B(p=>({...p,[u]:{origin:d,frameRef:l}}))},[]),$=e.useCallback(u=>{B(d=>{const l={...d};return delete l[u],l}),W(d=>{const l={...d};return delete l[u],l}),delete L.current[u],Object.keys(k.current).forEach(d=>{k.current[d].instanceId===u&&delete k.current[d]})},[]);e.useEffect(()=>()=>{k.current={}},[]),e.useEffect(()=>{const u=(l=[],p,h)=>{l.forEach(m=>m(p,h))},d=l=>{var X,j,K,r,s,n,i;if(!((X=l==null?void 0:l.data)!=null&&X.instanceId))return;const{instanceId:p,type:h}=l.data,m=F[p],E=(K=(j=m==null?void 0:m.frameRef)==null?void 0:j.current)==null?void 0:K.contentWindow;if(!E||l.source!==E||l.origin!==m.origin)return;const y={origin:l.origin},S=M.current;if(h==="response"){const{callbackId:b,response:z,error:f}=l.data,P=k.current[b];P&&P.instanceId===p&&(P.callback(z,f),delete k.current[b]);return}if(h==="mark-registered"){const{requestType:b}=l.data;L.current[p]||(L.current[p]=new Set),L.current[p].add(b);return}h==="ready"&&W(b=>({...b,[p]:!0})),u((r=S[p])==null?void 0:r[h],l.data,y),u((s=S["*"])==null?void 0:s[h],l.data,y),u((n=S[p])==null?void 0:n["*"],l.data,y),u((i=S["*"])==null?void 0:i["*"],l.data,y)};return window.addEventListener("message",d),()=>{window.removeEventListener("message",d)}},[F]);const A=e.useCallback((u,d,l,p)=>{var m,E;const h=F[u];if(!h){console.warn(`Origin not set for id: ${u}. Unable to send message.`);return}(E=(m=h==null?void 0:h.frameRef)==null?void 0:m.current)!=null&&E.contentWindow&&h.frameRef.current.contentWindow.postMessage({type:d,...l,instanceId:u},p||h.origin)},[F]),q=e.useRef(0),x=e.useCallback(()=>`${Date.now()}-${++q.current}`,[]),v=e.useCallback(async(u,d,l={})=>new Promise((p,h)=>{const m=x(),E=(y,S)=>{delete k.current[m],S?h(S):p(y)};k.current[m]={instanceId:u,callback:E},A(u,"request",{callbackId:m,requestType:d,data:l})}),[A]),U=e.useCallback((u,d)=>{A(u,"load-options",d)},[A]),I=e.useCallback((u,d)=>{A(u,"validate",d)},[A]),D=e.useMemo(()=>({registerFrame:_,unregisterFrame:$,sendMessage:A,sendRequest:v,loadOptions:U,validate:I,hasHandler:H,readyFrames:Z,ready:w,addListener:(u,d,l)=>(M.current[u]||(M.current[u]={}),M.current[u][d]||(M.current[u][d]=[]),M.current[u][d].push(l),()=>{M.current[u][d]=M.current[u][d].filter(p=>p!==l)})}),[_,$,A,v,U,I,H,Z,w]);return O.default.createElement(J.Provider,{value:D},O.default.createElement(ie,{launcher:o,broker:c},t))},Y=(t,o,c)=>{const a=e.useContext(J);if(a===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const w=e.useRef(c);e.useEffect(()=>{w.current=c},[c]),e.useEffect(()=>{if(!(!t||!o)){if(o.startsWith("key:")){const T=o.substring(4);return a.readyFrames[t]&&a.sendMessage(t,"subscribe-key",{keyChord:T}),a.addListener(t,`key-pressed:${T}`,(...B)=>w.current(...B))}return a.addListener(t,o,(...T)=>w.current(...T))}},[a,t,o])};fe.propTypes={children:C.default.node.isRequired,ready:C.default.bool.isRequired,authorizationLauncher:C.default.func,credentialBroker:C.default.func};const re=te.default.default||te.default,Te=1e4,_e="credentials",Ie=(t,o)=>`${t}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${_e}`,ye=re.iframe`
|
|
1
|
+
(function(g,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],e):(g=typeof globalThis!="undefined"?globalThis:g||self,e(g["mm-react-embeddable"]={},g.React,g.PropTypes,g.styled))})(this,(function(g,e,me,Ee){"use strict";const R=t=>t&&t.__esModule?t:{default:t},O=R(e),C=R(me),te=R(Ee),J=e.createContext(null),G=e.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ne="access_token",V=t=>t?t.kind?t:t.accessToken?{kind:ne,accessToken:t.accessToken,expiresAt:t.expiresAt||null}:null:null,ge=60,ke=120,Ce=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),Q=t=>{try{return new URL(t).origin}catch{return null}},se=(t,o)=>{const c=o==null?void 0:o.origin;return!c||Q(t==null?void 0:t.authUrl)!==c?null:c},oe=t=>{if(!t||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(t)||t.includes(":"))return t;const o=t.split(".");return o.length<=2?t:o.slice(-2).join(".")},ee=(t,o)=>{try{const c=new URL(t),a=new URL(o);return c.protocol!==a.protocol?!0:oe(c.hostname)!==oe(a.hostname)}catch{return!0}},ue=(t,{onBlocked:o,onClosed:c})=>{const a=window.open(t.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!a)return o(),()=>{};const w=setInterval(()=>{a.closed&&(clearInterval(w),c())},1e3);return()=>clearInterval(w)},ie=({children:t,launcher:o,broker:c})=>{const a=e.useContext(J),[w,T]=e.useState({}),[F,B]=e.useState({}),[Z,H]=e.useState({}),[M,k]=e.useState({}),L=e.useRef(Z);L.current=Z;const j=e.useRef(w);j.current=w;const _=e.useRef(null),$=e.useRef({}),A=e.useRef({}),v=e.useRef(c);v.current=c;const x=e.useCallback(r=>{const s=$.current[r];if(!s)return;const n=i=>!i[r]||i[r].clientId?i:{...i,[r]:{...i[r],clientId:s}};T(n),k(n)},[]),q=e.useCallback((r,s)=>{r&&(k(n=>n[r]?n:{...n,[r]:{origin:r,reason:s,clientId:$.current[r]||null}}),x(r))},[x]),U=e.useCallback((r,{v2:s=!1,origin:n=null}={})=>{n&&(s&&L.current[n]||(T(i=>i[n]?i:{...i,[n]:{origin:n,authUrl:r.authUrl,status:s&&v.current?"broker":"interactive",v2:s,scope:r.scope||null,acceptsCredentials:A.current[n]||null,consent:null,error:null,clientId:r.clientId||$.current[n]||null,popupBlocked:!1}}),x(n)))},[x]),I=e.useRef({}),D=e.useCallback(r=>{I.current[r]&&(clearTimeout(I.current[r]),delete I.current[r])},[]),u=e.useCallback(r=>{D(r),T(s=>{if(!s[r])return s;const n={...s};return delete n[r],n})},[D]),d=e.useCallback(r=>{r&&(u(r),B(s=>({...s,[r]:(s[r]||0)+1})))},[u]),l=e.useCallback(r=>{u(r.origin)},[u]),p=e.useCallback((r,s)=>{const n=se(r,s);if(n){if(ee(n,window.location.origin)){q(n,"cross-site-legacy");return}U(r,{origin:n})}},[U,q]);e.useEffect(()=>{if(!a)return;const r=[a.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&($.current[n.origin]=s.clientId,x(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?A.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&ee(n.origin,window.location.origin)&&q(n.origin,"cross-site-legacy")}),a.addListener("*","authorize",p),a.addListener("*","login",p),a.addListener("*","credential-request",(s,n)=>U(s,{v2:!0,origin:se(s,n)}))];return()=>r.forEach(s=>s())},[a,p,U,x,q]),e.useEffect(()=>{const r=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const i=Q(n.authUrl);if(!i||s.origin!==i)return;const b=j.current[i];if(!(!b||b.status!=="interactive")){if(n.accessToken){H(z=>({...z,[i]:V({accessToken:n.accessToken})})),u(i);return}d(i)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[u,d]);const h=e.useCallback((r,s)=>{const n=r==null?void 0:r.origin,i=V(s);!n||!i||(H(b=>({...b,[n]:i})),u(n))},[u]),m=e.useCallback((r,s)=>{T(n=>n[r]?{...n,[r]:{...n[r],...s}}:n)},[]),E=e.useRef({}),y=e.useCallback(async(r,{approve:s}={})=>{const n=v.current,{origin:i}=r;let b;try{b=await n({origin:i,clientId:r.clientId,scope:r.scope,authUrl:r.authUrl},{approve:s})}catch{s?m(i,{error:{reason:"broker_unavailable"}}):m(i,{status:"interactive"});return}const z=b==null?void 0:b.status,f=(b==null?void 0:b.body)||{};if(z===200&&f.credential){h(r,f.credential);return}if(z===409&&f.consentRequired){m(i,{status:"interactive",consent:{client:f.client||null,stepUp:!!f.stepUp,scope:f.scope||r.scope},error:null});return}const P=f.error||"broker_error";if(!s&&Ce.has(P)){m(i,{status:"interactive"});return}if(s&&P==="consent_denied"){m(i,{error:null});return}if(P==="rate_limited"&&!r.rateLimitRetried){const N=Math.min(Number(f.retryAfter)>0?Number(f.retryAfter):ge,ke),Le={...r,rateLimitRetried:!0};D(i),I.current[i]=setTimeout(()=>{delete I.current[i],E.current[i]=!0,S.current(Le,{approve:s}).finally(()=>{delete E.current[i]})},N*1e3),m(i,{rateLimitRetried:!0});return}u(i),k(N=>({...N,[i]:{origin:i,reason:`broker:${P}`,detail:{status:z!=null?z:null,reason:P},clientId:r.clientId||$.current[i]||null}}))},[h,m,u,D]),S=e.useRef(y);S.current=y,e.useEffect(()=>{Object.values(w).forEach(r=>{r.status!=="broker"||E.current[r.origin]||I.current[r.origin]||(E.current[r.origin]=!0,y(r).finally(()=>{delete E.current[r.origin]}))})},[w,y]);const X=e.useCallback(r=>!v.current||!(r!=null&&r.consent)||E.current[r.origin]?Promise.resolve():(E.current[r.origin]=!0,y(r,{approve:!0}).finally(()=>{delete E.current[r.origin]})),[y]);e.useEffect(()=>()=>{_.current&&_.current(),Object.values(I.current).forEach(clearTimeout)},[]);const W=e.useCallback(r=>{_.current&&(_.current(),_.current=null);const s=o||ue;_.current=s(r,{onBlocked:()=>{T(n=>n[r.origin]?{...n,[r.origin]:{...n[r.origin],popupBlocked:!0}}:n)},onClosed:()=>{const n=j.current[r.origin];!n||n.v2||d(r.origin)}})},[o,d]),K={pending:Object.values(w).filter(r=>r.status==="interactive"),authorize:W,approve:X,complete:h,dismiss:l,originEpochs:F,credentials:Z,unsupported:M};return O.default.createElement(G.Provider,{value:K},t)};ie.propTypes={children:C.default.node,launcher:C.default.func,broker:C.default.func};const we=()=>e.useContext(G),ce=t=>{const{originEpochs:o}=e.useContext(G),c=Q(t);return c&&o[c]||0},le=t=>{const{credentials:o}=e.useContext(G),c=Q(t);return c&&o[c]||null},de=t=>{const{unsupported:o}=e.useContext(G),c=Q(t);return c&&o[c]||null},ae="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.",fe=({children:t,authorizationLauncher:o,credentialBroker:c,ready:a})=>{const w=a===!0,T=e.useRef(!1);e.useEffect(()=>{a!==void 0||T.current||(T.current=!0,console.error(ae),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ae))},[a]);const[F,B]=e.useState({}),[Z,H]=e.useState({}),M=e.useRef({}),k=e.useRef({}),L=e.useRef({}),j=e.useCallback((u,d)=>{var l;return!!((l=L.current[u])!=null&&l.has(d))},[]),_=e.useCallback((u,d,l)=>{B(p=>({...p,[u]:{origin:d,frameRef:l}}))},[]),$=e.useCallback(u=>{B(d=>{const l={...d};return delete l[u],l}),H(d=>{const l={...d};return delete l[u],l}),delete L.current[u],Object.keys(k.current).forEach(d=>{k.current[d].instanceId===u&&delete k.current[d]})},[]);e.useEffect(()=>()=>{k.current={}},[]),e.useEffect(()=>{const u=(l=[],p,h)=>{l.forEach(m=>m(p,h))},d=l=>{var X,W,K,r,s,n,i;if(!((X=l==null?void 0:l.data)!=null&&X.instanceId))return;const{instanceId:p,type:h}=l.data,m=F[p],E=(K=(W=m==null?void 0:m.frameRef)==null?void 0:W.current)==null?void 0:K.contentWindow;if(!E||l.source!==E||l.origin!==m.origin)return;const y={origin:l.origin},S=M.current;if(h==="response"){const{callbackId:b,response:z,error:f}=l.data,P=k.current[b];P&&P.instanceId===p&&(P.callback(z,f),delete k.current[b]);return}if(h==="mark-registered"){const{requestType:b}=l.data;L.current[p]||(L.current[p]=new Set),L.current[p].add(b);return}h==="ready"&&H(b=>({...b,[p]:!0})),u((r=S[p])==null?void 0:r[h],l.data,y),u((s=S["*"])==null?void 0:s[h],l.data,y),u((n=S[p])==null?void 0:n["*"],l.data,y),u((i=S["*"])==null?void 0:i["*"],l.data,y)};return window.addEventListener("message",d),()=>{window.removeEventListener("message",d)}},[F]);const A=e.useCallback((u,d,l,p)=>{var m,E;const h=F[u];if(!h){console.warn(`Origin not set for id: ${u}. Unable to send message.`);return}(E=(m=h==null?void 0:h.frameRef)==null?void 0:m.current)!=null&&E.contentWindow&&h.frameRef.current.contentWindow.postMessage({type:d,...l,instanceId:u},p||h.origin)},[F]),v=e.useRef(0),x=e.useCallback(()=>`${Date.now()}-${++v.current}`,[]),q=e.useCallback(async(u,d,l={})=>new Promise((p,h)=>{const m=x(),E=(y,S)=>{delete k.current[m],S?h(S):p(y)};k.current[m]={instanceId:u,callback:E},A(u,"request",{callbackId:m,requestType:d,data:l})}),[A]),U=e.useCallback((u,d)=>{A(u,"load-options",d)},[A]),I=e.useCallback((u,d)=>{A(u,"validate",d)},[A]),D=e.useMemo(()=>({registerFrame:_,unregisterFrame:$,sendMessage:A,sendRequest:q,loadOptions:U,validate:I,hasHandler:j,readyFrames:Z,ready:w,addListener:(u,d,l)=>(M.current[u]||(M.current[u]={}),M.current[u][d]||(M.current[u][d]=[]),M.current[u][d].push(l),()=>{M.current[u][d]=M.current[u][d].filter(p=>p!==l)})}),[_,$,A,q,U,I,j,Z,w]);return O.default.createElement(J.Provider,{value:D},O.default.createElement(ie,{launcher:o,broker:c},t))},Y=(t,o,c)=>{const a=e.useContext(J);if(a===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const w=e.useRef(c);e.useEffect(()=>{w.current=c},[c]),e.useEffect(()=>{if(!(!t||!o)){if(o.startsWith("key:")){const T=o.substring(4);return a.readyFrames[t]&&a.sendMessage(t,"subscribe-key",{keyChord:T}),a.addListener(t,`key-pressed:${T}`,(...B)=>w.current(...B))}return a.addListener(t,o,(...T)=>w.current(...T))}},[a,t,o])};fe.propTypes={children:C.default.node.isRequired,ready:C.default.bool.isRequired,authorizationLauncher:C.default.func,credentialBroker:C.default.func};const re=te.default.default||te.default,Te=1e4,_e="credentials",Ie=(t,o)=>`${t}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${_e}`,ye=re.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
@@ -22,4 +22,4 @@
|
|
|
22
22
|
flex: 1;
|
|
23
23
|
align-items: center;
|
|
24
24
|
justify-content: center;
|
|
25
|
-
`,Ae=()=>O.default.createElement(Se,null,O.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),he=({id:t,src:o,path:c,onInit:a=()=>{},onTimeout:w,context:T={},params:F={},renderUnsupported:B,renderTimeout:Z,...
|
|
25
|
+
`,Ae=()=>O.default.createElement(Se,null,O.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),he=({id:t,src:o,path:c,onInit:a=()=>{},onTimeout:w,context:T={},params:F={},renderUnsupported:B,renderTimeout:Z,...H})=>{if("isConfiguring"in H)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in T)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in T)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const M=e.useRef(),k=Q(o),[L,j]=e.useState(),[_,$]=e.useState(0),[A,v]=e.useState(!1),[x,q]=e.useState(!1),U=ce(o),I=le(o),D=de(o),[u,d]=e.useState(0),[l,p]=e.useState(null),{registerFrame:h,unregisterFrame:m,sendMessage:E,ready:y}=e.useContext(J),[S,X]=e.useState(),W=e.useRef(),K=e.useRef(w),r=e.useRef(a),s=e.useRef(!1),n=e.useRef(),i=e.useCallback(()=>{s.current=!1,clearTimeout(W.current),clearTimeout(n.current),$(0),v(!1),q(!1),p(null)},[]);e.useEffect(()=>{(U>0||u>0)&&i()},[U,u,i]),e.useEffect(()=>{K.current=w},[w]),e.useEffect(()=>{r.current=a},[a]),e.useEffect(()=>{_&&E(t,"set-context",{context:{...T}},k)},[T,t,_,k]),e.useEffect(()=>{_&&E(t,"set-params",{params:F},k)},[F,t,_,k]),e.useEffect(()=>{c!==void 0&&X((c==null?void 0:c.indexOf("/"))===0?c:`/${c}`)},[c]),e.useEffect(()=>{S===void 0||!_||E(t,"navigate",{path:S},k)},[S,_,t,E,k]),e.useEffect(()=>{if(!o||!t||!M)return;if(!y){i(),j(void 0);return}i();const f=new URL(o);return h(t,f.origin,M),r.current(),j(Ie(f.origin,t)),()=>{m(t)}},[o,t,y,h,M,i]),e.useEffect(()=>{if(!(!L||s.current))return W.current=setTimeout(()=>{v(!0),K.current&&K.current()},Te),()=>clearTimeout(W.current)},[L,o,U,u]);const b=e.useCallback(()=>{s.current=!0,clearTimeout(W.current),v(!1)},[]);if(Y(t,"init",f=>{b(),Array.isArray(f==null?void 0:f.acceptsCredentials)&&p(f.acceptsCredentials)}),Y(t,"authorize",b),Y(t,"login",b),Y(t,"credential-request",()=>{b(),q(!0)}),e.useEffect(()=>{if(!x||!I)return;const f=l;if(Array.isArray(f)&&!f.includes(I.kind))return;const P=I.kind==="access_token"?{accessToken:I.accessToken}:{};E(t,"credential",{...P,credential:I},k)},[x,I,l,t,E,k]),Y(t,"ready",()=>{b(),$(f=>f+1)}),Y(t,"heartbeat",()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{d(f=>f+1)},6e3)}),e.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]),D)return B?B(D):O.default.createElement(be,{entry:D});if(A&&!_)return Z?Z():O.default.createElement(Ae,null);const z={...H};return delete z.skipManifestCheck,O.default.createElement(ye,{key:`auth-epoch-${U}-frame-${u}`,$isReady:_,ref:M,src:L,...z})};he.propTypes={id:C.default.string,src:C.default.string.isRequired,path:C.default.string,onInit:C.default.func,onTimeout:C.default.func,renderUnsupported:C.default.func,renderTimeout:C.default.func},g.CREDENTIAL_KIND_ACCESS_TOKEN=ne,g.EmbeddedAuthorizationContext=G,g.MMEmbeddableZone=he,g.MMEmbeddableZoneContext=J,g.MMEmbeddableZoneProvider=fe,g.isCrossSite=ee,g.normalizeCredential=V,g.popupAuthorizationLauncher=ue,g.unsupportedCopy=pe,g.useEmbeddedAuthorizations=we,g.useEmbeddedCredential=le,g.useEmbeddedEffect=Y,g.useEmbeddedOriginEpoch=ce,g.useEmbeddedUnsupported=de,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|