@machinemetrics/mm-react-embeddable 2.0.1-0 → 2.0.1-2

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