reifyui 0.19.0 → 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.cjs CHANGED
@@ -76,6 +76,7 @@ __export(src_exports, {
76
76
  MentionText: () => MentionText,
77
77
  MicrosoftButton: () => MicrosoftButton,
78
78
  Modal: () => Modal,
79
+ PERSON_CHECK_FAILED: () => PERSON_CHECK_FAILED,
79
80
  PaneResizer: () => PaneResizer,
80
81
  Panel: () => Panel,
81
82
  PanelGrid: () => PanelGrid,
@@ -121,12 +122,14 @@ __export(src_exports, {
121
122
  microsoftSignIn: () => microsoftSignIn,
122
123
  packLayout: () => packLayout,
123
124
  parseArgs: () => parseArgs,
125
+ personToken: () => personToken,
124
126
  prettyJson: () => prettyJson,
125
127
  pumpResponsesStream: () => pumpResponsesStream,
126
128
  readSSEStream: () => readSSEStream,
127
129
  refreshToken: () => refreshToken,
128
130
  register: () => register,
129
131
  requestPasswordReset: () => requestPasswordReset,
132
+ resendVerification: () => resendVerification,
130
133
  sheetToAoA: () => sheetToAoA,
131
134
  sheetToDelimited: () => sheetToDelimited,
132
135
  summarizeSteps: () => summarizeSteps,
@@ -987,10 +990,10 @@ var Chip = (0, import_react6.forwardRef)(function Chip2(props, ref) {
987
990
  removeLabel,
988
991
  trailing,
989
992
  className,
990
- slot,
993
+ slot: slot2,
991
994
  ...rest
992
995
  } = props;
993
- const isSlot = slot ?? (Boolean(onClick) && !selected);
996
+ const isSlot = slot2 ?? (Boolean(onClick) && !selected);
994
997
  const cls2 = [
995
998
  "uic-chip",
996
999
  selected ? "is-selected" : "",
@@ -1190,8 +1193,8 @@ function toolKind(name) {
1190
1193
  function str(v) {
1191
1194
  return v == null ? "" : typeof v === "string" ? v : Array.isArray(v) ? v.join(" ") : String(v);
1192
1195
  }
1193
- function firstOf(a, keys) {
1194
- for (const k of keys) {
1196
+ function firstOf(a, keys2) {
1197
+ for (const k of keys2) {
1195
1198
  const v = a[k];
1196
1199
  if (v != null && v !== "" && !(Array.isArray(v) && !v.length)) return v;
1197
1200
  }
@@ -2386,11 +2389,11 @@ function inputLines(d, item) {
2386
2389
  if (lines.length > (path ? 1 : 0)) return { lines, copy: typeof item.args === "string" ? item.args : JSON.stringify(a, null, 2) };
2387
2390
  }
2388
2391
  if (a._raw != null) return { lines: asLines(a._raw), copy: a._raw };
2389
- const keys = Object.keys(a);
2390
- const flat = keys.length && keys.every((k) => a[k] == null || typeof a[k] !== "object");
2392
+ const keys2 = Object.keys(a);
2393
+ const flat = keys2.length && keys2.every((k) => a[k] == null || typeof a[k] !== "object");
2391
2394
  if (flat) {
2392
2395
  const lines = [];
2393
- for (const k of keys) {
2396
+ for (const k of keys2) {
2394
2397
  const v = a[k] == null ? "" : String(a[k]);
2395
2398
  const vs = v.split("\n");
2396
2399
  lines.push({ text: `${k}: ${vs[0]}`, cls: "is-kv" });
@@ -2398,7 +2401,7 @@ function inputLines(d, item) {
2398
2401
  }
2399
2402
  return { lines, copy: typeof item.args === "string" ? item.args : JSON.stringify(a, null, 2) };
2400
2403
  }
2401
- const js = keys.length ? JSON.stringify(a, null, 2) : "";
2404
+ const js = keys2.length ? JSON.stringify(a, null, 2) : "";
2402
2405
  return { lines: js ? asLines(js) : [], copy: js };
2403
2406
  }
2404
2407
  function StepDetail(props) {
@@ -3460,8 +3463,8 @@ function PaneResizer(props) {
3460
3463
  const { pane, className, title = "Drag to resize (double-click to reset)" } = props;
3461
3464
  const vertical = pane.axis === "y";
3462
3465
  const onKeyDown = (e) => {
3463
- const keys = vertical ? ["ArrowUp", "ArrowDown"] : ["ArrowLeft", "ArrowRight"];
3464
- if (!keys.includes(e.key)) return;
3466
+ const keys2 = vertical ? ["ArrowUp", "ArrowDown"] : ["ArrowLeft", "ArrowRight"];
3467
+ if (!keys2.includes(e.key)) return;
3465
3468
  if (!pane.nudge) return;
3466
3469
  e.preventDefault();
3467
3470
  const step = e.shiftKey ? 96 : 24;
@@ -3977,6 +3980,96 @@ function ChoiceList({ label, entry, onPick }) {
3977
3980
  ] });
3978
3981
  }
3979
3982
 
3983
+ // src/auth/personCheck.js
3984
+ var SCRIPT = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit";
3985
+ var WAIT_MS = 6e4;
3986
+ var PERSON_CHECK_FAILED = "We couldn't confirm you're a person. Please try again.";
3987
+ var keys = /* @__PURE__ */ new Map();
3988
+ var script = null;
3989
+ function siteKey(engine) {
3990
+ let p = keys.get(engine);
3991
+ if (!p) {
3992
+ p = fetch(`${engine}/v1/auth/person-check`, { cache: "no-store" }).then(async (r) => {
3993
+ if (!r.ok) throw new Error("no answer");
3994
+ const b = await r.json();
3995
+ return typeof b?.site_key === "string" ? b.site_key : "";
3996
+ }).catch(() => {
3997
+ keys.delete(engine);
3998
+ return "";
3999
+ });
4000
+ keys.set(engine, p);
4001
+ }
4002
+ return p;
4003
+ }
4004
+ function loadScript() {
4005
+ script ?? (script = new Promise((resolve, reject) => {
4006
+ if (window.turnstile) {
4007
+ resolve(window.turnstile);
4008
+ return;
4009
+ }
4010
+ const s = document.createElement("script");
4011
+ s.src = SCRIPT;
4012
+ s.async = true;
4013
+ s.defer = true;
4014
+ s.onload = () => window.turnstile ? resolve(window.turnstile) : reject(new Error(PERSON_CHECK_FAILED));
4015
+ s.onerror = () => {
4016
+ script = null;
4017
+ s.remove();
4018
+ reject(new Error(PERSON_CHECK_FAILED));
4019
+ };
4020
+ document.head.appendChild(s);
4021
+ }));
4022
+ return script;
4023
+ }
4024
+ function slot() {
4025
+ const shown = Array.from(document.querySelectorAll("[data-person-check]")).find((el2) => el2.offsetParent !== null);
4026
+ if (shown) return shown;
4027
+ let el = document.getElementById("person-check-fallback");
4028
+ if (!el) {
4029
+ el = document.createElement("div");
4030
+ el.id = "person-check-fallback";
4031
+ el.className = "person-check-fallback";
4032
+ document.body.appendChild(el);
4033
+ }
4034
+ return el;
4035
+ }
4036
+ async function personToken(door, engine) {
4037
+ const key = await siteKey(engine);
4038
+ if (!key) return "";
4039
+ const ts = await loadScript();
4040
+ const host = document.createElement("div");
4041
+ slot().appendChild(host);
4042
+ return new Promise((resolve, reject) => {
4043
+ let id = "";
4044
+ const done = (fn) => {
4045
+ clearTimeout(timer);
4046
+ try {
4047
+ if (id) ts.remove(id);
4048
+ } catch {
4049
+ }
4050
+ host.remove();
4051
+ fn();
4052
+ };
4053
+ const fail = () => done(() => reject(new Error(PERSON_CHECK_FAILED)));
4054
+ const timer = setTimeout(fail, WAIT_MS);
4055
+ try {
4056
+ id = ts.render(host, {
4057
+ sitekey: key,
4058
+ action: door,
4059
+ appearance: "interaction-only",
4060
+ theme: "auto",
4061
+ "refresh-expired": "never",
4062
+ callback: (token) => done(() => resolve(token)),
4063
+ "error-callback": fail,
4064
+ "expired-callback": fail,
4065
+ "timeout-callback": fail
4066
+ });
4067
+ } catch {
4068
+ fail();
4069
+ }
4070
+ });
4071
+ }
4072
+
3980
4073
  // src/auth/client.js
3981
4074
  var _cfg = {
3982
4075
  // Same-origin. A product that forgets to configure gets the working default rather than the
@@ -4053,7 +4146,8 @@ async function login(email, password) {
4053
4146
  return s;
4054
4147
  }
4055
4148
  async function register(email, password, name = "") {
4056
- const s = toSession(await authPost("/v1/auth/register", { email, password, name, product: _cfg.product }));
4149
+ const turnstile_token = await personToken("register", _cfg.engine);
4150
+ const s = toSession(await authPost("/v1/auth/register", { email, password, name, product: _cfg.product, turnstile_token }));
4057
4151
  setSession(s);
4058
4152
  return s;
4059
4153
  }
@@ -4067,12 +4161,30 @@ async function microsoftSignIn(credential) {
4067
4161
  setSession(s);
4068
4162
  return s;
4069
4163
  }
4070
- async function requestPasswordReset(email) {
4071
- await fetch(`${_cfg.engine}/v1/auth/request-password-reset`, {
4164
+ async function readMailDoorError(res) {
4165
+ if (res.status === 400 || res.status === 403 || res.status === 503) {
4166
+ try {
4167
+ const d = (await res.json())?.detail;
4168
+ if (typeof d === "string" && d.length > 0 && d.length < 200) return d;
4169
+ } catch {
4170
+ }
4171
+ }
4172
+ return "We could not send the request. Please try again later.";
4173
+ }
4174
+ async function mailDoor(path, door, email) {
4175
+ const turnstile_token = await personToken(door, _cfg.engine);
4176
+ const res = await fetch(`${_cfg.engine}${path}`, {
4072
4177
  method: "POST",
4073
4178
  headers: { "content-type": "application/json" },
4074
- body: JSON.stringify({ email, product: _cfg.product })
4179
+ body: JSON.stringify({ email, product: _cfg.product, turnstile_token })
4075
4180
  });
4181
+ if (!res.ok) throw new Error(await readMailDoorError(res));
4182
+ }
4183
+ async function requestPasswordReset(email) {
4184
+ await mailDoor("/v1/auth/request-password-reset", "reset", email);
4185
+ }
4186
+ async function resendVerification(email) {
4187
+ await mailDoor("/v1/auth/resend-verification", "resend", email);
4076
4188
  }
4077
4189
  async function switchOrg(orgId) {
4078
4190
  const current = getSession();
@@ -4450,6 +4562,7 @@ function AuthForm({ onDone, subtitle: subtitle2, brand = null, productName = ""
4450
4562
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("label", { children: "Email" }),
4451
4563
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("input", { className: "input", type: "email", value: email, onChange: (e) => setEmail(e.target.value), autoFocus: true, required: true, autoComplete: "email" })
4452
4564
  ] }),
4565
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { "data-person-check": "", className: "person-check" }),
4453
4566
  err && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "auth-err", children: err }),
4454
4567
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "submit", className: "btn primary lg", style: { width: "100%", marginTop: 8 }, disabled: busy, children: busy ? "Please wait..." : "Send reset link" }),
4455
4568
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { className: "auth-switch", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", onClick: () => {
@@ -4487,6 +4600,7 @@ function AuthForm({ onDone, subtitle: subtitle2, brand = null, productName = ""
4487
4600
  }
4488
4601
  )
4489
4602
  ] }),
4603
+ mode === "register" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { "data-person-check": "", className: "person-check" }),
4490
4604
  err && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "auth-err", children: err }),
4491
4605
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "submit", className: "btn primary lg", style: { width: "100%", marginTop: 8 }, disabled: busy, children: busy ? "Please wait..." : mode === "register" ? "Create account" : "Sign in" }),
4492
4606
  (GOOGLE_ENABLED || MICROSOFT_ENABLED) && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "auth-or", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: "or" }) }),