@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.
@@ -1,7 +1,7 @@
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";
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 D from "styled-components";
4
- const Y = oe(null), J = oe({
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
- }), ae = "access_token", re = (r) => r ? r.kind ? r : r.accessToken ? {
18
- kind: ae,
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, le = /* @__PURE__ */ new Set(["host_not_allowed", "invalid_token", "provider_unavailable"]), X = typeof window != "undefined" && window.location.protocol === "https:", de = 8e3, Q = (r) => {
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, s) => {
28
- const c = s == null ? void 0 : s.origin;
29
- return !c || Q(r == null ? void 0 : r.authUrl) !== c ? null : c;
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 s = r.split(".");
34
- return s.length <= 2 ? r : s.slice(-2).join(".");
35
- }, fe = (r, s) => {
38
+ const i = r.split(".");
39
+ return i.length <= 2 ? r : i.slice(-2).join(".");
40
+ }, fe = (r, i) => {
36
41
  try {
37
- const c = new URL(r), d = new URL(s);
38
- return c.protocol !== d.protocol ? !0 : se(c.hostname) !== se(d.hostname);
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: s, onClosed: c }) => {
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 s(), () => {
54
+ return i(), () => {
50
55
  };
51
56
  const p = setInterval(() => {
52
- d.closed && (clearInterval(p), c());
57
+ d.closed && (clearInterval(p), u());
53
58
  }, 1e3);
54
59
  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
- const z = h((e) => {
63
- const t = C.current[e];
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 = (i) => !i[e] || i[e].clientId ? i : { ...i, [e]: { ...i[e], clientId: t } };
67
- b(n), y(n);
68
- }, []), u = h(
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 && (y((n) => n[e] ? n : {
75
+ e && (S((n) => n[e] ? n : {
71
76
  ...n,
72
- [e]: { origin: e, reason: t, clientId: C.current[e] || null }
73
- }), z(e));
77
+ [e]: { origin: e, reason: t, clientId: _.current[e] || null }
78
+ }), U(e));
74
79
  },
75
- [z]
76
- ), a = h(
80
+ [U]
81
+ ), l = h(
77
82
  (e, { v2: t = !1, origin: n = null } = {}) => {
78
- n && (t && H.current[n] || (b((i) => i[n] ? i : {
79
- ...i,
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 && S.current ? "broker" : t && e.silentUrl && X ? "silent" : "interactive",
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: v.current[n] || null,
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 || C.current[n] || null,
101
+ clientId: e.clientId || _.current[n] || null,
97
102
  popupBlocked: !1
98
103
  }
99
- }), z(n)));
104
+ }), U(n)));
100
105
  },
101
- [z]
102
- ), o = h((e) => {
103
- b((t) => {
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
- }, []), l = h(
114
+ }, []), a = h(
110
115
  (e) => {
111
- e && (o(e), I((t) => ({
116
+ e && (s(e), I((t) => ({
112
117
  ...t,
113
118
  [e]: (t[e] || 0) + 1
114
119
  })));
115
120
  },
116
- [o]
117
- ), w = h((e) => {
118
- b((t) => !t[e] || t[e].status === "interactive" ? t : {
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
- }, []), x = h(
127
+ }, []), w = h(
123
128
  (e) => {
124
- o(e.origin);
129
+ s(e.origin);
125
130
  },
126
- [o]
127
- ), L = h(
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
- u(n, "cross-site-legacy");
137
+ c(n, "cross-site-legacy");
133
138
  return;
134
139
  }
135
- a(e, { origin: n });
140
+ l(e, { origin: n });
136
141
  }
137
142
  },
138
- [a, u]
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) && (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);
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", L),
154
- d.addListener("*", "login", L),
158
+ d.addListener("*", "authorize", $),
159
+ d.addListener("*", "login", $),
155
160
  d.addListener(
156
161
  "*",
157
162
  "credential-request",
158
- (t, n) => a(t, { v2: !0, origin: ne(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, L, a, z]), k(() => {
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 i = Q(n.authUrl);
168
- if (!(!i || t.origin !== i)) {
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 (!E.current[i])
176
+ if (!b.current[o])
172
177
  return;
173
- A((f) => ({
178
+ O((f) => ({
174
179
  ...f,
175
- [i]: re({ accessToken: n.accessToken })
176
- })), o(i);
180
+ [o]: re({ accessToken: n.accessToken })
181
+ })), s(o);
177
182
  } else
178
- l(i);
183
+ a(o);
179
184
  return;
180
185
  }
181
- w(i);
186
+ E(o);
182
187
  }
183
188
  };
184
189
  return window.addEventListener("message", e), () => window.removeEventListener("message", e);
185
- }, [o, l, w]);
190
+ }, [s, a, E]);
186
191
  const M = h(
187
192
  (e, t) => {
188
- const n = e == null ? void 0 : e.origin, i = re(t);
189
- !n || !i || (A((f) => ({ ...f, [n]: i })), o(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
- [o]
192
- ), m = h((e, t) => {
193
- b((n) => n[e] ? { ...n, [e]: { ...n[e], ...t } } : n);
194
- }, []), $ = h(
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 = S.current, { origin: i } = e;
201
+ const n = F.current, { origin: o } = e;
197
202
  let f;
198
203
  try {
199
204
  f = await n(
200
- { origin: i, clientId: e.clientId, scope: e.scope, authUrl: e.authUrl },
205
+ { origin: o, clientId: e.clientId, scope: e.scope, authUrl: e.authUrl },
201
206
  { approve: t }
202
207
  );
203
208
  } catch {
204
- t ? m(i, { error: { reason: "broker_unavailable" } }) : m(i, {
205
- status: e.silentUrl && X ? "silent" : "interactive"
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
- m(i, {
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 N = (f == null ? void 0 : f.error) || "broker_error";
226
- if (!t && le.has(N)) {
227
- m(i, {
228
- status: e.silentUrl && X ? "silent" : "interactive"
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 && N === "consent_denied") {
233
- m(i, { error: null });
237
+ if (t && Y === "consent_denied") {
238
+ g(o, { error: null });
234
239
  return;
235
240
  }
236
- o(i), y((te) => ({
237
- ...te,
238
- [i]: {
239
- origin: i,
240
- reason: `broker:${N}`,
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 || C.current[i] || null
247
+ clientId: e.clientId || _.current[o] || null
243
248
  }
244
249
  }));
245
250
  },
246
- [M, m, o]
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, $(e).finally(() => {
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 P = h(
256
- (e) => !S.current || !(e != null && e.consent) ? Promise.resolve() : $(e, { approve: !0 }),
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 = G.current;
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], w(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, w]), k(() => () => {
269
- O.current && O.current(), Object.values(G.current).forEach(clearTimeout);
273
+ }, [p, E]), k(() => () => {
274
+ x.current && x.current(), Object.values(K.current).forEach(clearTimeout);
270
275
  }, []);
271
- const q = h(
276
+ const W = h(
272
277
  (e) => {
273
- O.current && (O.current(), O.current = null);
274
- const t = s || pe;
275
- O.current = t(e, {
278
+ x.current && (x.current(), x.current = null);
279
+ const t = i || pe;
280
+ x.current = t(e, {
276
281
  onBlocked: () => {
277
- b((n) => n[e.origin] ? {
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
- X && b((n) => !n[e.origin] || !n[e.origin].silentUrl ? n : {
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
- l(e.origin);
295
+ a(e.origin);
291
296
  }
292
297
  });
293
298
  },
294
- [s, l]
295
- ), Z = {
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: q,
302
- approve: P,
306
+ authorize: W,
307
+ approve: y,
303
308
  complete: M,
304
- dismiss: x,
309
+ dismiss: w,
305
310
  originEpochs: j,
306
- credentials: _,
307
- unsupported: F
308
- }, W = Object.values(p).filter(
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__ */ g.createElement(J.Provider, { value: Z }, r, W.map((e) => /* @__PURE__ */ g.createElement(
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 he = () => K(J), ge = (r) => {
336
- const { originEpochs: s } = K(J), c = Q(r);
337
- return c && s[c] || 0;
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 { 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
- var o;
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];
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 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
+ 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: 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)
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: 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]);
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 (w === "mark-registered") {
376
- const { requestType: t } = o.data;
377
- A.current[l] || (A.current[l] = /* @__PURE__ */ new Set()), A.current[l].add(t);
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
- 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);
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", a), () => {
383
- window.removeEventListener("message", a);
387
+ return window.addEventListener("message", l), () => {
388
+ window.removeEventListener("message", l);
384
389
  };
385
390
  }, [d]);
386
- const E = h(
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.`);
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
- (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
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
- ), 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);
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
- _.current[x] = L, E(u, "request", { callbackId: x, requestType: a, data: o });
410
+ L.current[w] = $, b(c, "request", { callbackId: w, requestType: l, data: s });
406
411
  }),
407
- [E]
408
- ), v = h(
409
- (u, a) => {
410
- E(u, "load-options", a);
412
+ [b]
413
+ ), q = h(
414
+ (c, l) => {
415
+ b(c, "load-options", l);
411
416
  },
412
- [E]
413
- ), S = h(
414
- (u, a) => {
415
- E(u, "validate", a);
417
+ [b]
418
+ ), F = h(
419
+ (c, l) => {
420
+ b(c, "validate", l);
416
421
  },
417
- [E]
418
- ), z = ue(
422
+ [b]
423
+ ), U = ue(
419
424
  () => ({
420
- registerFrame: y,
421
- unregisterFrame: H,
422
- sendMessage: E,
423
- sendRequest: C,
424
- loadOptions: v,
425
- validate: S,
426
- hasHandler: F,
427
- readyFrames: b,
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);
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
- b
444
+ P,
445
+ m
441
446
  ]
442
447
  );
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);
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(c);
455
+ const p = R(u);
451
456
  k(() => {
452
- p.current = c;
453
- }, [c]), k(() => {
454
- if (!(!r || !s)) {
455
- if (s.startsWith("key:")) {
456
- const b = s.substring(4);
457
- return d.readyFrames[r] && d.sendMessage(r, "subscribe-key", { keyChord: b }), d.addListener(
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:${b}`,
464
+ `key-pressed:${m}`,
460
465
  (...I) => p.current(...I)
461
466
  );
462
467
  }
463
468
  return d.addListener(
464
469
  r,
465
- s,
466
- (...b) => p.current(...b)
470
+ i,
471
+ (...m) => p.current(...m)
467
472
  );
468
473
  }
469
- }, [d, r, s]);
474
+ }, [d, r, i]);
470
475
  };
471
- Ee.propTypes = {
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 ee = D.default || D, we = 1e4, ke = "credentials", Re = (r, s) => `${r}/mm-embedded-interop?id=${encodeURIComponent(s)}&origin=${encodeURIComponent(
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}`, xe = ee.iframe`
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 = ee.div`
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 s = r && r.origin || "This app", c = r && r.reason || "";
510
- switch (c) {
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: `${s} can’t be authorized here`,
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: `${s} can’t be authorized here`,
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: `${s} can’t be authorized here`,
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 c.startsWith("broker:") ? {
529
- title: `${s} can’t be authorized here`,
533
+ return u.startsWith("broker:") ? {
534
+ title: `${i} can’t be authorized here`,
530
535
  detail: "Authorization was refused."
531
536
  } : {
532
- title: `${s} can’t be embedded here`,
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 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));
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 ze = ee.div`
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
- `, Ue = () => /* @__PURE__ */ g.createElement(ze, null, /* @__PURE__ */ g.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), Ce = ({
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: s,
557
- path: c,
561
+ src: i,
562
+ path: u,
558
563
  onInit: d = () => {
559
564
  },
560
565
  onTimeout: p,
561
- context: b = {},
566
+ context: m = {},
562
567
  params: j = {},
563
568
  renderUnsupported: I,
564
- renderTimeout: _,
565
- ...A
569
+ renderTimeout: L,
570
+ ...O
566
571
  }) => {
567
- if ("isConfiguring" in A)
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 b)
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 b)
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 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(
580
- Y
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);
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
- (z > 0 || o > 0) && e();
586
- }, [z, o, e]), k(() => {
587
- q.current = p;
590
+ (U > 0 || s > 0) && e();
591
+ }, [U, s, e]), k(() => {
592
+ W.current = p;
588
593
  }, [p]), k(() => {
589
- Z.current = d;
594
+ D.current = d;
590
595
  }, [d]), k(() => {
591
- E && m(r, "set-context", {
596
+ b && g(r, "set-context", {
592
597
  context: {
593
- ...b
598
+ ...m
594
599
  }
595
600
  });
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)
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 i = new URL(s);
607
- return L(r, i.origin, F), Z.current(), H(Re(i.origin, r)), () => {
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
- }, [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]);
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
- W.current = !0, clearTimeout(P.current), C(!1);
622
+ H.current = !0, clearTimeout(y.current), _(!1);
618
623
  }, []);
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);
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 (!v || !u)
629
+ if (!q || !c)
625
630
  return;
626
- const i = w;
627
- if (Array.isArray(i) && !i.includes(u.kind))
631
+ const o = E;
632
+ if (Array.isArray(o) && !o.includes(c.kind))
628
633
  return;
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);
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 V(r, "heartbeat", () => {
640
+ return G(r, "heartbeat", () => {
636
641
  n.current && clearTimeout(n.current), n.current = setTimeout(() => {
637
- l((i) => i + 1);
642
+ a((o) => o + 1);
638
643
  }, 6e3);
639
644
  }), k(() => () => {
640
645
  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(
642
- xe,
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-${z}-frame-${o}`,
645
- $isReady: E,
646
- ref: F,
647
- src: y,
648
- ...A
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
- Ce.propTypes = {
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
- ae as CREDENTIAL_KIND_ACCESS_TOKEN,
713
- J as EmbeddedAuthorizationContext,
714
- Fe as EmbeddedAuthorizationPrompt,
715
- Ce as MMEmbeddableZone,
716
- Y as MMEmbeddableZoneContext,
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
- he as useEmbeddedAuthorizations,
723
- me as useEmbeddedCredential,
724
- V as useEmbeddedEffect,
725
- ge as useEmbeddedOriginEpoch,
726
- be as useEmbeddedUnsupported
686
+ Oe as useEmbeddedAuthorizations,
687
+ ge as useEmbeddedCredential,
688
+ G as useEmbeddedEffect,
689
+ he as useEmbeddedOriginEpoch,
690
+ me as useEmbeddedUnsupported
727
691
  };