@neetru/sdk 3.6.0 → 3.8.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.
Files changed (117) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +66 -1
  3. package/dist/ai.cjs +298 -391
  4. package/dist/ai.d.cts +1 -1
  5. package/dist/ai.d.ts +1 -1
  6. package/dist/ai.mjs +298 -391
  7. package/dist/auth.cjs +3717 -5005
  8. package/dist/auth.d.cts +1 -1
  9. package/dist/auth.d.ts +1 -1
  10. package/dist/auth.mjs +3714 -5002
  11. package/dist/build-guard.cjs +101 -119
  12. package/dist/build-guard.mjs +91 -109
  13. package/dist/catalog.cjs +220 -225
  14. package/dist/catalog.d.cts +1 -1
  15. package/dist/catalog.d.ts +1 -1
  16. package/dist/catalog.mjs +220 -225
  17. package/dist/checkout.cjs +307 -323
  18. package/dist/checkout.d.cts +1 -1
  19. package/dist/checkout.d.ts +1 -1
  20. package/dist/checkout.mjs +306 -322
  21. package/dist/db-react.cjs +59 -87
  22. package/dist/db-react.d.cts +1 -1
  23. package/dist/db-react.d.ts +1 -1
  24. package/dist/db-react.mjs +56 -84
  25. package/dist/db.cjs +2128 -3014
  26. package/dist/db.d.cts +1 -1
  27. package/dist/db.d.ts +1 -1
  28. package/dist/db.mjs +2141 -3027
  29. package/dist/entitlements.cjs +19 -20
  30. package/dist/entitlements.d.cts +1 -1
  31. package/dist/entitlements.d.ts +1 -1
  32. package/dist/entitlements.mjs +19 -20
  33. package/dist/errors.cjs +16 -12
  34. package/dist/errors.d.cts +59 -3
  35. package/dist/errors.d.ts +59 -3
  36. package/dist/errors.mjs +15 -12
  37. package/dist/firestore-compat.cjs +241 -297
  38. package/dist/firestore-compat.d.cts +1 -1
  39. package/dist/firestore-compat.d.ts +1 -1
  40. package/dist/firestore-compat.mjs +215 -271
  41. package/dist/index.cjs +3942 -5134
  42. package/dist/index.d.cts +181 -5
  43. package/dist/index.d.ts +181 -5
  44. package/dist/index.mjs +4040 -5239
  45. package/dist/mobile.cjs +459 -344
  46. package/dist/mobile.d.cts +59 -4
  47. package/dist/mobile.d.ts +59 -4
  48. package/dist/mobile.mjs +459 -344
  49. package/dist/mocks.cjs +319 -447
  50. package/dist/mocks.d.cts +1 -1
  51. package/dist/mocks.d.ts +1 -1
  52. package/dist/mocks.mjs +313 -441
  53. package/dist/notifications.cjs +296 -317
  54. package/dist/notifications.d.cts +1 -1
  55. package/dist/notifications.d.ts +1 -1
  56. package/dist/notifications.mjs +295 -316
  57. package/dist/react.cjs +557 -707
  58. package/dist/react.d.cts +1 -1
  59. package/dist/react.d.ts +1 -1
  60. package/dist/react.mjs +547 -697
  61. package/dist/support.cjs +402 -328
  62. package/dist/support.d.cts +29 -3
  63. package/dist/support.d.ts +29 -3
  64. package/dist/support.mjs +401 -328
  65. package/dist/telemetry.cjs +267 -304
  66. package/dist/telemetry.d.cts +1 -1
  67. package/dist/telemetry.d.ts +1 -1
  68. package/dist/telemetry.mjs +267 -304
  69. package/dist/{types-Du_iioJ7.d.cts → types-D-9bjlM0.d.cts} +74 -1
  70. package/dist/{types-BPATkXYu.d.ts → types-bVztFQTI.d.ts} +74 -1
  71. package/dist/usage.cjs +233 -230
  72. package/dist/usage.d.cts +1 -1
  73. package/dist/usage.d.ts +1 -1
  74. package/dist/usage.mjs +233 -230
  75. package/dist/webhooks.cjs +328 -362
  76. package/dist/webhooks.d.cts +1 -1
  77. package/dist/webhooks.d.ts +1 -1
  78. package/dist/webhooks.mjs +325 -359
  79. package/package.json +5 -3
  80. package/dist/ai.cjs.map +0 -1
  81. package/dist/ai.mjs.map +0 -1
  82. package/dist/auth.cjs.map +0 -1
  83. package/dist/auth.mjs.map +0 -1
  84. package/dist/build-guard.cjs.map +0 -1
  85. package/dist/build-guard.mjs.map +0 -1
  86. package/dist/catalog.cjs.map +0 -1
  87. package/dist/catalog.mjs.map +0 -1
  88. package/dist/checkout.cjs.map +0 -1
  89. package/dist/checkout.mjs.map +0 -1
  90. package/dist/db-react.cjs.map +0 -1
  91. package/dist/db-react.mjs.map +0 -1
  92. package/dist/db.cjs.map +0 -1
  93. package/dist/db.mjs.map +0 -1
  94. package/dist/entitlements.cjs.map +0 -1
  95. package/dist/entitlements.mjs.map +0 -1
  96. package/dist/errors.cjs.map +0 -1
  97. package/dist/errors.mjs.map +0 -1
  98. package/dist/firestore-compat.cjs.map +0 -1
  99. package/dist/firestore-compat.mjs.map +0 -1
  100. package/dist/index.cjs.map +0 -1
  101. package/dist/index.mjs.map +0 -1
  102. package/dist/mobile.cjs.map +0 -1
  103. package/dist/mobile.mjs.map +0 -1
  104. package/dist/mocks.cjs.map +0 -1
  105. package/dist/mocks.mjs.map +0 -1
  106. package/dist/notifications.cjs.map +0 -1
  107. package/dist/notifications.mjs.map +0 -1
  108. package/dist/react.cjs.map +0 -1
  109. package/dist/react.mjs.map +0 -1
  110. package/dist/support.cjs.map +0 -1
  111. package/dist/support.mjs.map +0 -1
  112. package/dist/telemetry.cjs.map +0 -1
  113. package/dist/telemetry.mjs.map +0 -1
  114. package/dist/usage.cjs.map +0 -1
  115. package/dist/usage.mjs.map +0 -1
  116. package/dist/webhooks.cjs.map +0 -1
  117. package/dist/webhooks.mjs.map +0 -1
package/dist/react.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var React2 = require('react');
3
+ var l = require('react');
4
4
 
5
5
  function _interopNamespace(e) {
6
6
  if (e && e.__esModule) return e;
@@ -20,12 +20,12 @@ function _interopNamespace(e) {
20
20
  return Object.freeze(n);
21
21
  }
22
22
 
23
- var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
23
+ var l__namespace = /*#__PURE__*/_interopNamespace(l);
24
24
 
25
25
  // src/react.ts
26
26
 
27
27
  // src/errors.ts
28
- var NeetruError = class _NeetruError extends Error {
28
+ var E = class e extends Error {
29
29
  code;
30
30
  status;
31
31
  requestId;
@@ -38,23 +38,37 @@ var NeetruError = class _NeetruError extends Error {
38
38
  * para um `NeetruDbErrorCode` mais específico (recuperável vs não).
39
39
  */
40
40
  reason;
41
- constructor(code, message, status, requestId, reason) {
42
- super(message);
43
- this.name = "NeetruError";
44
- this.code = code;
45
- this.status = status;
46
- this.requestId = requestId;
47
- this.reason = reason;
48
- Object.setPrototypeOf(this, _NeetruError.prototype);
41
+ /**
42
+ * 3.8.0: `x-correlation-id` da requisição que falhou. O SDK gera um UUID por
43
+ * chamada (ou usa o que o chamador passou) e manda no header; o Core grava o
44
+ * mesmo id nos logs/auditoria — cite-o ao abrir um ticket de suporte.
45
+ * `undefined` em erros que acontecem antes de qualquer requisição.
46
+ */
47
+ correlationId;
48
+ constructor(t, i, n, s, c, o) {
49
+ super(i), this.name = "NeetruError", this.code = t, this.status = n, this.requestId = s, this.reason = c, this.correlationId = o, Object.setPrototypeOf(this, e.prototype);
49
50
  }
50
51
  };
51
52
 
52
53
  // src/types.ts
53
- var DEFAULT_BASE_URL = "https://api.neetru.com";
54
+ var O = "https://api.neetru.com";
55
+
56
+ // src/end-user-token.ts
57
+ var ee = /* @__PURE__ */ new WeakMap();
58
+ function te(e) {
59
+ return ee.get(e);
60
+ }
61
+ async function M(e) {
62
+ try {
63
+ let t = te(e), i = e.auth, n = t ? await t.getIdToken() : typeof i?.getIdToken == "function" ? await i.getIdToken() : null;
64
+ return typeof n == "string" && n.length > 0 ? n : null;
65
+ } catch {
66
+ return null;
67
+ }
68
+ }
54
69
 
55
70
  // src/account-bar.ts
56
- var h = React2__namespace.createElement;
57
- var DEFAULT_LABELS = {
71
+ var y = l__namespace.createElement, ne = {
58
72
  accountButton: "Abrir menu da conta",
59
73
  appsButton: "Seus produtos Neetru",
60
74
  appsTitle: "Trocar de produto",
@@ -64,191 +78,141 @@ var DEFAULT_LABELS = {
64
78
  currentBadge: "Atual",
65
79
  emptyProducts: "Nenhum outro produto dispon\xEDvel."
66
80
  };
67
- async function fetchNeetruAccountBar(client) {
68
- const auth = client.auth;
69
- const idToken = typeof auth?.getIdToken === "function" ? auth.getIdToken() : null;
70
- if (!idToken) return null;
71
- const config = client.config;
72
- const baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
73
- const fetchFn = config.fetch ?? globalThis.fetch;
74
- const url = `${baseUrl}/api/sdk/v1/account/bar`;
81
+ async function W(e) {
82
+ let t = await M(e);
83
+ if (!t) return null;
84
+ let i = e.config, n = (i.baseUrl ?? O).replace(/\/+$/, ""), s = i.fetch ?? globalThis.fetch, c = `${n}/api/sdk/v1/account/bar`;
75
85
  try {
76
- const res = await fetchFn(url, {
77
- headers: { authorization: `Bearer ${idToken}`, accept: "application/json" }
86
+ let o = await s(c, {
87
+ headers: { authorization: `Bearer ${t}`, accept: "application/json" }
78
88
  });
79
- if (!res.ok) return null;
80
- const body = await res.json();
81
- if (!body || typeof body !== "object" || !body.account) return null;
82
- return {
89
+ if (!o.ok) return null;
90
+ let r = await o.json();
91
+ return !r || typeof r != "object" || !r.account ? null : {
83
92
  account: {
84
- displayName: String(body.account.displayName ?? ""),
85
- email: String(body.account.email ?? ""),
86
- photoUrl: body.account.photoUrl ?? null
93
+ displayName: String(r.account.displayName ?? ""),
94
+ email: String(r.account.email ?? ""),
95
+ photoUrl: r.account.photoUrl ?? null
87
96
  },
88
- accountUrl: String(body.accountUrl ?? "https://minhaconta.neetru.com"),
89
- products: Array.isArray(body.products) ? body.products.filter(
90
- (p) => !!p && typeof p.slug === "string" && typeof p.url === "string"
97
+ accountUrl: String(r.accountUrl ?? "https://minhaconta.neetru.com"),
98
+ products: Array.isArray(r.products) ? r.products.filter(
99
+ (b) => !!b && typeof b.slug == "string" && typeof b.url == "string"
91
100
  ) : []
92
101
  };
93
102
  } catch {
94
103
  return null;
95
104
  }
96
105
  }
97
- function initialsFrom(nameOrEmail) {
98
- const s = (nameOrEmail ?? "").trim();
99
- if (!s) return "?";
100
- const local = s.includes("@") ? s.split("@")[0] : s;
101
- const parts = local.split(/[\s._-]+/).filter(Boolean);
102
- if (parts.length === 0) return local.slice(0, 1).toUpperCase();
103
- if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
104
- return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
106
+ function N(e) {
107
+ let t = (e ?? "").trim();
108
+ if (!t) return "?";
109
+ let i = t.includes("@") ? t.split("@")[0] : t, n = i.split(/[\s._-]+/).filter(Boolean);
110
+ return n.length === 0 ? i.slice(0, 1).toUpperCase() : n.length === 1 ? n[0].slice(0, 2).toUpperCase() : (n[0][0] + n[n.length - 1][0]).toUpperCase();
105
111
  }
106
- var C = {
112
+ var h = {
107
113
  bg: "#ffffff",
108
114
  bgHover: "#f5f5f5",
109
115
  fg: "#0a0a0a",
110
116
  muted: "#666666",
111
117
  border: "#0a0a0a",
112
118
  borderSoft: "#e5e5e5"
113
- };
114
- var SQUARE = 0;
115
- function WaffleIcon({ size = 18, color = C.fg }) {
116
- const dots = [0, 1, 2].flatMap((r) => [0, 1, 2].map((c) => ({ r, c })));
117
- const gap = size / 3;
118
- const dot = Math.max(2, size / 7);
119
- return h(
119
+ }, H = 0;
120
+ function re({ size: e = 18, color: t = h.fg }) {
121
+ let i = [0, 1, 2].flatMap((c) => [0, 1, 2].map((o) => ({ r: c, c: o }))), n = e / 3, s = Math.max(2, e / 7);
122
+ return y(
120
123
  "svg",
121
- { width: size, height: size, viewBox: `0 0 ${size} ${size}`, "aria-hidden": true, style: { display: "block" } },
122
- dots.map(
123
- ({ r, c }) => h("rect", {
124
- key: `${r}-${c}`,
125
- x: c * gap + (gap - dot) / 2,
126
- y: r * gap + (gap - dot) / 2,
127
- width: dot,
128
- height: dot,
129
- fill: color
124
+ { width: e, height: e, viewBox: `0 0 ${e} ${e}`, "aria-hidden": true, style: { display: "block" } },
125
+ i.map(
126
+ ({ r: c, c: o }) => y("rect", {
127
+ key: `${c}-${o}`,
128
+ x: o * n + (n - s) / 2,
129
+ y: c * n + (n - s) / 2,
130
+ width: s,
131
+ height: s,
132
+ fill: t
130
133
  })
131
134
  )
132
135
  );
133
136
  }
134
- function focusables(container) {
135
- if (!container) return [];
136
- return Array.from(
137
- container.querySelectorAll(
137
+ function Q(e) {
138
+ return e ? Array.from(
139
+ e.querySelectorAll(
138
140
  'a[href], button:not([disabled]), [tabindex]:not([tabindex="-1"])'
139
141
  )
140
- ).filter((el) => el.offsetParent !== null || el === document.activeElement);
142
+ ).filter((t) => t.offsetParent !== null || t === document.activeElement) : [];
141
143
  }
142
- function NeetruAccountBar({
143
- client,
144
- currentProductSlug,
145
- settingsUrl,
146
- onSignOut,
147
- fetchBar,
148
- labels,
149
- className
144
+ function oe({
145
+ client: e,
146
+ currentProductSlug: t,
147
+ settingsUrl: i,
148
+ onSignOut: n,
149
+ fetchBar: s,
150
+ labels: c,
151
+ className: o
150
152
  }) {
151
- const L = { ...DEFAULT_LABELS, ...labels };
152
- const seedAccount = React2__namespace.useMemo(() => {
153
+ let r = { ...ne, ...c }, b = l__namespace.useMemo(() => {
153
154
  try {
154
- const u = client.auth.getUser();
155
- if (!u) return null;
156
- return {
157
- displayName: u.displayName || u.email || "",
158
- email: u.email || "",
159
- photoUrl: u.photoURL ?? null
160
- };
155
+ let a = e.auth.getUser();
156
+ return a ? {
157
+ displayName: a.displayName || a.email || "",
158
+ email: a.email || "",
159
+ photoUrl: a.photoURL ?? null
160
+ } : null;
161
161
  } catch {
162
162
  return null;
163
163
  }
164
- }, [client]);
165
- const [data, setData] = React2__namespace.useState(null);
166
- const [open, setOpen] = React2__namespace.useState(null);
167
- const [signingOut, setSigningOut] = React2__namespace.useState(false);
168
- const containerRef = React2__namespace.useRef(null);
169
- const accountBtnRef = React2__namespace.useRef(null);
170
- const appsBtnRef = React2__namespace.useRef(null);
171
- const popoverRef = React2__namespace.useRef(null);
172
- React2__namespace.useEffect(() => {
173
- let cancelled = false;
174
- const run = fetchBar ?? fetchNeetruAccountBar;
175
- Promise.resolve(run(client)).then((res) => {
176
- if (!cancelled && res) setData(res);
164
+ }, [e]), [u, f] = l__namespace.useState(null), [m, w] = l__namespace.useState(null), [T, R] = l__namespace.useState(false), p = l__namespace.useRef(null), d = l__namespace.useRef(null), g = l__namespace.useRef(null), C = l__namespace.useRef(null);
165
+ l__namespace.useEffect(() => {
166
+ let a = false, k = s ?? W;
167
+ return Promise.resolve(k(e)).then((S) => {
168
+ !a && S && f(S);
177
169
  }).catch(() => {
178
- });
179
- return () => {
180
- cancelled = true;
170
+ }), () => {
171
+ a = true;
181
172
  };
182
- }, [client, fetchBar]);
183
- const account = data?.account ?? seedAccount;
184
- const accountUrl = data?.accountUrl ?? "https://minhaconta.neetru.com";
185
- const products = data?.products ?? [];
186
- const closeAndRefocus = React2__namespace.useCallback((which) => {
187
- setOpen(null);
188
- const trigger = which === "apps" ? appsBtnRef.current : accountBtnRef.current;
189
- trigger?.focus();
173
+ }, [e, s]);
174
+ let v = u?.account ?? b, G = u?.accountUrl ?? "https://minhaconta.neetru.com", A = u?.products ?? [], L = l__namespace.useCallback((a) => {
175
+ w(null), (a === "apps" ? g.current : d.current)?.focus();
190
176
  }, []);
191
- React2__namespace.useEffect(() => {
192
- if (!open) return;
193
- const first = focusables(popoverRef.current)[0];
194
- first?.focus();
195
- const onDocMouseDown = (e) => {
196
- if (containerRef.current && !containerRef.current.contains(e.target)) {
197
- setOpen(null);
198
- }
177
+ l__namespace.useEffect(() => {
178
+ if (!m) return;
179
+ Q(C.current)[0]?.focus();
180
+ let k = (S) => {
181
+ p.current && !p.current.contains(S.target) && w(null);
199
182
  };
200
- document.addEventListener("mousedown", onDocMouseDown);
201
- return () => document.removeEventListener("mousedown", onDocMouseDown);
202
- }, [open]);
203
- const onPopoverKeyDown = React2__namespace.useCallback(
204
- (e) => {
205
- if (e.key === "Escape") {
206
- e.stopPropagation();
207
- closeAndRefocus(open);
183
+ return document.addEventListener("mousedown", k), () => document.removeEventListener("mousedown", k);
184
+ }, [m]);
185
+ let P = l__namespace.useCallback(
186
+ (a) => {
187
+ if (a.key === "Escape") {
188
+ a.stopPropagation(), L(m);
208
189
  return;
209
190
  }
210
- const items = focusables(popoverRef.current);
211
- if (items.length === 0) return;
212
- const idx = items.indexOf(document.activeElement);
213
- if (e.key === "Tab") {
214
- if (e.shiftKey && idx <= 0) {
215
- e.preventDefault();
216
- items[items.length - 1].focus();
217
- } else if (!e.shiftKey && idx === items.length - 1) {
218
- e.preventDefault();
219
- items[0].focus();
220
- }
221
- } else if (e.key === "ArrowDown") {
222
- e.preventDefault();
223
- items[(idx + 1) % items.length].focus();
224
- } else if (e.key === "ArrowUp") {
225
- e.preventDefault();
226
- items[(idx - 1 + items.length) % items.length].focus();
227
- }
191
+ let k = Q(C.current);
192
+ if (k.length === 0) return;
193
+ let S = k.indexOf(document.activeElement);
194
+ a.key === "Tab" ? a.shiftKey && S <= 0 ? (a.preventDefault(), k[k.length - 1].focus()) : !a.shiftKey && S === k.length - 1 && (a.preventDefault(), k[0].focus()) : a.key === "ArrowDown" ? (a.preventDefault(), k[(S + 1) % k.length].focus()) : a.key === "ArrowUp" && (a.preventDefault(), k[(S - 1 + k.length) % k.length].focus());
228
195
  },
229
- [open, closeAndRefocus]
230
- );
231
- const handleSignOut = React2__namespace.useCallback(async () => {
232
- if (signingOut) return;
233
- setSigningOut(true);
234
- try {
235
- await client.auth.signOut();
236
- } catch {
237
- } finally {
238
- setSigningOut(false);
239
- setOpen(null);
240
- onSignOut?.();
196
+ [m, L]
197
+ ), K = l__namespace.useCallback(async () => {
198
+ if (!T) {
199
+ R(true);
200
+ try {
201
+ await e.auth.signOut();
202
+ } catch {
203
+ } finally {
204
+ R(false), w(null), n?.();
205
+ }
241
206
  }
242
- }, [client, signingOut, onSignOut]);
243
- if (!account) return null;
244
- const initials = initialsFrom(account.displayName || account.email);
245
- const avatarInner = account.photoUrl ? h("img", {
246
- src: account.photoUrl,
207
+ }, [e, T, n]);
208
+ if (!v) return null;
209
+ let I = N(v.displayName || v.email), V = v.photoUrl ? y("img", {
210
+ src: v.photoUrl,
247
211
  alt: "",
248
212
  width: 32,
249
213
  height: 32,
250
214
  style: { width: 32, height: 32, objectFit: "cover", display: "block" }
251
- }) : h(
215
+ }) : y(
252
216
  "span",
253
217
  {
254
218
  "aria-hidden": true,
@@ -258,74 +222,69 @@ function NeetruAccountBar({
258
222
  display: "inline-flex",
259
223
  alignItems: "center",
260
224
  justifyContent: "center",
261
- backgroundColor: C.fg,
225
+ backgroundColor: h.fg,
262
226
  color: "#ffffff",
263
227
  fontSize: 13,
264
228
  fontWeight: 700,
265
229
  letterSpacing: "0.02em"
266
230
  }
267
231
  },
268
- initials
269
- );
270
- const iconBtnStyle = (active) => ({
232
+ I
233
+ ), B = (a) => ({
271
234
  display: "inline-flex",
272
235
  alignItems: "center",
273
236
  justifyContent: "center",
274
237
  width: 36,
275
238
  height: 36,
276
239
  padding: 0,
277
- borderRadius: SQUARE,
278
- border: `1px solid ${active ? C.border : C.borderSoft}`,
279
- backgroundColor: active ? C.bgHover : C.bg,
280
- color: C.fg,
240
+ borderRadius: H,
241
+ border: `1px solid ${a ? h.border : h.borderSoft}`,
242
+ backgroundColor: a ? h.bgHover : h.bg,
243
+ color: h.fg,
281
244
  cursor: "pointer",
282
245
  boxSizing: "border-box",
283
246
  fontFamily: "inherit",
284
247
  overflow: "hidden"
285
- });
286
- const appsButton = h(
248
+ }), J = y(
287
249
  "button",
288
250
  {
289
251
  type: "button",
290
- ref: appsBtnRef,
291
- "aria-label": L.appsButton,
252
+ ref: g,
253
+ "aria-label": r.appsButton,
292
254
  "aria-haspopup": "menu",
293
- "aria-expanded": open === "apps",
255
+ "aria-expanded": m === "apps",
294
256
  "data-neetru-appswitcher-button": "true",
295
- onClick: () => setOpen((o) => o === "apps" ? null : "apps"),
296
- style: iconBtnStyle(open === "apps")
257
+ onClick: () => w((a) => a === "apps" ? null : "apps"),
258
+ style: B(m === "apps")
297
259
  },
298
- h(WaffleIcon, {})
299
- );
300
- const accountButton = h(
260
+ y(re, {})
261
+ ), X = y(
301
262
  "button",
302
263
  {
303
264
  type: "button",
304
- ref: accountBtnRef,
305
- "aria-label": `${L.accountButton}${account.displayName ? ` (${account.displayName})` : ""}`,
265
+ ref: d,
266
+ "aria-label": `${r.accountButton}${v.displayName ? ` (${v.displayName})` : ""}`,
306
267
  "aria-haspopup": "menu",
307
- "aria-expanded": open === "account",
268
+ "aria-expanded": m === "account",
308
269
  "data-neetru-account-button": "true",
309
- onClick: () => setOpen((o) => o === "account" ? null : "account"),
310
- style: { ...iconBtnStyle(open === "account"), width: 36, height: 36 }
270
+ onClick: () => w((a) => a === "account" ? null : "account"),
271
+ style: { ...B(m === "account"), width: 36, height: 36 }
311
272
  },
312
- avatarInner
313
- );
314
- const popoverStyle = {
273
+ V
274
+ ), F = {
315
275
  position: "absolute",
316
276
  top: "calc(100% + 6px)",
317
277
  right: 0,
318
278
  minWidth: 260,
319
279
  maxWidth: 320,
320
- backgroundColor: C.bg,
321
- border: `1px solid ${C.border}`,
322
- borderRadius: SQUARE,
280
+ backgroundColor: h.bg,
281
+ border: `1px solid ${h.border}`,
282
+ borderRadius: H,
323
283
  zIndex: 1e3,
324
- color: C.fg,
284
+ color: h.fg,
325
285
  fontFamily: "inherit"
326
286
  // BMW: sem sombra/glassmorphism — borda sólida define o recorte.
327
- };
328
- const menuItemStyle = {
287
+ }, D = {
329
288
  display: "flex",
330
289
  alignItems: "center",
331
290
  gap: 10,
@@ -333,8 +292,8 @@ function NeetruAccountBar({
333
292
  padding: "10px 14px",
334
293
  background: "transparent",
335
294
  border: "none",
336
- borderTop: `1px solid ${C.borderSoft}`,
337
- color: C.fg,
295
+ borderTop: `1px solid ${h.borderSoft}`,
296
+ color: h.fg,
338
297
  fontSize: 14,
339
298
  fontWeight: 400,
340
299
  textAlign: "left",
@@ -342,30 +301,28 @@ function NeetruAccountBar({
342
301
  cursor: "pointer",
343
302
  boxSizing: "border-box",
344
303
  fontFamily: "inherit"
345
- };
346
- const hoverHandlers = {
347
- onMouseEnter: (e) => {
348
- e.currentTarget.style.backgroundColor = C.bgHover;
304
+ }, _ = {
305
+ onMouseEnter: (a) => {
306
+ a.currentTarget.style.backgroundColor = h.bgHover;
349
307
  },
350
- onMouseLeave: (e) => {
351
- e.currentTarget.style.backgroundColor = "transparent";
308
+ onMouseLeave: (a) => {
309
+ a.currentTarget.style.backgroundColor = "transparent";
352
310
  }
353
- };
354
- const accountPopover = open === "account" ? h(
311
+ }, Y = m === "account" ? y(
355
312
  "div",
356
313
  {
357
- ref: popoverRef,
314
+ ref: C,
358
315
  role: "menu",
359
- "aria-label": L.accountButton,
316
+ "aria-label": r.accountButton,
360
317
  "data-neetru-account-menu": "true",
361
- onKeyDown: onPopoverKeyDown,
362
- style: popoverStyle
318
+ onKeyDown: P,
319
+ style: F
363
320
  },
364
321
  // Header identidade
365
- h(
322
+ y(
366
323
  "div",
367
324
  { style: { display: "flex", gap: 12, alignItems: "center", padding: 14 } },
368
- h(
325
+ y(
369
326
  "span",
370
327
  {
371
328
  "aria-hidden": true,
@@ -377,24 +334,24 @@ function NeetruAccountBar({
377
334
  alignItems: "center",
378
335
  justifyContent: "center",
379
336
  overflow: "hidden",
380
- backgroundColor: account.photoUrl ? "transparent" : C.fg,
337
+ backgroundColor: v.photoUrl ? "transparent" : h.fg,
381
338
  color: "#ffffff",
382
339
  fontSize: 15,
383
340
  fontWeight: 700
384
341
  }
385
342
  },
386
- account.photoUrl ? h("img", {
387
- src: account.photoUrl,
343
+ v.photoUrl ? y("img", {
344
+ src: v.photoUrl,
388
345
  alt: "",
389
346
  width: 40,
390
347
  height: 40,
391
348
  style: { width: 40, height: 40, objectFit: "cover", display: "block" }
392
- }) : initials
349
+ }) : I
393
350
  ),
394
- h(
351
+ y(
395
352
  "span",
396
353
  { style: { display: "flex", flexDirection: "column", minWidth: 0 } },
397
- h(
354
+ y(
398
355
  "span",
399
356
  {
400
357
  style: {
@@ -405,68 +362,67 @@ function NeetruAccountBar({
405
362
  textOverflow: "ellipsis"
406
363
  }
407
364
  },
408
- account.displayName || account.email
365
+ v.displayName || v.email
409
366
  ),
410
- account.email ? h(
367
+ v.email ? y(
411
368
  "span",
412
369
  {
413
370
  style: {
414
- color: C.muted,
371
+ color: h.muted,
415
372
  fontSize: 12,
416
373
  whiteSpace: "nowrap",
417
374
  overflow: "hidden",
418
375
  textOverflow: "ellipsis"
419
376
  }
420
377
  },
421
- account.email
378
+ v.email
422
379
  ) : null
423
380
  )
424
381
  ),
425
382
  // Minha conta Neetru
426
- h(
383
+ y(
427
384
  "a",
428
385
  {
429
386
  role: "menuitem",
430
- href: accountUrl,
387
+ href: G,
431
388
  target: "_blank",
432
389
  rel: "noopener noreferrer",
433
- style: menuItemStyle,
434
- ...hoverHandlers
390
+ style: D,
391
+ ..._
435
392
  },
436
- L.myAccount
393
+ r.myAccount
437
394
  ),
438
395
  // Configurações da conta (deste produto)
439
- settingsUrl ? h(
396
+ i ? y(
440
397
  "a",
441
- { role: "menuitem", href: settingsUrl, style: menuItemStyle, ...hoverHandlers },
442
- L.accountSettings
398
+ { role: "menuitem", href: i, style: D, ..._ },
399
+ r.accountSettings
443
400
  ) : null,
444
401
  // Sair
445
- h(
402
+ y(
446
403
  "button",
447
404
  {
448
405
  type: "button",
449
406
  role: "menuitem",
450
- onClick: handleSignOut,
451
- disabled: signingOut,
407
+ onClick: K,
408
+ disabled: T,
452
409
  "data-neetru-signout": "true",
453
- style: { ...menuItemStyle, cursor: signingOut ? "not-allowed" : "pointer" },
454
- ...hoverHandlers
410
+ style: { ...D, cursor: T ? "not-allowed" : "pointer" },
411
+ ..._
455
412
  },
456
- signingOut ? `${L.signOut}\u2026` : L.signOut
413
+ T ? `${r.signOut}\u2026` : r.signOut
457
414
  )
458
- ) : null;
459
- const appsPopover = open === "apps" ? h(
415
+ ) : null, Z = m === "apps" ? y(
460
416
  "div",
461
417
  {
462
- ref: popoverRef,
418
+ ref: C,
463
419
  role: "menu",
464
- "aria-label": L.appsTitle,
420
+ "aria-label": r.appsTitle,
465
421
  "data-neetru-appswitcher-menu": "true",
466
- onKeyDown: onPopoverKeyDown,
467
- style: { ...popoverStyle, minWidth: 280 }
422
+ onKeyDown: P,
423
+ style: { ...F, minWidth: 280 }
468
424
  },
469
- h(
425
+ y(
470
426
  "div",
471
427
  {
472
428
  style: {
@@ -475,16 +431,16 @@ function NeetruAccountBar({
475
431
  fontWeight: 700,
476
432
  letterSpacing: "0.08em",
477
433
  textTransform: "uppercase",
478
- color: C.muted
434
+ color: h.muted
479
435
  }
480
436
  },
481
- L.appsTitle
437
+ r.appsTitle
482
438
  ),
483
- products.length === 0 ? h(
439
+ A.length === 0 ? y(
484
440
  "div",
485
- { style: { padding: "4px 14px 16px", fontSize: 13, color: C.muted } },
486
- L.emptyProducts
487
- ) : h(
441
+ { style: { padding: "4px 14px 16px", fontSize: 13, color: h.muted } },
442
+ r.emptyProducts
443
+ ) : y(
488
444
  "div",
489
445
  {
490
446
  style: {
@@ -492,21 +448,21 @@ function NeetruAccountBar({
492
448
  gridTemplateColumns: "1fr 1fr",
493
449
  gap: 1,
494
450
  padding: 1,
495
- backgroundColor: C.borderSoft
451
+ backgroundColor: h.borderSoft
496
452
  }
497
453
  },
498
- products.map((p) => {
499
- const isCurrent = !!currentProductSlug && p.slug === currentProductSlug;
500
- return h(
454
+ A.map((a) => {
455
+ let k = !!t && a.slug === t;
456
+ return y(
501
457
  "a",
502
458
  {
503
- key: p.slug,
459
+ key: a.slug,
504
460
  role: "menuitem",
505
- href: p.url,
506
- "aria-current": isCurrent ? "true" : void 0,
507
- "data-neetru-product": p.slug,
508
- "data-current": isCurrent ? "true" : void 0,
509
- title: p.name,
461
+ href: a.url,
462
+ "aria-current": k ? "true" : void 0,
463
+ "data-neetru-product": a.slug,
464
+ "data-current": k ? "true" : void 0,
465
+ title: a.name,
510
466
  style: {
511
467
  display: "flex",
512
468
  flexDirection: "column",
@@ -514,26 +470,26 @@ function NeetruAccountBar({
514
470
  gap: 6,
515
471
  padding: "14px 8px",
516
472
  textDecoration: "none",
517
- color: C.fg,
518
- backgroundColor: isCurrent ? C.bgHover : C.bg,
473
+ color: h.fg,
474
+ backgroundColor: k ? h.bgHover : h.bg,
519
475
  cursor: "pointer",
520
476
  boxSizing: "border-box"
521
477
  },
522
- onMouseEnter: (e) => {
523
- e.currentTarget.style.backgroundColor = C.bgHover;
478
+ onMouseEnter: (S) => {
479
+ S.currentTarget.style.backgroundColor = h.bgHover;
524
480
  },
525
- onMouseLeave: (e) => {
526
- e.currentTarget.style.backgroundColor = isCurrent ? C.bgHover : C.bg;
481
+ onMouseLeave: (S) => {
482
+ S.currentTarget.style.backgroundColor = k ? h.bgHover : h.bg;
527
483
  }
528
484
  },
529
485
  // Tile/ícone
530
- p.iconUrl ? h("img", {
531
- src: p.iconUrl,
486
+ a.iconUrl ? y("img", {
487
+ src: a.iconUrl,
532
488
  alt: "",
533
489
  width: 32,
534
490
  height: 32,
535
491
  style: { width: 32, height: 32, objectFit: "cover", display: "block" }
536
- }) : h(
492
+ }) : y(
537
493
  "span",
538
494
  {
539
495
  "aria-hidden": true,
@@ -543,20 +499,20 @@ function NeetruAccountBar({
543
499
  display: "inline-flex",
544
500
  alignItems: "center",
545
501
  justifyContent: "center",
546
- backgroundColor: C.fg,
502
+ backgroundColor: h.fg,
547
503
  color: "#ffffff",
548
504
  fontSize: 13,
549
505
  fontWeight: 700
550
506
  }
551
507
  },
552
- initialsFrom(p.name)
508
+ N(a.name)
553
509
  ),
554
- h(
510
+ y(
555
511
  "span",
556
512
  {
557
513
  style: {
558
514
  fontSize: 12,
559
- fontWeight: isCurrent ? 700 : 400,
515
+ fontWeight: k ? 700 : 400,
560
516
  textAlign: "center",
561
517
  lineHeight: 1.2,
562
518
  maxWidth: "100%",
@@ -566,9 +522,9 @@ function NeetruAccountBar({
566
522
  width: "100%"
567
523
  }
568
524
  },
569
- p.name
525
+ a.name
570
526
  ),
571
- isCurrent ? h(
527
+ k ? y(
572
528
  "span",
573
529
  {
574
530
  style: {
@@ -576,20 +532,20 @@ function NeetruAccountBar({
576
532
  fontWeight: 700,
577
533
  letterSpacing: "0.08em",
578
534
  textTransform: "uppercase",
579
- color: C.muted
535
+ color: h.muted
580
536
  }
581
537
  },
582
- L.currentBadge
538
+ r.currentBadge
583
539
  ) : null
584
540
  );
585
541
  })
586
542
  )
587
543
  ) : null;
588
- return h(
544
+ return y(
589
545
  "div",
590
546
  {
591
- ref: containerRef,
592
- className,
547
+ ref: p,
548
+ className: o,
593
549
  "data-neetru-account-bar": "true",
594
550
  style: {
595
551
  position: "relative",
@@ -601,234 +557,205 @@ function NeetruAccountBar({
601
557
  fontFamily: "inherit"
602
558
  }
603
559
  },
604
- appsButton,
605
- accountButton,
606
- accountPopover,
607
- appsPopover
560
+ J,
561
+ X,
562
+ Y,
563
+ Z
608
564
  );
609
565
  }
610
566
 
611
567
  // src/firestore-compat.ts
612
- function toDbQuery(constraints) {
613
- const whereFilters = [];
614
- let orderByClause;
615
- let limitValue;
616
- for (const c of constraints) {
568
+ function U(e) {
569
+ let t = [], i, n;
570
+ for (let c of e)
617
571
  if (c.__constraint === "where") {
618
- const w = c;
619
- whereFilters.push({ field: w.field, op: normalizeOp(w.op), value: w.value });
572
+ let o = c;
573
+ t.push({ field: o.field, op: o.op, value: o.value });
620
574
  } else if (c.__constraint === "orderBy") {
621
- const o = c;
622
- orderByClause = { field: o.field, direction: o.direction };
623
- } else if (c.__constraint === "limit") {
624
- limitValue = c.value;
625
- }
626
- }
627
- const out = {};
628
- if (whereFilters.length > 0) out.where = whereFilters;
629
- if (orderByClause) out.orderBy = orderByClause;
630
- if (limitValue !== void 0) out.limit = limitValue;
631
- return out;
632
- }
633
- function normalizeOp(op) {
634
- return op;
575
+ let o = c;
576
+ i = { field: o.field, direction: o.direction };
577
+ } else c.__constraint === "limit" && (n = c.value);
578
+ let s = {};
579
+ return t.length > 0 && (s.where = t), i && (s.orderBy = i), n !== void 0 && (s.limit = n), s;
635
580
  }
636
581
 
637
582
  // src/react.ts
638
- async function startCheckoutViaBff(startPath, input) {
639
- const res = await fetch(startPath, {
583
+ async function ie(e, t) {
584
+ let i = await fetch(e, {
640
585
  method: "POST",
641
586
  headers: { "content-type": "application/json", accept: "application/json" },
642
587
  credentials: "include",
643
- body: JSON.stringify(input)
644
- });
645
- let payload = null;
588
+ body: JSON.stringify(t)
589
+ }), n = null;
646
590
  try {
647
- payload = await res.json();
591
+ n = await i.json();
648
592
  } catch {
649
- payload = null;
593
+ n = null;
650
594
  }
651
- if (!res.ok) {
652
- const p = payload;
653
- const errField = p?.error;
654
- const code = (errField && typeof errField === "object" && typeof errField.code === "string" ? errField.code : void 0) ?? "server_error";
655
- const msg = p && (typeof p.error === "object" && p.error?.message || typeof p.error === "string" && p.error || typeof p.message === "string" && p.message) || `Checkout BFF respondeu HTTP ${res.status}`;
656
- throw new NeetruError(
657
- code,
658
- typeof msg === "string" ? msg : `Checkout BFF respondeu HTTP ${res.status}`,
659
- res.status
595
+ if (!i.ok) {
596
+ let o = n, r = o?.error, b = (r && typeof r == "object" && typeof r.code == "string" ? r.code : void 0) ?? "server_error", u = o && (typeof o.error == "object" && o.error?.message || typeof o.error == "string" && o.error || typeof o.message == "string" && o.message) || `Checkout BFF respondeu HTTP ${i.status}`;
597
+ throw new E(
598
+ b,
599
+ typeof u == "string" ? u : `Checkout BFF respondeu HTTP ${i.status}`,
600
+ i.status
660
601
  );
661
602
  }
662
- const intent = payload?.intent ?? payload ?? {};
663
- const redirectUrl = payload?.redirectUrl ?? intent.redirectUrl;
664
- if (!redirectUrl || typeof redirectUrl !== "string") {
665
- throw new NeetruError(
603
+ let s = n?.intent ?? n ?? {}, c = n?.redirectUrl ?? s.redirectUrl;
604
+ if (!c || typeof c != "string")
605
+ throw new E(
666
606
  "invalid_response",
667
607
  "Resposta do route BFF de checkout sem `redirectUrl`."
668
608
  );
669
- }
670
609
  return {
671
- intentId: String(payload?.intentId ?? intent.intentId ?? ""),
672
- redirectUrl,
673
- status: payload?.status ?? intent.status ?? "pending",
674
- expiresAt: typeof payload?.expiresAt === "string" ? payload.expiresAt : typeof intent.expiresAt === "string" ? intent.expiresAt : "",
675
- requiresKyc: payload?.requiresKyc === true || intent.requiresKyc === true
610
+ intentId: String(n?.intentId ?? s.intentId ?? ""),
611
+ redirectUrl: c,
612
+ status: n?.status ?? s.status ?? "pending",
613
+ expiresAt: typeof n?.expiresAt == "string" ? n.expiresAt : typeof s.expiresAt == "string" ? s.expiresAt : "",
614
+ requiresKyc: n?.requiresKyc === true || s.requiresKyc === true
676
615
  };
677
616
  }
678
- function checkoutRedirect(url) {
679
- const loc = globalThis.location;
680
- if (loc && typeof loc.assign === "function") loc.assign(url);
617
+ function se(e) {
618
+ let t = globalThis.location;
619
+ t && typeof t.assign == "function" && t.assign(e);
681
620
  }
682
- function CheckoutLink({
683
- client,
684
- startPath,
685
- productId,
686
- planId,
687
- callbackUrl,
688
- tenantType,
689
- tenantId,
690
- children,
691
- onIntentCreated,
692
- onError,
693
- noAutoRedirect,
694
- ...rest
621
+ function Ee({
622
+ client: e,
623
+ startPath: t,
624
+ productId: i,
625
+ planId: n,
626
+ callbackUrl: s,
627
+ tenantType: c,
628
+ tenantId: o,
629
+ children: r,
630
+ onIntentCreated: b,
631
+ onError: u,
632
+ noAutoRedirect: f,
633
+ ...m
695
634
  }) {
696
- const [submitting, setSubmitting] = React2__namespace.useState(false);
697
- const checkout = client?.checkout;
698
- const handleClick = React2__namespace.useCallback(
699
- async (event) => {
700
- event.preventDefault();
701
- if (submitting) return;
702
- if (startPath) {
703
- setSubmitting(true);
635
+ let [w, T] = l__namespace.useState(false), R = e?.checkout, p = l__namespace.useCallback(
636
+ async (d) => {
637
+ if (d.preventDefault(), !w) {
638
+ if (t) {
639
+ T(true);
640
+ try {
641
+ let g = await ie(t, {
642
+ productId: i,
643
+ planId: n,
644
+ callbackUrl: s,
645
+ tenantType: c,
646
+ tenantId: o
647
+ });
648
+ b?.(g), f || se(g.redirectUrl);
649
+ } catch (g) {
650
+ u?.(g instanceof Error ? g : new Error(String(g)));
651
+ } finally {
652
+ T(false);
653
+ }
654
+ return;
655
+ }
656
+ if (!R || typeof R.start != "function") {
657
+ u?.(
658
+ new Error(
659
+ "CheckoutLink: passe `startPath` (padr\xE3o BFF/cookie recomendado) OU um `client` com o namespace `checkout` (SDK 1.1+)."
660
+ )
661
+ );
662
+ return;
663
+ }
664
+ T(true);
704
665
  try {
705
- const result = await startCheckoutViaBff(startPath, {
706
- productId,
707
- planId,
708
- callbackUrl,
709
- tenantType,
710
- tenantId
666
+ let g = await R.start({
667
+ productId: i,
668
+ planId: n,
669
+ callbackUrl: s,
670
+ tenantType: c,
671
+ tenantId: o,
672
+ autoRedirect: !f
711
673
  });
712
- onIntentCreated?.(result);
713
- if (!noAutoRedirect) checkoutRedirect(result.redirectUrl);
714
- } catch (err) {
715
- onError?.(err instanceof Error ? err : new Error(String(err)));
674
+ b?.(g);
675
+ } catch (g) {
676
+ u?.(g instanceof Error ? g : new Error(String(g)));
716
677
  } finally {
717
- setSubmitting(false);
678
+ T(false);
718
679
  }
719
- return;
720
- }
721
- if (!checkout || typeof checkout.start !== "function") {
722
- onError?.(
723
- new Error(
724
- "CheckoutLink: passe `startPath` (padr\xE3o BFF/cookie recomendado) OU um `client` com o namespace `checkout` (SDK 1.1+)."
725
- )
726
- );
727
- return;
728
- }
729
- setSubmitting(true);
730
- try {
731
- const result = await checkout.start({
732
- productId,
733
- planId,
734
- callbackUrl,
735
- tenantType,
736
- tenantId,
737
- autoRedirect: !noAutoRedirect
738
- });
739
- onIntentCreated?.(result);
740
- } catch (err) {
741
- onError?.(err instanceof Error ? err : new Error(String(err)));
742
- } finally {
743
- setSubmitting(false);
744
680
  }
745
681
  },
746
- [submitting, checkout, startPath, productId, planId, callbackUrl, tenantType, tenantId, noAutoRedirect, onIntentCreated, onError]
682
+ [w, R, t, i, n, s, c, o, f, b, u]
747
683
  );
748
- return React2__namespace.createElement(
684
+ return l__namespace.createElement(
749
685
  "a",
750
686
  {
751
- ...rest,
752
- href: rest.href ?? "#",
753
- onClick: handleClick,
754
- "aria-busy": submitting || void 0,
687
+ ...m,
688
+ href: m.href ?? "#",
689
+ onClick: p,
690
+ "aria-busy": w || void 0,
755
691
  "data-neetru-checkout-link": "true"
756
692
  },
757
- children
693
+ r
758
694
  );
759
695
  }
760
- var NEETRU_FLAME_PATH = "M 281 5.163 C 240.659 26.308, 211.260 52.739, 187.750 89 C 177.297 105.123, 167.942 126.107, 162.988 144.543 C 154.486 176.188, 153.303 204.118, 159.101 236.317 C 161.553 249.934, 164.601 259.065, 171.539 273.568 C 179.323 289.843, 188.311 302.619, 205.856 322.343 C 216.993 334.865, 218.719 337.460, 223.536 348.944 C 233.797 373.403, 237.419 401.984, 232.417 419.032 C 229.111 430.300, 219.859 441.975, 210.427 446.779 C 186.006 459.218, 155.612 448.383, 142.319 422.500 C 128.813 396.204, 123.953 356.753, 129.495 318.395 C 131.172 306.786, 138.276 276.222, 140.080 272.850 C 140.675 271.738, 140.944 270.610, 140.676 270.343 C 139.995 269.662, 121.004 281.262, 112 287.859 C 100.565 296.237, 95.542 300.566, 83.993 312 C 44.470 351.127, 19.275 398.763, 8.623 454.500 C 4.302 477.115, 3.308 513.551, 6.332 538.569 C 9.164 562.011, 17.855 591.852, 27.324 610.648 C 37.693 631.233, 54.130 653.987, 71.900 672.357 C 80.540 681.289, 98.477 696.992, 104.478 700.878 C 106.690 702.310, 108.725 703.766, 109 704.114 C 109.836 705.172, 125.939 715.307, 135.539 720.817 C 152.923 730.795, 169.097 737.316, 200.500 747.009 C 204.454 748.230, 222.087 751.463, 234 753.153 C 246.383 754.909, 283.484 754.921, 296 753.173 C 310.006 751.217, 321.722 749.122, 328.500 747.360 C 384.024 732.928, 433.393 701.075, 469.555 656.351 C 491.448 629.275, 505.223 601.823, 514.391 567 C 519.380 548.047, 520.999 536.377, 521.686 514.410 C 523.126 468.370, 514.560 426.479, 494.812 383 C 471.567 331.818, 436.019 282.480, 379.951 223.582 C 354.302 196.638, 349.024 190.981, 341.670 182.551 C 318.918 156.471, 301.763 128.316, 293.505 103.500 C 286.625 82.826, 285.662 76.446, 285.578 51 C 285.500 27.576, 285.510 27.460, 288.750 15.129 C 290.538 8.326, 292 2.363, 292 1.879 C 292 0.197, 288.454 1.255, 281 5.163";
761
- var NEETRU_FLAME_VIEWBOX = "0 0 527 760";
762
- var NEETRU_FLAME_ASPECT = 527 / 760;
763
- function NeetruFlameIcon({ fill, size = 16 }) {
764
- return React2__namespace.createElement(
696
+ var ae = "M 281 5.163 C 240.659 26.308, 211.260 52.739, 187.750 89 C 177.297 105.123, 167.942 126.107, 162.988 144.543 C 154.486 176.188, 153.303 204.118, 159.101 236.317 C 161.553 249.934, 164.601 259.065, 171.539 273.568 C 179.323 289.843, 188.311 302.619, 205.856 322.343 C 216.993 334.865, 218.719 337.460, 223.536 348.944 C 233.797 373.403, 237.419 401.984, 232.417 419.032 C 229.111 430.300, 219.859 441.975, 210.427 446.779 C 186.006 459.218, 155.612 448.383, 142.319 422.500 C 128.813 396.204, 123.953 356.753, 129.495 318.395 C 131.172 306.786, 138.276 276.222, 140.080 272.850 C 140.675 271.738, 140.944 270.610, 140.676 270.343 C 139.995 269.662, 121.004 281.262, 112 287.859 C 100.565 296.237, 95.542 300.566, 83.993 312 C 44.470 351.127, 19.275 398.763, 8.623 454.500 C 4.302 477.115, 3.308 513.551, 6.332 538.569 C 9.164 562.011, 17.855 591.852, 27.324 610.648 C 37.693 631.233, 54.130 653.987, 71.900 672.357 C 80.540 681.289, 98.477 696.992, 104.478 700.878 C 106.690 702.310, 108.725 703.766, 109 704.114 C 109.836 705.172, 125.939 715.307, 135.539 720.817 C 152.923 730.795, 169.097 737.316, 200.500 747.009 C 204.454 748.230, 222.087 751.463, 234 753.153 C 246.383 754.909, 283.484 754.921, 296 753.173 C 310.006 751.217, 321.722 749.122, 328.500 747.360 C 384.024 732.928, 433.393 701.075, 469.555 656.351 C 491.448 629.275, 505.223 601.823, 514.391 567 C 519.380 548.047, 520.999 536.377, 521.686 514.410 C 523.126 468.370, 514.560 426.479, 494.812 383 C 471.567 331.818, 436.019 282.480, 379.951 223.582 C 354.302 196.638, 349.024 190.981, 341.670 182.551 C 318.918 156.471, 301.763 128.316, 293.505 103.500 C 286.625 82.826, 285.662 76.446, 285.578 51 C 285.500 27.576, 285.510 27.460, 288.750 15.129 C 290.538 8.326, 292 2.363, 292 1.879 C 292 0.197, 288.454 1.255, 281 5.163", ce = "0 0 527 760", le = 527 / 760;
697
+ function ue({ fill: e, size: t = 16 }) {
698
+ return l__namespace.createElement(
765
699
  "svg",
766
700
  {
767
- viewBox: NEETRU_FLAME_VIEWBOX,
768
- width: Math.round(size * NEETRU_FLAME_ASPECT),
769
- height: size,
701
+ viewBox: ce,
702
+ width: Math.round(t * le),
703
+ height: t,
770
704
  "aria-hidden": true,
771
705
  style: { flexShrink: 0 }
772
706
  },
773
- React2__namespace.createElement("path", { d: NEETRU_FLAME_PATH, fill })
707
+ l__namespace.createElement("path", { d: ae, fill: e })
774
708
  );
775
709
  }
776
- var NEETRU_LOGIN_BUTTON_THEME = {
710
+ var de = {
777
711
  dark: { bg: "#0a0a0a", bgHover: "#1a1a1a", fg: "#ffffff", border: "#0a0a0a" },
778
712
  light: { bg: "#ffffff", bgHover: "#f5f5f5", fg: "#0a0a0a", border: "#0a0a0a" }
779
- };
780
- var NEETRU_LOGIN_FOCUS_STYLE_ID = "neetru-login-button-focus-style";
781
- var NEETRU_LOGIN_FOCUS_CSS = "button[data-neetru-login-button]:focus-visible{outline:2px solid var(--neetru-login-focus-ring,#ffffff);outline-offset:2px;}";
782
- function ensureLoginFocusStyleInjected() {
783
- if (typeof document === "undefined" || !document.head) return;
784
- if (document.getElementById(NEETRU_LOGIN_FOCUS_STYLE_ID)) return;
785
- const styleEl = document.createElement("style");
786
- styleEl.id = NEETRU_LOGIN_FOCUS_STYLE_ID;
787
- styleEl.textContent = NEETRU_LOGIN_FOCUS_CSS;
788
- document.head.appendChild(styleEl);
713
+ }, j = "neetru-login-button-focus-style", pe = "button[data-neetru-login-button]:focus-visible{outline:2px solid var(--neetru-login-focus-ring,#ffffff);outline-offset:2px;}";
714
+ function ge() {
715
+ if (typeof document > "u" || !document.head || document.getElementById(j)) return;
716
+ let e = document.createElement("style");
717
+ e.id = j, e.textContent = pe, document.head.appendChild(e);
789
718
  }
790
- function NeetruLoginButton({
791
- client,
792
- redirectUri,
793
- scope,
794
- postLoginRedirect,
795
- theme = "dark",
796
- label = "Entrar com Neetru",
797
- onError,
798
- style,
799
- disabled,
800
- ...rest
719
+ function De({
720
+ client: e,
721
+ redirectUri: t,
722
+ scope: i,
723
+ postLoginRedirect: n,
724
+ theme: s = "dark",
725
+ label: c = "Entrar com Neetru",
726
+ onError: o,
727
+ style: r,
728
+ disabled: b,
729
+ ...u
801
730
  }) {
802
- const [isLoading, setIsLoading] = React2__namespace.useState(false);
803
- const [isHover, setIsHover] = React2__namespace.useState(false);
804
- const colors = NEETRU_LOGIN_BUTTON_THEME[theme];
805
- const isDisabled = Boolean(disabled) || isLoading;
806
- React2__namespace.useEffect(() => {
807
- ensureLoginFocusStyleInjected();
731
+ let [f, m] = l__namespace.useState(false), [w, T] = l__namespace.useState(false), R = de[s], p = !!b || f;
732
+ l__namespace.useEffect(() => {
733
+ ge();
808
734
  }, []);
809
- const handleClick = React2__namespace.useCallback(async () => {
810
- if (isDisabled) return;
811
- setIsLoading(true);
812
- try {
813
- const options = { redirectUri, scope, postLoginRedirect };
814
- await client.auth.signIn(options);
815
- } catch (err) {
816
- onError?.(err instanceof Error ? err : new Error(String(err)));
817
- } finally {
818
- setIsLoading(false);
735
+ let d = l__namespace.useCallback(async () => {
736
+ if (!p) {
737
+ m(true);
738
+ try {
739
+ let g = { redirectUri: t, scope: i, postLoginRedirect: n };
740
+ await e.auth.signIn(g);
741
+ } catch (g) {
742
+ o?.(g instanceof Error ? g : new Error(String(g)));
743
+ } finally {
744
+ m(false);
745
+ }
819
746
  }
820
- }, [client, redirectUri, scope, postLoginRedirect, isDisabled, onError]);
821
- return React2__namespace.createElement(
747
+ }, [e, t, i, n, p, o]);
748
+ return l__namespace.createElement(
822
749
  "button",
823
750
  {
824
- ...rest,
751
+ ...u,
825
752
  type: "button",
826
- onClick: handleClick,
827
- disabled: isDisabled,
828
- onMouseEnter: () => setIsHover(true),
829
- onMouseLeave: () => setIsHover(false),
830
- "aria-label": rest["aria-label"] ?? label,
831
- "aria-busy": isLoading || void 0,
753
+ onClick: d,
754
+ disabled: p,
755
+ onMouseEnter: () => T(true),
756
+ onMouseLeave: () => T(false),
757
+ "aria-label": u["aria-label"] ?? c,
758
+ "aria-busy": f || void 0,
832
759
  "data-neetru-login-button": "true",
833
760
  style: {
834
761
  display: "inline-flex",
@@ -839,355 +766,278 @@ function NeetruLoginButton({
839
766
  height: "48px",
840
767
  padding: "0 20px",
841
768
  borderRadius: 0,
842
- border: `1px solid ${colors.border}`,
843
- backgroundColor: isHover && !isDisabled ? colors.bgHover : colors.bg,
844
- color: colors.fg,
769
+ border: `1px solid ${R.border}`,
770
+ backgroundColor: w && !p ? R.bgHover : R.bg,
771
+ color: R.fg,
845
772
  fontSize: "14px",
846
773
  fontWeight: 700,
847
774
  textTransform: "uppercase",
848
775
  letterSpacing: "0.08em",
849
776
  fontFamily: "inherit",
850
777
  lineHeight: 1,
851
- cursor: isDisabled ? "not-allowed" : "pointer",
852
- opacity: isDisabled && !isLoading ? 0.6 : 1,
778
+ cursor: p ? "not-allowed" : "pointer",
779
+ opacity: p && !f ? 0.6 : 1,
853
780
  transition: "background-color 150ms ease",
854
781
  boxSizing: "border-box",
855
782
  // Cor do ring de foco de teclado (:focus-visible) — ver
856
783
  // NEETRU_LOGIN_FOCUS_CSS. Usa a cor do texto (contraste AA garantido).
857
- "--neetru-login-focus-ring": colors.fg,
858
- ...style
784
+ "--neetru-login-focus-ring": R.fg,
785
+ ...r
859
786
  }
860
787
  },
861
- React2__namespace.createElement(NeetruFlameIcon, { fill: colors.fg }),
862
- React2__namespace.createElement("span", null, isLoading ? "Entrando\u2026" : label)
788
+ l__namespace.createElement(ue, { fill: R.fg }),
789
+ l__namespace.createElement("span", null, f ? "Entrando\u2026" : c)
863
790
  );
864
791
  }
865
- var EntitlementContext = React2__namespace.createContext({
792
+ var $ = l__namespace.createContext({
866
793
  readonly: false
867
794
  });
868
- function useEntitlementContext() {
869
- return React2__namespace.useContext(EntitlementContext);
795
+ function _e() {
796
+ return l__namespace.useContext($);
870
797
  }
871
- function EntitlementGate({
872
- client,
873
- feature,
874
- productSlug,
875
- mode = "block",
876
- fallback,
877
- loading,
878
- children
798
+ function Ne({
799
+ client: e,
800
+ feature: t,
801
+ productSlug: i,
802
+ mode: n = "block",
803
+ fallback: s,
804
+ loading: c,
805
+ children: o
879
806
  }) {
880
- const [state, setState] = React2__namespace.useState({
807
+ let [r, b] = l__namespace.useState({
881
808
  status: "loading"
882
- });
883
- const resolvedSlug = productSlug ?? client.config.productId ?? "";
884
- const resolvedTenantId = client.config.tenantId;
885
- React2__namespace.useEffect(() => {
886
- let cancelled = false;
887
- const run = async () => {
809
+ }), u = i ?? e.config.productId ?? "", f = e.config.tenantId;
810
+ if (l__namespace.useEffect(() => {
811
+ let R = false;
812
+ return (async () => {
888
813
  try {
889
- let result2;
890
- const usage = client.usage;
891
- if (usage && typeof usage.check === "function" && resolvedTenantId) {
892
- const res = await usage.check(feature, {
893
- productId: resolvedSlug,
894
- tenantId: resolvedTenantId
814
+ let d, g = e.usage;
815
+ if (g && typeof g.check == "function" && f) {
816
+ let C = await g.check(t, {
817
+ productId: u,
818
+ tenantId: f
895
819
  });
896
- result2 = {
897
- allowed: res.allowed === true,
898
- reason: res.reason,
899
- limit: res.limit,
900
- currentUsage: res.currentUsage,
901
- behavior: res.behavior
820
+ d = {
821
+ allowed: C.allowed === !0,
822
+ reason: C.reason,
823
+ limit: C.limit,
824
+ currentUsage: C.currentUsage,
825
+ behavior: C.behavior
902
826
  };
903
- } else {
904
- if (typeof console !== "undefined") {
905
- console.warn(
906
- "[EntitlementGate] tenantId ausente em client.config \u2014 n\xE3o \xE9 poss\xEDvel verificar entitlement (client.entitlements.check() est\xE1 deprecado, ver src/entitlements.ts). Configure tenantId no createNeetruClient() ou passe via props. Bloqueando por padr\xE3o (fail-closed)."
907
- );
908
- }
909
- result2 = { allowed: false, reason: "tenant_id_required" };
910
- }
911
- if (!cancelled) setState({ status: "ready", result: result2 });
912
- } catch (err) {
913
- if (!cancelled) {
914
- setState({ status: "ready", result: { allowed: true, reason: "check_error_fallback" } });
915
- }
916
- if (typeof console !== "undefined") console.warn("[EntitlementGate] check failed \u2014 fail-open", err);
827
+ } else
828
+ typeof console < "u" && console.warn(
829
+ "[EntitlementGate] tenantId ausente em client.config \u2014 n\xE3o \xE9 poss\xEDvel verificar entitlement (client.entitlements.check() est\xE1 deprecado, ver src/entitlements.ts). Configure tenantId no createNeetruClient() ou passe via props. Bloqueando por padr\xE3o (fail-closed)."
830
+ ), d = { allowed: !1, reason: "tenant_id_required" };
831
+ R || b({ status: "ready", result: d });
832
+ } catch (d) {
833
+ R || b({ status: "ready", result: { allowed: true, reason: "check_error_fallback" } }), typeof console < "u" && console.warn("[EntitlementGate] check failed \u2014 fail-open", d);
917
834
  }
835
+ })(), () => {
836
+ R = true;
918
837
  };
919
- run();
920
- return () => {
921
- cancelled = true;
922
- };
923
- }, [client, feature, resolvedSlug, resolvedTenantId]);
924
- if (state.status === "loading") {
925
- return React2__namespace.createElement(React2__namespace.Fragment, null, loading ?? null);
926
- }
927
- const result = state.result;
928
- const allowed = result?.allowed === true;
929
- const isReadonly = !allowed && (mode === "readonly" || result?.behavior === "readonly");
930
- if (!allowed && mode === "block" && !isReadonly) {
931
- return React2__namespace.createElement(React2__namespace.Fragment, null, fallback ?? null);
932
- }
933
- return React2__namespace.createElement(
934
- EntitlementContext.Provider,
838
+ }, [e, t, u, f]), r.status === "loading")
839
+ return l__namespace.createElement(l__namespace.Fragment, null, c ?? null);
840
+ let m = r.result, w = m?.allowed === true, T = !w && (n === "readonly" || m?.behavior === "readonly");
841
+ return !w && n === "block" && !T ? l__namespace.createElement(l__namespace.Fragment, null, s ?? null) : l__namespace.createElement(
842
+ $.Provider,
935
843
  {
936
844
  value: {
937
- readonly: isReadonly,
938
- reason: result?.reason,
939
- limit: result?.limit,
940
- currentUsage: result?.currentUsage
845
+ readonly: T,
846
+ reason: m?.reason,
847
+ limit: m?.limit,
848
+ currentUsage: m?.currentUsage
941
849
  }
942
850
  },
943
- children
851
+ o
944
852
  );
945
853
  }
946
- var DEFAULT_INTERVAL_MS = 5e3;
947
- function isDocumentHidden() {
948
- return typeof document !== "undefined" && document.hidden === true;
854
+ var q = 5e3;
855
+ function z() {
856
+ return typeof document < "u" && document.hidden === true;
949
857
  }
950
- function serializeSource(source) {
951
- if (!source) return null;
952
- if (source.__kind === "collection") {
953
- return `collection:${source.id}`;
954
- }
955
- const dbQuery = toDbQuery(source.constraints);
956
- return `query:${source.collection}:${JSON.stringify(dbQuery)}`;
858
+ function fe(e) {
859
+ if (!e) return null;
860
+ if (e.__kind === "collection")
861
+ return `collection:${e.id}`;
862
+ let t = U(e.constraints);
863
+ return `query:${e.collection}:${JSON.stringify(t)}`;
957
864
  }
958
- function rowsFromList(snap) {
959
- return snap.docs.map((d) => {
960
- const data = d.data;
961
- const { id: _omit, ...rest } = data;
962
- return { ...rest, id: d.id };
865
+ function me(e) {
866
+ return e.docs.map((t) => {
867
+ let i = t.data, { id: n, ...s } = i;
868
+ return { ...s, id: t.id };
963
869
  });
964
870
  }
965
- function rowFromGet(snap, id) {
966
- const first = snap?.docs[0];
967
- if (!first) return null;
968
- const data = first.data;
969
- const { id: _omit, ...rest } = data;
970
- return { ...rest, id };
871
+ function ye(e, t) {
872
+ let i = e?.docs[0];
873
+ if (!i) return null;
874
+ let n = i.data, { id: s, ...c } = n;
875
+ return { ...c, id: t };
971
876
  }
972
- function useCollection(source, options) {
973
- const intervalMs = options?.intervalMs ?? DEFAULT_INTERVAL_MS;
974
- const poll = options?.poll ?? false;
975
- const sourceKey = serializeSource(
976
- source
977
- );
978
- const [state, setState] = React2__namespace.useState({
877
+ function Ue(e, t) {
878
+ let i = t?.intervalMs ?? q, n = t?.poll ?? false, s = fe(
879
+ e
880
+ ), [c, o] = l__namespace.useState({
979
881
  data: null,
980
- isLoading: sourceKey !== null,
882
+ isLoading: s !== null,
981
883
  error: null,
982
884
  isStale: false,
983
885
  lastUpdated: null
984
- });
985
- const mountedRef = React2__namespace.useRef(true);
986
- const sourceRef = React2__namespace.useRef(source);
987
- sourceRef.current = source;
988
- React2__namespace.useEffect(() => {
989
- mountedRef.current = true;
990
- const current = sourceRef.current;
991
- if (!current || sourceKey === null) {
992
- setState({ data: null, isLoading: false, error: null, isStale: false, lastUpdated: null });
993
- return () => {
994
- mountedRef.current = false;
886
+ }), r = l__namespace.useRef(true), b = l__namespace.useRef(e);
887
+ return b.current = e, l__namespace.useEffect(() => {
888
+ r.current = true;
889
+ let u = b.current;
890
+ if (!u || s === null)
891
+ return o({ data: null, isLoading: false, error: null, isStale: false, lastUpdated: null }), () => {
892
+ r.current = false;
995
893
  };
996
- }
997
- setState((prev) => ({ ...prev, isLoading: prev.data === null }));
998
- const collectionName = current.__kind === "query" ? current.collection : current.id;
999
- const dbQuery = current.__kind === "query" ? toDbQuery(current.constraints) : void 0;
1000
- const col = current.db.collection(collectionName);
1001
- const applySnap = (snap) => {
1002
- if (!mountedRef.current) return;
1003
- setState({
1004
- data: rowsFromList(snap),
894
+ o((d) => ({ ...d, isLoading: d.data === null }));
895
+ let f = u.__kind === "query" ? u.collection : u.id, m = u.__kind === "query" ? U(u.constraints) : void 0, w = u.db.collection(f), T = (d) => {
896
+ r.current && o({
897
+ data: me(d),
1005
898
  isLoading: false,
1006
899
  error: null,
1007
- isStale: snap.stale === true,
900
+ isStale: d.stale === true,
1008
901
  lastUpdated: Date.now()
1009
902
  });
1010
- };
1011
- const applyError = (e) => {
1012
- if (!mountedRef.current) return;
1013
- setState((prev) => ({
1014
- ...prev,
903
+ }, R = (d) => {
904
+ r.current && o((g) => ({
905
+ ...g,
1015
906
  // Mantém o último data bom — não limpa em erro de refresh.
1016
907
  isLoading: false,
1017
- error: e instanceof Error ? e : new Error(String(e)),
908
+ error: d instanceof Error ? d : new Error(String(d)),
1018
909
  isStale: true
1019
910
  }));
1020
911
  };
1021
- if (poll) {
1022
- let cancelled = false;
1023
- const fetchOnce = async () => {
1024
- if (cancelled || isDocumentHidden()) return;
1025
- try {
1026
- const snap = await col.list(dbQuery);
1027
- if (!cancelled) applySnap(snap);
1028
- } catch (e) {
1029
- if (!cancelled) applyError(e);
1030
- }
912
+ if (n) {
913
+ let d = false, g = async () => {
914
+ if (!(d || z()))
915
+ try {
916
+ let v = await w.list(m);
917
+ d || T(v);
918
+ } catch (v) {
919
+ d || R(v);
920
+ }
1031
921
  };
1032
- void fetchOnce();
1033
- const timer = setInterval(fetchOnce, intervalMs);
922
+ g();
923
+ let C = setInterval(g, i);
1034
924
  return () => {
1035
- cancelled = true;
1036
- clearInterval(timer);
1037
- mountedRef.current = false;
925
+ d = true, clearInterval(C), r.current = false;
1038
926
  };
1039
927
  }
1040
- let unsub;
928
+ let p;
1041
929
  try {
1042
- unsub = col.onSnapshot(dbQuery, applySnap);
1043
- } catch (e) {
1044
- applyError(e);
930
+ p = w.onSnapshot(m, T);
931
+ } catch (d) {
932
+ R(d);
1045
933
  }
1046
934
  return () => {
1047
- mountedRef.current = false;
1048
- unsub?.();
935
+ r.current = false, p?.();
1049
936
  };
1050
- }, [sourceKey, intervalMs, poll]);
1051
- return state;
937
+ }, [s, i, n]), c;
1052
938
  }
1053
- function useDoc(ref, options) {
1054
- const intervalMs = options?.intervalMs ?? DEFAULT_INTERVAL_MS;
1055
- const poll = options?.poll ?? false;
1056
- const refKey = ref && ref.id ? `${ref.collection}/${ref.id}` : null;
1057
- const [state, setState] = React2__namespace.useState({
939
+ function Ae(e, t) {
940
+ let i = t?.intervalMs ?? q, n = t?.poll ?? false, s = e && e.id ? `${e.collection}/${e.id}` : null, [c, o] = l__namespace.useState({
1058
941
  data: null,
1059
- isLoading: refKey !== null,
942
+ isLoading: s !== null,
1060
943
  error: null,
1061
944
  isStale: false,
1062
945
  lastUpdated: null
1063
- });
1064
- const mountedRef = React2__namespace.useRef(true);
1065
- const refRef = React2__namespace.useRef(ref);
1066
- refRef.current = ref;
1067
- React2__namespace.useEffect(() => {
1068
- mountedRef.current = true;
1069
- const current = refRef.current;
1070
- if (!current || refKey === null) {
1071
- setState({ data: null, isLoading: false, error: null, isStale: false, lastUpdated: null });
1072
- return () => {
1073
- mountedRef.current = false;
946
+ }), r = l__namespace.useRef(true), b = l__namespace.useRef(e);
947
+ return b.current = e, l__namespace.useEffect(() => {
948
+ r.current = true;
949
+ let u = b.current;
950
+ if (!u || s === null)
951
+ return o({ data: null, isLoading: false, error: null, isStale: false, lastUpdated: null }), () => {
952
+ r.current = false;
1074
953
  };
1075
- }
1076
- setState((prev) => ({ ...prev, isLoading: prev.data === null }));
1077
- const docRef = current.db.collection(current.collection).doc(current.id);
1078
- const id = current.id;
1079
- const applySnap = (snap) => {
1080
- if (!mountedRef.current) return;
1081
- setState({
1082
- data: rowFromGet(snap, id),
954
+ o((p) => ({ ...p, isLoading: p.data === null }));
955
+ let f = u.db.collection(u.collection).doc(u.id), m = u.id, w = (p) => {
956
+ r.current && o({
957
+ data: ye(p, m),
1083
958
  isLoading: false,
1084
959
  error: null,
1085
- isStale: snap?.stale === true,
960
+ isStale: p?.stale === true,
1086
961
  lastUpdated: Date.now()
1087
962
  });
1088
- };
1089
- const applyError = (e) => {
1090
- if (!mountedRef.current) return;
1091
- setState((prev) => ({
1092
- ...prev,
963
+ }, T = (p) => {
964
+ r.current && o((d) => ({
965
+ ...d,
1093
966
  isLoading: false,
1094
- error: e instanceof Error ? e : new Error(String(e)),
967
+ error: p instanceof Error ? p : new Error(String(p)),
1095
968
  isStale: true
1096
969
  }));
1097
970
  };
1098
- if (poll) {
1099
- let cancelled = false;
1100
- const fetchOnce = async () => {
1101
- if (cancelled || isDocumentHidden()) return;
1102
- try {
1103
- const snap = await docRef.get();
1104
- if (!cancelled) applySnap(snap);
1105
- } catch (e) {
1106
- if (!cancelled) applyError(e);
1107
- }
971
+ if (n) {
972
+ let p = false, d = async () => {
973
+ if (!(p || z()))
974
+ try {
975
+ let C = await f.get();
976
+ p || w(C);
977
+ } catch (C) {
978
+ p || T(C);
979
+ }
1108
980
  };
1109
- void fetchOnce();
1110
- const timer = setInterval(fetchOnce, intervalMs);
981
+ d();
982
+ let g = setInterval(d, i);
1111
983
  return () => {
1112
- cancelled = true;
1113
- clearInterval(timer);
1114
- mountedRef.current = false;
984
+ p = true, clearInterval(g), r.current = false;
1115
985
  };
1116
986
  }
1117
- let unsub;
987
+ let R;
1118
988
  try {
1119
- unsub = docRef.onSnapshot(applySnap);
1120
- } catch (e) {
1121
- applyError(e);
989
+ R = f.onSnapshot(w);
990
+ } catch (p) {
991
+ T(p);
1122
992
  }
1123
993
  return () => {
1124
- mountedRef.current = false;
1125
- unsub?.();
994
+ r.current = false, R?.();
1126
995
  };
1127
- }, [refKey, intervalMs, poll]);
1128
- return state;
996
+ }, [s, i, n]), c;
1129
997
  }
1130
- function resolveAuth(input) {
1131
- const maybe = input;
1132
- if (maybe.auth && typeof maybe.auth.onAuthStateChanged === "function") {
1133
- return maybe.auth;
1134
- }
1135
- return input;
998
+ function he(e) {
999
+ let t = e;
1000
+ return t.auth && typeof t.auth.onAuthStateChanged == "function" ? t.auth : e;
1136
1001
  }
1137
- function useUser(input, options) {
1138
- const timeoutMs = options?.timeoutMs ?? 8e3;
1139
- const auth = resolveAuth(input);
1140
- const [state, setState] = React2__namespace.useState(() => {
1141
- let seeded = null;
1002
+ function Le(e, t) {
1003
+ let i = t?.timeoutMs ?? 8e3, n = he(e), [s, c] = l__namespace.useState(() => {
1004
+ let r = null;
1142
1005
  try {
1143
- seeded = auth.getUser();
1006
+ r = n.getUser();
1144
1007
  } catch {
1145
- seeded = null;
1008
+ r = null;
1146
1009
  }
1147
- return { user: seeded, isLoading: seeded === null, error: null };
1148
- });
1149
- const mountedRef = React2__namespace.useRef(true);
1150
- React2__namespace.useEffect(() => {
1151
- mountedRef.current = true;
1152
- let settled = false;
1153
- const timer = setTimeout(() => {
1154
- if (!mountedRef.current || settled) return;
1155
- setState((prev) => prev.isLoading ? { ...prev, isLoading: false } : prev);
1156
- }, timeoutMs);
1157
- let unsub;
1010
+ return { user: r, isLoading: r === null, error: null };
1011
+ }), o = l__namespace.useRef(true);
1012
+ return l__namespace.useEffect(() => {
1013
+ o.current = true;
1014
+ let r = false, b = setTimeout(() => {
1015
+ !o.current || r || c((f) => f.isLoading ? { ...f, isLoading: false } : f);
1016
+ }, i), u;
1158
1017
  try {
1159
- unsub = auth.onAuthStateChanged((user) => {
1160
- if (!mountedRef.current) return;
1161
- settled = true;
1162
- setState({ user: user ?? null, isLoading: false, error: null });
1018
+ u = n.onAuthStateChanged((f) => {
1019
+ o.current && (r = !0, c({ user: f ?? null, isLoading: !1, error: null }));
1020
+ });
1021
+ } catch (f) {
1022
+ o.current && c({
1023
+ user: null,
1024
+ isLoading: false,
1025
+ error: f instanceof Error ? f : new Error(String(f))
1163
1026
  });
1164
- } catch (e) {
1165
- if (mountedRef.current) {
1166
- setState({
1167
- user: null,
1168
- isLoading: false,
1169
- error: e instanceof Error ? e : new Error(String(e))
1170
- });
1171
- }
1172
1027
  }
1173
1028
  return () => {
1174
- mountedRef.current = false;
1175
- clearTimeout(timer);
1176
- unsub?.();
1029
+ o.current = false, clearTimeout(b), u?.();
1177
1030
  };
1178
- }, [auth, timeoutMs]);
1179
- return state;
1031
+ }, [n, i]), s;
1180
1032
  }
1181
1033
 
1182
- exports.CheckoutLink = CheckoutLink;
1183
- exports.EntitlementGate = EntitlementGate;
1184
- exports.NeetruAccountBar = NeetruAccountBar;
1185
- exports.NeetruLoginButton = NeetruLoginButton;
1186
- exports.fetchNeetruAccountBar = fetchNeetruAccountBar;
1187
- exports.initialsFrom = initialsFrom;
1188
- exports.useCollection = useCollection;
1189
- exports.useDoc = useDoc;
1190
- exports.useEntitlementContext = useEntitlementContext;
1191
- exports.useUser = useUser;
1192
- //# sourceMappingURL=react.cjs.map
1193
- //# sourceMappingURL=react.cjs.map
1034
+ exports.CheckoutLink = Ee;
1035
+ exports.EntitlementGate = Ne;
1036
+ exports.NeetruAccountBar = oe;
1037
+ exports.NeetruLoginButton = De;
1038
+ exports.fetchNeetruAccountBar = W;
1039
+ exports.initialsFrom = N;
1040
+ exports.useCollection = Ue;
1041
+ exports.useDoc = Ae;
1042
+ exports.useEntitlementContext = _e;
1043
+ exports.useUser = Le;