@orangecheck/auth-client 2.48.0 → 2.50.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 (37) hide show
  1. package/dist/bond.mjs +6 -6
  2. package/dist/{chunk-PBDOIRFF.mjs → chunk-33ZCBA2C.mjs} +5 -5
  3. package/dist/{chunk-MEN6WL3W.mjs → chunk-6IUIO5QX.mjs} +36 -10
  4. package/dist/chunk-6IUIO5QX.mjs.map +1 -0
  5. package/dist/{chunk-F7O4OREM.mjs → chunk-FNGBJD4S.mjs} +2 -2
  6. package/dist/{chunk-X4IFJDCV.mjs → chunk-IKNAIRW5.mjs} +14 -2
  7. package/dist/chunk-IKNAIRW5.mjs.map +1 -0
  8. package/dist/{chunk-UHQCVPT4.mjs → chunk-MIBVEZLP.mjs} +15 -12
  9. package/dist/chunk-MIBVEZLP.mjs.map +1 -0
  10. package/dist/{chunk-KD4XTVFV.mjs → chunk-OKIFTNEO.mjs} +26 -3
  11. package/dist/chunk-OKIFTNEO.mjs.map +1 -0
  12. package/dist/{chunk-KL4QKCE3.mjs → chunk-UTR42EZW.mjs} +5 -5
  13. package/dist/{chunk-PQHFAVVM.mjs → chunk-X4PPXI3K.mjs} +1 -1
  14. package/dist/chunk-X4PPXI3K.mjs.map +1 -0
  15. package/dist/{chunk-YGXMLIQ3.mjs → chunk-XVLOTOCX.mjs} +3 -3
  16. package/dist/components.mjs +5 -3
  17. package/dist/index.d.ts +3 -2
  18. package/dist/index.js +122 -75
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +10 -10
  21. package/dist/linked-identities.mjs +5 -5
  22. package/dist/provider.mjs +4 -2
  23. package/dist/refusal.mjs +11 -1
  24. package/dist/signin.mjs +7 -6
  25. package/dist/sudo.mjs +2 -2
  26. package/dist/types.mjs +1 -1
  27. package/dist/webauthn.mjs +5 -3
  28. package/package.json +1 -1
  29. package/dist/chunk-KD4XTVFV.mjs.map +0 -1
  30. package/dist/chunk-MEN6WL3W.mjs.map +0 -1
  31. package/dist/chunk-PQHFAVVM.mjs.map +0 -1
  32. package/dist/chunk-UHQCVPT4.mjs.map +0 -1
  33. package/dist/chunk-X4IFJDCV.mjs.map +0 -1
  34. /package/dist/{chunk-PBDOIRFF.mjs.map → chunk-33ZCBA2C.mjs.map} +0 -0
  35. /package/dist/{chunk-F7O4OREM.mjs.map → chunk-FNGBJD4S.mjs.map} +0 -0
  36. /package/dist/{chunk-KL4QKCE3.mjs.map → chunk-UTR42EZW.mjs.map} +0 -0
  37. /package/dist/{chunk-YGXMLIQ3.mjs.map → chunk-XVLOTOCX.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -325,6 +325,87 @@ function buildAddAccountUrl(cfg, returnTo) {
325
325
  u.searchParams.set("add", "1");
326
326
  return u.toString();
327
327
  }
328
+
329
+ // src/own-word.ts
330
+ function ownWord(table, code) {
331
+ return Object.prototype.hasOwnProperty.call(table, code) ? table[code] : void 0;
332
+ }
333
+
334
+ // src/refusal.ts
335
+ var ENDED_ERRORS = {
336
+ signed_out: "You were signed out while signing in. Sign in again.",
337
+ account_deleted: "This account is being deleted, so you can't sign in to it.",
338
+ no_roster: "An account in this browser was signed out while you were signing in, so this sign-in wasn't kept. Sign in again."
339
+ };
340
+ function endedSigninText(reason) {
341
+ return ownWord(ENDED_ERRORS, reason);
342
+ }
343
+ var SEVERAL_SESSIONS_TEXT = "Your browser sent more than one ochk.io sign-in, so this account wasn't added. Check which account is signed in now, then try again.";
344
+ var SIGN_OUT_SEVERAL_SESSIONS_TEXT = "Your browser sent more than one ochk.io sign-in, so you weren't signed out. Check which account is signed in now, then try again.";
345
+ var SWITCH_SEVERAL_SESSIONS_TEXT = "Your browser sent more than one ochk.io sign-in, so the account wasn't switched. Check which account is signed in now, then try again.";
346
+ async function isSeveralSessionsAnswer(res) {
347
+ if (res.status !== 409) return false;
348
+ try {
349
+ const body = await res.clone().json();
350
+ return body?.reason === "several_sessions";
351
+ } catch {
352
+ return false;
353
+ }
354
+ }
355
+ function isSeveralSessions(err) {
356
+ return err instanceof Error && err.message === "several_sessions";
357
+ }
358
+ var SIGNIN_ERRORS = {
359
+ bad_request: "That doesn't look like a Bitcoin address.",
360
+ invalid_challenge: "That signature doesn't match this address. Sign with the wallet that holds it.",
361
+ sig_invalid: "That signature doesn't match this address. Sign with the wallet that holds it.",
362
+ sig_unsupported_scheme: "We can't check this wallet's signature format yet. Try another wallet, or use email.",
363
+ expired: "That request timed out. Try again for a fresh one.",
364
+ not_yet_valid: "That request is not valid yet. Check your device clock, then try again.",
365
+ nonce_mismatch: "That request didn't match. Try again for a fresh one.",
366
+ audience_mismatch: "That request didn't match this site. Reload the page and try again.",
367
+ purpose_mismatch: "That request didn't match. Try again for a fresh one.",
368
+ malformed: "That signature couldn't be read. Copy it again, whole.",
369
+ challenge_mismatch: "That sign-in message changed after it was issued. Get a new one and sign it again.",
370
+ mainnet_only: "Sign in with a mainnet Bitcoin address.",
371
+ cross_site_blocked: "Your browser blocked this request. Reload the page and try again.",
372
+ rate_limited: "Too many tries. Wait a minute, then try again.",
373
+ invalid_email: "That email address doesn't look right.",
374
+ mailer_unavailable: "We couldn't send the email right now. Try again in a minute.",
375
+ mailer_error: "We couldn't send the email right now. Try again in a minute.",
376
+ wrong_code: "That code isn't right. Check the newest email from us.",
377
+ replay: "That code was already used. Send a new one.",
378
+ invalid_token: "That code is no longer valid. Send a new one.",
379
+ email_mismatch: "That code was sent to a different address. Send a new one.",
380
+ several_sessions: SEVERAL_SESSIONS_TEXT,
381
+ ...ENDED_ERRORS
382
+ };
383
+ var EMAIL_ERRORS = {
384
+ expired: "That code expired. Send a new one.",
385
+ signed_out: "You were signed out while signing in. Send a new code to sign in again.",
386
+ no_roster: "An account in this browser was signed out while you were signing in, so this sign-in wasn't kept. Send a new code to sign in again."
387
+ };
388
+ var SUBMIT_ERRORS = {
389
+ bad_request: "That signature couldn't be read. Copy it again, whole."
390
+ };
391
+ function networkError(authOrigin) {
392
+ let host = authOrigin;
393
+ try {
394
+ host = new URL(authOrigin).host;
395
+ } catch {
396
+ }
397
+ return `We couldn't reach the orangecheck sign-in service at ${host}. Check your connection, then try again.`;
398
+ }
399
+ function humanSigninError(reason, path, step = "challenge") {
400
+ if (!/^[a-z0-9_]+$/.test(reason)) return reason;
401
+ const own = path === "wallet" && step === "submit" && ownWord(SUBMIT_ERRORS, reason) || path === "email" && ownWord(EMAIL_ERRORS, reason);
402
+ if (own) return own;
403
+ return ownWord(SIGNIN_ERRORS, reason) ?? (path === "email" ? "That didn't work. Try again, or send a new code." : "That didn't work. Try again.");
404
+ }
405
+ function failureMessage(err, path, step, authOrigin) {
406
+ if (err instanceof TypeError || err instanceof SyntaxError) return networkError(authOrigin);
407
+ return humanSigninError(err instanceof Error ? err.message : "failed", path, step);
408
+ }
328
409
  var SessionContext = React4__namespace.createContext(null);
329
410
  function onHistory(change) {
330
411
  window.addEventListener("popstate", change);
@@ -574,6 +655,10 @@ function OcSessionProvider({
574
655
  return { ok: false, reason: "unreachable" };
575
656
  }
576
657
  if (!res.ok && res.status !== 401) {
658
+ if (await isSeveralSessionsAnswer(res)) {
659
+ await refresh();
660
+ return { ok: false, reason: "several_sessions", status: 409 };
661
+ }
577
662
  return { ok: false, reason: "refused", status: res.status };
578
663
  }
579
664
  clearTabSession();
@@ -605,6 +690,10 @@ function OcSessionProvider({
605
690
  body: JSON.stringify({ did_oc: didOc })
606
691
  });
607
692
  if (!res.ok) {
693
+ if (await isSeveralSessionsAnswer(res)) {
694
+ await refresh();
695
+ throw new Error(SWITCH_SEVERAL_SESSIONS_TEXT);
696
+ }
608
697
  let reason = `http_${res.status}`;
609
698
  try {
610
699
  const body = await res.json();
@@ -737,7 +826,7 @@ function OcAccountChip({
737
826
  const { status, account, signInUrl: sessionSignInUrl, trySignOut } = useOcSession();
738
827
  const signInUrl = signInUrlOverride ?? sessionSignInUrl;
739
828
  const [open, setOpen] = React4__namespace.useState(false);
740
- const [signOutFailed, setSignOutFailed] = React4__namespace.useState(false);
829
+ const [signOutFailed, setSignOutFailed] = React4__namespace.useState(null);
741
830
  const wrapRef = React4__namespace.useRef(null);
742
831
  React4__namespace.useEffect(() => {
743
832
  if (!open) return;
@@ -949,8 +1038,8 @@ function OcAccountChip({
949
1038
  role: "menuitem",
950
1039
  onClick: () => {
951
1040
  setOpen(false);
952
- setSignOutFailed(false);
953
- void trySignOut().then((r) => setSignOutFailed(!r.ok));
1041
+ setSignOutFailed(null);
1042
+ void trySignOut().then((r) => setSignOutFailed(r.ok ? null : r.reason));
954
1043
  },
955
1044
  className: menuItemClassName,
956
1045
  "data-oc-account-chip-item": "",
@@ -986,19 +1075,19 @@ function OcAccountChip({
986
1075
  ]
987
1076
  }
988
1077
  ),
989
- signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, {}) : null
1078
+ signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, { reason: signOutFailed }) : null
990
1079
  ]
991
1080
  }
992
1081
  );
993
1082
  }
994
- function SignOutFailed() {
1083
+ function SignOutFailed({ reason }) {
995
1084
  return /* @__PURE__ */ jsxRuntime.jsx(
996
1085
  "span",
997
1086
  {
998
1087
  role: "alert",
999
1088
  "data-oc-signout-failed": "",
1000
1089
  style: { display: "block", marginTop: 4, fontSize: 12, color: "var(--destructive, #dc2626)" },
1001
- children: "Couldn\u2019t sign out. You\u2019re still signed in; try again."
1090
+ children: reason === "several_sessions" ? SIGN_OUT_SEVERAL_SESSIONS_TEXT : "Couldn\u2019t sign out. You\u2019re still signed in; try again."
1002
1091
  }
1003
1092
  );
1004
1093
  }
@@ -1031,7 +1120,7 @@ function OcAccountPill({
1031
1120
  ...rest
1032
1121
  }) {
1033
1122
  const { status, account, trySignOut } = useOcSession();
1034
- const [signOutFailed, setSignOutFailed] = React4__namespace.useState(false);
1123
+ const [signOutFailed, setSignOutFailed] = React4__namespace.useState(null);
1035
1124
  if (status !== "authenticated" || !account) return null;
1036
1125
  const label = render ? render({ address: account.didOc, displayName: account.displayName }) : account.displayName ?? shortenAddress(account.didOc);
1037
1126
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1048,8 +1137,8 @@ function OcAccountPill({
1048
1137
  {
1049
1138
  type: "button",
1050
1139
  onClick: () => {
1051
- setSignOutFailed(false);
1052
- void trySignOut().then((r) => setSignOutFailed(!r.ok));
1140
+ setSignOutFailed(null);
1141
+ void trySignOut().then((r) => setSignOutFailed(r.ok ? null : r.reason));
1053
1142
  },
1054
1143
  "aria-label": "Sign out",
1055
1144
  style: {
@@ -1063,7 +1152,7 @@ function OcAccountPill({
1063
1152
  children: "sign out"
1064
1153
  }
1065
1154
  ),
1066
- signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, {}) : null
1155
+ signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, { reason: signOutFailed }) : null
1067
1156
  ]
1068
1157
  }
1069
1158
  );
@@ -1486,69 +1575,6 @@ var SIGNIN_BUTTON_RADIUS = "var(--oc-signin-button-radius, 6px)";
1486
1575
  var SIGNIN_STRONG = "var(--oc-signin-strong, 600)";
1487
1576
  var SIGNIN_ARROW = "var(--oc-signin-arrow, inline)";
1488
1577
  var signinRoleSize = (role, fallback) => `var(--oc-signin-${role}-size, ${fallback})`;
1489
-
1490
- // src/own-word.ts
1491
- function ownWord(table, code) {
1492
- return Object.prototype.hasOwnProperty.call(table, code) ? table[code] : void 0;
1493
- }
1494
-
1495
- // src/refusal.ts
1496
- var ENDED_ERRORS = {
1497
- signed_out: "You were signed out while signing in. Sign in again.",
1498
- account_deleted: "This account is being deleted, so you can't sign in to it."
1499
- };
1500
- function endedSigninText(reason) {
1501
- return ownWord(ENDED_ERRORS, reason);
1502
- }
1503
- var SIGNIN_ERRORS = {
1504
- bad_request: "That doesn't look like a Bitcoin address.",
1505
- invalid_challenge: "That signature doesn't match this address. Sign with the wallet that holds it.",
1506
- sig_invalid: "That signature doesn't match this address. Sign with the wallet that holds it.",
1507
- sig_unsupported_scheme: "We can't check this wallet's signature format yet. Try another wallet, or use email.",
1508
- expired: "That request timed out. Try again for a fresh one.",
1509
- not_yet_valid: "That request is not valid yet. Check your device clock, then try again.",
1510
- nonce_mismatch: "That request didn't match. Try again for a fresh one.",
1511
- audience_mismatch: "That request didn't match this site. Reload the page and try again.",
1512
- purpose_mismatch: "That request didn't match. Try again for a fresh one.",
1513
- malformed: "That signature couldn't be read. Copy it again, whole.",
1514
- challenge_mismatch: "That sign-in message changed after it was issued. Get a new one and sign it again.",
1515
- mainnet_only: "Sign in with a mainnet Bitcoin address.",
1516
- cross_site_blocked: "Your browser blocked this request. Reload the page and try again.",
1517
- rate_limited: "Too many tries. Wait a minute, then try again.",
1518
- invalid_email: "That email address doesn't look right.",
1519
- mailer_unavailable: "We couldn't send the email right now. Try again in a minute.",
1520
- mailer_error: "We couldn't send the email right now. Try again in a minute.",
1521
- wrong_code: "That code isn't right. Check the newest email from us.",
1522
- replay: "That code was already used. Send a new one.",
1523
- invalid_token: "That code is no longer valid. Send a new one.",
1524
- email_mismatch: "That code was sent to a different address. Send a new one.",
1525
- ...ENDED_ERRORS
1526
- };
1527
- var EMAIL_ERRORS = {
1528
- expired: "That code expired. Send a new one.",
1529
- signed_out: "You were signed out while signing in. Send a new code to sign in again."
1530
- };
1531
- var SUBMIT_ERRORS = {
1532
- bad_request: "That signature couldn't be read. Copy it again, whole."
1533
- };
1534
- function networkError(authOrigin) {
1535
- let host = authOrigin;
1536
- try {
1537
- host = new URL(authOrigin).host;
1538
- } catch {
1539
- }
1540
- return `We couldn't reach the orangecheck sign-in service at ${host}. Check your connection, then try again.`;
1541
- }
1542
- function humanSigninError(reason, path, step = "challenge") {
1543
- if (!/^[a-z0-9_]+$/.test(reason)) return reason;
1544
- const own = path === "wallet" && step === "submit" && ownWord(SUBMIT_ERRORS, reason) || path === "email" && ownWord(EMAIL_ERRORS, reason);
1545
- if (own) return own;
1546
- return ownWord(SIGNIN_ERRORS, reason) ?? (path === "email" ? "That didn't work. Try again, or send a new code." : "That didn't work. Try again.");
1547
- }
1548
- function failureMessage(err, path, step, authOrigin) {
1549
- if (err instanceof TypeError || err instanceof SyntaxError) return networkError(authOrigin);
1550
- return humanSigninError(err instanceof Error ? err.message : "failed", path, step);
1551
- }
1552
1578
  var DEFAULT_AUTH_ORIGIN = "https://ochk.io";
1553
1579
  async function fetchOcLinkedIdentities(opts) {
1554
1580
  const authOrigin = opts?.authOrigin ?? DEFAULT_AUTH_ORIGIN;
@@ -2510,6 +2536,7 @@ function oauthErrorText(reason, retryAt, provider) {
2510
2536
  if (cap) return cap;
2511
2537
  const ended = endedSigninText(reason);
2512
2538
  if (ended) return ended;
2539
+ if (reason === "several_sessions") return SEVERAL_SESSIONS_TEXT;
2513
2540
  if (reason === "email_code_required") {
2514
2541
  return "This email already has an orangecheck account. Sign in to it with an email code below.";
2515
2542
  }
@@ -2525,6 +2552,7 @@ function OcSignIn({
2525
2552
  resolveReturnTo,
2526
2553
  linkPrompt: linkPromptProp = true,
2527
2554
  add: addProp,
2555
+ onSeveralSessions,
2528
2556
  authOrigin = "https://ochk.io",
2529
2557
  initialPath,
2530
2558
  providersFirst = true,
@@ -2538,6 +2566,8 @@ function OcSignIn({
2538
2566
  const firstParty = mode === "first-party";
2539
2567
  const credentials = firstParty ? "omit" : "include";
2540
2568
  const linkPrompt = linkPromptProp && !firstParty;
2569
+ const providerSession = useOptionalOcSession();
2570
+ const recheck = onSeveralSessions ?? providerSession?.refresh;
2541
2571
  const [resolvedReturn, setResolvedReturn] = React4__namespace.useState(
2542
2572
  () => familyReturnTarget(returnTo) ?? safeReturnTo(returnTo)
2543
2573
  );
@@ -2794,6 +2824,7 @@ function OcSignIn({
2794
2824
  audience,
2795
2825
  add: addMode,
2796
2826
  credentials,
2827
+ onSeveralSessions: recheck,
2797
2828
  onSuccess: (a, t) => void handleSuccess(a, t, "wallet")
2798
2829
  }
2799
2830
  ),
@@ -2803,6 +2834,7 @@ function OcSignIn({
2803
2834
  authOrigin,
2804
2835
  add: addMode,
2805
2836
  credentials,
2837
+ onSeveralSessions: recheck,
2806
2838
  onSuccess: (a, t) => void handleSuccess(a, t, "email")
2807
2839
  }
2808
2840
  )
@@ -2993,6 +3025,11 @@ function ProviderSignIn({
2993
3025
  }
2994
3026
  );
2995
3027
  }
3028
+ function recheckAfter(err, recheck) {
3029
+ if (!recheck || !isSeveralSessions(err)) return;
3030
+ void Promise.resolve().then(recheck).catch(() => {
3031
+ });
3032
+ }
2996
3033
  async function loadAdapter() {
2997
3034
  return await import('@orangecheck/wallet-adapter');
2998
3035
  }
@@ -3004,7 +3041,8 @@ function WalletFlow({
3004
3041
  audience,
3005
3042
  add,
3006
3043
  credentials,
3007
- onSuccess
3044
+ onSuccess,
3045
+ onSeveralSessions
3008
3046
  }) {
3009
3047
  const uid = React4__namespace.useId();
3010
3048
  const ids = {
@@ -3113,6 +3151,7 @@ function WalletFlow({
3113
3151
  } catch (err) {
3114
3152
  setError(failureMessage(err, "wallet", step, authOrigin));
3115
3153
  setSubmitting(false);
3154
+ recheckAfter(err, onSeveralSessions);
3116
3155
  }
3117
3156
  }
3118
3157
  async function signInManual(e) {
@@ -3130,6 +3169,7 @@ function WalletFlow({
3130
3169
  } catch (err) {
3131
3170
  setError(failureMessage(err, "wallet", "submit", authOrigin));
3132
3171
  setSubmitting(false);
3172
+ recheckAfter(err, onSeveralSessions);
3133
3173
  }
3134
3174
  }
3135
3175
  async function copyMessage() {
@@ -3269,7 +3309,13 @@ function WalletFlow({
3269
3309
  ] });
3270
3310
  }
3271
3311
  var ALSO_LISTED_TEXT = "An account made with Google or GitHub also lists this email. If that account is yours, sign in with Google or GitHub and add this email there to confirm it.";
3272
- function EmailFlow({ authOrigin, add, credentials, onSuccess }) {
3312
+ function EmailFlow({
3313
+ authOrigin,
3314
+ add,
3315
+ credentials,
3316
+ onSuccess,
3317
+ onSeveralSessions
3318
+ }) {
3273
3319
  const uid = React4__namespace.useId();
3274
3320
  const [stage, setStage] = React4__namespace.useState("enter");
3275
3321
  const [email, setEmail] = React4__namespace.useState("");
@@ -3369,6 +3415,7 @@ function EmailFlow({ authOrigin, add, credentials, onSuccess }) {
3369
3415
  onSuccess(json.account, json.token);
3370
3416
  } catch (err) {
3371
3417
  setCodeError(failureMessage(err, "email", "submit", authOrigin));
3418
+ recheckAfter(err, onSeveralSessions);
3372
3419
  } finally {
3373
3420
  setSubmitting(false);
3374
3421
  }