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