reifyui 0.13.14 → 0.13.15

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.
package/dist/index.d.ts CHANGED
@@ -501,7 +501,13 @@ export function isAuthed(): boolean;
501
501
  export function login(email: string, password: string): Promise<unknown>;
502
502
  export function register(payload: Record<string, unknown>): Promise<unknown>;
503
503
  export function googleSignIn(credential: string, extra?: Record<string, unknown>): Promise<unknown>;
504
- export function requestPasswordReset(email: string): Promise<unknown>;
504
+ /** Throws with words for the person when the engine refused (the person check, a domain that takes no mail). */
505
+ export function requestPasswordReset(email: string): Promise<void>;
506
+ /** Send the confirmation email again; throws as requestPasswordReset does. */
507
+ export function resendVerification(email: string): Promise<void>;
508
+ /** A fresh person-check token for one of the engine's mail doors, or '' when the engine sets no site key. */
509
+ export function personToken(door: 'register' | 'reset' | 'resend', engine: string): Promise<string>;
510
+ export const PERSON_CHECK_FAILED: string;
505
511
  export function switchOrg(orgId: string): Promise<unknown>;
506
512
  export function refreshToken(): Promise<unknown>;
507
513
  export function handleAuthExpired(): void;
package/dist/index.js CHANGED
@@ -665,10 +665,10 @@ var Chip = forwardRef(function Chip2(props, ref) {
665
665
  removeLabel,
666
666
  trailing,
667
667
  className,
668
- slot,
668
+ slot: slot2,
669
669
  ...rest
670
670
  } = props;
671
- const isSlot = slot ?? (Boolean(onClick) && !selected);
671
+ const isSlot = slot2 ?? (Boolean(onClick) && !selected);
672
672
  const cls = [
673
673
  "uic-chip",
674
674
  selected ? "is-selected" : "",
@@ -1260,8 +1260,8 @@ function PaneResizer(props) {
1260
1260
  const { pane, className, title = "Drag to resize (double-click to reset)" } = props;
1261
1261
  const vertical = pane.axis === "y";
1262
1262
  const onKeyDown = (e) => {
1263
- const keys = vertical ? ["ArrowUp", "ArrowDown"] : ["ArrowLeft", "ArrowRight"];
1264
- if (!keys.includes(e.key)) return;
1263
+ const keys2 = vertical ? ["ArrowUp", "ArrowDown"] : ["ArrowLeft", "ArrowRight"];
1264
+ if (!keys2.includes(e.key)) return;
1265
1265
  if (!pane.nudge) return;
1266
1266
  e.preventDefault();
1267
1267
  const step = e.shiftKey ? 96 : 24;
@@ -1747,6 +1747,96 @@ function ChoiceList({ label, entry, onPick }) {
1747
1747
  ] });
1748
1748
  }
1749
1749
 
1750
+ // src/auth/personCheck.js
1751
+ var SCRIPT = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit";
1752
+ var WAIT_MS = 6e4;
1753
+ var PERSON_CHECK_FAILED = "We couldn't confirm you're a person. Please try again.";
1754
+ var keys = /* @__PURE__ */ new Map();
1755
+ var script = null;
1756
+ function siteKey(engine) {
1757
+ let p = keys.get(engine);
1758
+ if (!p) {
1759
+ p = fetch(`${engine}/v1/auth/person-check`, { cache: "no-store" }).then(async (r) => {
1760
+ if (!r.ok) throw new Error("no answer");
1761
+ const b = await r.json();
1762
+ return typeof b?.site_key === "string" ? b.site_key : "";
1763
+ }).catch(() => {
1764
+ keys.delete(engine);
1765
+ return "";
1766
+ });
1767
+ keys.set(engine, p);
1768
+ }
1769
+ return p;
1770
+ }
1771
+ function loadScript() {
1772
+ script ?? (script = new Promise((resolve, reject) => {
1773
+ if (window.turnstile) {
1774
+ resolve(window.turnstile);
1775
+ return;
1776
+ }
1777
+ const s = document.createElement("script");
1778
+ s.src = SCRIPT;
1779
+ s.async = true;
1780
+ s.defer = true;
1781
+ s.onload = () => window.turnstile ? resolve(window.turnstile) : reject(new Error(PERSON_CHECK_FAILED));
1782
+ s.onerror = () => {
1783
+ script = null;
1784
+ s.remove();
1785
+ reject(new Error(PERSON_CHECK_FAILED));
1786
+ };
1787
+ document.head.appendChild(s);
1788
+ }));
1789
+ return script;
1790
+ }
1791
+ function slot() {
1792
+ const shown = Array.from(document.querySelectorAll("[data-person-check]")).find((el2) => el2.offsetParent !== null);
1793
+ if (shown) return shown;
1794
+ let el = document.getElementById("person-check-fallback");
1795
+ if (!el) {
1796
+ el = document.createElement("div");
1797
+ el.id = "person-check-fallback";
1798
+ el.className = "person-check-fallback";
1799
+ document.body.appendChild(el);
1800
+ }
1801
+ return el;
1802
+ }
1803
+ async function personToken(door, engine) {
1804
+ const key = await siteKey(engine);
1805
+ if (!key) return "";
1806
+ const ts = await loadScript();
1807
+ const host = document.createElement("div");
1808
+ slot().appendChild(host);
1809
+ return new Promise((resolve, reject) => {
1810
+ let id = "";
1811
+ const done = (fn) => {
1812
+ clearTimeout(timer);
1813
+ try {
1814
+ if (id) ts.remove(id);
1815
+ } catch {
1816
+ }
1817
+ host.remove();
1818
+ fn();
1819
+ };
1820
+ const fail = () => done(() => reject(new Error(PERSON_CHECK_FAILED)));
1821
+ const timer = setTimeout(fail, WAIT_MS);
1822
+ try {
1823
+ id = ts.render(host, {
1824
+ sitekey: key,
1825
+ action: door,
1826
+ appearance: "interaction-only",
1827
+ theme: "auto",
1828
+ "refresh-expired": "never",
1829
+ callback: (token) => done(() => resolve(token)),
1830
+ "error-callback": fail,
1831
+ "expired-callback": fail,
1832
+ "timeout-callback": fail
1833
+ });
1834
+ } catch {
1835
+ fail();
1836
+ }
1837
+ });
1838
+ }
1839
+
1750
1840
  // src/auth/client.js
1751
1841
  var _cfg = {
1752
1842
  // Same-origin. A product that forgets to configure gets the working default rather than the
@@ -1823,7 +1913,8 @@ async function login(email, password) {
1823
1913
  return s;
1824
1914
  }
1825
1915
  async function register(email, password, name = "") {
1826
- const s = toSession(await authPost("/v1/auth/register", { email, password, name, product: _cfg.product }));
1916
+ const turnstile_token = await personToken("register", _cfg.engine);
1917
+ const s = toSession(await authPost("/v1/auth/register", { email, password, name, product: _cfg.product, turnstile_token }));
1827
1918
  setSession(s);
1828
1919
  return s;
1829
1920
  }
@@ -1837,12 +1928,30 @@ async function microsoftSignIn(credential) {
1837
1928
  setSession(s);
1838
1929
  return s;
1839
1930
  }
1840
- async function requestPasswordReset(email) {
1841
- await fetch(`${_cfg.engine}/v1/auth/request-password-reset`, {
1931
+ async function readMailDoorError(res) {
1932
+ if (res.status === 400 || res.status === 403 || res.status === 503) {
1933
+ try {
1934
+ const d = (await res.json())?.detail;
1935
+ if (typeof d === "string" && d.length > 0 && d.length < 200) return d;
1936
+ } catch {
1937
+ }
1938
+ }
1939
+ return "We could not send the request. Please try again later.";
1940
+ }
1941
+ async function mailDoor(path, door, email) {
1942
+ const turnstile_token = await personToken(door, _cfg.engine);
1943
+ const res = await fetch(`${_cfg.engine}${path}`, {
1842
1944
  method: "POST",
1843
1945
  headers: { "content-type": "application/json" },
1844
- body: JSON.stringify({ email, product: _cfg.product })
1946
+ body: JSON.stringify({ email, product: _cfg.product, turnstile_token })
1845
1947
  });
1948
+ if (!res.ok) throw new Error(await readMailDoorError(res));
1949
+ }
1950
+ async function requestPasswordReset(email) {
1951
+ await mailDoor("/v1/auth/request-password-reset", "reset", email);
1952
+ }
1953
+ async function resendVerification(email) {
1954
+ await mailDoor("/v1/auth/resend-verification", "resend", email);
1846
1955
  }
1847
1956
  async function switchOrg(orgId) {
1848
1957
  const current = getSession();
@@ -2220,6 +2329,7 @@ function AuthForm({ onDone, subtitle: subtitle2, brand = null, productName = ""
2220
2329
  /* @__PURE__ */ jsx11("label", { children: "Email" }),
2221
2330
  /* @__PURE__ */ jsx11("input", { className: "input", type: "email", value: email, onChange: (e) => setEmail(e.target.value), autoFocus: true, required: true, autoComplete: "email" })
2222
2331
  ] }),
2332
+ /* @__PURE__ */ jsx11("div", { "data-person-check": "", className: "person-check" }),
2223
2333
  err && /* @__PURE__ */ jsx11("div", { className: "auth-err", children: err }),
2224
2334
  /* @__PURE__ */ jsx11("button", { type: "submit", className: "btn primary lg", style: { width: "100%", marginTop: 8 }, disabled: busy, children: busy ? "Please wait..." : "Send reset link" }),
2225
2335
  /* @__PURE__ */ jsx11("p", { className: "auth-switch", children: /* @__PURE__ */ jsx11("button", { type: "button", onClick: () => {
@@ -2257,6 +2367,7 @@ function AuthForm({ onDone, subtitle: subtitle2, brand = null, productName = ""
2257
2367
  }
2258
2368
  )
2259
2369
  ] }),
2370
+ mode === "register" && /* @__PURE__ */ jsx11("div", { "data-person-check": "", className: "person-check" }),
2260
2371
  err && /* @__PURE__ */ jsx11("div", { className: "auth-err", children: err }),
2261
2372
  /* @__PURE__ */ jsx11("button", { type: "submit", className: "btn primary lg", style: { width: "100%", marginTop: 8 }, disabled: busy, children: busy ? "Please wait..." : mode === "register" ? "Create account" : "Sign in" }),
2262
2373
  (GOOGLE_ENABLED || MICROSOFT_ENABLED) && /* @__PURE__ */ jsx11("div", { className: "auth-or", children: /* @__PURE__ */ jsx11("span", { children: "or" }) }),
@@ -4049,6 +4160,7 @@ export {
4049
4160
  MentionText,
4050
4161
  MicrosoftButton,
4051
4162
  Modal,
4163
+ PERSON_CHECK_FAILED,
4052
4164
  PaneResizer,
4053
4165
  Panel,
4054
4166
  PanelGrid,
@@ -4094,12 +4206,14 @@ export {
4094
4206
  microsoftSignIn,
4095
4207
  packLayout,
4096
4208
  parseArgs,
4209
+ personToken,
4097
4210
  prettyJson,
4098
4211
  pumpResponsesStream,
4099
4212
  readSSEStream,
4100
4213
  refreshToken,
4101
4214
  register,
4102
4215
  requestPasswordReset,
4216
+ resendVerification,
4103
4217
  sheetToAoA,
4104
4218
  sheetToDelimited,
4105
4219
  summarizeSteps,