@machinemetrics/mm-react-embeddable 2.0.0-3 → 2.0.0-4

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