@ai-matrx/vault 0.1.49 → 0.1.51

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
@@ -435,6 +435,7 @@ function IdentityGate({ identity, children }) {
435
435
  setAsking(false);
436
436
  return () => {
437
437
  activeIdentity.current = null;
438
+ identity?.cancel?.();
438
439
  for (const waiter of waiters.current.splice(0)) waiter.reject(new Error(CANCELLED));
439
440
  };
440
441
  }, [identityVersion]);
@@ -483,6 +484,7 @@ function IdentityGate({ identity, children }) {
483
484
  };
484
485
  const settle = (ok) => {
485
486
  if (activeIdentity.current !== identityVersion) return;
487
+ if (!ok) identity?.cancel?.();
486
488
  const w = waiters.current;
487
489
  waiters.current = [];
488
490
  if (ok) confirmationVersion.current += 1;
@@ -492,7 +494,7 @@ function IdentityGate({ identity, children }) {
492
494
  };
493
495
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Ctx2.Provider, { value: confirmed, children: [
494
496
  children,
495
- identity ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfirmIdentityDialog, { open: asking, identity, onDone: () => settle(true), onCancel: () => settle(false) }, identityVersion.key) : null,
497
+ identity && asking ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfirmIdentityDialog, { open: true, identity, onDone: () => settle(true), onCancel: () => settle(false) }, identityVersion.key) : null,
496
498
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_design_system2.Dialog, { open: returnProblem !== null, onOpenChange: (o) => o ? void 0 : setReturnProblem(null), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_design_system2.DialogContent, { size: "sm", children: [
497
499
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_design_system2.DialogHeader, { children: [
498
500
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_design_system2.DialogTitle, { children: "Different account" }),
@@ -504,6 +506,16 @@ function IdentityGate({ identity, children }) {
504
506
  }
505
507
  var wasCancelled = (e) => e instanceof Error && e.message === CANCELLED;
506
508
  function ConfirmIdentityDialog({ open, identity, onDone, onCancel }) {
509
+ const live = (0, import_react2.useRef)(false);
510
+ (0, import_react2.useLayoutEffect)(() => {
511
+ live.current = true;
512
+ return () => {
513
+ live.current = false;
514
+ };
515
+ }, []);
516
+ const finish = () => {
517
+ if (live.current) onDone();
518
+ };
507
519
  const [account10, setAccount] = (0, import_react2.useState)(null);
508
520
  const [password, setPassword] = (0, import_react2.useState)("");
509
521
  const [code, setCode] = (0, import_react2.useState)("");
@@ -516,18 +528,29 @@ function ConfirmIdentityDialog({ open, identity, onDone, onCancel }) {
516
528
  setCode("");
517
529
  setCodeSent(false);
518
530
  setError(null);
519
- identity.account().then(setAccount, (e) => setError(e instanceof Error ? e.message : "Your account could not be read."));
531
+ let current = true;
532
+ identity.account().then(
533
+ (value) => {
534
+ if (current && live.current) setAccount(value);
535
+ },
536
+ (e) => {
537
+ if (current && live.current) setError(e instanceof Error ? e.message : "Your account could not be read.");
538
+ }
539
+ );
540
+ return () => {
541
+ current = false;
542
+ };
520
543
  }, [open, identity]);
521
544
  const attempt = async (step, done = true) => {
522
545
  setBusy(true);
523
546
  setError(null);
524
547
  try {
525
548
  await step();
526
- if (done) onDone();
549
+ if (done) finish();
527
550
  } catch (e) {
528
- setError(e instanceof Error ? e.message : "That did not work. Try again.");
551
+ if (live.current) setError(e instanceof Error ? e.message : "That did not work. Try again.");
529
552
  } finally {
530
- setBusy(false);
553
+ if (live.current) setBusy(false);
531
554
  }
532
555
  };
533
556
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_design_system2.Dialog, { open, onOpenChange: (o) => o ? void 0 : onCancel(), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_design_system2.DialogContent, { size: "sm", children: [
@@ -550,7 +573,7 @@ function ConfirmIdentityDialog({ open, identity, onDone, onCancel }) {
550
573
  variant: identity.dev ? "outline" : "primary",
551
574
  disabled: busy,
552
575
  onClick: () => void attempt(async () => {
553
- if (await identity.withProvider(p) === "confirmed") onDone();
576
+ if (await identity.withProvider(p) === "confirmed") finish();
554
577
  }, false),
555
578
  children: [
556
579
  "Continue with ",
@@ -574,7 +597,7 @@ function ConfirmIdentityDialog({ open, identity, onDone, onCancel }) {
574
597
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_controls.Button, { variant: "outline", type: "submit", disabled: busy || !code.trim(), children: "Confirm" })
575
598
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_controls.Button, { variant: "quiet", disabled: busy, onClick: () => void attempt(async () => {
576
599
  await identity.sendEmailCode();
577
- setCodeSent(true);
600
+ if (live.current) setCodeSent(true);
578
601
  }, false), children: "Email me a code instead" }) : null,
579
602
  error ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { role: "alert", className: "text-sm text-destructive", children: error }) : null
580
603
  ] })
@@ -2179,8 +2202,10 @@ var import_icons5 = require("@ai-matrx/design-system/icons");
2179
2202
  // src/authenticator/port.ts
2180
2203
  var OTP_SEED_KEY = "totp_seed";
2181
2204
  function mfaMethodOf(item) {
2182
- const v = item.custom.find((c) => c.key === MFA_METHOD_KEY)?.value;
2183
- return v === "sms" ? "sms" : v ? "push_or_other" : null;
2205
+ const declarations = item.custom.filter((c) => c.key === MFA_METHOD_KEY);
2206
+ if (declarations.length !== 1) return null;
2207
+ const value = declarations[0]?.value;
2208
+ return value === "sms" || value === "push_or_other" ? value : null;
2184
2209
  }
2185
2210
 
2186
2211
  // src/authenticator/TotpRows.tsx
@@ -5534,7 +5559,7 @@ function withMfaMethod(custom, v) {
5534
5559
  return v === "sms" || v === "push_or_other" ? [...rest, { key: MFA_METHOD_KEY, label: "Two-factor method", value: v }] : rest;
5535
5560
  }
5536
5561
  function DraftTwoFactorRow({ custom, onCustom }) {
5537
- const value = custom.find((c) => c.key === MFA_METHOD_KEY)?.value || "none";
5562
+ const value = mfaMethodOf({ custom }) ?? "none";
5538
5563
  return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(VaultRow, { label: "Two-factor", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
5539
5564
  import_controls18.Select,
5540
5565
  {