@machinemetrics/mm-react-embeddable 2.0.0-6 → 2.0.0

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