@orangecheck/auth-client 2.33.2 → 2.33.4

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.mjs CHANGED
@@ -4,115 +4,6 @@ import { startRegistration, startAuthentication } from '@simplewebauthn/browser'
4
4
 
5
5
  // src/provider.tsx
6
6
 
7
- // src/return-to.ts
8
- var PREFIX = "oc:return-fragment:";
9
- var FRAGMENT_TTL_MS = 15 * 60 * 1e3;
10
- function store() {
11
- try {
12
- return window.sessionStorage;
13
- } catch {
14
- return null;
15
- }
16
- }
17
- function stripFragment(target) {
18
- const cut = target.indexOf("#");
19
- return cut < 0 ? target : target.slice(0, cut);
20
- }
21
- function keep(pathAndQuery, hash) {
22
- if (hash.length < 2) return;
23
- try {
24
- store()?.setItem(PREFIX + pathAndQuery, JSON.stringify({ hash, at: Date.now() }));
25
- } catch {
26
- }
27
- }
28
- function withoutFragment(target) {
29
- if (typeof window !== "undefined" && target.includes("#")) {
30
- try {
31
- const u = new URL(target, window.location.href);
32
- if (u.origin === window.location.origin) keep(u.pathname + u.search, u.hash);
33
- } catch {
34
- }
35
- }
36
- return stripFragment(target);
37
- }
38
- function returnToHere() {
39
- if (typeof window === "undefined") return "/";
40
- const { pathname, search, hash } = window.location;
41
- return withoutFragment(pathname + search + hash);
42
- }
43
- function keepFragmentOnReturnLinks() {
44
- if (typeof document === "undefined") return () => {
45
- };
46
- const onClick = (e) => {
47
- const { pathname, search, hash, href } = window.location;
48
- if (hash.length < 2 || e.defaultPrevented) return;
49
- const link = e.target?.closest?.("a[href]");
50
- if (!link) return;
51
- try {
52
- const to = new URL(link.getAttribute("href") ?? "", href);
53
- const back = to.searchParams.get("return_to");
54
- if (!back) return;
55
- const here = new URL(back, href);
56
- if (here.origin === window.location.origin && here.pathname === pathname && here.search === search) {
57
- keep(pathname + search, hash);
58
- }
59
- } catch {
60
- }
61
- };
62
- document.addEventListener("click", onClick, true);
63
- return () => document.removeEventListener("click", onClick, true);
64
- }
65
- function restoreReturnFragment() {
66
- if (typeof window === "undefined") return false;
67
- const s = store();
68
- if (!s) return false;
69
- const { pathname, search, hash } = window.location;
70
- const key = PREFIX + pathname + search;
71
- let raw;
72
- try {
73
- raw = s.getItem(key);
74
- if (raw === null) return false;
75
- s.removeItem(key);
76
- } catch {
77
- return false;
78
- }
79
- if (hash) return false;
80
- try {
81
- const kept = JSON.parse(raw);
82
- if (typeof kept.hash !== "string" || !kept.hash.startsWith("#")) return false;
83
- if (typeof kept.at !== "number" || Date.now() - kept.at > FRAGMENT_TTL_MS) return false;
84
- window.history.replaceState(window.history.state, "", pathname + search + kept.hash);
85
- return true;
86
- } catch {
87
- return false;
88
- }
89
- }
90
-
91
- // src/types.ts
92
- var DISPLAY_IDENTITY_KINDS = ["did", "btc", "email", "nostr"];
93
- var DEFAULT_CONFIG = {
94
- authOrigin: "https://ochk.io",
95
- signInPath: "/signin",
96
- mePath: "/api/auth/me",
97
- logoutPath: "/api/auth/logout",
98
- multiAccount: true
99
- };
100
- function resolveConfig(cfg) {
101
- return { ...DEFAULT_CONFIG, ...cfg ?? {} };
102
- }
103
- function buildSignInUrl(cfg, returnTo) {
104
- const base = `${cfg.authOrigin}${cfg.signInPath}`;
105
- if (!returnTo) return base;
106
- const u = new URL(base);
107
- u.searchParams.set("return_to", stripFragment(returnTo));
108
- return u.toString();
109
- }
110
- function buildAddAccountUrl(cfg, returnTo) {
111
- const u = new URL(buildSignInUrl(cfg, returnTo));
112
- u.searchParams.set("add", "1");
113
- return u.toString();
114
- }
115
-
116
7
  // src/tab-session.ts
117
8
  var TAB_SESSION_HEADER = "x-oc-tab-session";
118
9
  var TAB_SESSION_STORAGE_KEY = "oc_tab_session";
@@ -284,6 +175,136 @@ async function consumeTabAccountHint(authOrigin) {
284
175
  }
285
176
  return null;
286
177
  }
178
+
179
+ // src/return-to.ts
180
+ var PREFIX = "oc:return-fragment:";
181
+ var HOLD_MS = 1e4;
182
+ var FRAGMENT_TTL_MS = 15 * 60 * 1e3;
183
+ function store() {
184
+ try {
185
+ return window.sessionStorage;
186
+ } catch {
187
+ return null;
188
+ }
189
+ }
190
+ function stripFragment(target) {
191
+ const cut = target.indexOf("#");
192
+ return cut < 0 ? target : target.slice(0, cut);
193
+ }
194
+ function keep(pathAndQuery, hash) {
195
+ if (hash.length < 2) return;
196
+ try {
197
+ store()?.setItem(PREFIX + pathAndQuery, JSON.stringify({ hash, at: Date.now() }));
198
+ } catch {
199
+ }
200
+ }
201
+ function withoutFragment(target) {
202
+ if (typeof window !== "undefined" && target.includes("#")) {
203
+ try {
204
+ const u = new URL(target, window.location.href);
205
+ if (u.origin === window.location.origin) keep(u.pathname + u.search, u.hash);
206
+ } catch {
207
+ }
208
+ }
209
+ return stripFragment(target);
210
+ }
211
+ function returnToHere() {
212
+ if (typeof window === "undefined") return "/";
213
+ const { pathname, search, hash } = window.location;
214
+ return withoutFragment(pathname + search + hash);
215
+ }
216
+ function keepFragmentOnReturnLinks() {
217
+ if (typeof document === "undefined") return () => {
218
+ };
219
+ const onClick = (e) => {
220
+ const { pathname, search, hash, href } = window.location;
221
+ if (hash.length < 2 || e.defaultPrevented) return;
222
+ const link = e.target?.closest?.("a[href]");
223
+ if (!link) return;
224
+ try {
225
+ const to = new URL(link.getAttribute("href") ?? "", href);
226
+ const back = to.searchParams.get("return_to");
227
+ if (!back) return;
228
+ const here = new URL(back, href);
229
+ if (here.origin === window.location.origin && here.pathname === pathname && here.search === search) {
230
+ keep(pathname + search, hash);
231
+ }
232
+ } catch {
233
+ }
234
+ };
235
+ document.addEventListener("click", onClick, true);
236
+ return () => document.removeEventListener("click", onClick, true);
237
+ }
238
+ function restoreReturnFragment() {
239
+ if (typeof window === "undefined") return false;
240
+ const s = store();
241
+ if (!s) return false;
242
+ const { pathname, search, hash } = window.location;
243
+ const key = PREFIX + pathname + search;
244
+ let raw;
245
+ try {
246
+ raw = s.getItem(key);
247
+ if (raw === null) return false;
248
+ s.removeItem(key);
249
+ } catch {
250
+ return false;
251
+ }
252
+ if (hash) return false;
253
+ try {
254
+ const kept = JSON.parse(raw);
255
+ if (typeof kept.hash !== "string" || !kept.hash.startsWith("#")) return false;
256
+ if (typeof kept.at !== "number" || Date.now() - kept.at > FRAGMENT_TTL_MS) return false;
257
+ const restored = pathname + search + kept.hash;
258
+ window.history.replaceState(window.history.state, "", restored);
259
+ holdFragment(pathname + search, kept.hash, restored);
260
+ return true;
261
+ } catch {
262
+ return false;
263
+ }
264
+ }
265
+ function holdFragment(pathAndQuery, hash, restored) {
266
+ const until = Date.now() + HOLD_MS;
267
+ const check = () => {
268
+ const l = window.location;
269
+ if (l.pathname + l.search !== pathAndQuery || l.hash === hash) {
270
+ if (l.pathname + l.search === pathAndQuery && Date.now() < until) {
271
+ window.setTimeout(check, 50);
272
+ }
273
+ return;
274
+ }
275
+ if (l.hash && l.hash !== TAB_ADOPT_HASH) return;
276
+ try {
277
+ window.history.replaceState(window.history.state, "", restored);
278
+ } catch {
279
+ }
280
+ };
281
+ window.setTimeout(check, 0);
282
+ }
283
+
284
+ // src/types.ts
285
+ var DISPLAY_IDENTITY_KINDS = ["did", "btc", "email", "nostr"];
286
+ var DEFAULT_CONFIG = {
287
+ authOrigin: "https://ochk.io",
288
+ signInPath: "/signin",
289
+ mePath: "/api/auth/me",
290
+ logoutPath: "/api/auth/logout",
291
+ multiAccount: true
292
+ };
293
+ function resolveConfig(cfg) {
294
+ return { ...DEFAULT_CONFIG, ...cfg ?? {} };
295
+ }
296
+ function buildSignInUrl(cfg, returnTo) {
297
+ const base = `${cfg.authOrigin}${cfg.signInPath}`;
298
+ if (!returnTo) return base;
299
+ const u = new URL(base);
300
+ u.searchParams.set("return_to", stripFragment(returnTo));
301
+ return u.toString();
302
+ }
303
+ function buildAddAccountUrl(cfg, returnTo) {
304
+ const u = new URL(buildSignInUrl(cfg, returnTo));
305
+ u.searchParams.set("add", "1");
306
+ return u.toString();
307
+ }
287
308
  var SessionContext = React4.createContext(null);
288
309
  function normalizeDisplayIdentity(raw, didOc) {
289
310
  const di = raw.display_identity ?? raw.displayIdentity;
@@ -1271,6 +1292,7 @@ var signinRadius = (px) => `var(--oc-signin-radius, ${px}px)`;
1271
1292
  var SIGNIN_BUTTON_RADIUS = "var(--oc-signin-button-radius, 6px)";
1272
1293
  var SIGNIN_STRONG = "var(--oc-signin-strong, 600)";
1273
1294
  var SIGNIN_ARROW = "var(--oc-signin-arrow, inline)";
1295
+ var signinRoleSize = (role, fallback) => `var(--oc-signin-${role}-size, ${fallback})`;
1274
1296
  var DEFAULT_AUTH_ORIGIN = "https://ochk.io";
1275
1297
  async function fetchOcLinkedIdentities(opts) {
1276
1298
  const authOrigin = opts?.authOrigin ?? DEFAULT_AUTH_ORIGIN;
@@ -2381,7 +2403,7 @@ function OcSignIn({
2381
2403
  borderRadius: signinRadius(6),
2382
2404
  color: "var(--destructive, #ef4444)",
2383
2405
  fontFamily: SIGNIN_FONT,
2384
- fontSize: signinSize(11)
2406
+ fontSize: signinRoleSize("text", signinSize(11))
2385
2407
  },
2386
2408
  children: "That sign-in didn't finish. Try again, or use another way below."
2387
2409
  }
@@ -2399,7 +2421,7 @@ function OcSignIn({
2399
2421
  background: "color-mix(in srgb, var(--primary, #f97316) 8%, transparent)",
2400
2422
  color: "var(--foreground, #fafafa)",
2401
2423
  fontFamily: SIGNIN_FONT,
2402
- fontSize: signinSize(11),
2424
+ fontSize: signinRoleSize("text", signinSize(11)),
2403
2425
  lineHeight: 1.6
2404
2426
  },
2405
2427
  children: [
@@ -2555,7 +2577,7 @@ function SigninTab({
2555
2577
  borderBottom: active ? "2px solid var(--primary, #f97316)" : "2px solid transparent",
2556
2578
  color: active ? "var(--foreground, #fafafa)" : "var(--muted-foreground, #a1a1aa)",
2557
2579
  fontFamily: SIGNIN_FONT,
2558
- fontSize: signinSize(11),
2580
+ fontSize: signinRoleSize("label", signinSize(11)),
2559
2581
  letterSpacing: signinTracking("0.12em"),
2560
2582
  textTransform: SIGNIN_CASE,
2561
2583
  cursor: "pointer",
@@ -2628,7 +2650,7 @@ function ProviderSignIn({
2628
2650
  margin: first ? `${BLOCK_GAP}px 0` : `0 0 ${BLOCK_GAP}px`,
2629
2651
  color: "var(--muted-foreground, #a1a1aa)",
2630
2652
  fontFamily: SIGNIN_FONT,
2631
- fontSize: signinSize(10),
2653
+ fontSize: signinRoleSize("hint", signinSize(10)),
2632
2654
  letterSpacing: signinTracking("0.16em"),
2633
2655
  textTransform: SIGNIN_CASE
2634
2656
  },
@@ -3159,7 +3181,7 @@ function FlowHeader({
3159
3181
  {
3160
3182
  style: {
3161
3183
  color: "var(--muted-foreground, #a1a1aa)",
3162
- fontSize: 13,
3184
+ fontSize: signinRoleSize("text", "13px"),
3163
3185
  lineHeight: 1.55,
3164
3186
  margin: 0
3165
3187
  },
@@ -3178,7 +3200,7 @@ var linkButtonStyle = {
3178
3200
  border: "none",
3179
3201
  color: "var(--muted-foreground, #a1a1aa)",
3180
3202
  fontFamily: SIGNIN_FONT,
3181
- fontSize: signinSize(11),
3203
+ fontSize: signinRoleSize("button", signinSize(11)),
3182
3204
  letterSpacing: signinTracking("0.12em"),
3183
3205
  textTransform: SIGNIN_CASE,
3184
3206
  cursor: "pointer",
@@ -3196,7 +3218,7 @@ function Label({
3196
3218
  display: "block",
3197
3219
  color: "var(--foreground, #fafafa)",
3198
3220
  fontFamily: SIGNIN_FONT,
3199
- fontSize: signinSize(11),
3221
+ fontSize: signinRoleSize("label", signinSize(11)),
3200
3222
  letterSpacing: signinTracking("0.12em"),
3201
3223
  textTransform: SIGNIN_CASE,
3202
3224
  marginBottom: 6
@@ -3230,7 +3252,7 @@ var linkAlsoStyle = {
3230
3252
  borderTop: "1px solid var(--border, #27272a)",
3231
3253
  color: "var(--muted-foreground, #a1a1aa)",
3232
3254
  fontFamily: SIGNIN_FONT,
3233
- fontSize: signinSize(12),
3255
+ fontSize: signinRoleSize("text", signinSize(12)),
3234
3256
  lineHeight: 1.5,
3235
3257
  cursor: "pointer"
3236
3258
  };
@@ -3243,7 +3265,7 @@ function submitStyle(disabled) {
3243
3265
  border: "none",
3244
3266
  borderRadius: SIGNIN_BUTTON_RADIUS,
3245
3267
  fontFamily: SIGNIN_FONT,
3246
- fontSize: signinSize(11),
3268
+ fontSize: signinRoleSize("button", signinSize(11)),
3247
3269
  letterSpacing: signinTracking("0.14em"),
3248
3270
  textTransform: SIGNIN_CASE,
3249
3271
  fontWeight: SIGNIN_STRONG,
@@ -3262,7 +3284,7 @@ function ErrorLine2({ children }) {
3262
3284
  marginBottom: 0,
3263
3285
  color: "var(--destructive, #ef4444)",
3264
3286
  fontFamily: SIGNIN_FONT,
3265
- fontSize: signinSize(11),
3287
+ fontSize: signinRoleSize("hint", signinSize(11)),
3266
3288
  letterSpacing: "0.04em"
3267
3289
  },
3268
3290
  children
@@ -3278,7 +3300,7 @@ function Hint({ children }) {
3278
3300
  marginBottom: 0,
3279
3301
  color: "var(--muted-foreground, #a1a1aa)",
3280
3302
  fontFamily: SIGNIN_FONT,
3281
- fontSize: 10.5,
3303
+ fontSize: signinRoleSize("hint", "10.5px"),
3282
3304
  lineHeight: 1.55
3283
3305
  },
3284
3306
  children