@machinemetrics/mm-react-embeddable 2.0.0-0 → 2.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import g, { createContext as oe, useContext as K, useState as U, useRef as R, useCallback as h, useEffect as k, useMemo as ue } from "react";
|
|
2
2
|
import T from "prop-types";
|
|
3
3
|
import D from "styled-components";
|
|
4
|
-
const Y =
|
|
4
|
+
const Y = oe(null), J = oe({
|
|
5
5
|
pending: [],
|
|
6
6
|
authorize: () => {
|
|
7
7
|
},
|
|
@@ -14,128 +14,128 @@ const Y = ie(null), J = ie({
|
|
|
14
14
|
originEpochs: {},
|
|
15
15
|
credentials: {},
|
|
16
16
|
unsupported: {}
|
|
17
|
-
}), ae = "access_token",
|
|
17
|
+
}), ae = "access_token", re = (r) => r ? r.kind ? r : r.accessToken ? {
|
|
18
18
|
kind: ae,
|
|
19
|
-
accessToken:
|
|
20
|
-
expiresAt:
|
|
21
|
-
} : null : null,
|
|
19
|
+
accessToken: r.accessToken,
|
|
20
|
+
expiresAt: r.expiresAt || null
|
|
21
|
+
} : null : null, le = /* @__PURE__ */ new Set(["host_not_allowed", "invalid_token", "provider_unavailable"]), X = typeof window != "undefined" && window.location.protocol === "https:", de = 8e3, Q = (r) => {
|
|
22
22
|
try {
|
|
23
|
-
return new URL(
|
|
23
|
+
return new URL(r).origin;
|
|
24
24
|
} catch {
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
const
|
|
29
|
-
return !
|
|
30
|
-
}, se = (
|
|
31
|
-
if (!
|
|
32
|
-
return
|
|
33
|
-
const s =
|
|
34
|
-
return s.length <= 2 ?
|
|
35
|
-
},
|
|
27
|
+
}, ne = (r, s) => {
|
|
28
|
+
const c = s == null ? void 0 : s.origin;
|
|
29
|
+
return !c || Q(r == null ? void 0 : r.authUrl) !== c ? null : c;
|
|
30
|
+
}, se = (r) => {
|
|
31
|
+
if (!r || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(r) || r.includes(":"))
|
|
32
|
+
return 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 c = new URL(r), d = new URL(s);
|
|
38
|
+
return c.protocol !== d.protocol ? !0 : se(c.hostname) !== se(d.hostname);
|
|
39
39
|
} catch {
|
|
40
40
|
return !0;
|
|
41
41
|
}
|
|
42
|
-
},
|
|
42
|
+
}, pe = (r, { onBlocked: s, onClosed: c }) => {
|
|
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
49
|
return s(), () => {
|
|
50
50
|
};
|
|
51
|
-
const
|
|
52
|
-
d.closed && (clearInterval(
|
|
51
|
+
const p = setInterval(() => {
|
|
52
|
+
d.closed && (clearInterval(p), c());
|
|
53
53
|
}, 1e3);
|
|
54
|
-
return () => clearInterval(
|
|
55
|
-
},
|
|
56
|
-
const d =
|
|
57
|
-
|
|
58
|
-
const E = R(
|
|
59
|
-
E.current =
|
|
60
|
-
const
|
|
61
|
-
|
|
54
|
+
return () => clearInterval(p);
|
|
55
|
+
}, ie = ({ children: r, launcher: s, broker: c }) => {
|
|
56
|
+
const d = K(Y), [p, b] = U({}), [j, I] = U({}), [_, A] = U({}), [F, y] = U({}), H = R(_);
|
|
57
|
+
H.current = _;
|
|
58
|
+
const E = R(p);
|
|
59
|
+
E.current = p;
|
|
60
|
+
const O = R(null), G = R({}), C = R({}), v = R({}), S = R(c);
|
|
61
|
+
S.current = c;
|
|
62
62
|
const z = h((e) => {
|
|
63
|
-
const
|
|
64
|
-
if (!
|
|
63
|
+
const t = C.current[e];
|
|
64
|
+
if (!t)
|
|
65
65
|
return;
|
|
66
|
-
const
|
|
67
|
-
b(
|
|
68
|
-
}, []),
|
|
69
|
-
(e,
|
|
70
|
-
e && (y((
|
|
71
|
-
...
|
|
72
|
-
[e]: { origin: e, reason:
|
|
66
|
+
const n = (i) => !i[e] || i[e].clientId ? i : { ...i, [e]: { ...i[e], clientId: t } };
|
|
67
|
+
b(n), y(n);
|
|
68
|
+
}, []), u = h(
|
|
69
|
+
(e, t) => {
|
|
70
|
+
e && (y((n) => n[e] ? n : {
|
|
71
|
+
...n,
|
|
72
|
+
[e]: { origin: e, reason: t, clientId: C.current[e] || null }
|
|
73
73
|
}), z(e));
|
|
74
74
|
},
|
|
75
75
|
[z]
|
|
76
|
-
),
|
|
77
|
-
(e, { v2:
|
|
78
|
-
|
|
79
|
-
...
|
|
80
|
-
[
|
|
81
|
-
origin:
|
|
76
|
+
), a = h(
|
|
77
|
+
(e, { v2: t = !1, origin: n = null } = {}) => {
|
|
78
|
+
n && (t && H.current[n] || (b((i) => i[n] ? i : {
|
|
79
|
+
...i,
|
|
80
|
+
[n]: {
|
|
81
|
+
origin: n,
|
|
82
82
|
authUrl: e.authUrl,
|
|
83
83
|
silentUrl: e.silentUrl || null,
|
|
84
84
|
// v2 entries try the invisible silent resolver first — but only on a host that can
|
|
85
85
|
// frame login (https). Otherwise (and for legacy signals) go straight to interactive,
|
|
86
86
|
// so an http host doesn't wait out a silent frame that can never load login.
|
|
87
|
-
status:
|
|
88
|
-
v2:
|
|
87
|
+
status: t && S.current ? "broker" : t && e.silentUrl && X ? "silent" : "interactive",
|
|
88
|
+
v2: t,
|
|
89
89
|
// v1.9: the scope the guest asked for; forwarded verbatim to the broker.
|
|
90
90
|
scope: e.scope || null,
|
|
91
|
-
acceptsCredentials:
|
|
91
|
+
acceptsCredentials: v.current[n] || null,
|
|
92
92
|
consent: null,
|
|
93
93
|
error: null,
|
|
94
94
|
// clientId from the request payload (v2) or the cached init (legacy);
|
|
95
95
|
// the host resolves the display name from it.
|
|
96
|
-
clientId: e.clientId ||
|
|
96
|
+
clientId: e.clientId || C.current[n] || null,
|
|
97
97
|
popupBlocked: !1
|
|
98
98
|
}
|
|
99
|
-
}), z(
|
|
99
|
+
}), z(n)));
|
|
100
100
|
},
|
|
101
101
|
[z]
|
|
102
102
|
), o = h((e) => {
|
|
103
|
-
b((
|
|
104
|
-
if (!
|
|
105
|
-
return
|
|
106
|
-
const
|
|
107
|
-
return delete
|
|
103
|
+
b((t) => {
|
|
104
|
+
if (!t[e])
|
|
105
|
+
return t;
|
|
106
|
+
const n = { ...t };
|
|
107
|
+
return delete n[e], n;
|
|
108
108
|
});
|
|
109
|
-
}, []),
|
|
109
|
+
}, []), l = h(
|
|
110
110
|
(e) => {
|
|
111
|
-
e && (o(e), I((
|
|
112
|
-
...
|
|
113
|
-
[e]: (
|
|
111
|
+
e && (o(e), I((t) => ({
|
|
112
|
+
...t,
|
|
113
|
+
[e]: (t[e] || 0) + 1
|
|
114
114
|
})));
|
|
115
115
|
},
|
|
116
116
|
[o]
|
|
117
|
-
),
|
|
118
|
-
b((
|
|
119
|
-
...
|
|
120
|
-
[e]: { ...
|
|
117
|
+
), w = h((e) => {
|
|
118
|
+
b((t) => !t[e] || t[e].status === "interactive" ? t : {
|
|
119
|
+
...t,
|
|
120
|
+
[e]: { ...t[e], status: "interactive" }
|
|
121
121
|
});
|
|
122
|
-
}, []),
|
|
122
|
+
}, []), x = h(
|
|
123
123
|
(e) => {
|
|
124
124
|
o(e.origin);
|
|
125
125
|
},
|
|
126
126
|
[o]
|
|
127
|
-
),
|
|
128
|
-
(e,
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
131
|
-
if (
|
|
132
|
-
|
|
127
|
+
), L = h(
|
|
128
|
+
(e, t) => {
|
|
129
|
+
const n = ne(e, t);
|
|
130
|
+
if (n) {
|
|
131
|
+
if (fe(n, window.location.origin)) {
|
|
132
|
+
u(n, "cross-site-legacy");
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
a(e, { origin: n });
|
|
136
136
|
}
|
|
137
137
|
},
|
|
138
|
-
[
|
|
138
|
+
[a, u]
|
|
139
139
|
);
|
|
140
140
|
k(() => {
|
|
141
141
|
if (!d)
|
|
@@ -147,168 +147,168 @@ const Y = ie(null), J = ie({
|
|
|
147
147
|
// signals, so it is usually cached by the time an entry is created. The
|
|
148
148
|
// clientId is only a lookup key: the host resolves the display name from
|
|
149
149
|
// it, and a broker binds it to the attested origin server-side.
|
|
150
|
-
d.addListener("*", "init", (
|
|
151
|
-
|
|
150
|
+
d.addListener("*", "init", (t, n) => {
|
|
151
|
+
n != null && n.origin && (t != null && t.clientId) && (C.current[n.origin] = t.clientId, z(n.origin)), n != null && n.origin && Array.isArray(t == null ? void 0 : t.acceptsCredentials) && (v.current[n.origin] = t.acceptsCredentials);
|
|
152
152
|
}),
|
|
153
|
-
d.addListener("*", "authorize",
|
|
154
|
-
d.addListener("*", "login",
|
|
153
|
+
d.addListener("*", "authorize", L),
|
|
154
|
+
d.addListener("*", "login", L),
|
|
155
155
|
d.addListener(
|
|
156
156
|
"*",
|
|
157
157
|
"credential-request",
|
|
158
|
-
(
|
|
158
|
+
(t, n) => a(t, { v2: !0, origin: ne(t, n) })
|
|
159
159
|
)
|
|
160
160
|
];
|
|
161
|
-
return () => e.forEach((
|
|
162
|
-
}, [d,
|
|
163
|
-
const e = (
|
|
164
|
-
const
|
|
165
|
-
if (!
|
|
161
|
+
return () => e.forEach((t) => t());
|
|
162
|
+
}, [d, L, a, z]), k(() => {
|
|
163
|
+
const e = (t) => {
|
|
164
|
+
const n = t == null ? void 0 : t.data;
|
|
165
|
+
if (!n || n.type !== "authorized" && n.type !== "authorize-failed")
|
|
166
166
|
return;
|
|
167
|
-
const
|
|
168
|
-
if (!(!
|
|
169
|
-
if (
|
|
170
|
-
if (
|
|
171
|
-
if (!E.current[
|
|
167
|
+
const i = Q(n.authUrl);
|
|
168
|
+
if (!(!i || t.origin !== i)) {
|
|
169
|
+
if (n.type === "authorized") {
|
|
170
|
+
if (n.accessToken) {
|
|
171
|
+
if (!E.current[i])
|
|
172
172
|
return;
|
|
173
|
-
|
|
174
|
-
...
|
|
175
|
-
[
|
|
176
|
-
})), o(
|
|
173
|
+
A((f) => ({
|
|
174
|
+
...f,
|
|
175
|
+
[i]: re({ accessToken: n.accessToken })
|
|
176
|
+
})), o(i);
|
|
177
177
|
} else
|
|
178
|
-
|
|
178
|
+
l(i);
|
|
179
179
|
return;
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
w(i);
|
|
182
182
|
}
|
|
183
183
|
};
|
|
184
184
|
return window.addEventListener("message", e), () => window.removeEventListener("message", e);
|
|
185
|
-
}, [o,
|
|
186
|
-
const
|
|
187
|
-
(e,
|
|
188
|
-
const
|
|
189
|
-
!
|
|
185
|
+
}, [o, l, w]);
|
|
186
|
+
const M = h(
|
|
187
|
+
(e, t) => {
|
|
188
|
+
const n = e == null ? void 0 : e.origin, i = re(t);
|
|
189
|
+
!n || !i || (A((f) => ({ ...f, [n]: i })), o(n));
|
|
190
190
|
},
|
|
191
191
|
[o]
|
|
192
|
-
),
|
|
193
|
-
b((
|
|
194
|
-
}, []),
|
|
195
|
-
async (e, { approve:
|
|
196
|
-
const
|
|
197
|
-
let
|
|
192
|
+
), m = h((e, t) => {
|
|
193
|
+
b((n) => n[e] ? { ...n, [e]: { ...n[e], ...t } } : n);
|
|
194
|
+
}, []), $ = h(
|
|
195
|
+
async (e, { approve: t } = {}) => {
|
|
196
|
+
const n = S.current, { origin: i } = e;
|
|
197
|
+
let f;
|
|
198
198
|
try {
|
|
199
|
-
|
|
200
|
-
{ origin:
|
|
201
|
-
{ approve:
|
|
199
|
+
f = await n(
|
|
200
|
+
{ origin: i, clientId: e.clientId, scope: e.scope, authUrl: e.authUrl },
|
|
201
|
+
{ approve: t }
|
|
202
202
|
);
|
|
203
203
|
} catch {
|
|
204
|
-
|
|
204
|
+
t ? m(i, { error: { reason: "broker_unavailable" } }) : m(i, {
|
|
205
205
|
status: e.silentUrl && X ? "silent" : "interactive"
|
|
206
206
|
});
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
|
-
if ((
|
|
210
|
-
|
|
209
|
+
if ((f == null ? void 0 : f.status) === 200 && f.credential) {
|
|
210
|
+
M(e, f.credential);
|
|
211
211
|
return;
|
|
212
212
|
}
|
|
213
|
-
if ((
|
|
214
|
-
|
|
213
|
+
if ((f == null ? void 0 : f.status) === 409 && f.consentRequired) {
|
|
214
|
+
m(i, {
|
|
215
215
|
status: "interactive",
|
|
216
216
|
consent: {
|
|
217
|
-
client:
|
|
218
|
-
stepUp: !!
|
|
219
|
-
scope:
|
|
217
|
+
client: f.client || null,
|
|
218
|
+
stepUp: !!f.stepUp,
|
|
219
|
+
scope: f.scope || e.scope
|
|
220
220
|
},
|
|
221
221
|
error: null
|
|
222
222
|
});
|
|
223
223
|
return;
|
|
224
224
|
}
|
|
225
|
-
const N = (
|
|
226
|
-
if (!
|
|
227
|
-
|
|
225
|
+
const N = (f == null ? void 0 : f.error) || "broker_error";
|
|
226
|
+
if (!t && le.has(N)) {
|
|
227
|
+
m(i, {
|
|
228
228
|
status: e.silentUrl && X ? "silent" : "interactive"
|
|
229
229
|
});
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
|
-
if (
|
|
233
|
-
|
|
232
|
+
if (t && N === "consent_denied") {
|
|
233
|
+
m(i, { error: null });
|
|
234
234
|
return;
|
|
235
235
|
}
|
|
236
|
-
o(
|
|
236
|
+
o(i), y((te) => ({
|
|
237
237
|
...te,
|
|
238
|
-
[
|
|
239
|
-
origin:
|
|
238
|
+
[i]: {
|
|
239
|
+
origin: i,
|
|
240
240
|
reason: `broker:${N}`,
|
|
241
|
-
detail:
|
|
242
|
-
clientId: e.clientId ||
|
|
241
|
+
detail: f || null,
|
|
242
|
+
clientId: e.clientId || C.current[i] || null
|
|
243
243
|
}
|
|
244
244
|
}));
|
|
245
245
|
},
|
|
246
|
-
[
|
|
247
|
-
),
|
|
246
|
+
[M, m, o]
|
|
247
|
+
), B = R({});
|
|
248
248
|
k(() => {
|
|
249
|
-
Object.values(
|
|
250
|
-
e.status !== "broker" ||
|
|
251
|
-
delete
|
|
249
|
+
Object.values(p).forEach((e) => {
|
|
250
|
+
e.status !== "broker" || B.current[e.origin] || (B.current[e.origin] = !0, $(e).finally(() => {
|
|
251
|
+
delete B.current[e.origin];
|
|
252
252
|
}));
|
|
253
253
|
});
|
|
254
|
-
}, [
|
|
255
|
-
const
|
|
256
|
-
(e) => !
|
|
257
|
-
[
|
|
254
|
+
}, [p, $]);
|
|
255
|
+
const P = h(
|
|
256
|
+
(e) => !S.current || !(e != null && e.consent) ? Promise.resolve() : $(e, { approve: !0 }),
|
|
257
|
+
[$]
|
|
258
258
|
);
|
|
259
259
|
k(() => {
|
|
260
|
-
const e =
|
|
261
|
-
Object.values(
|
|
262
|
-
|
|
263
|
-
delete e[
|
|
264
|
-
},
|
|
265
|
-
}), Object.keys(e).forEach((
|
|
266
|
-
(!
|
|
260
|
+
const e = G.current;
|
|
261
|
+
Object.values(p).forEach((t) => {
|
|
262
|
+
t.status === "silent" && !e[t.origin] && (e[t.origin] = setTimeout(() => {
|
|
263
|
+
delete e[t.origin], w(t.origin);
|
|
264
|
+
}, de));
|
|
265
|
+
}), Object.keys(e).forEach((t) => {
|
|
266
|
+
(!p[t] || p[t].status !== "silent") && (clearTimeout(e[t]), delete e[t]);
|
|
267
267
|
});
|
|
268
|
-
}, [
|
|
269
|
-
|
|
268
|
+
}, [p, w]), k(() => () => {
|
|
269
|
+
O.current && O.current(), Object.values(G.current).forEach(clearTimeout);
|
|
270
270
|
}, []);
|
|
271
|
-
const
|
|
271
|
+
const q = h(
|
|
272
272
|
(e) => {
|
|
273
|
-
|
|
274
|
-
const
|
|
275
|
-
|
|
273
|
+
O.current && (O.current(), O.current = null);
|
|
274
|
+
const t = s || pe;
|
|
275
|
+
O.current = t(e, {
|
|
276
276
|
onBlocked: () => {
|
|
277
|
-
b((
|
|
278
|
-
...
|
|
279
|
-
[e.origin]: { ...
|
|
280
|
-
} :
|
|
277
|
+
b((n) => n[e.origin] ? {
|
|
278
|
+
...n,
|
|
279
|
+
[e.origin]: { ...n[e.origin], popupBlocked: !0 }
|
|
280
|
+
} : n);
|
|
281
281
|
},
|
|
282
282
|
onClosed: () => {
|
|
283
283
|
if (e.v2) {
|
|
284
|
-
X && b((
|
|
285
|
-
...
|
|
286
|
-
[e.origin]: { ...
|
|
284
|
+
X && b((n) => !n[e.origin] || !n[e.origin].silentUrl ? n : {
|
|
285
|
+
...n,
|
|
286
|
+
[e.origin]: { ...n[e.origin], status: "silent" }
|
|
287
287
|
});
|
|
288
288
|
return;
|
|
289
289
|
}
|
|
290
|
-
|
|
290
|
+
l(e.origin);
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
},
|
|
294
|
-
[s,
|
|
295
|
-
),
|
|
294
|
+
[s, l]
|
|
295
|
+
), Z = {
|
|
296
296
|
// Hosts render UI for interactive entries only; silent resolution is
|
|
297
297
|
// invisible by design.
|
|
298
|
-
pending: Object.values(
|
|
298
|
+
pending: Object.values(p).filter(
|
|
299
299
|
(e) => e.status === "interactive"
|
|
300
300
|
),
|
|
301
|
-
authorize:
|
|
302
|
-
approve:
|
|
303
|
-
complete:
|
|
304
|
-
dismiss:
|
|
305
|
-
originEpochs:
|
|
306
|
-
credentials:
|
|
307
|
-
unsupported:
|
|
308
|
-
},
|
|
301
|
+
authorize: q,
|
|
302
|
+
approve: P,
|
|
303
|
+
complete: M,
|
|
304
|
+
dismiss: x,
|
|
305
|
+
originEpochs: j,
|
|
306
|
+
credentials: _,
|
|
307
|
+
unsupported: F
|
|
308
|
+
}, W = Object.values(p).filter(
|
|
309
309
|
(e) => e.status === "silent" && e.silentUrl
|
|
310
310
|
);
|
|
311
|
-
return /* @__PURE__ */
|
|
311
|
+
return /* @__PURE__ */ g.createElement(J.Provider, { value: Z }, r, W.map((e) => /* @__PURE__ */ g.createElement(
|
|
312
312
|
"iframe",
|
|
313
313
|
{
|
|
314
314
|
key: `mm-silent-auth-${e.origin}`,
|
|
@@ -320,7 +320,7 @@ const Y = ie(null), J = ie({
|
|
|
320
320
|
}
|
|
321
321
|
)));
|
|
322
322
|
};
|
|
323
|
-
|
|
323
|
+
ie.propTypes = {
|
|
324
324
|
children: T.node,
|
|
325
325
|
launcher: T.func,
|
|
326
326
|
/**
|
|
@@ -332,143 +332,143 @@ ce.propTypes = {
|
|
|
332
332
|
*/
|
|
333
333
|
broker: T.func
|
|
334
334
|
};
|
|
335
|
-
const he = () =>
|
|
336
|
-
const { originEpochs: s } =
|
|
337
|
-
return
|
|
338
|
-
},
|
|
339
|
-
const { credentials: s } =
|
|
340
|
-
return
|
|
341
|
-
},
|
|
342
|
-
const { unsupported: s } =
|
|
343
|
-
return
|
|
344
|
-
},
|
|
345
|
-
const [d,
|
|
335
|
+
const he = () => K(J), ge = (r) => {
|
|
336
|
+
const { originEpochs: s } = K(J), c = Q(r);
|
|
337
|
+
return c && s[c] || 0;
|
|
338
|
+
}, me = (r) => {
|
|
339
|
+
const { credentials: s } = K(J), c = Q(r);
|
|
340
|
+
return c && s[c] || null;
|
|
341
|
+
}, be = (r) => {
|
|
342
|
+
const { unsupported: s } = K(J), c = Q(r);
|
|
343
|
+
return c && s[c] || null;
|
|
344
|
+
}, Ee = ({ children: r, authorizationLauncher: s, credentialBroker: c }) => {
|
|
345
|
+
const [d, p] = U({}), [b, j] = U({}), I = R({}), _ = R({}), A = R({}), F = h((u, a) => {
|
|
346
346
|
var o;
|
|
347
|
-
return !!((o =
|
|
348
|
-
}, []), y = h((
|
|
349
|
-
|
|
350
|
-
}, []),
|
|
351
|
-
|
|
352
|
-
const o = { ...
|
|
353
|
-
return delete o[
|
|
354
|
-
}),
|
|
355
|
-
const o = { ...
|
|
356
|
-
return delete o[
|
|
357
|
-
}), delete
|
|
347
|
+
return !!((o = A.current[u]) != null && o.has(a));
|
|
348
|
+
}, []), y = h((u, a, o) => {
|
|
349
|
+
p((l) => ({ ...l, [u]: { origin: a, frameRef: o } }));
|
|
350
|
+
}, []), H = h((u) => {
|
|
351
|
+
p((a) => {
|
|
352
|
+
const o = { ...a };
|
|
353
|
+
return delete o[u], o;
|
|
354
|
+
}), j((a) => {
|
|
355
|
+
const o = { ...a };
|
|
356
|
+
return delete o[u], o;
|
|
357
|
+
}), delete A.current[u];
|
|
358
358
|
}, []);
|
|
359
359
|
k(() => {
|
|
360
|
-
const
|
|
361
|
-
o.forEach((
|
|
362
|
-
},
|
|
363
|
-
var
|
|
364
|
-
if (!((
|
|
360
|
+
const u = (o = [], l, w) => {
|
|
361
|
+
o.forEach((x) => x(l, w));
|
|
362
|
+
}, a = (o) => {
|
|
363
|
+
var $, B, P, q, Z, W, e;
|
|
364
|
+
if (!(($ = o == null ? void 0 : o.data) != null && $.instanceId))
|
|
365
365
|
return;
|
|
366
|
-
const { instanceId:
|
|
367
|
-
if (
|
|
366
|
+
const { instanceId: l, type: w } = o.data, x = d[l], L = (P = (B = x == null ? void 0 : x.frameRef) == null ? void 0 : B.current) == null ? void 0 : P.contentWindow;
|
|
367
|
+
if (!L || o.source !== L || o.origin !== x.origin)
|
|
368
368
|
return;
|
|
369
|
-
const
|
|
370
|
-
if (
|
|
371
|
-
const { callbackId:
|
|
372
|
-
|
|
369
|
+
const M = { origin: o.origin }, m = I.current;
|
|
370
|
+
if (w === "response") {
|
|
371
|
+
const { callbackId: t, response: n, error: i } = o.data, f = _.current[t];
|
|
372
|
+
f && (f(n, i), delete _.current[t]);
|
|
373
373
|
return;
|
|
374
374
|
}
|
|
375
|
-
if (
|
|
376
|
-
const { requestType:
|
|
377
|
-
|
|
375
|
+
if (w === "mark-registered") {
|
|
376
|
+
const { requestType: t } = o.data;
|
|
377
|
+
A.current[l] || (A.current[l] = /* @__PURE__ */ new Set()), A.current[l].add(t);
|
|
378
378
|
return;
|
|
379
379
|
}
|
|
380
|
-
|
|
380
|
+
w === "ready" && j((t) => ({ ...t, [l]: !0 })), u((q = m[l]) == null ? void 0 : q[w], o.data, M), u((Z = m["*"]) == null ? void 0 : Z[w], o.data, M), u((W = m[l]) == null ? void 0 : W["*"], o.data, M), u((e = m["*"]) == null ? void 0 : e["*"], o.data, M);
|
|
381
381
|
};
|
|
382
|
-
return window.addEventListener("message",
|
|
383
|
-
window.removeEventListener("message",
|
|
382
|
+
return window.addEventListener("message", a), () => {
|
|
383
|
+
window.removeEventListener("message", a);
|
|
384
384
|
};
|
|
385
385
|
}, [d]);
|
|
386
386
|
const E = h(
|
|
387
|
-
(
|
|
388
|
-
var
|
|
389
|
-
const
|
|
390
|
-
if (!
|
|
391
|
-
console.warn(`Origin not set for id: ${
|
|
387
|
+
(u, a, o) => {
|
|
388
|
+
var w, x;
|
|
389
|
+
const l = d[u];
|
|
390
|
+
if (!l) {
|
|
391
|
+
console.warn(`Origin not set for id: ${u}. Unable to send message.`);
|
|
392
392
|
return;
|
|
393
393
|
}
|
|
394
|
-
(
|
|
395
|
-
{ type:
|
|
396
|
-
|
|
394
|
+
(x = (w = l == null ? void 0 : l.frameRef) == null ? void 0 : w.current) != null && x.contentWindow && l.frameRef.current.contentWindow.postMessage(
|
|
395
|
+
{ type: a, ...o, instanceId: u },
|
|
396
|
+
l.origin
|
|
397
397
|
);
|
|
398
398
|
},
|
|
399
399
|
[d]
|
|
400
|
-
),
|
|
401
|
-
async (
|
|
402
|
-
const
|
|
403
|
-
delete
|
|
400
|
+
), O = R(0), G = h(() => `${Date.now()}-${++O.current}`, []), C = h(
|
|
401
|
+
async (u, a, o = {}) => new Promise((l, w) => {
|
|
402
|
+
const x = G(), L = (M, m) => {
|
|
403
|
+
delete _.current[x], m ? w(m) : l(M);
|
|
404
404
|
};
|
|
405
|
-
|
|
405
|
+
_.current[x] = L, E(u, "request", { callbackId: x, requestType: a, data: o });
|
|
406
406
|
}),
|
|
407
407
|
[E]
|
|
408
|
-
),
|
|
409
|
-
(
|
|
410
|
-
E(
|
|
408
|
+
), v = h(
|
|
409
|
+
(u, a) => {
|
|
410
|
+
E(u, "load-options", a);
|
|
411
411
|
},
|
|
412
412
|
[E]
|
|
413
|
-
),
|
|
414
|
-
(
|
|
415
|
-
E(
|
|
413
|
+
), S = h(
|
|
414
|
+
(u, a) => {
|
|
415
|
+
E(u, "validate", a);
|
|
416
416
|
},
|
|
417
417
|
[E]
|
|
418
|
-
), z =
|
|
418
|
+
), z = ue(
|
|
419
419
|
() => ({
|
|
420
420
|
registerFrame: y,
|
|
421
|
-
unregisterFrame:
|
|
421
|
+
unregisterFrame: H,
|
|
422
422
|
sendMessage: E,
|
|
423
|
-
sendRequest:
|
|
424
|
-
loadOptions:
|
|
425
|
-
validate:
|
|
426
|
-
hasHandler:
|
|
423
|
+
sendRequest: C,
|
|
424
|
+
loadOptions: v,
|
|
425
|
+
validate: S,
|
|
426
|
+
hasHandler: F,
|
|
427
427
|
readyFrames: b,
|
|
428
|
-
addListener: (
|
|
429
|
-
I.current[
|
|
428
|
+
addListener: (u, a, o) => (I.current[u] || (I.current[u] = {}), I.current[u][a] || (I.current[u][a] = []), I.current[u][a].push(o), () => {
|
|
429
|
+
I.current[u][a] = I.current[u][a].filter((l) => l !== o);
|
|
430
430
|
})
|
|
431
431
|
}),
|
|
432
432
|
[
|
|
433
433
|
y,
|
|
434
|
-
|
|
434
|
+
H,
|
|
435
435
|
E,
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
436
|
+
C,
|
|
437
|
+
v,
|
|
438
|
+
S,
|
|
439
|
+
F,
|
|
440
440
|
b
|
|
441
441
|
]
|
|
442
442
|
);
|
|
443
|
-
return /* @__PURE__ */
|
|
444
|
-
}, V = (
|
|
445
|
-
const d =
|
|
443
|
+
return /* @__PURE__ */ g.createElement(Y.Provider, { value: z }, /* @__PURE__ */ g.createElement(ie, { launcher: s, broker: c }, r));
|
|
444
|
+
}, V = (r, s, c) => {
|
|
445
|
+
const d = K(Y);
|
|
446
446
|
if (d === null)
|
|
447
447
|
throw new Error(
|
|
448
448
|
"useEmbeddedEffect must be used within a MMEmbeddableZoneProvider"
|
|
449
449
|
);
|
|
450
|
-
const
|
|
450
|
+
const p = R(c);
|
|
451
451
|
k(() => {
|
|
452
|
-
|
|
453
|
-
}, [
|
|
454
|
-
if (!(!
|
|
452
|
+
p.current = c;
|
|
453
|
+
}, [c]), k(() => {
|
|
454
|
+
if (!(!r || !s)) {
|
|
455
455
|
if (s.startsWith("key:")) {
|
|
456
456
|
const b = s.substring(4);
|
|
457
|
-
return d.readyFrames[
|
|
458
|
-
|
|
457
|
+
return d.readyFrames[r] && d.sendMessage(r, "subscribe-key", { keyChord: b }), d.addListener(
|
|
458
|
+
r,
|
|
459
459
|
`key-pressed:${b}`,
|
|
460
|
-
(...I) =>
|
|
460
|
+
(...I) => p.current(...I)
|
|
461
461
|
);
|
|
462
462
|
}
|
|
463
463
|
return d.addListener(
|
|
464
|
-
|
|
464
|
+
r,
|
|
465
465
|
s,
|
|
466
|
-
(...b) =>
|
|
466
|
+
(...b) => p.current(...b)
|
|
467
467
|
);
|
|
468
468
|
}
|
|
469
|
-
}, [d,
|
|
469
|
+
}, [d, r, s]);
|
|
470
470
|
};
|
|
471
|
-
|
|
471
|
+
Ee.propTypes = {
|
|
472
472
|
children: T.node.isRequired,
|
|
473
473
|
/**
|
|
474
474
|
* Optional interactive-step launcher for embedded authorizations,
|
|
@@ -485,13 +485,13 @@ we.propTypes = {
|
|
|
485
485
|
*/
|
|
486
486
|
credentialBroker: T.func
|
|
487
487
|
};
|
|
488
|
-
const ee = D.default || D,
|
|
488
|
+
const ee = D.default || D, we = 1e4, ke = "credentials", Re = (r, s) => `${r}/mm-embedded-interop?id=${encodeURIComponent(s)}&origin=${encodeURIComponent(
|
|
489
489
|
window.location.origin
|
|
490
|
-
)}&caps=${
|
|
490
|
+
)}&caps=${ke}`, xe = ee.iframe`
|
|
491
491
|
width: 100%;
|
|
492
492
|
height: 100%;
|
|
493
493
|
border: none;
|
|
494
|
-
visibility: ${(
|
|
494
|
+
visibility: ${(r) => r.$isReady ? "visible" : "hidden"};
|
|
495
495
|
`, Te = ee.div`
|
|
496
496
|
width: 100%;
|
|
497
497
|
height: 100%;
|
|
@@ -505,9 +505,9 @@ const ee = D.default || D, ke = 1e4, Re = "credentials", oe = (t, s) => `${t}/mm
|
|
|
505
505
|
text-align: center;
|
|
506
506
|
color: #555;
|
|
507
507
|
font-size: 14px;
|
|
508
|
-
`, Ie = (
|
|
509
|
-
const s =
|
|
510
|
-
switch (
|
|
508
|
+
`, Ie = (r) => {
|
|
509
|
+
const s = r && r.origin || "This app", c = r && r.reason || "";
|
|
510
|
+
switch (c) {
|
|
511
511
|
case "broker:scope_above_ceiling":
|
|
512
512
|
return {
|
|
513
513
|
title: `${s} can’t be authorized here`,
|
|
@@ -525,7 +525,7 @@ const ee = D.default || D, ke = 1e4, Re = "credentials", oe = (t, s) => `${t}/mm
|
|
|
525
525
|
detail: "It can’t be authorized for this account."
|
|
526
526
|
};
|
|
527
527
|
default:
|
|
528
|
-
return
|
|
528
|
+
return c.startsWith("broker:") ? {
|
|
529
529
|
title: `${s} can’t be authorized here`,
|
|
530
530
|
detail: "Authorization was refused."
|
|
531
531
|
} : {
|
|
@@ -533,11 +533,11 @@ const ee = D.default || D, ke = 1e4, Re = "credentials", oe = (t, s) => `${t}/mm
|
|
|
533
533
|
detail: "It needs an update to support embedding from a different domain."
|
|
534
534
|
};
|
|
535
535
|
}
|
|
536
|
-
},
|
|
537
|
-
const s = Ie(
|
|
538
|
-
return /* @__PURE__ */
|
|
536
|
+
}, ce = ({ entry: r }) => {
|
|
537
|
+
const s = Ie(r);
|
|
538
|
+
return /* @__PURE__ */ g.createElement(Te, { "data-reason": r && r.reason || void 0 }, /* @__PURE__ */ g.createElement("div", { style: { fontWeight: 600 } }, s.title), /* @__PURE__ */ g.createElement("div", { style: { fontSize: 12, color: "#888" } }, s.detail));
|
|
539
539
|
};
|
|
540
|
-
|
|
540
|
+
ce.propTypes = {
|
|
541
541
|
entry: T.shape({
|
|
542
542
|
origin: T.string,
|
|
543
543
|
name: T.string,
|
|
@@ -545,26 +545,26 @@ ue.propTypes = {
|
|
|
545
545
|
detail: T.object
|
|
546
546
|
})
|
|
547
547
|
};
|
|
548
|
-
const
|
|
548
|
+
const ze = ee.div`
|
|
549
549
|
height: 100%;
|
|
550
550
|
display: flex;
|
|
551
551
|
flex: 1;
|
|
552
552
|
align-items: center;
|
|
553
553
|
justify-content: center;
|
|
554
|
-
`,
|
|
555
|
-
id:
|
|
554
|
+
`, Ue = () => /* @__PURE__ */ g.createElement(ze, null, /* @__PURE__ */ g.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), Ce = ({
|
|
555
|
+
id: r,
|
|
556
556
|
src: s,
|
|
557
|
-
path:
|
|
557
|
+
path: c,
|
|
558
558
|
onInit: d = () => {
|
|
559
559
|
},
|
|
560
|
-
onTimeout:
|
|
560
|
+
onTimeout: p,
|
|
561
561
|
context: b = {},
|
|
562
|
-
params:
|
|
562
|
+
params: j = {},
|
|
563
563
|
renderUnsupported: I,
|
|
564
|
-
renderTimeout:
|
|
565
|
-
...
|
|
564
|
+
renderTimeout: _,
|
|
565
|
+
...A
|
|
566
566
|
}) => {
|
|
567
|
-
if ("isConfiguring" in
|
|
567
|
+
if ("isConfiguring" in A)
|
|
568
568
|
return console.error(
|
|
569
569
|
"isConfiguring must be passed via the params prop to MMEmbeddableZone"
|
|
570
570
|
), null;
|
|
@@ -576,78 +576,76 @@ const Ue = ee.div`
|
|
|
576
576
|
return console.error(
|
|
577
577
|
"isFullScreen must be passed via the params prop to MMEmbeddableZone"
|
|
578
578
|
), null;
|
|
579
|
-
const
|
|
580
|
-
k(() => {
|
|
581
|
-
z > 0 && L(0);
|
|
582
|
-
}, [z]);
|
|
583
|
-
const { registerFrame: o, unregisterFrame: a, sendMessage: p } = H(
|
|
579
|
+
const F = R(), [y, H] = U(), [E, O] = U(0), [G, C] = U(!1), [v, S] = U(!1), z = ge(s), u = me(s), a = be(s), [o, l] = U(0), [w, x] = U(null), { registerFrame: L, unregisterFrame: M, sendMessage: m } = K(
|
|
584
580
|
Y
|
|
585
|
-
), [
|
|
581
|
+
), [$, B] = U(), P = R(), q = R(p), Z = R(d), W = R(!1), e = h(() => {
|
|
582
|
+
W.current = !1, clearTimeout(P.current), O(0), C(!1), S(!1), x(null);
|
|
583
|
+
}, []);
|
|
586
584
|
k(() => {
|
|
587
|
-
|
|
588
|
-
}, [
|
|
589
|
-
|
|
585
|
+
(z > 0 || o > 0) && e();
|
|
586
|
+
}, [z, o, e]), k(() => {
|
|
587
|
+
q.current = p;
|
|
588
|
+
}, [p]), k(() => {
|
|
589
|
+
Z.current = d;
|
|
590
590
|
}, [d]), k(() => {
|
|
591
|
-
E &&
|
|
591
|
+
E && m(r, "set-context", {
|
|
592
592
|
context: {
|
|
593
593
|
...b
|
|
594
594
|
}
|
|
595
595
|
});
|
|
596
|
-
}, [b,
|
|
597
|
-
E &&
|
|
598
|
-
}, [
|
|
599
|
-
|
|
600
|
-
}, [
|
|
601
|
-
|
|
602
|
-
}, [
|
|
603
|
-
if (!s || !
|
|
596
|
+
}, [b, r, E]), k(() => {
|
|
597
|
+
E && m(r, "set-params", { params: j });
|
|
598
|
+
}, [j, r, E]), k(() => {
|
|
599
|
+
c !== void 0 && B((c == null ? void 0 : c.indexOf("/")) === 0 ? c : `/${c}`);
|
|
600
|
+
}, [c]), k(() => {
|
|
601
|
+
$ === void 0 || !E || m(r, "navigate", { path: $ });
|
|
602
|
+
}, [$, E, r, m]), k(() => {
|
|
603
|
+
if (!s || !r || !F)
|
|
604
604
|
return;
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
605
|
+
e();
|
|
606
|
+
const i = new URL(s);
|
|
607
|
+
return L(r, i.origin, F), Z.current(), H(Re(i.origin, r)), () => {
|
|
608
|
+
M(r);
|
|
608
609
|
};
|
|
609
|
-
}, [s,
|
|
610
|
-
if (!(!y ||
|
|
611
|
-
return
|
|
612
|
-
|
|
613
|
-
},
|
|
614
|
-
}, [y]);
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
}, [])
|
|
618
|
-
V(
|
|
619
|
-
|
|
620
|
-
}), V(
|
|
621
|
-
|
|
610
|
+
}, [s, r, L, F, e]), k(() => {
|
|
611
|
+
if (!(!y || W.current))
|
|
612
|
+
return P.current = setTimeout(() => {
|
|
613
|
+
C(!0), q.current && q.current();
|
|
614
|
+
}, we), () => clearTimeout(P.current);
|
|
615
|
+
}, [y, s, z, o]);
|
|
616
|
+
const t = h(() => {
|
|
617
|
+
W.current = !0, clearTimeout(P.current), C(!1);
|
|
618
|
+
}, []);
|
|
619
|
+
V(r, "init", (i) => {
|
|
620
|
+
t(), Array.isArray(i == null ? void 0 : i.acceptsCredentials) && x(i.acceptsCredentials);
|
|
621
|
+
}), V(r, "authorize", t), V(r, "login", t), V(r, "credential-request", () => {
|
|
622
|
+
t(), S(!0);
|
|
622
623
|
}), k(() => {
|
|
623
|
-
if (!
|
|
624
|
+
if (!v || !u)
|
|
624
625
|
return;
|
|
625
|
-
const
|
|
626
|
-
if (Array.isArray(
|
|
626
|
+
const i = w;
|
|
627
|
+
if (Array.isArray(i) && !i.includes(u.kind))
|
|
627
628
|
return;
|
|
628
|
-
const
|
|
629
|
-
|
|
630
|
-
}, [
|
|
631
|
-
|
|
629
|
+
const f = u.kind === "access_token" ? { accessToken: u.accessToken } : {};
|
|
630
|
+
m(r, "credential", { ...f, credential: u });
|
|
631
|
+
}, [v, u, w, r, m]), V(r, "ready", () => {
|
|
632
|
+
t(), O((i) => i + 1);
|
|
632
633
|
});
|
|
633
|
-
const
|
|
634
|
-
return V(
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
const e = new URL(s);
|
|
638
|
-
A.current.src = oe(e.origin, t);
|
|
639
|
-
}
|
|
634
|
+
const n = R();
|
|
635
|
+
return V(r, "heartbeat", () => {
|
|
636
|
+
n.current && clearTimeout(n.current), n.current = setTimeout(() => {
|
|
637
|
+
l((i) => i + 1);
|
|
640
638
|
}, 6e3);
|
|
641
639
|
}), k(() => () => {
|
|
642
|
-
|
|
643
|
-
}, []),
|
|
640
|
+
n.current && clearTimeout(n.current);
|
|
641
|
+
}, []), a ? I ? I(a) : /* @__PURE__ */ g.createElement(ce, { entry: a }) : G && !E ? _ ? _() : /* @__PURE__ */ g.createElement(Ue, null) : /* @__PURE__ */ g.createElement(
|
|
644
642
|
xe,
|
|
645
643
|
{
|
|
646
|
-
key: `auth-epoch-${z}`,
|
|
644
|
+
key: `auth-epoch-${z}-frame-${o}`,
|
|
647
645
|
$isReady: E,
|
|
648
|
-
ref:
|
|
646
|
+
ref: F,
|
|
649
647
|
src: y,
|
|
650
|
-
...
|
|
648
|
+
...A
|
|
651
649
|
}
|
|
652
650
|
);
|
|
653
651
|
};
|
|
@@ -693,7 +691,7 @@ const Me = D.div`
|
|
|
693
691
|
justify-content: space-between;
|
|
694
692
|
padding: 10px 0;
|
|
695
693
|
gap: 16px;
|
|
696
|
-
`,
|
|
694
|
+
`, Oe = D.button`
|
|
697
695
|
background: #16a500;
|
|
698
696
|
color: #fff;
|
|
699
697
|
border: none;
|
|
@@ -702,13 +700,13 @@ const Me = D.div`
|
|
|
702
700
|
font-size: 14px;
|
|
703
701
|
cursor: pointer;
|
|
704
702
|
white-space: nowrap;
|
|
705
|
-
`,
|
|
703
|
+
`, Le = D.p`
|
|
706
704
|
color: #b3261e;
|
|
707
705
|
font-size: 13px;
|
|
708
706
|
margin: 4px 0 0;
|
|
709
707
|
`, Fe = () => {
|
|
710
|
-
const { pending:
|
|
711
|
-
return
|
|
708
|
+
const { pending: r, authorize: s } = he();
|
|
709
|
+
return r.length === 0 ? null : /* @__PURE__ */ g.createElement(Me, null, /* @__PURE__ */ g.createElement(_e, null, /* @__PURE__ */ g.createElement("h3", { style: { margin: "0 0 8px" } }, "Authorization Required"), /* @__PURE__ */ g.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((c) => /* @__PURE__ */ g.createElement("div", { key: c.origin }, /* @__PURE__ */ g.createElement(Ae, null, /* @__PURE__ */ g.createElement("div", null, /* @__PURE__ */ g.createElement("div", { style: { fontWeight: 600 } }, c.origin)), /* @__PURE__ */ g.createElement(Oe, { onClick: () => s(c) }, "Authorize")), c.popupBlocked && /* @__PURE__ */ g.createElement(Le, null, "The sign-in window was blocked. Allow popups for this site, then try again.")))));
|
|
712
710
|
};
|
|
713
711
|
export {
|
|
714
712
|
ae as CREDENTIAL_KIND_ACCESS_TOKEN,
|
|
@@ -716,14 +714,14 @@ export {
|
|
|
716
714
|
Fe as EmbeddedAuthorizationPrompt,
|
|
717
715
|
Ce as MMEmbeddableZone,
|
|
718
716
|
Y as MMEmbeddableZoneContext,
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
717
|
+
Ee as MMEmbeddableZoneProvider,
|
|
718
|
+
fe as isCrossSite,
|
|
719
|
+
re as normalizeCredential,
|
|
720
|
+
pe as popupAuthorizationLauncher,
|
|
723
721
|
Ie as unsupportedCopy,
|
|
724
722
|
he as useEmbeddedAuthorizations,
|
|
725
|
-
|
|
723
|
+
me as useEmbeddedCredential,
|
|
726
724
|
V as useEmbeddedEffect,
|
|
727
|
-
|
|
728
|
-
|
|
725
|
+
ge as useEmbeddedOriginEpoch,
|
|
726
|
+
be as useEmbeddedUnsupported
|
|
729
727
|
};
|