reifyui 0.18.5 → 0.19.1

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
@@ -513,7 +513,13 @@ export function isAuthed(): boolean;
513
513
  export function login(email: string, password: string): Promise<unknown>;
514
514
  export function register(payload: Record<string, unknown>): Promise<unknown>;
515
515
  export function googleSignIn(credential: string, extra?: Record<string, unknown>): Promise<unknown>;
516
- export function requestPasswordReset(email: string): Promise<unknown>;
516
+ /** Throws with words for the person when the engine refused (the person check, a domain that takes no mail). */
517
+ export function requestPasswordReset(email: string): Promise<void>;
518
+ /** Send the confirmation email again; throws as requestPasswordReset does. */
519
+ export function resendVerification(email: string): Promise<void>;
520
+ /** A fresh person-check token for one of the engine's mail doors, or '' when the engine sets no site key. */
521
+ export function personToken(door: 'register' | 'reset' | 'resend', engine: string): Promise<string>;
522
+ export const PERSON_CHECK_FAILED: string;
517
523
  export function switchOrg(orgId: string): Promise<unknown>;
518
524
  export function refreshToken(): Promise<unknown>;
519
525
  export function handleAuthExpired(): void;
package/dist/index.js CHANGED
@@ -679,10 +679,10 @@ var Chip = forwardRef(function Chip2(props, ref) {
679
679
  removeLabel,
680
680
  trailing,
681
681
  className,
682
- slot,
682
+ slot: slot2,
683
683
  ...rest
684
684
  } = props;
685
- const isSlot = slot ?? (Boolean(onClick) && !selected);
685
+ const isSlot = slot2 ?? (Boolean(onClick) && !selected);
686
686
  const cls = [
687
687
  "uic-chip",
688
688
  selected ? "is-selected" : "",
@@ -1302,8 +1302,8 @@ function PaneResizer(props) {
1302
1302
  const { pane, className, title = "Drag to resize (double-click to reset)" } = props;
1303
1303
  const vertical = pane.axis === "y";
1304
1304
  const onKeyDown = (e) => {
1305
- const keys = vertical ? ["ArrowUp", "ArrowDown"] : ["ArrowLeft", "ArrowRight"];
1306
- if (!keys.includes(e.key)) return;
1305
+ const keys2 = vertical ? ["ArrowUp", "ArrowDown"] : ["ArrowLeft", "ArrowRight"];
1306
+ if (!keys2.includes(e.key)) return;
1307
1307
  if (!pane.nudge) return;
1308
1308
  e.preventDefault();
1309
1309
  const step = e.shiftKey ? 96 : 24;
@@ -1789,6 +1789,96 @@ function ChoiceList({ label, entry, onPick }) {
1789
1789
  ] });
1790
1790
  }
1791
1791
 
1792
+ // src/auth/personCheck.js
1793
+ var SCRIPT = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit";
1794
+ var WAIT_MS = 6e4;
1795
+ var PERSON_CHECK_FAILED = "We couldn't confirm you're a person. Please try again.";
1796
+ var keys = /* @__PURE__ */ new Map();
1797
+ var script = null;
1798
+ function siteKey(engine) {
1799
+ let p = keys.get(engine);
1800
+ if (!p) {
1801
+ p = fetch(`${engine}/v1/auth/person-check`, { cache: "no-store" }).then(async (r) => {
1802
+ if (!r.ok) throw new Error("no answer");
1803
+ const b = await r.json();
1804
+ return typeof b?.site_key === "string" ? b.site_key : "";
1805
+ }).catch(() => {
1806
+ keys.delete(engine);
1807
+ return "";
1808
+ });
1809
+ keys.set(engine, p);
1810
+ }
1811
+ return p;
1812
+ }
1813
+ function loadScript() {
1814
+ script ?? (script = new Promise((resolve, reject) => {
1815
+ if (window.turnstile) {
1816
+ resolve(window.turnstile);
1817
+ return;
1818
+ }
1819
+ const s = document.createElement("script");
1820
+ s.src = SCRIPT;
1821
+ s.async = true;
1822
+ s.defer = true;
1823
+ s.onload = () => window.turnstile ? resolve(window.turnstile) : reject(new Error(PERSON_CHECK_FAILED));
1824
+ s.onerror = () => {
1825
+ script = null;
1826
+ s.remove();
1827
+ reject(new Error(PERSON_CHECK_FAILED));
1828
+ };
1829
+ document.head.appendChild(s);
1830
+ }));
1831
+ return script;
1832
+ }
1833
+ function slot() {
1834
+ const shown = Array.from(document.querySelectorAll("[data-person-check]")).find((el2) => el2.offsetParent !== null);
1835
+ if (shown) return shown;
1836
+ let el = document.getElementById("person-check-fallback");
1837
+ if (!el) {
1838
+ el = document.createElement("div");
1839
+ el.id = "person-check-fallback";
1840
+ el.className = "person-check-fallback";
1841
+ document.body.appendChild(el);
1842
+ }
1843
+ return el;
1844
+ }
1845
+ async function personToken(door, engine) {
1846
+ const key = await siteKey(engine);
1847
+ if (!key) return "";
1848
+ const ts = await loadScript();
1849
+ const host = document.createElement("div");
1850
+ slot().appendChild(host);
1851
+ return new Promise((resolve, reject) => {
1852
+ let id = "";
1853
+ const done = (fn) => {
1854
+ clearTimeout(timer);
1855
+ try {
1856
+ if (id) ts.remove(id);
1857
+ } catch {
1858
+ }
1859
+ host.remove();
1860
+ fn();
1861
+ };
1862
+ const fail = () => done(() => reject(new Error(PERSON_CHECK_FAILED)));
1863
+ const timer = setTimeout(fail, WAIT_MS);
1864
+ try {
1865
+ id = ts.render(host, {
1866
+ sitekey: key,
1867
+ action: door,
1868
+ appearance: "interaction-only",
1869
+ theme: "auto",
1870
+ "refresh-expired": "never",
1871
+ callback: (token) => done(() => resolve(token)),
1872
+ "error-callback": fail,
1873
+ "expired-callback": fail,
1874
+ "timeout-callback": fail
1875
+ });
1876
+ } catch {
1877
+ fail();
1878
+ }
1879
+ });
1880
+ }
1881
+
1792
1882
  // src/auth/client.js
1793
1883
  var _cfg = {
1794
1884
  // Same-origin. A product that forgets to configure gets the working default rather than the
@@ -1865,7 +1955,8 @@ async function login(email, password) {
1865
1955
  return s;
1866
1956
  }
1867
1957
  async function register(email, password, name = "") {
1868
- const s = toSession(await authPost("/v1/auth/register", { email, password, name, product: _cfg.product }));
1958
+ const turnstile_token = await personToken("register", _cfg.engine);
1959
+ const s = toSession(await authPost("/v1/auth/register", { email, password, name, product: _cfg.product, turnstile_token }));
1869
1960
  setSession(s);
1870
1961
  return s;
1871
1962
  }
@@ -1879,12 +1970,30 @@ async function microsoftSignIn(credential) {
1879
1970
  setSession(s);
1880
1971
  return s;
1881
1972
  }
1882
- async function requestPasswordReset(email) {
1883
- await fetch(`${_cfg.engine}/v1/auth/request-password-reset`, {
1973
+ async function readMailDoorError(res) {
1974
+ if (res.status === 400 || res.status === 403 || res.status === 503) {
1975
+ try {
1976
+ const d = (await res.json())?.detail;
1977
+ if (typeof d === "string" && d.length > 0 && d.length < 200) return d;
1978
+ } catch {
1979
+ }
1980
+ }
1981
+ return "We could not send the request. Please try again later.";
1982
+ }
1983
+ async function mailDoor(path, door, email) {
1984
+ const turnstile_token = await personToken(door, _cfg.engine);
1985
+ const res = await fetch(`${_cfg.engine}${path}`, {
1884
1986
  method: "POST",
1885
1987
  headers: { "content-type": "application/json" },
1886
- body: JSON.stringify({ email, product: _cfg.product })
1988
+ body: JSON.stringify({ email, product: _cfg.product, turnstile_token })
1887
1989
  });
1990
+ if (!res.ok) throw new Error(await readMailDoorError(res));
1991
+ }
1992
+ async function requestPasswordReset(email) {
1993
+ await mailDoor("/v1/auth/request-password-reset", "reset", email);
1994
+ }
1995
+ async function resendVerification(email) {
1996
+ await mailDoor("/v1/auth/resend-verification", "resend", email);
1888
1997
  }
1889
1998
  async function switchOrg(orgId) {
1890
1999
  const current = getSession();
@@ -2262,6 +2371,7 @@ function AuthForm({ onDone, subtitle, brand = null, productName = "" }) {
2262
2371
  /* @__PURE__ */ jsx11("label", { children: "Email" }),
2263
2372
  /* @__PURE__ */ jsx11("input", { className: "input", type: "email", value: email, onChange: (e) => setEmail(e.target.value), autoFocus: true, required: true, autoComplete: "email" })
2264
2373
  ] }),
2374
+ /* @__PURE__ */ jsx11("div", { "data-person-check": "", className: "person-check" }),
2265
2375
  err && /* @__PURE__ */ jsx11("div", { className: "auth-err", children: err }),
2266
2376
  /* @__PURE__ */ jsx11("button", { type: "submit", className: "btn primary lg", style: { width: "100%", marginTop: 8 }, disabled: busy, children: busy ? "Please wait..." : "Send reset link" }),
2267
2377
  /* @__PURE__ */ jsx11("p", { className: "auth-switch", children: /* @__PURE__ */ jsx11("button", { type: "button", onClick: () => {
@@ -2299,6 +2409,7 @@ function AuthForm({ onDone, subtitle, brand = null, productName = "" }) {
2299
2409
  }
2300
2410
  )
2301
2411
  ] }),
2412
+ mode === "register" && /* @__PURE__ */ jsx11("div", { "data-person-check": "", className: "person-check" }),
2302
2413
  err && /* @__PURE__ */ jsx11("div", { className: "auth-err", children: err }),
2303
2414
  /* @__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" }),
2304
2415
  (GOOGLE_ENABLED || MICROSOFT_ENABLED) && /* @__PURE__ */ jsx11("div", { className: "auth-or", children: /* @__PURE__ */ jsx11("span", { children: "or" }) }),
@@ -3751,6 +3862,7 @@ export {
3751
3862
  MentionText,
3752
3863
  MicrosoftButton,
3753
3864
  Modal,
3865
+ PERSON_CHECK_FAILED,
3754
3866
  PaneResizer,
3755
3867
  Panel,
3756
3868
  PanelGrid,
@@ -3796,12 +3908,14 @@ export {
3796
3908
  microsoftSignIn,
3797
3909
  packLayout,
3798
3910
  parseArgs,
3911
+ personToken,
3799
3912
  prettyJson,
3800
3913
  pumpResponsesStream,
3801
3914
  readSSEStream,
3802
3915
  refreshToken,
3803
3916
  register,
3804
3917
  requestPasswordReset,
3918
+ resendVerification,
3805
3919
  sheetToAoA,
3806
3920
  sheetToDelimited,
3807
3921
  summarizeSteps,