@orangecheck/auth-client 2.40.1 → 2.42.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 (39) hide show
  1. package/README.md +16 -6
  2. package/dist/bond.mjs +6 -5
  3. package/dist/{chunk-S6YP5Q5X.mjs → chunk-CVK452X3.mjs} +9 -14
  4. package/dist/chunk-CVK452X3.mjs.map +1 -0
  5. package/dist/{chunk-O45WZCJI.mjs → chunk-F7O4OREM.mjs} +2 -2
  6. package/dist/{chunk-JMXIH6AH.mjs → chunk-FMPBHB3Q.mjs} +2 -2
  7. package/dist/{chunk-FKROF5NN.mjs → chunk-JLMDCC6K.mjs} +24 -12
  8. package/dist/chunk-JLMDCC6K.mjs.map +1 -0
  9. package/dist/{chunk-AIP3GYPO.mjs → chunk-M2VUFCZU.mjs} +3 -3
  10. package/dist/{chunk-AIP3GYPO.mjs.map → chunk-M2VUFCZU.mjs.map} +1 -1
  11. package/dist/{chunk-IYK4KW6B.mjs → chunk-MK45WO7U.mjs} +12 -9
  12. package/dist/chunk-MK45WO7U.mjs.map +1 -0
  13. package/dist/chunk-OKHAVNEU.mjs +48 -0
  14. package/dist/chunk-OKHAVNEU.mjs.map +1 -0
  15. package/dist/{chunk-A4A6OEVX.mjs → chunk-PQHFAVVM.mjs} +1 -1
  16. package/dist/chunk-PQHFAVVM.mjs.map +1 -0
  17. package/dist/{chunk-LA2VDQSE.mjs → chunk-VQY7IYHV.mjs} +26 -9
  18. package/dist/chunk-VQY7IYHV.mjs.map +1 -0
  19. package/dist/components.mjs +3 -3
  20. package/dist/controls.mjs +9 -0
  21. package/dist/controls.mjs.map +1 -0
  22. package/dist/index.d.ts +11 -1
  23. package/dist/index.js +91 -30
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mjs +10 -9
  26. package/dist/linked-identities.mjs +3 -3
  27. package/dist/provider.mjs +2 -2
  28. package/dist/signin.mjs +6 -5
  29. package/dist/sudo.mjs +2 -2
  30. package/dist/types.mjs +1 -1
  31. package/dist/webauthn.mjs +3 -3
  32. package/package.json +1 -1
  33. package/dist/chunk-A4A6OEVX.mjs.map +0 -1
  34. package/dist/chunk-FKROF5NN.mjs.map +0 -1
  35. package/dist/chunk-IYK4KW6B.mjs.map +0 -1
  36. package/dist/chunk-LA2VDQSE.mjs.map +0 -1
  37. package/dist/chunk-S6YP5Q5X.mjs.map +0 -1
  38. /package/dist/{chunk-O45WZCJI.mjs.map → chunk-F7O4OREM.mjs.map} +0 -0
  39. /package/dist/{chunk-JMXIH6AH.mjs.map → chunk-FMPBHB3Q.mjs.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -27,6 +27,13 @@ interface OcAccountSummary {
27
27
  lastSeenAt: string | null;
28
28
  }
29
29
  type OcSignOutScope = 'all' | 'current';
30
+ type OcSignOutResult = {
31
+ ok: true;
32
+ } | {
33
+ ok: false;
34
+ reason: 'unreachable' | 'refused';
35
+ status?: number;
36
+ };
30
37
  interface OcSessionState {
31
38
  status: OcSessionStatus;
32
39
  account: OcAccount | null;
@@ -37,6 +44,9 @@ interface OcSessionState {
37
44
  signOut: (opts?: {
38
45
  scope?: OcSignOutScope;
39
46
  }) => Promise<void>;
47
+ trySignOut: (opts?: {
48
+ scope?: OcSignOutScope;
49
+ }) => Promise<OcSignOutResult>;
40
50
  switchAccount: (didOc: string) => Promise<void>;
41
51
  addAccountUrl: (returnTo?: string) => string;
42
52
  setDisplayIdentity: (kind: DisplayIdentityKind) => Promise<void>;
@@ -303,4 +313,4 @@ declare function isSudoAccountMismatch(body: {
303
313
  reason?: string;
304
314
  } | null | undefined): boolean;
305
315
 
306
- export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, type DisplayIdentity, type DisplayIdentityKind, FRAGMENT_TTL_MS, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, type OcAccountSummary, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcBond, type OcBondProps, type OcBondView, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type OcSignOutScope, type OcTabSession, type RedirectToSudoArgs, SUDO_ACCOUNT_MISMATCH_MESSAGE, TAB_ACCOUNT_HINT_KEY, TAB_ADOPT_HASH, TAB_SESSION_HEADER, TAB_SESSION_STORAGE_KEY, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, bondFloorsText, buildAddAccountUrl, buildSignInUrl, clearTabSession, consumeTabAccountHint, consumeTabAdoptMarker, familyReturnTarget, fetchOcBond, fetchOcLinkedIdentities, handleSudoRequired, installTabFetchInterceptor, installTabLinkDecorator, isSudoAccountMismatch, keepFragmentOnReturnLinks, newAccountsCapText, otpNetworkCapText, readTabSession, redirectToSudo, restoreReturnFragment, returnToHere, safeReturnTo, stripFragment, tabSessionHeader, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister, withoutFragment, writeTabSession };
316
+ export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, type DisplayIdentity, type DisplayIdentityKind, FRAGMENT_TTL_MS, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, type OcAccountSummary, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcBond, type OcBondProps, type OcBondView, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type OcSignOutResult, type OcSignOutScope, type OcTabSession, type RedirectToSudoArgs, SUDO_ACCOUNT_MISMATCH_MESSAGE, TAB_ACCOUNT_HINT_KEY, TAB_ADOPT_HASH, TAB_SESSION_HEADER, TAB_SESSION_STORAGE_KEY, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, bondFloorsText, buildAddAccountUrl, buildSignInUrl, clearTabSession, consumeTabAccountHint, consumeTabAdoptMarker, familyReturnTarget, fetchOcBond, fetchOcLinkedIdentities, handleSudoRequired, installTabFetchInterceptor, installTabLinkDecorator, isSudoAccountMismatch, keepFragmentOnReturnLinks, newAccountsCapText, otpNetworkCapText, readTabSession, redirectToSudo, restoreReturnFragment, returnToHere, safeReturnTo, stripFragment, tabSessionHeader, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister, withoutFragment, writeTabSession };
package/dist/index.js CHANGED
@@ -516,13 +516,14 @@ function OcSessionProvider({
516
516
  () => cfg.multiAccount ? installTabLinkDecorator(cfg.authOrigin) : void 0,
517
517
  [cfg.authOrigin, cfg.multiAccount]
518
518
  );
519
- const signOut = React4__namespace.useCallback(
519
+ const trySignOut = React4__namespace.useCallback(
520
520
  async (opts) => {
521
521
  const scope = opts?.scope ?? "all";
522
+ let res;
522
523
  try {
523
524
  const url = new URL(`${cfg.authOrigin}${cfg.logoutPath}`);
524
525
  if (scope === "current") url.searchParams.set("scope", "current");
525
- const res = await fetch(url.toString(), {
526
+ res = await fetch(url.toString(), {
526
527
  method: "POST",
527
528
  credentials: "include",
528
529
  // Per-tab · carry the pin so scope='current' signs out
@@ -536,22 +537,31 @@ function OcSessionProvider({
536
537
  // and the `.ochk.io` cookie may never get cleared.
537
538
  keepalive: true
538
539
  });
539
- clearTabSession();
540
- setTabPinned(false);
541
- if (scope === "current" && res.ok) {
542
- await refresh();
543
- return;
544
- }
545
540
  } catch {
546
- clearTabSession();
547
- setTabPinned(false);
541
+ return { ok: false, reason: "unreachable" };
542
+ }
543
+ if (!res.ok && res.status !== 401) {
544
+ return { ok: false, reason: "refused", status: res.status };
545
+ }
546
+ clearTabSession();
547
+ setTabPinned(false);
548
+ if (scope === "current" && res.ok) {
549
+ await refresh();
550
+ return { ok: true };
548
551
  }
549
552
  setAccount(null);
550
553
  setRoster([]);
551
554
  setStatus("anonymous");
555
+ return { ok: true };
552
556
  },
553
557
  [cfg.authOrigin, cfg.logoutPath, refresh]
554
558
  );
559
+ const signOut = React4__namespace.useCallback(
560
+ async (opts) => {
561
+ await trySignOut(opts);
562
+ },
563
+ [trySignOut]
564
+ );
555
565
  const switchAccount = React4__namespace.useCallback(
556
566
  async (didOc) => {
557
567
  if (typeof window === "undefined") return;
@@ -630,6 +640,7 @@ function OcSessionProvider({
630
640
  error,
631
641
  refresh,
632
642
  signOut,
643
+ trySignOut,
633
644
  switchAccount,
634
645
  addAccountUrl,
635
646
  setDisplayIdentity,
@@ -643,6 +654,7 @@ function OcSessionProvider({
643
654
  error,
644
655
  refresh,
645
656
  signOut,
657
+ trySignOut,
646
658
  switchAccount,
647
659
  addAccountUrl,
648
660
  setDisplayIdentity,
@@ -681,7 +693,7 @@ function useUniqueId(prefix) {
681
693
  return id;
682
694
  }
683
695
  function OcAccountChip({
684
- dashboardUrl = "https://ochk.io/dashboard",
696
+ dashboardUrl = "https://ochk.app/me/account",
685
697
  signInUrl: signInUrlOverride,
686
698
  signInLabel = "sign in",
687
699
  className,
@@ -689,9 +701,10 @@ function OcAccountChip({
689
701
  popoverClassName,
690
702
  menuItemClassName
691
703
  }) {
692
- const { status, account, signInUrl: sessionSignInUrl, signOut } = useOcSession();
704
+ const { status, account, signInUrl: sessionSignInUrl, trySignOut } = useOcSession();
693
705
  const signInUrl = signInUrlOverride ?? sessionSignInUrl;
694
706
  const [open, setOpen] = React4__namespace.useState(false);
707
+ const [signOutFailed, setSignOutFailed] = React4__namespace.useState(false);
695
708
  const wrapRef = React4__namespace.useRef(null);
696
709
  React4__namespace.useEffect(() => {
697
710
  if (!open) return;
@@ -903,7 +916,8 @@ function OcAccountChip({
903
916
  role: "menuitem",
904
917
  onClick: () => {
905
918
  setOpen(false);
906
- void signOut();
919
+ setSignOutFailed(false);
920
+ void trySignOut().then((r) => setSignOutFailed(!r.ok));
907
921
  },
908
922
  className: menuItemClassName,
909
923
  "data-oc-account-chip-item": "",
@@ -938,11 +952,23 @@ function OcAccountChip({
938
952
  ] })
939
953
  ]
940
954
  }
941
- )
955
+ ),
956
+ signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, {}) : null
942
957
  ]
943
958
  }
944
959
  );
945
960
  }
961
+ function SignOutFailed() {
962
+ return /* @__PURE__ */ jsxRuntime.jsx(
963
+ "span",
964
+ {
965
+ role: "alert",
966
+ "data-oc-signout-failed": "",
967
+ style: { display: "block", marginTop: 4, fontSize: 12, color: "var(--destructive, #dc2626)" },
968
+ children: "Couldn\u2019t sign out. You\u2019re still signed in; try again."
969
+ }
970
+ );
971
+ }
946
972
  function OcSignInButton({
947
973
  label = "sign in",
948
974
  eager = false,
@@ -971,7 +997,8 @@ function OcAccountPill({
971
997
  className,
972
998
  ...rest
973
999
  }) {
974
- const { status, account, signOut } = useOcSession();
1000
+ const { status, account, trySignOut } = useOcSession();
1001
+ const [signOutFailed, setSignOutFailed] = React4__namespace.useState(false);
975
1002
  if (status !== "authenticated" || !account) return null;
976
1003
  const label = render ? render({ address: account.didOc, displayName: account.displayName }) : account.displayName ?? shortenAddress(account.didOc);
977
1004
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -988,7 +1015,8 @@ function OcAccountPill({
988
1015
  {
989
1016
  type: "button",
990
1017
  onClick: () => {
991
- void signOut();
1018
+ setSignOutFailed(false);
1019
+ void trySignOut().then((r) => setSignOutFailed(!r.ok));
992
1020
  },
993
1021
  "aria-label": "Sign out",
994
1022
  style: {
@@ -1001,7 +1029,8 @@ function OcAccountPill({
1001
1029
  },
1002
1030
  children: "sign out"
1003
1031
  }
1004
- )
1032
+ ),
1033
+ signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, {}) : null
1005
1034
  ]
1006
1035
  }
1007
1036
  );
@@ -1341,6 +1370,46 @@ function capText(reason, retryAt, alternative = "sign in another way") {
1341
1370
  return null;
1342
1371
  }
1343
1372
  }
1373
+ var WRAP = { position: "relative", display: "inline-flex", flexShrink: 0, width: 20, height: 20 };
1374
+ var FORCED = [
1375
+ "@media (forced-colors: active){",
1376
+ "[data-oc-control] input{border-color:CanvasText!important;background:Canvas!important}",
1377
+ "[data-oc-control] input[type=checkbox]:checked{border-color:Highlight!important;background:Highlight!important}",
1378
+ "[data-oc-control] input[type=radio]:checked{border-color:Highlight!important}",
1379
+ "[data-oc-control] svg[data-oc-check]{color:HighlightText!important}",
1380
+ "[data-oc-control] svg[data-oc-dot]{color:Highlight!important}",
1381
+ "[data-oc-control] input:disabled{border-color:GrayText!important}",
1382
+ "}"
1383
+ ].join("");
1384
+ function boxStyle(kind, checked, disabled) {
1385
+ return {
1386
+ appearance: "none",
1387
+ WebkitAppearance: "none",
1388
+ margin: 0,
1389
+ width: 20,
1390
+ height: 20,
1391
+ borderRadius: kind === "radio" ? "50%" : 0,
1392
+ border: checked ? "1px solid var(--primary, #f97316)" : "1px solid var(--input, var(--border, #52525b))",
1393
+ background: checked && kind === "checkbox" ? "var(--primary, #f97316)" : "var(--oca-surface, var(--background, transparent))",
1394
+ cursor: disabled ? "not-allowed" : "pointer",
1395
+ opacity: disabled ? 0.5 : 1
1396
+ };
1397
+ }
1398
+ var MARK = { position: "absolute", inset: 3, width: 14, height: 14, pointerEvents: "none" };
1399
+ function DesignCheckbox({ checked, disabled, ...props }) {
1400
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { "data-oc-control": "", style: WRAP, children: [
1401
+ /* @__PURE__ */ jsxRuntime.jsx("style", { dangerouslySetInnerHTML: { __html: FORCED } }),
1402
+ /* @__PURE__ */ jsxRuntime.jsx("input", { ...props, type: "checkbox", checked, disabled, style: boxStyle("checkbox", checked, Boolean(disabled)) }),
1403
+ checked ? /* @__PURE__ */ jsxRuntime.jsx("svg", { "data-oc-check": "", "aria-hidden": "true", viewBox: "0 0 24 24", style: { ...MARK, color: "var(--primary-foreground, #ffffff)" }, children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5", fill: "none", stroke: "currentColor", strokeWidth: 3, strokeLinecap: "square" }) }) : null
1404
+ ] });
1405
+ }
1406
+ function DesignRadio({ checked, disabled, ...props }) {
1407
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { "data-oc-control": "", style: WRAP, children: [
1408
+ /* @__PURE__ */ jsxRuntime.jsx("style", { dangerouslySetInnerHTML: { __html: FORCED } }),
1409
+ /* @__PURE__ */ jsxRuntime.jsx("input", { ...props, type: "radio", checked, disabled, style: boxStyle("radio", checked, Boolean(disabled)) }),
1410
+ checked ? /* @__PURE__ */ jsxRuntime.jsx("svg", { "data-oc-dot": "", "aria-hidden": "true", viewBox: "0 0 14 14", style: { ...MARK, color: "var(--primary, #f97316)" }, children: /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "7", cy: "7", r: "4", fill: "currentColor" }) }) : null
1411
+ ] });
1412
+ }
1344
1413
 
1345
1414
  // src/sudo.tsx
1346
1415
  function redirectToSudo(args = {}) {
@@ -2666,15 +2735,7 @@ function OcSignIn({
2666
2735
  }
2667
2736
  ),
2668
2737
  linkPrompt && /* @__PURE__ */ jsxRuntime.jsxs("label", { "data-oc-signin-linkalso": "", style: linkAlsoStyle, children: [
2669
- /* @__PURE__ */ jsxRuntime.jsx(
2670
- "input",
2671
- {
2672
- type: "checkbox",
2673
- checked: linkAlso,
2674
- onChange: (e) => setLinkAlso(e.target.checked),
2675
- style: { margin: 0, accentColor: "var(--primary, #f97316)" }
2676
- }
2677
- ),
2738
+ /* @__PURE__ */ jsxRuntime.jsx(DesignCheckbox, { checked: linkAlso, onChange: (e) => setLinkAlso(e.target.checked) }),
2678
2739
  /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
2679
2740
  "After signing in, also link",
2680
2741
  " ",
@@ -3502,6 +3563,8 @@ function coinStyle(picked, young) {
3502
3563
  background: V.card,
3503
3564
  border: `1px ${young ? "dashed" : "solid"} ${picked ? V.primary : V.border}`,
3504
3565
  padding: "0.75rem",
3566
+ // The whole row is the radio's target.
3567
+ minHeight: 44,
3505
3568
  display: "flex",
3506
3569
  gap: 10,
3507
3570
  alignItems: "flex-start",
@@ -3788,15 +3851,13 @@ function BondForm({
3788
3851
  style: coinStyle(chosen === c.outpoint, young),
3789
3852
  children: [
3790
3853
  /* @__PURE__ */ jsxRuntime.jsx(
3791
- "input",
3854
+ DesignRadio,
3792
3855
  {
3793
- type: "radio",
3794
3856
  name: "oc-bond-coin",
3795
3857
  value: c.outpoint,
3796
3858
  checked: chosen === c.outpoint,
3797
3859
  disabled: young,
3798
- onChange: () => setChosen(c.outpoint),
3799
- style: { accentColor: V.primary, margin: "2px 0 0" }
3860
+ onChange: () => setChosen(c.outpoint)
3800
3861
  }
3801
3862
  ),
3802
3863
  /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { display: "grid", gap: 2, minWidth: 0 }, children: [