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