@machinemetrics/mm-react-embeddable 1.4.0-2 → 1.4.0-3
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"),h=require("prop-types"),j=require("styled-components"),B=e.createContext(null),Z=e.createContext({pending:[],authorize:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ee=2e4,P=r=>{try{return new URL(r).origin}catch{return null}},W=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const u=r.split(".");return u.length<=2?r:u.slice(-2).join(".")},D=(r,u)=>{try{const i=new URL(r),d=new URL(u);return i.protocol!==d.protocol?!0:W(i.hostname)!==W(d.hostname)}catch{return!0}},H=(r,{onBlocked:u,onClosed:i})=>{const d=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!d)return u(),()=>{};const m=setInterval(()=>{d.closed&&(clearInterval(m),i())},1e3);return()=>clearInterval(m)},K=({children:r,launcher:u})=>{const i=e.useContext(B),[d,m]=e.useState({}),[E,R]=e.useState({}),[x,M]=e.useState({}),[$,w]=e.useState({}),S=e.useRef(x);S.current=x;const g=e.useRef(null),k=e.useRef({}),I=e.useRef({}),C=e.useCallback(t=>{const n=I.current[t];if(!n)return;const s=f=>!f[t]||f[t].clientId?f:{...f,[t]:{...f[t],clientId:n}};m(s),w(s)},[]),O=e.useCallback((t,n)=>{const s=P(t==null?void 0:t.authUrl);s&&(w(f=>f[s]?f:{...f,[s]:{origin:s,reason:n,clientId:I.current[s]||null}}),C(s))},[C]),z=e.useCallback((t,{v2:n=!1}={})=>{const s=P(t==null?void 0:t.authUrl);s&&(n&&S.current[s]||(m(f=>f[s]?f:{...f,[s]:{origin:s,authUrl:t.authUrl,silentUrl:t.silentUrl||null,status:n&&t.silentUrl?"silent":"interactive",v2:n,clientId:t.clientId||I.current[s]||null,popupBlocked:!1}}),C(s)))},[C]),y=e.useCallback(t=>{m(n=>{if(!n[t])return n;const s={...n};return delete s[t],s})},[]),o=e.useCallback(t=>{t&&(y(t),R(n=>({...n,[t]:(n[t]||0)+1})))},[y]),l=e.useCallback(t=>{m(n=>!n[t]||n[t].status==="interactive"?n:{...n,[t]:{...n[t],status:"interactive"}})},[]),c=e.useCallback(t=>{y(t.origin)},[y]),a=e.useCallback(t=>{const n=P(t==null?void 0:t.authUrl);if(n&&D(n,window.location.origin)){O(t,"cross-site-legacy");return}z(t)},[z,O]);e.useEffect(()=>{if(!i)return;const t=[i.addListener("*","init",n=>{n!=null&&n.origin&&n.clientId&&(I.current[n.origin]=n.clientId,C(n.origin))}),i.addListener("*","authorize",a),i.addListener("*","login",a),i.addListener("*","credential-request",n=>z(n,{v2:!0})),i.addListener("*","authorized",n=>{n!=null&&n.accessToken||o(P(n==null?void 0:n.authUrl))})];return()=>t.forEach(n=>n())},[i,a,z,o,C]),e.useEffect(()=>{const t=n=>{const s=n==null?void 0:n.data;if(!s||s.type!=="authorized"&&s.type!=="authorize-failed")return;const f=P(s.authUrl);if(!(!f||n.origin!==f)){if(s.type==="authorized"&&s.accessToken){M(T=>({...T,[f]:{accessToken:s.accessToken}})),y(f);return}s.type==="authorize-failed"&&l(f)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[y,l]),e.useEffect(()=>{const t=k.current;Object.values(d).forEach(n=>{n.status==="silent"&&!t[n.origin]&&(t[n.origin]=setTimeout(()=>{delete t[n.origin],l(n.origin)},ee))}),Object.keys(t).forEach(n=>{(!d[n]||d[n].status!=="silent")&&(clearTimeout(t[n]),delete t[n])})},[d,l]),e.useEffect(()=>()=>{g.current&&g.current(),Object.values(k.current).forEach(clearTimeout)},[]);const b=e.useCallback(t=>{g.current&&(g.current(),g.current=null);const n=u||H;g.current=n(t,{onBlocked:()=>{m(s=>s[t.origin]?{...s,[t.origin]:{...s[t.origin],popupBlocked:!0}}:s)},onClosed:()=>{if(t.v2){m(s=>!s[t.origin]||!s[t.origin].silentUrl?s:{...s,[t.origin]:{...s[t.origin],status:"silent"}});return}o(t.origin)}})},[u,o]),p={pending:Object.values(d).filter(t=>t.status==="interactive"),authorize:b,dismiss:c,originEpochs:E,credentials:x,unsupported:$},U=Object.values(d).filter(t=>t.status==="silent"&&t.silentUrl);return e.createElement(Z.Provider,{value:p},r,U.map(t=>e.createElement("iframe",{key:`mm-silent-auth-${t.origin}`,src:t.silentUrl,title:`MachineMetrics silent authorization (${t.origin})`,"aria-hidden":"true",tabIndex:-1,style:{display:"none"}})))};K.propTypes={children:h.node,launcher:h.func};const V=()=>e.useContext(Z),G=r=>{const{originEpochs:u}=e.useContext(Z),i=P(r);return i&&u[i]||0},J=r=>{const{credentials:u}=e.useContext(Z),i=P(r);return i&&u[i]||null},Q=r=>{const{unsupported:u}=e.useContext(Z),i=P(r);return i&&u[i]||null},X=({children:r,authorizationLauncher:u})=>{const[i,d]=e.useState({}),[m,E]=e.useState({}),R=e.useRef({}),x=e.useRef({}),M=e.useRef({}),$=e.useCallback((o,l)=>{var c;return!!((c=M.current[o])!=null&&c.has(l))},[]),w=e.useCallback((o,l,c)=>{d(a=>({...a,[o]:{origin:l,frameRef:c}}))},[]),S=e.useCallback(o=>{d(l=>{const c={...l};return delete c[o],c}),E(l=>{const c={...l};return delete c[o],c}),delete M.current[o]},[]);e.useEffect(()=>{const o=(c=[],a)=>{c.forEach(b=>b(a))},l=c=>{var U,t,n,s,f;if(!((U=c==null?void 0:c.data)!=null&&U.instanceId))return;const{instanceId:a,type:b}=c.data,p=R.current;if(b==="response"){const{callbackId:T,response:A,error:F}=c.data,L=x.current[T];L&&(L(A,F),delete x.current[T]);return}if(b==="mark-registered"){const{requestType:T}=c.data;M.current[a]||(M.current[a]=new Set),M.current[a].add(T);return}b==="ready"&&E(T=>({...T,[a]:!0})),o((t=p[a])==null?void 0:t[b],c.data),o((n=p["*"])==null?void 0:n[b],c.data),o((s=p[a])==null?void 0:s["*"],c.data),o((f=p["*"])==null?void 0:f["*"],c.data)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[i]);const g=e.useCallback((o,l,c)=>{var b,p;const a=i[o];if(!a){console.warn(`Origin not set for id: ${o}. Unable to send message.`);return}(p=(b=a==null?void 0:a.frameRef)==null?void 0:b.current)!=null&&p.contentWindow&&a.frameRef.current.contentWindow.postMessage({type:l,...c,instanceId:o},a.origin)},[i]),k=e.useRef(0),I=e.useCallback(()=>`${Date.now()}-${++k.current}`,[]),C=e.useCallback(async(o,l,c={})=>new Promise((a,b)=>{const p=I(),U=(t,n)=>{delete x.current[p],n?b(n):a(t)};x.current[p]=U,g(o,"request",{callbackId:p,requestType:l,data:c})}),[g]),O=e.useCallback((o,l)=>{g(o,"load-options",l)},[g]),z=e.useCallback((o,l)=>{g(o,"validate",l)},[g]),y=e.useMemo(()=>({registerFrame:w,unregisterFrame:S,sendMessage:g,sendRequest:C,loadOptions:O,validate:z,hasHandler:$,readyFrames:m,addListener:(o,l,c)=>(R.current[o]||(R.current[o]={}),R.current[o][l]||(R.current[o][l]=[]),R.current[o][l].push(c),()=>{R.current[o][l]=R.current[o][l].filter(a=>a!==c)})}),[w,S,g,C,O,z,$,m]);return e.createElement(B.Provider,{value:y},e.createElement(K,{launcher:u},r))},q=(r,u,i)=>{const d=e.useContext(B);if(d===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const m=e.useRef(i);e.useEffect(()=>{m.current=i},[i]),e.useEffect(()=>{if(!(!r||!u)){if(u.startsWith("key:")){const E=u.substring(4);return d.readyFrames[r]&&d.sendMessage(r,"subscribe-key",{keyChord:E}),d.addListener(r,`key-pressed:${E}`,(...x)=>m.current(...x))}return d.addListener(r,u,(...E)=>m.current(...E))}},[d,r,u])};X.propTypes={children:h.node.isRequired,authorizationLauncher:h.func};const v=j.default||j,te=1e4,ne="credentials",_=(r,u)=>`${r}/mm-embedded-interop?id=${u}&origin=${window.location.origin}&caps=${ne}`,re=v.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
text-align: center;
|
|
17
17
|
color: #555;
|
|
18
18
|
font-size: 14px;
|
|
19
|
-
`,Y=({entry:r})=>e.createElement(se,null,e.createElement("div",{style:{fontWeight:600}},r&&r.origin||"This app"," can’t be embedded here"),e.createElement("div",{style:{fontSize:12,color:"#888"}},"It needs an update to support embedding from a different domain."));Y.propTypes={entry:
|
|
19
|
+
`,Y=({entry:r})=>e.createElement(se,null,e.createElement("div",{style:{fontWeight:600}},r&&r.origin||"This app"," can’t be embedded here"),e.createElement("div",{style:{fontSize:12,color:"#888"}},"It needs an update to support embedding from a different domain."));Y.propTypes={entry:h.shape({origin:h.string,name:h.string,reason:h.string})};const ie=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
|
-
`,oe=()=>e.createElement(ie,null,e.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),N=({id:r,src:
|
|
25
|
+
`,oe=()=>e.createElement(ie,null,e.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),N=({id:r,src:u,path:i,onInit:d=()=>{},onTimeout:m,context:E={},params:R={},renderUnsupported:x,renderTimeout:M,...$})=>{if("isConfiguring"in $)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 w=e.useRef(),[S,g]=e.useState(),[k,I]=e.useState(0),[C,O]=e.useState(!1),[z,y]=e.useState(!1),o=G(u),l=J(u),c=Q(u);e.useEffect(()=>{o>0&&I(0)},[o]);const{registerFrame:a,unregisterFrame:b,sendMessage:p}=e.useContext(B),[U,t]=e.useState(),n=e.useRef(),s=e.useRef(m),f=e.useRef(d),T=e.useRef(!1);e.useEffect(()=>{s.current=m},[m]),e.useEffect(()=>{f.current=d},[d]),e.useEffect(()=>{k&&p(r,"set-context",{context:{...E}})},[E,r,k]),e.useEffect(()=>{k&&p(r,"set-params",{params:R})},[R,r,k]),e.useEffect(()=>{i!==void 0&&t((i==null?void 0:i.indexOf("/"))===0?i:`/${i}`)},[i]),e.useEffect(()=>{U===void 0||!k||p(r,"navigate",{path:U})},[U,k,r,p]),e.useEffect(()=>{if(!u||!r||!w)return;const L=new URL(u);return a(r,L.origin,w),f.current(),g(_(L.origin,r)),()=>{b(r)}},[u,r,a,w]),e.useEffect(()=>{if(!(!S||T.current))return n.current=setTimeout(()=>{O(!0),s.current&&s.current()},te),()=>clearTimeout(n.current)},[S]);const A=e.useCallback(()=>{T.current=!0,clearTimeout(n.current),O(!1)},[]);q(r,"init",A),q(r,"authorize",A),q(r,"login",A),q(r,"credential-request",()=>{A(),y(!0)}),e.useEffect(()=>{!z||!l||p(r,"credential",{accessToken:l.accessToken})},[z,l,r,p]),q(r,"ready",()=>{A(),I(L=>L+1)});const F=e.useRef();return q(r,"heartbeat",()=>{F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{if(w.current){const L=new URL(u);w.current.src=_(L.origin,r)}},6e3)}),e.useEffect(()=>()=>{F.current&&clearTimeout(F.current)},[]),c?x?x(c):e.createElement(Y,{entry:c}):C&&!k?M?M():e.createElement(oe,null):e.createElement(re,{key:`auth-epoch-${o}`,$isReady:k,ref:w,src:S,...$})};N.propTypes={id:h.string,src:h.string.isRequired,path:h.string,onInit:h.func,onTimeout:h.func,renderUnsupported:h.func,renderTimeout:h.func};const ue=j.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
|
+
`,ce=j.div`
|
|
34
34
|
background: #fff;
|
|
35
35
|
border-radius: 8px;
|
|
36
36
|
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
|
|
@@ -58,4 +58,4 @@
|
|
|
58
58
|
color: #b3261e;
|
|
59
59
|
font-size: 13px;
|
|
60
60
|
margin: 4px 0 0;
|
|
61
|
-
`,fe=()=>{const{pending:r,authorize:
|
|
61
|
+
`,fe=()=>{const{pending:r,authorize:u}=V();return r.length===0?null:e.createElement(ue,null,e.createElement(ce,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(i=>e.createElement("div",{key:i.origin},e.createElement(le,null,e.createElement("div",null,e.createElement("div",{style:{fontWeight:600}},i.origin)),e.createElement(ae,{onClick:()=>u(i)},"Authorize")),i.popupBlocked&&e.createElement(de,null,"The sign-in window was blocked. Allow popups for this site, then try again.")))))};exports.EmbeddedAuthorizationContext=Z;exports.EmbeddedAuthorizationPrompt=fe;exports.MMEmbeddableZone=N;exports.MMEmbeddableZoneContext=B;exports.MMEmbeddableZoneProvider=X;exports.isCrossSite=D;exports.popupAuthorizationLauncher=H;exports.useEmbeddedAuthorizations=V;exports.useEmbeddedCredential=J;exports.useEmbeddedEffect=q;exports.useEmbeddedOriginEpoch=G;exports.useEmbeddedUnsupported=Q;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import f, { createContext as J, useContext as _, useState as I, useRef as
|
|
2
|
-
import
|
|
1
|
+
import f, { createContext as J, useContext as _, useState as I, useRef as x, useCallback as h, useEffect as g, useMemo as Y } from "react";
|
|
2
|
+
import w from "prop-types";
|
|
3
3
|
import Z from "styled-components";
|
|
4
4
|
const H = J(null), D = J({
|
|
5
5
|
pending: [],
|
|
@@ -23,12 +23,12 @@ const H = J(null), D = J({
|
|
|
23
23
|
return o.length <= 2 ? n : o.slice(-2).join(".");
|
|
24
24
|
}, ee = (n, o) => {
|
|
25
25
|
try {
|
|
26
|
-
const
|
|
27
|
-
return
|
|
26
|
+
const s = new URL(n), a = new URL(o);
|
|
27
|
+
return s.protocol !== a.protocol ? !0 : V(s.hostname) !== V(a.hostname);
|
|
28
28
|
} catch {
|
|
29
29
|
return !0;
|
|
30
30
|
}
|
|
31
|
-
}, te = (n, { onBlocked: o, onClosed:
|
|
31
|
+
}, te = (n, { onBlocked: o, onClosed: s }) => {
|
|
32
32
|
const a = window.open(
|
|
33
33
|
n.authUrl,
|
|
34
34
|
"mm-embed-auth",
|
|
@@ -38,31 +38,31 @@ const H = J(null), D = J({
|
|
|
38
38
|
return o(), () => {
|
|
39
39
|
};
|
|
40
40
|
const m = setInterval(() => {
|
|
41
|
-
a.closed && (clearInterval(m),
|
|
41
|
+
a.closed && (clearInterval(m), s());
|
|
42
42
|
}, 1e3);
|
|
43
43
|
return () => clearInterval(m);
|
|
44
44
|
}, Q = ({ children: n, launcher: o }) => {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const t =
|
|
45
|
+
const s = _(H), [a, m] = I({}), [R, T] = I({}), [k, L] = I({}), [q, y] = I({}), F = x(k);
|
|
46
|
+
F.current = k;
|
|
47
|
+
const b = x(null), U = x({}), P = x({}), z = h((e) => {
|
|
48
|
+
const t = P.current[e];
|
|
49
49
|
if (!t)
|
|
50
50
|
return;
|
|
51
51
|
const r = (d) => !d[e] || d[e].clientId ? d : { ...d, [e]: { ...d[e], clientId: t } };
|
|
52
|
-
m(r),
|
|
53
|
-
}, []), A =
|
|
52
|
+
m(r), y(r);
|
|
53
|
+
}, []), A = h(
|
|
54
54
|
(e, t) => {
|
|
55
55
|
const r = j(e == null ? void 0 : e.authUrl);
|
|
56
|
-
r && (
|
|
56
|
+
r && (y((d) => d[r] ? d : {
|
|
57
57
|
...d,
|
|
58
|
-
[r]: { origin: r, reason: t, clientId:
|
|
59
|
-
}),
|
|
58
|
+
[r]: { origin: r, reason: t, clientId: P.current[r] || null }
|
|
59
|
+
}), z(r));
|
|
60
60
|
},
|
|
61
|
-
[
|
|
62
|
-
),
|
|
61
|
+
[z]
|
|
62
|
+
), O = h(
|
|
63
63
|
(e, { v2: t = !1 } = {}) => {
|
|
64
64
|
const r = j(e == null ? void 0 : e.authUrl);
|
|
65
|
-
r && (t &&
|
|
65
|
+
r && (t && F.current[r] || (m((d) => d[r] ? d : {
|
|
66
66
|
...d,
|
|
67
67
|
[r]: {
|
|
68
68
|
origin: r,
|
|
@@ -74,50 +74,50 @@ const H = J(null), D = J({
|
|
|
74
74
|
v2: t,
|
|
75
75
|
// clientId from the request payload (v2) or the cached init (legacy);
|
|
76
76
|
// the host resolves the display name from it.
|
|
77
|
-
clientId: e.clientId ||
|
|
77
|
+
clientId: e.clientId || P.current[r] || null,
|
|
78
78
|
popupBlocked: !1
|
|
79
79
|
}
|
|
80
|
-
}),
|
|
80
|
+
}), z(r)));
|
|
81
81
|
},
|
|
82
|
-
[
|
|
83
|
-
),
|
|
82
|
+
[z]
|
|
83
|
+
), C = h((e) => {
|
|
84
84
|
m((t) => {
|
|
85
85
|
if (!t[e])
|
|
86
86
|
return t;
|
|
87
87
|
const r = { ...t };
|
|
88
88
|
return delete r[e], r;
|
|
89
89
|
});
|
|
90
|
-
}, []),
|
|
90
|
+
}, []), i = h(
|
|
91
91
|
(e) => {
|
|
92
|
-
e && (
|
|
92
|
+
e && (C(e), T((t) => ({
|
|
93
93
|
...t,
|
|
94
94
|
[e]: (t[e] || 0) + 1
|
|
95
95
|
})));
|
|
96
96
|
},
|
|
97
|
-
[
|
|
98
|
-
), u =
|
|
97
|
+
[C]
|
|
98
|
+
), u = h((e) => {
|
|
99
99
|
m((t) => !t[e] || t[e].status === "interactive" ? t : {
|
|
100
100
|
...t,
|
|
101
101
|
[e]: { ...t[e], status: "interactive" }
|
|
102
102
|
});
|
|
103
|
-
}, []), c =
|
|
103
|
+
}, []), c = h(
|
|
104
104
|
(e) => {
|
|
105
|
-
|
|
105
|
+
C(e.origin);
|
|
106
106
|
},
|
|
107
|
-
[
|
|
108
|
-
), l =
|
|
107
|
+
[C]
|
|
108
|
+
), l = h(
|
|
109
109
|
(e) => {
|
|
110
110
|
const t = j(e == null ? void 0 : e.authUrl);
|
|
111
111
|
if (t && ee(t, window.location.origin)) {
|
|
112
112
|
A(e, "cross-site-legacy");
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
O(e);
|
|
116
116
|
},
|
|
117
|
-
[
|
|
117
|
+
[O, A]
|
|
118
118
|
);
|
|
119
|
-
|
|
120
|
-
if (!
|
|
119
|
+
g(() => {
|
|
120
|
+
if (!s)
|
|
121
121
|
return;
|
|
122
122
|
const e = [
|
|
123
123
|
// `init` carries the app's OAuth clientId. Cache it by app origin and
|
|
@@ -125,22 +125,22 @@ const H = J(null), D = J({
|
|
|
125
125
|
// authorize/login/credential-request signals, so it is usually cached by
|
|
126
126
|
// the time an entry is created. The host resolves the display name from
|
|
127
127
|
// the clientId.
|
|
128
|
-
|
|
129
|
-
t != null && t.origin && t.clientId && (
|
|
128
|
+
s.addListener("*", "init", (t) => {
|
|
129
|
+
t != null && t.origin && t.clientId && (P.current[t.origin] = t.clientId, z(t.origin));
|
|
130
130
|
}),
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
s.addListener("*", "authorize", l),
|
|
132
|
+
s.addListener("*", "login", l),
|
|
133
|
+
s.addListener(
|
|
134
134
|
"*",
|
|
135
135
|
"credential-request",
|
|
136
|
-
(t) =>
|
|
136
|
+
(t) => O(t, { v2: !0 })
|
|
137
137
|
),
|
|
138
|
-
|
|
139
|
-
t != null && t.accessToken ||
|
|
138
|
+
s.addListener("*", "authorized", (t) => {
|
|
139
|
+
t != null && t.accessToken || i(j(t == null ? void 0 : t.authUrl));
|
|
140
140
|
})
|
|
141
141
|
];
|
|
142
142
|
return () => e.forEach((t) => t());
|
|
143
|
-
}, [
|
|
143
|
+
}, [s, l, O, i, z]), g(() => {
|
|
144
144
|
const e = (t) => {
|
|
145
145
|
const r = t == null ? void 0 : t.data;
|
|
146
146
|
if (!r || r.type !== "authorized" && r.type !== "authorize-failed")
|
|
@@ -148,18 +148,18 @@ const H = J(null), D = J({
|
|
|
148
148
|
const d = j(r.authUrl);
|
|
149
149
|
if (!(!d || t.origin !== d)) {
|
|
150
150
|
if (r.type === "authorized" && r.accessToken) {
|
|
151
|
-
L((
|
|
152
|
-
...
|
|
151
|
+
L((M) => ({
|
|
152
|
+
...M,
|
|
153
153
|
[d]: { accessToken: r.accessToken }
|
|
154
|
-
})),
|
|
154
|
+
})), C(d);
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
157
|
r.type === "authorize-failed" && u(d);
|
|
158
158
|
}
|
|
159
159
|
};
|
|
160
160
|
return window.addEventListener("message", e), () => window.removeEventListener("message", e);
|
|
161
|
-
}, [
|
|
162
|
-
const e =
|
|
161
|
+
}, [C, u]), g(() => {
|
|
162
|
+
const e = U.current;
|
|
163
163
|
Object.values(a).forEach((t) => {
|
|
164
164
|
t.status === "silent" && !e[t.origin] && (e[t.origin] = setTimeout(() => {
|
|
165
165
|
delete e[t.origin], u(t.origin);
|
|
@@ -167,14 +167,14 @@ const H = J(null), D = J({
|
|
|
167
167
|
}), Object.keys(e).forEach((t) => {
|
|
168
168
|
(!a[t] || a[t].status !== "silent") && (clearTimeout(e[t]), delete e[t]);
|
|
169
169
|
});
|
|
170
|
-
}, [a, u]),
|
|
171
|
-
|
|
170
|
+
}, [a, u]), g(() => () => {
|
|
171
|
+
b.current && b.current(), Object.values(U.current).forEach(clearTimeout);
|
|
172
172
|
}, []);
|
|
173
|
-
const
|
|
173
|
+
const E = h(
|
|
174
174
|
(e) => {
|
|
175
|
-
|
|
175
|
+
b.current && (b.current(), b.current = null);
|
|
176
176
|
const t = o || te;
|
|
177
|
-
|
|
177
|
+
b.current = t(e, {
|
|
178
178
|
onBlocked: () => {
|
|
179
179
|
m((r) => r[e.origin] ? {
|
|
180
180
|
...r,
|
|
@@ -189,26 +189,26 @@ const H = J(null), D = J({
|
|
|
189
189
|
});
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
|
-
|
|
192
|
+
i(e.origin);
|
|
193
193
|
}
|
|
194
194
|
});
|
|
195
195
|
},
|
|
196
|
-
[o,
|
|
197
|
-
),
|
|
196
|
+
[o, i]
|
|
197
|
+
), p = {
|
|
198
198
|
// Hosts render UI for interactive entries only; silent resolution is
|
|
199
199
|
// invisible by design.
|
|
200
200
|
pending: Object.values(a).filter(
|
|
201
201
|
(e) => e.status === "interactive"
|
|
202
202
|
),
|
|
203
|
-
authorize:
|
|
203
|
+
authorize: E,
|
|
204
204
|
dismiss: c,
|
|
205
|
-
originEpochs:
|
|
206
|
-
credentials:
|
|
205
|
+
originEpochs: R,
|
|
206
|
+
credentials: k,
|
|
207
207
|
unsupported: q
|
|
208
|
-
},
|
|
208
|
+
}, $ = Object.values(a).filter(
|
|
209
209
|
(e) => e.status === "silent" && e.silentUrl
|
|
210
210
|
);
|
|
211
|
-
return /* @__PURE__ */ f.createElement(D.Provider, { value:
|
|
211
|
+
return /* @__PURE__ */ f.createElement(D.Provider, { value: p }, n, $.map((e) => /* @__PURE__ */ f.createElement(
|
|
212
212
|
"iframe",
|
|
213
213
|
{
|
|
214
214
|
key: `mm-silent-auth-${e.origin}`,
|
|
@@ -221,151 +221,151 @@ const H = J(null), D = J({
|
|
|
221
221
|
)));
|
|
222
222
|
};
|
|
223
223
|
Q.propTypes = {
|
|
224
|
-
children:
|
|
225
|
-
launcher:
|
|
224
|
+
children: w.node,
|
|
225
|
+
launcher: w.func
|
|
226
226
|
};
|
|
227
227
|
const ne = () => _(D), re = (n) => {
|
|
228
|
-
const { originEpochs: o } = _(D),
|
|
229
|
-
return
|
|
230
|
-
}, ie = (n) => {
|
|
231
|
-
const { credentials: o } = _(D), i = j(n);
|
|
232
|
-
return i && o[i] || null;
|
|
228
|
+
const { originEpochs: o } = _(D), s = j(n);
|
|
229
|
+
return s && o[s] || 0;
|
|
233
230
|
}, se = (n) => {
|
|
234
|
-
const {
|
|
235
|
-
return
|
|
231
|
+
const { credentials: o } = _(D), s = j(n);
|
|
232
|
+
return s && o[s] || null;
|
|
233
|
+
}, ie = (n) => {
|
|
234
|
+
const { unsupported: o } = _(D), s = j(n);
|
|
235
|
+
return s && o[s] || null;
|
|
236
236
|
}, oe = ({ children: n, authorizationLauncher: o }) => {
|
|
237
|
-
const [
|
|
237
|
+
const [s, a] = I({}), [m, R] = I({}), T = x({}), k = x({}), L = x({}), q = h((i, u) => {
|
|
238
238
|
var c;
|
|
239
|
-
return !!((c = L.current[
|
|
240
|
-
}, []),
|
|
241
|
-
a((l) => ({ ...l, [
|
|
242
|
-
}, []),
|
|
239
|
+
return !!((c = L.current[i]) != null && c.has(u));
|
|
240
|
+
}, []), y = h((i, u, c) => {
|
|
241
|
+
a((l) => ({ ...l, [i]: { origin: u, frameRef: c } }));
|
|
242
|
+
}, []), F = h((i) => {
|
|
243
243
|
a((u) => {
|
|
244
244
|
const c = { ...u };
|
|
245
|
-
return delete c[
|
|
246
|
-
}),
|
|
245
|
+
return delete c[i], c;
|
|
246
|
+
}), R((u) => {
|
|
247
247
|
const c = { ...u };
|
|
248
|
-
return delete c[
|
|
249
|
-
}), delete L.current[
|
|
248
|
+
return delete c[i], c;
|
|
249
|
+
}), delete L.current[i];
|
|
250
250
|
}, []);
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
c.forEach((
|
|
251
|
+
g(() => {
|
|
252
|
+
const i = (c = [], l) => {
|
|
253
|
+
c.forEach((E) => E(l));
|
|
254
254
|
}, u = (c) => {
|
|
255
|
-
var
|
|
256
|
-
if (!((
|
|
255
|
+
var $, e, t, r, d;
|
|
256
|
+
if (!(($ = c == null ? void 0 : c.data) != null && $.instanceId))
|
|
257
257
|
return;
|
|
258
|
-
const { instanceId: l, type:
|
|
259
|
-
if (
|
|
260
|
-
const { callbackId:
|
|
261
|
-
|
|
258
|
+
const { instanceId: l, type: E } = c.data, p = T.current;
|
|
259
|
+
if (E === "response") {
|
|
260
|
+
const { callbackId: M, response: B, error: W } = c.data, S = k.current[M];
|
|
261
|
+
S && (S(B, W), delete k.current[M]);
|
|
262
262
|
return;
|
|
263
263
|
}
|
|
264
|
-
if (
|
|
265
|
-
const { requestType:
|
|
266
|
-
L.current[l] || (L.current[l] = /* @__PURE__ */ new Set()), L.current[l].add(
|
|
264
|
+
if (E === "mark-registered") {
|
|
265
|
+
const { requestType: M } = c.data;
|
|
266
|
+
L.current[l] || (L.current[l] = /* @__PURE__ */ new Set()), L.current[l].add(M);
|
|
267
267
|
return;
|
|
268
268
|
}
|
|
269
|
-
|
|
269
|
+
E === "ready" && R((M) => ({ ...M, [l]: !0 })), i((e = p[l]) == null ? void 0 : e[E], c.data), i((t = p["*"]) == null ? void 0 : t[E], c.data), i((r = p[l]) == null ? void 0 : r["*"], c.data), i((d = p["*"]) == null ? void 0 : d["*"], c.data);
|
|
270
270
|
};
|
|
271
271
|
return window.addEventListener("message", u), () => {
|
|
272
272
|
window.removeEventListener("message", u);
|
|
273
273
|
};
|
|
274
|
-
}, [
|
|
275
|
-
const
|
|
276
|
-
(
|
|
277
|
-
var
|
|
278
|
-
const l = i
|
|
274
|
+
}, [s]);
|
|
275
|
+
const b = h(
|
|
276
|
+
(i, u, c) => {
|
|
277
|
+
var E, p;
|
|
278
|
+
const l = s[i];
|
|
279
279
|
if (!l) {
|
|
280
|
-
console.warn(`Origin not set for id: ${
|
|
280
|
+
console.warn(`Origin not set for id: ${i}. Unable to send message.`);
|
|
281
281
|
return;
|
|
282
282
|
}
|
|
283
|
-
(
|
|
284
|
-
{ type: u, ...c, instanceId:
|
|
283
|
+
(p = (E = l == null ? void 0 : l.frameRef) == null ? void 0 : E.current) != null && p.contentWindow && l.frameRef.current.contentWindow.postMessage(
|
|
284
|
+
{ type: u, ...c, instanceId: i },
|
|
285
285
|
l.origin
|
|
286
286
|
);
|
|
287
287
|
},
|
|
288
|
-
[
|
|
289
|
-
),
|
|
290
|
-
async (
|
|
291
|
-
const
|
|
292
|
-
delete
|
|
288
|
+
[s]
|
|
289
|
+
), U = x(0), P = h(() => `${Date.now()}-${++U.current}`, []), z = h(
|
|
290
|
+
async (i, u, c = {}) => new Promise((l, E) => {
|
|
291
|
+
const p = P(), $ = (e, t) => {
|
|
292
|
+
delete k.current[p], t ? E(t) : l(e);
|
|
293
293
|
};
|
|
294
|
-
|
|
294
|
+
k.current[p] = $, b(i, "request", { callbackId: p, requestType: u, data: c });
|
|
295
295
|
}),
|
|
296
|
-
[
|
|
297
|
-
), A =
|
|
298
|
-
(
|
|
299
|
-
|
|
296
|
+
[b]
|
|
297
|
+
), A = h(
|
|
298
|
+
(i, u) => {
|
|
299
|
+
b(i, "load-options", u);
|
|
300
300
|
},
|
|
301
|
-
[
|
|
302
|
-
),
|
|
303
|
-
(
|
|
304
|
-
|
|
301
|
+
[b]
|
|
302
|
+
), O = h(
|
|
303
|
+
(i, u) => {
|
|
304
|
+
b(i, "validate", u);
|
|
305
305
|
},
|
|
306
|
-
[
|
|
307
|
-
),
|
|
306
|
+
[b]
|
|
307
|
+
), C = Y(
|
|
308
308
|
() => ({
|
|
309
|
-
registerFrame:
|
|
310
|
-
unregisterFrame:
|
|
311
|
-
sendMessage:
|
|
312
|
-
sendRequest:
|
|
309
|
+
registerFrame: y,
|
|
310
|
+
unregisterFrame: F,
|
|
311
|
+
sendMessage: b,
|
|
312
|
+
sendRequest: z,
|
|
313
313
|
loadOptions: A,
|
|
314
|
-
validate:
|
|
314
|
+
validate: O,
|
|
315
315
|
hasHandler: q,
|
|
316
316
|
readyFrames: m,
|
|
317
|
-
addListener: (
|
|
318
|
-
|
|
317
|
+
addListener: (i, u, c) => (T.current[i] || (T.current[i] = {}), T.current[i][u] || (T.current[i][u] = []), T.current[i][u].push(c), () => {
|
|
318
|
+
T.current[i][u] = T.current[i][u].filter((l) => l !== c);
|
|
319
319
|
})
|
|
320
320
|
}),
|
|
321
321
|
[
|
|
322
|
-
U,
|
|
323
|
-
S,
|
|
324
|
-
E,
|
|
325
322
|
y,
|
|
323
|
+
F,
|
|
324
|
+
b,
|
|
325
|
+
z,
|
|
326
326
|
A,
|
|
327
|
-
|
|
327
|
+
O,
|
|
328
328
|
q,
|
|
329
329
|
m
|
|
330
330
|
]
|
|
331
331
|
);
|
|
332
|
-
return /* @__PURE__ */ f.createElement(H.Provider, { value:
|
|
333
|
-
}, v = (n, o,
|
|
332
|
+
return /* @__PURE__ */ f.createElement(H.Provider, { value: C }, /* @__PURE__ */ f.createElement(Q, { launcher: o }, n));
|
|
333
|
+
}, v = (n, o, s) => {
|
|
334
334
|
const a = _(H);
|
|
335
335
|
if (a === null)
|
|
336
336
|
throw new Error(
|
|
337
337
|
"useEmbeddedEffect must be used within a MMEmbeddableZoneProvider"
|
|
338
338
|
);
|
|
339
|
-
const m =
|
|
340
|
-
|
|
341
|
-
m.current =
|
|
342
|
-
}, [
|
|
339
|
+
const m = x(s);
|
|
340
|
+
g(() => {
|
|
341
|
+
m.current = s;
|
|
342
|
+
}, [s]), g(() => {
|
|
343
343
|
if (!(!n || !o)) {
|
|
344
344
|
if (o.startsWith("key:")) {
|
|
345
|
-
const
|
|
346
|
-
return a.readyFrames[n] && a.sendMessage(n, "subscribe-key", { keyChord:
|
|
345
|
+
const R = o.substring(4);
|
|
346
|
+
return a.readyFrames[n] && a.sendMessage(n, "subscribe-key", { keyChord: R }), a.addListener(
|
|
347
347
|
n,
|
|
348
|
-
`key-pressed:${
|
|
349
|
-
(...
|
|
348
|
+
`key-pressed:${R}`,
|
|
349
|
+
(...k) => m.current(...k)
|
|
350
350
|
);
|
|
351
351
|
}
|
|
352
352
|
return a.addListener(
|
|
353
353
|
n,
|
|
354
354
|
o,
|
|
355
|
-
(...
|
|
355
|
+
(...R) => m.current(...R)
|
|
356
356
|
);
|
|
357
357
|
}
|
|
358
358
|
}, [a, n, o]);
|
|
359
359
|
};
|
|
360
360
|
oe.propTypes = {
|
|
361
|
-
children:
|
|
361
|
+
children: w.node.isRequired,
|
|
362
362
|
/**
|
|
363
363
|
* Optional interactive-step launcher for embedded authorizations,
|
|
364
364
|
* `(entry, { onBlocked, onClosed }) => cleanup`. Defaults to a top-level
|
|
365
365
|
* popup. Hosts that cannot open windows (Android WebView shells) drive
|
|
366
366
|
* their own UI from useEmbeddedAuthorizations() instead.
|
|
367
367
|
*/
|
|
368
|
-
authorizationLauncher:
|
|
368
|
+
authorizationLauncher: w.func
|
|
369
369
|
};
|
|
370
370
|
const K = Z.default || Z, ce = 1e4, ue = "credentials", G = (n, o) => `${n}/mm-embedded-interop?id=${o}&origin=${window.location.origin}&caps=${ue}`, le = K.iframe`
|
|
371
371
|
width: 100%;
|
|
@@ -387,10 +387,10 @@ const K = Z.default || Z, ce = 1e4, ue = "credentials", G = (n, o) => `${n}/mm-e
|
|
|
387
387
|
font-size: 14px;
|
|
388
388
|
`, X = ({ entry: n }) => /* @__PURE__ */ f.createElement(ae, null, /* @__PURE__ */ f.createElement("div", { style: { fontWeight: 600 } }, n && n.origin || "This app", " can’t be embedded here"), /* @__PURE__ */ f.createElement("div", { style: { fontSize: 12, color: "#888" } }, "It needs an update to support embedding from a different domain."));
|
|
389
389
|
X.propTypes = {
|
|
390
|
-
entry:
|
|
391
|
-
origin:
|
|
392
|
-
name:
|
|
393
|
-
reason:
|
|
390
|
+
entry: w.shape({
|
|
391
|
+
origin: w.string,
|
|
392
|
+
name: w.string,
|
|
393
|
+
reason: w.string
|
|
394
394
|
})
|
|
395
395
|
};
|
|
396
396
|
const de = K.div`
|
|
@@ -399,16 +399,16 @@ const de = K.div`
|
|
|
399
399
|
flex: 1;
|
|
400
400
|
align-items: center;
|
|
401
401
|
justify-content: center;
|
|
402
|
-
`, fe = () => /* @__PURE__ */ f.createElement(de, null, /* @__PURE__ */ f.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")),
|
|
402
|
+
`, fe = () => /* @__PURE__ */ f.createElement(de, null, /* @__PURE__ */ f.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), me = ({
|
|
403
403
|
id: n,
|
|
404
404
|
src: o,
|
|
405
|
-
path:
|
|
405
|
+
path: s,
|
|
406
406
|
onInit: a = () => {
|
|
407
407
|
},
|
|
408
408
|
onTimeout: m,
|
|
409
|
-
context:
|
|
410
|
-
params:
|
|
411
|
-
renderUnsupported:
|
|
409
|
+
context: R = {},
|
|
410
|
+
params: T = {},
|
|
411
|
+
renderUnsupported: k,
|
|
412
412
|
renderTimeout: L,
|
|
413
413
|
...q
|
|
414
414
|
}) => {
|
|
@@ -416,104 +416,101 @@ const de = K.div`
|
|
|
416
416
|
return console.error(
|
|
417
417
|
"isConfiguring must be passed via the params prop to MMEmbeddableZone"
|
|
418
418
|
), null;
|
|
419
|
-
if ("colorMode" in
|
|
419
|
+
if ("colorMode" in R)
|
|
420
420
|
return console.error(
|
|
421
421
|
"colorMode must be passed via the params prop to MMEmbeddableZone"
|
|
422
422
|
), null;
|
|
423
|
-
if ("isFullScreen" in
|
|
423
|
+
if ("isFullScreen" in R)
|
|
424
424
|
return console.error(
|
|
425
425
|
"isFullScreen must be passed via the params prop to MMEmbeddableZone"
|
|
426
426
|
), null;
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}, [
|
|
431
|
-
const { registerFrame: l, unregisterFrame:
|
|
427
|
+
const y = x(), [F, b] = I(), [U, P] = I(0), [z, A] = I(!1), [O, C] = I(!1), i = re(o), u = se(o), c = ie(o);
|
|
428
|
+
g(() => {
|
|
429
|
+
i > 0 && P(0);
|
|
430
|
+
}, [i]);
|
|
431
|
+
const { registerFrame: l, unregisterFrame: E, sendMessage: p } = _(
|
|
432
432
|
H
|
|
433
|
-
), [
|
|
434
|
-
|
|
433
|
+
), [$, e] = I(), t = x(), r = x(m), d = x(a), M = x(!1);
|
|
434
|
+
g(() => {
|
|
435
435
|
r.current = m;
|
|
436
|
-
}, [m]),
|
|
436
|
+
}, [m]), g(() => {
|
|
437
437
|
d.current = a;
|
|
438
|
-
}, [a]),
|
|
439
|
-
|
|
438
|
+
}, [a]), g(() => {
|
|
439
|
+
U && p(n, "set-context", {
|
|
440
440
|
context: {
|
|
441
|
-
...
|
|
442
|
-
// TODO: Remove this once everything is migrated to params
|
|
443
|
-
colorMode: p.colorMode,
|
|
444
|
-
isFullScreen: p.isFullScreen
|
|
441
|
+
...R
|
|
445
442
|
}
|
|
446
443
|
});
|
|
447
|
-
}, [
|
|
448
|
-
|
|
449
|
-
}, [
|
|
450
|
-
|
|
451
|
-
}, [
|
|
452
|
-
|
|
453
|
-
}, [
|
|
454
|
-
if (!o || !n || !
|
|
444
|
+
}, [R, n, U]), g(() => {
|
|
445
|
+
U && p(n, "set-params", { params: T });
|
|
446
|
+
}, [T, n, U]), g(() => {
|
|
447
|
+
s !== void 0 && e((s == null ? void 0 : s.indexOf("/")) === 0 ? s : `/${s}`);
|
|
448
|
+
}, [s]), g(() => {
|
|
449
|
+
$ === void 0 || !U || p(n, "navigate", { path: $ });
|
|
450
|
+
}, [$, U, n, p]), g(() => {
|
|
451
|
+
if (!o || !n || !y)
|
|
455
452
|
return;
|
|
456
|
-
const
|
|
457
|
-
return l(n,
|
|
458
|
-
|
|
453
|
+
const S = new URL(o);
|
|
454
|
+
return l(n, S.origin, y), d.current(), b(G(S.origin, n)), () => {
|
|
455
|
+
E(n);
|
|
459
456
|
};
|
|
460
|
-
}, [o, n, l,
|
|
461
|
-
if (!(!
|
|
457
|
+
}, [o, n, l, y]), g(() => {
|
|
458
|
+
if (!(!F || M.current))
|
|
462
459
|
return t.current = setTimeout(() => {
|
|
463
460
|
A(!0), r.current && r.current();
|
|
464
461
|
}, ce), () => clearTimeout(t.current);
|
|
465
|
-
}, [
|
|
466
|
-
const B =
|
|
467
|
-
|
|
462
|
+
}, [F]);
|
|
463
|
+
const B = h(() => {
|
|
464
|
+
M.current = !0, clearTimeout(t.current), A(!1);
|
|
468
465
|
}, []);
|
|
469
466
|
v(n, "init", B), v(n, "authorize", B), v(n, "login", B), v(n, "credential-request", () => {
|
|
470
|
-
B(),
|
|
471
|
-
}),
|
|
472
|
-
!
|
|
473
|
-
}, [
|
|
474
|
-
B(),
|
|
467
|
+
B(), C(!0);
|
|
468
|
+
}), g(() => {
|
|
469
|
+
!O || !u || p(n, "credential", { accessToken: u.accessToken });
|
|
470
|
+
}, [O, u, n, p]), v(n, "ready", () => {
|
|
471
|
+
B(), P((S) => S + 1);
|
|
475
472
|
});
|
|
476
|
-
const W =
|
|
473
|
+
const W = x();
|
|
477
474
|
return v(n, "heartbeat", () => {
|
|
478
475
|
W.current && clearTimeout(W.current), W.current = setTimeout(() => {
|
|
479
|
-
if (
|
|
480
|
-
const
|
|
481
|
-
|
|
476
|
+
if (y.current) {
|
|
477
|
+
const S = new URL(o);
|
|
478
|
+
y.current.src = G(S.origin, n);
|
|
482
479
|
}
|
|
483
480
|
}, 6e3);
|
|
484
|
-
}),
|
|
481
|
+
}), g(() => () => {
|
|
485
482
|
W.current && clearTimeout(W.current);
|
|
486
|
-
}, []), c ?
|
|
483
|
+
}, []), c ? k ? k(c) : /* @__PURE__ */ f.createElement(X, { entry: c }) : z && !U ? L ? L() : /* @__PURE__ */ f.createElement(fe, null) : /* @__PURE__ */ f.createElement(
|
|
487
484
|
le,
|
|
488
485
|
{
|
|
489
|
-
key: `auth-epoch-${
|
|
490
|
-
$isReady:
|
|
491
|
-
ref:
|
|
492
|
-
src:
|
|
486
|
+
key: `auth-epoch-${i}`,
|
|
487
|
+
$isReady: U,
|
|
488
|
+
ref: y,
|
|
489
|
+
src: F,
|
|
493
490
|
...q
|
|
494
491
|
}
|
|
495
492
|
);
|
|
496
493
|
};
|
|
497
|
-
|
|
498
|
-
id:
|
|
499
|
-
src:
|
|
500
|
-
path:
|
|
501
|
-
onInit:
|
|
502
|
-
onTimeout:
|
|
494
|
+
me.propTypes = {
|
|
495
|
+
id: w.string,
|
|
496
|
+
src: w.string.isRequired,
|
|
497
|
+
path: w.string,
|
|
498
|
+
onInit: w.func,
|
|
499
|
+
onTimeout: w.func,
|
|
503
500
|
/**
|
|
504
501
|
* Optional host-styled renderer for the structurally-unsupported embed
|
|
505
502
|
* state (legacy app on a cross-site origin), `(entry) => ReactNode`. Falls
|
|
506
503
|
* back to a minimal built-in placeholder.
|
|
507
504
|
*/
|
|
508
|
-
renderUnsupported:
|
|
505
|
+
renderUnsupported: w.func,
|
|
509
506
|
/**
|
|
510
507
|
* Optional host-styled renderer for the handshake-timeout failure state
|
|
511
508
|
* (the app is not embeddable / could not load), `() => ReactNode`. Falls
|
|
512
509
|
* back to a minimal centered message.
|
|
513
510
|
*/
|
|
514
|
-
renderTimeout:
|
|
511
|
+
renderTimeout: w.func
|
|
515
512
|
};
|
|
516
|
-
const
|
|
513
|
+
const pe = Z.div`
|
|
517
514
|
position: fixed;
|
|
518
515
|
inset: 0;
|
|
519
516
|
background: rgba(0, 0, 0, 0.45);
|
|
@@ -521,7 +518,7 @@ const me = Z.div`
|
|
|
521
518
|
align-items: center;
|
|
522
519
|
justify-content: center;
|
|
523
520
|
z-index: 10000;
|
|
524
|
-
`,
|
|
521
|
+
`, ge = Z.div`
|
|
525
522
|
background: #fff;
|
|
526
523
|
border-radius: 8px;
|
|
527
524
|
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
|
|
@@ -551,19 +548,19 @@ const me = Z.div`
|
|
|
551
548
|
margin: 4px 0 0;
|
|
552
549
|
`, Te = () => {
|
|
553
550
|
const { pending: n, authorize: o } = ne();
|
|
554
|
-
return n.length === 0 ? null : /* @__PURE__ */ f.createElement(
|
|
551
|
+
return n.length === 0 ? null : /* @__PURE__ */ f.createElement(pe, null, /* @__PURE__ */ f.createElement(ge, null, /* @__PURE__ */ f.createElement("h3", { style: { margin: "0 0 8px" } }, "Authorization Required"), /* @__PURE__ */ f.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."), n.map((s) => /* @__PURE__ */ f.createElement("div", { key: s.origin }, /* @__PURE__ */ f.createElement(he, null, /* @__PURE__ */ f.createElement("div", null, /* @__PURE__ */ f.createElement("div", { style: { fontWeight: 600 } }, s.origin)), /* @__PURE__ */ f.createElement(be, { onClick: () => o(s) }, "Authorize")), s.popupBlocked && /* @__PURE__ */ f.createElement(Ee, null, "The sign-in window was blocked. Allow popups for this site, then try again.")))));
|
|
555
552
|
};
|
|
556
553
|
export {
|
|
557
554
|
D as EmbeddedAuthorizationContext,
|
|
558
555
|
Te as EmbeddedAuthorizationPrompt,
|
|
559
|
-
|
|
556
|
+
me as MMEmbeddableZone,
|
|
560
557
|
H as MMEmbeddableZoneContext,
|
|
561
558
|
oe as MMEmbeddableZoneProvider,
|
|
562
559
|
ee as isCrossSite,
|
|
563
560
|
te as popupAuthorizationLauncher,
|
|
564
561
|
ne as useEmbeddedAuthorizations,
|
|
565
|
-
|
|
562
|
+
se as useEmbeddedCredential,
|
|
566
563
|
v as useEmbeddedEffect,
|
|
567
564
|
re as useEmbeddedOriginEpoch,
|
|
568
|
-
|
|
565
|
+
ie as useEmbeddedUnsupported
|
|
569
566
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(m,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):(m=typeof globalThis!="undefined"?globalThis:m||self,e(m["mm-react-embeddable"]={},m.React,m.PropTypes,m.styled))})(this,(function(m,e,p,q){"use strict";const _=e.createContext(null),W=e.createContext({pending:[],authorize:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ne=2e4,F=r=>{try{return new URL(r).origin}catch{return null}},H=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const u=r.split(".");return u.length<=2?r:u.slice(-2).join(".")},P=(r,u)=>{try{const i=new URL(r),f=new URL(u);return i.protocol!==f.protocol?!0:H(i.hostname)!==H(f.hostname)}catch{return!0}},K=(r,{onBlocked:u,onClosed:i})=>{const f=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!f)return u(),()=>{};const g=setInterval(()=>{f.closed&&(clearInterval(g),i())},1e3);return()=>clearInterval(g)},V=({children:r,launcher:u})=>{const i=e.useContext(_),[f,g]=e.useState({}),[k,w]=e.useState({}),[C,S]=e.useState({}),[$,M]=e.useState({}),O=e.useRef(C);O.current=C;const h=e.useRef(null),x=e.useRef({}),y=e.useRef({}),z=e.useCallback(n=>{const t=y.current[n];if(!t)return;const s=a=>!a[n]||a[n].clientId?a:{...a,[n]:{...a[n],clientId:t}};g(s),M(s)},[]),j=e.useCallback((n,t)=>{const s=F(n==null?void 0:n.authUrl);s&&(M(a=>a[s]?a:{...a,[s]:{origin:s,reason:t,clientId:y.current[s]||null}}),z(s))},[z]),I=e.useCallback((n,{v2:t=!1}={})=>{const s=F(n==null?void 0:n.authUrl);s&&(t&&O.current[s]||(g(a=>a[s]?a:{...a,[s]:{origin:s,authUrl:n.authUrl,silentUrl:n.silentUrl||null,status:t&&n.silentUrl?"silent":"interactive",v2:t,clientId:n.clientId||y.current[s]||null,popupBlocked:!1}}),z(s)))},[z]),T=e.useCallback(n=>{g(t=>{if(!t[n])return t;const s={...t};return delete s[n],s})},[]),o=e.useCallback(n=>{n&&(T(n),w(t=>({...t,[n]:(t[n]||0)+1})))},[T]),l=e.useCallback(n=>{g(t=>!t[n]||t[n].status==="interactive"?t:{...t,[n]:{...t[n],status:"interactive"}})},[]),c=e.useCallback(n=>{T(n.origin)},[T]),d=e.useCallback(n=>{const t=F(n==null?void 0:n.authUrl);if(t&&P(t,window.location.origin)){j(n,"cross-site-legacy");return}I(n)},[I,j]);e.useEffect(()=>{if(!i)return;const n=[i.addListener("*","init",t=>{t!=null&&t.origin&&t.clientId&&(y.current[t.origin]=t.clientId,z(t.origin))}),i.addListener("*","authorize",d),i.addListener("*","login",d),i.addListener("*","credential-request",t=>I(t,{v2:!0})),i.addListener("*","authorized",t=>{t!=null&&t.accessToken||o(F(t==null?void 0:t.authUrl))})];return()=>n.forEach(t=>t())},[i,d,I,o,z]),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=F(s.authUrl);if(!(!a||t.origin!==a)){if(s.type==="authorized"&&s.accessToken){S(U=>({...U,[a]:{accessToken:s.accessToken}})),T(a);return}s.type==="authorize-failed"&&l(a)}};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[T,l]),e.useEffect(()=>{const n=x.current;Object.values(f).forEach(t=>{t.status==="silent"&&!n[t.origin]&&(n[t.origin]=setTimeout(()=>{delete n[t.origin],l(t.origin)},ne))}),Object.keys(n).forEach(t=>{(!f[t]||f[t].status!=="silent")&&(clearTimeout(n[t]),delete n[t])})},[f,l]),e.useEffect(()=>()=>{h.current&&h.current(),Object.values(x.current).forEach(clearTimeout)},[]);const E=e.useCallback(n=>{h.current&&(h.current(),h.current=null);const t=u||K;h.current=t(n,{onBlocked:()=>{g(s=>s[n.origin]?{...s,[n.origin]:{...s[n.origin],popupBlocked:!0}}:s)},onClosed:()=>{if(n.v2){g(s=>!s[n.origin]||!s[n.origin].silentUrl?s:{...s,[n.origin]:{...s[n.origin],status:"silent"}});return}o(n.origin)}})},[u,o]),b={pending:Object.values(f).filter(n=>n.status==="interactive"),authorize:E,dismiss:c,originEpochs:k,credentials:C,unsupported:$},L=Object.values(f).filter(n=>n.status==="silent"&&n.silentUrl);return e.createElement(W.Provider,{value:b},r,L.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"}})))};V.propTypes={children:p.node,launcher:p.func};const G=()=>e.useContext(W),J=r=>{const{originEpochs:u}=e.useContext(W),i=F(r);return i&&u[i]||0},Q=r=>{const{credentials:u}=e.useContext(W),i=F(r);return i&&u[i]||null},X=r=>{const{unsupported:u}=e.useContext(W),i=F(r);return i&&u[i]||null},Y=({children:r,authorizationLauncher:u})=>{const[i,f]=e.useState({}),[g,k]=e.useState({}),w=e.useRef({}),C=e.useRef({}),S=e.useRef({}),$=e.useCallback((o,l)=>{var c;return!!((c=S.current[o])!=null&&c.has(l))},[]),M=e.useCallback((o,l,c)=>{f(d=>({...d,[o]:{origin:l,frameRef:c}}))},[]),O=e.useCallback(o=>{f(l=>{const c={...l};return delete c[o],c}),k(l=>{const c={...l};return delete c[o],c}),delete S.current[o]},[]);e.useEffect(()=>{const o=(c=[],d)=>{c.forEach(E=>E(d))},l=c=>{var L,n,t,s,a;if(!((L=c==null?void 0:c.data)!=null&&L.instanceId))return;const{instanceId:d,type:E}=c.data,b=w.current;if(E==="response"){const{callbackId:U,response:B,error:v}=c.data,A=C.current[U];A&&(A(B,v),delete C.current[U]);return}if(E==="mark-registered"){const{requestType:U}=c.data;S.current[d]||(S.current[d]=new Set),S.current[d].add(U);return}E==="ready"&&k(U=>({...U,[d]:!0})),o((n=b[d])==null?void 0:n[E],c.data),o((t=b["*"])==null?void 0:t[E],c.data),o((s=b[d])==null?void 0:s["*"],c.data),o((a=b["*"])==null?void 0:a["*"],c.data)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[i]);const h=e.useCallback((o,l,c)=>{var E,b;const d=i[o];if(!d){console.warn(`Origin not set for id: ${o}. Unable to send message.`);return}(b=(E=d==null?void 0:d.frameRef)==null?void 0:E.current)!=null&&b.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:l,...c,instanceId:o},d.origin)},[i]),x=e.useRef(0),y=e.useCallback(()=>`${Date.now()}-${++x.current}`,[]),z=e.useCallback(async(o,l,c={})=>new Promise((d,E)=>{const b=y(),L=(n,t)=>{delete C.current[b],t?E(t):d(n)};C.current[b]=L,h(o,"request",{callbackId:b,requestType:l,data:c})}),[h]),j=e.useCallback((o,l)=>{h(o,"load-options",l)},[h]),I=e.useCallback((o,l)=>{h(o,"validate",l)},[h]),T=e.useMemo(()=>({registerFrame:M,unregisterFrame:O,sendMessage:h,sendRequest:z,loadOptions:j,validate:I,hasHandler:$,readyFrames:g,addListener:(o,l,c)=>(w.current[o]||(w.current[o]={}),w.current[o][l]||(w.current[o][l]=[]),w.current[o][l].push(c),()=>{w.current[o][l]=w.current[o][l].filter(d=>d!==c)})}),[M,O,h,z,j,I,$,g]);return e.createElement(_.Provider,{value:T},e.createElement(V,{launcher:u},r))},Z=(r,u,i)=>{const f=e.useContext(_);if(f===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const g=e.useRef(i);e.useEffect(()=>{g.current=i},[i]),e.useEffect(()=>{if(!(!r||!u)){if(u.startsWith("key:")){const k=u.substring(4);return f.readyFrames[r]&&f.sendMessage(r,"subscribe-key",{keyChord:k}),f.addListener(r,`key-pressed:${k}`,(...C)=>g.current(...C))}return f.addListener(r,u,(...k)=>g.current(...k))}},[f,r,u])};Y.propTypes={children:p.node.isRequired,authorizationLauncher:p.func};const D=q.default||q,te=1e4,re="credentials",N=(r,u)=>`${r}/mm-embedded-interop?id=${u}&origin=${window.location.origin}&caps=${re}`,se=D.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
text-align: center;
|
|
17
17
|
color: #555;
|
|
18
18
|
font-size: 14px;
|
|
19
|
-
`,R=({entry:r})=>e.createElement(ie,null,e.createElement("div",{style:{fontWeight:600}},r&&r.origin||"This app"," can’t be embedded here"),e.createElement("div",{style:{fontSize:12,color:"#888"}},"It needs an update to support embedding from a different domain."));R.propTypes={entry:
|
|
19
|
+
`,R=({entry:r})=>e.createElement(ie,null,e.createElement("div",{style:{fontWeight:600}},r&&r.origin||"This app"," can’t be embedded here"),e.createElement("div",{style:{fontSize:12,color:"#888"}},"It needs an update to support embedding from a different domain."));R.propTypes={entry:p.shape({origin:p.string,name:p.string,reason:p.string})};const oe=D.div`
|
|
20
20
|
height: 100%;
|
|
21
21
|
display: flex;
|
|
22
22
|
flex: 1;
|
|
23
23
|
align-items: center;
|
|
24
24
|
justify-content: center;
|
|
25
|
-
`,ue=()=>e.createElement(oe,null,e.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),ee=({id:r,src:u,path:i,onInit:f=()=>{},onTimeout:
|
|
25
|
+
`,ue=()=>e.createElement(oe,null,e.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),ee=({id:r,src:u,path:i,onInit:f=()=>{},onTimeout:g,context:k={},params:w={},renderUnsupported:C,renderTimeout:S,...$})=>{if("isConfiguring"in $)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 M=e.useRef(),[O,h]=e.useState(),[x,y]=e.useState(0),[z,j]=e.useState(!1),[I,T]=e.useState(!1),o=J(u),l=Q(u),c=X(u);e.useEffect(()=>{o>0&&y(0)},[o]);const{registerFrame:d,unregisterFrame:E,sendMessage:b}=e.useContext(_),[L,n]=e.useState(),t=e.useRef(),s=e.useRef(g),a=e.useRef(f),U=e.useRef(!1);e.useEffect(()=>{s.current=g},[g]),e.useEffect(()=>{a.current=f},[f]),e.useEffect(()=>{x&&b(r,"set-context",{context:{...k}})},[k,r,x]),e.useEffect(()=>{x&&b(r,"set-params",{params:w})},[w,r,x]),e.useEffect(()=>{i!==void 0&&n((i==null?void 0:i.indexOf("/"))===0?i:`/${i}`)},[i]),e.useEffect(()=>{L===void 0||!x||b(r,"navigate",{path:L})},[L,x,r,b]),e.useEffect(()=>{if(!u||!r||!M)return;const A=new URL(u);return d(r,A.origin,M),a.current(),h(N(A.origin,r)),()=>{E(r)}},[u,r,d,M]),e.useEffect(()=>{if(!(!O||U.current))return t.current=setTimeout(()=>{j(!0),s.current&&s.current()},te),()=>clearTimeout(t.current)},[O]);const B=e.useCallback(()=>{U.current=!0,clearTimeout(t.current),j(!1)},[]);Z(r,"init",B),Z(r,"authorize",B),Z(r,"login",B),Z(r,"credential-request",()=>{B(),T(!0)}),e.useEffect(()=>{!I||!l||b(r,"credential",{accessToken:l.accessToken})},[I,l,r,b]),Z(r,"ready",()=>{B(),y(A=>A+1)});const v=e.useRef();return Z(r,"heartbeat",()=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{if(M.current){const A=new URL(u);M.current.src=N(A.origin,r)}},6e3)}),e.useEffect(()=>()=>{v.current&&clearTimeout(v.current)},[]),c?C?C(c):e.createElement(R,{entry:c}):z&&!x?S?S():e.createElement(ue,null):e.createElement(se,{key:`auth-epoch-${o}`,$isReady:x,ref:M,src:O,...$})};ee.propTypes={id:p.string,src:p.string.isRequired,path:p.string,onInit:p.func,onTimeout:p.func,renderUnsupported:p.func,renderTimeout:p.func};const ce=q.div`
|
|
26
26
|
position: fixed;
|
|
27
27
|
inset: 0;
|
|
28
28
|
background: rgba(0, 0, 0, 0.45);
|
|
@@ -58,4 +58,4 @@
|
|
|
58
58
|
color: #b3261e;
|
|
59
59
|
font-size: 13px;
|
|
60
60
|
margin: 4px 0 0;
|
|
61
|
-
`,me=()=>{const{pending:r,authorize:u}=G();return r.length===0?null:e.createElement(ce,null,e.createElement(le,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(i=>e.createElement("div",{key:i.origin},e.createElement(de,null,e.createElement("div",null,e.createElement("div",{style:{fontWeight:600}},i.origin)),e.createElement(fe,{onClick:()=>u(i)},"Authorize")),i.popupBlocked&&e.createElement(ae,null,"The sign-in window was blocked. Allow popups for this site, then try again.")))))};
|
|
61
|
+
`,me=()=>{const{pending:r,authorize:u}=G();return r.length===0?null:e.createElement(ce,null,e.createElement(le,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(i=>e.createElement("div",{key:i.origin},e.createElement(de,null,e.createElement("div",null,e.createElement("div",{style:{fontWeight:600}},i.origin)),e.createElement(fe,{onClick:()=>u(i)},"Authorize")),i.popupBlocked&&e.createElement(ae,null,"The sign-in window was blocked. Allow popups for this site, then try again.")))))};m.EmbeddedAuthorizationContext=W,m.EmbeddedAuthorizationPrompt=me,m.MMEmbeddableZone=ee,m.MMEmbeddableZoneContext=_,m.MMEmbeddableZoneProvider=Y,m.isCrossSite=P,m.popupAuthorizationLauncher=K,m.useEmbeddedAuthorizations=G,m.useEmbeddedCredential=Q,m.useEmbeddedEffect=Z,m.useEmbeddedOriginEpoch=J,m.useEmbeddedUnsupported=X,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|