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