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