@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.js CHANGED
@@ -26,115 +26,6 @@ var React4__namespace = /*#__PURE__*/_interopNamespace(React4);
26
26
 
27
27
  // src/provider.tsx
28
28
 
29
- // src/return-to.ts
30
- var PREFIX = "oc:return-fragment:";
31
- var FRAGMENT_TTL_MS = 15 * 60 * 1e3;
32
- function store() {
33
- try {
34
- return window.sessionStorage;
35
- } catch {
36
- return null;
37
- }
38
- }
39
- function stripFragment(target) {
40
- const cut = target.indexOf("#");
41
- return cut < 0 ? target : target.slice(0, cut);
42
- }
43
- function keep(pathAndQuery, hash) {
44
- if (hash.length < 2) return;
45
- try {
46
- store()?.setItem(PREFIX + pathAndQuery, JSON.stringify({ hash, at: Date.now() }));
47
- } catch {
48
- }
49
- }
50
- function withoutFragment(target) {
51
- if (typeof window !== "undefined" && target.includes("#")) {
52
- try {
53
- const u = new URL(target, window.location.href);
54
- if (u.origin === window.location.origin) keep(u.pathname + u.search, u.hash);
55
- } catch {
56
- }
57
- }
58
- return stripFragment(target);
59
- }
60
- function returnToHere() {
61
- if (typeof window === "undefined") return "/";
62
- const { pathname, search, hash } = window.location;
63
- return withoutFragment(pathname + search + hash);
64
- }
65
- function keepFragmentOnReturnLinks() {
66
- if (typeof document === "undefined") return () => {
67
- };
68
- const onClick = (e) => {
69
- const { pathname, search, hash, href } = window.location;
70
- if (hash.length < 2 || e.defaultPrevented) return;
71
- const link = e.target?.closest?.("a[href]");
72
- if (!link) return;
73
- try {
74
- const to = new URL(link.getAttribute("href") ?? "", href);
75
- const back = to.searchParams.get("return_to");
76
- if (!back) return;
77
- const here = new URL(back, href);
78
- if (here.origin === window.location.origin && here.pathname === pathname && here.search === search) {
79
- keep(pathname + search, hash);
80
- }
81
- } catch {
82
- }
83
- };
84
- document.addEventListener("click", onClick, true);
85
- return () => document.removeEventListener("click", onClick, true);
86
- }
87
- function restoreReturnFragment() {
88
- if (typeof window === "undefined") return false;
89
- const s = store();
90
- if (!s) return false;
91
- const { pathname, search, hash } = window.location;
92
- const key = PREFIX + pathname + search;
93
- let raw;
94
- try {
95
- raw = s.getItem(key);
96
- if (raw === null) return false;
97
- s.removeItem(key);
98
- } catch {
99
- return false;
100
- }
101
- if (hash) return false;
102
- try {
103
- const kept = JSON.parse(raw);
104
- if (typeof kept.hash !== "string" || !kept.hash.startsWith("#")) return false;
105
- if (typeof kept.at !== "number" || Date.now() - kept.at > FRAGMENT_TTL_MS) return false;
106
- window.history.replaceState(window.history.state, "", pathname + search + kept.hash);
107
- return true;
108
- } catch {
109
- return false;
110
- }
111
- }
112
-
113
- // src/types.ts
114
- var DISPLAY_IDENTITY_KINDS = ["did", "btc", "email", "nostr"];
115
- var DEFAULT_CONFIG = {
116
- authOrigin: "https://ochk.io",
117
- signInPath: "/signin",
118
- mePath: "/api/auth/me",
119
- logoutPath: "/api/auth/logout",
120
- multiAccount: true
121
- };
122
- function resolveConfig(cfg) {
123
- return { ...DEFAULT_CONFIG, ...cfg ?? {} };
124
- }
125
- function buildSignInUrl(cfg, returnTo) {
126
- const base = `${cfg.authOrigin}${cfg.signInPath}`;
127
- if (!returnTo) return base;
128
- const u = new URL(base);
129
- u.searchParams.set("return_to", stripFragment(returnTo));
130
- return u.toString();
131
- }
132
- function buildAddAccountUrl(cfg, returnTo) {
133
- const u = new URL(buildSignInUrl(cfg, returnTo));
134
- u.searchParams.set("add", "1");
135
- return u.toString();
136
- }
137
-
138
29
  // src/tab-session.ts
139
30
  var TAB_SESSION_HEADER = "x-oc-tab-session";
140
31
  var TAB_SESSION_STORAGE_KEY = "oc_tab_session";
@@ -306,6 +197,136 @@ async function consumeTabAccountHint(authOrigin) {
306
197
  }
307
198
  return null;
308
199
  }
200
+
201
+ // src/return-to.ts
202
+ var PREFIX = "oc:return-fragment:";
203
+ var HOLD_MS = 1e4;
204
+ var FRAGMENT_TTL_MS = 15 * 60 * 1e3;
205
+ function store() {
206
+ try {
207
+ return window.sessionStorage;
208
+ } catch {
209
+ return null;
210
+ }
211
+ }
212
+ function stripFragment(target) {
213
+ const cut = target.indexOf("#");
214
+ return cut < 0 ? target : target.slice(0, cut);
215
+ }
216
+ function keep(pathAndQuery, hash) {
217
+ if (hash.length < 2) return;
218
+ try {
219
+ store()?.setItem(PREFIX + pathAndQuery, JSON.stringify({ hash, at: Date.now() }));
220
+ } catch {
221
+ }
222
+ }
223
+ function withoutFragment(target) {
224
+ if (typeof window !== "undefined" && target.includes("#")) {
225
+ try {
226
+ const u = new URL(target, window.location.href);
227
+ if (u.origin === window.location.origin) keep(u.pathname + u.search, u.hash);
228
+ } catch {
229
+ }
230
+ }
231
+ return stripFragment(target);
232
+ }
233
+ function returnToHere() {
234
+ if (typeof window === "undefined") return "/";
235
+ const { pathname, search, hash } = window.location;
236
+ return withoutFragment(pathname + search + hash);
237
+ }
238
+ function keepFragmentOnReturnLinks() {
239
+ if (typeof document === "undefined") return () => {
240
+ };
241
+ const onClick = (e) => {
242
+ const { pathname, search, hash, href } = window.location;
243
+ if (hash.length < 2 || e.defaultPrevented) return;
244
+ const link = e.target?.closest?.("a[href]");
245
+ if (!link) return;
246
+ try {
247
+ const to = new URL(link.getAttribute("href") ?? "", href);
248
+ const back = to.searchParams.get("return_to");
249
+ if (!back) return;
250
+ const here = new URL(back, href);
251
+ if (here.origin === window.location.origin && here.pathname === pathname && here.search === search) {
252
+ keep(pathname + search, hash);
253
+ }
254
+ } catch {
255
+ }
256
+ };
257
+ document.addEventListener("click", onClick, true);
258
+ return () => document.removeEventListener("click", onClick, true);
259
+ }
260
+ function restoreReturnFragment() {
261
+ if (typeof window === "undefined") return false;
262
+ const s = store();
263
+ if (!s) return false;
264
+ const { pathname, search, hash } = window.location;
265
+ const key = PREFIX + pathname + search;
266
+ let raw;
267
+ try {
268
+ raw = s.getItem(key);
269
+ if (raw === null) return false;
270
+ s.removeItem(key);
271
+ } catch {
272
+ return false;
273
+ }
274
+ if (hash) return false;
275
+ try {
276
+ const kept = JSON.parse(raw);
277
+ if (typeof kept.hash !== "string" || !kept.hash.startsWith("#")) return false;
278
+ if (typeof kept.at !== "number" || Date.now() - kept.at > FRAGMENT_TTL_MS) return false;
279
+ const restored = pathname + search + kept.hash;
280
+ window.history.replaceState(window.history.state, "", restored);
281
+ holdFragment(pathname + search, kept.hash, restored);
282
+ return true;
283
+ } catch {
284
+ return false;
285
+ }
286
+ }
287
+ function holdFragment(pathAndQuery, hash, restored) {
288
+ const until = Date.now() + HOLD_MS;
289
+ const check = () => {
290
+ const l = window.location;
291
+ if (l.pathname + l.search !== pathAndQuery || l.hash === hash) {
292
+ if (l.pathname + l.search === pathAndQuery && Date.now() < until) {
293
+ window.setTimeout(check, 50);
294
+ }
295
+ return;
296
+ }
297
+ if (l.hash && l.hash !== TAB_ADOPT_HASH) return;
298
+ try {
299
+ window.history.replaceState(window.history.state, "", restored);
300
+ } catch {
301
+ }
302
+ };
303
+ window.setTimeout(check, 0);
304
+ }
305
+
306
+ // src/types.ts
307
+ var DISPLAY_IDENTITY_KINDS = ["did", "btc", "email", "nostr"];
308
+ var DEFAULT_CONFIG = {
309
+ authOrigin: "https://ochk.io",
310
+ signInPath: "/signin",
311
+ mePath: "/api/auth/me",
312
+ logoutPath: "/api/auth/logout",
313
+ multiAccount: true
314
+ };
315
+ function resolveConfig(cfg) {
316
+ return { ...DEFAULT_CONFIG, ...cfg ?? {} };
317
+ }
318
+ function buildSignInUrl(cfg, returnTo) {
319
+ const base = `${cfg.authOrigin}${cfg.signInPath}`;
320
+ if (!returnTo) return base;
321
+ const u = new URL(base);
322
+ u.searchParams.set("return_to", stripFragment(returnTo));
323
+ return u.toString();
324
+ }
325
+ function buildAddAccountUrl(cfg, returnTo) {
326
+ const u = new URL(buildSignInUrl(cfg, returnTo));
327
+ u.searchParams.set("add", "1");
328
+ return u.toString();
329
+ }
309
330
  var SessionContext = React4__namespace.createContext(null);
310
331
  function normalizeDisplayIdentity(raw, didOc) {
311
332
  const di = raw.display_identity ?? raw.displayIdentity;
@@ -1293,6 +1314,7 @@ var signinRadius = (px) => `var(--oc-signin-radius, ${px}px)`;
1293
1314
  var SIGNIN_BUTTON_RADIUS = "var(--oc-signin-button-radius, 6px)";
1294
1315
  var SIGNIN_STRONG = "var(--oc-signin-strong, 600)";
1295
1316
  var SIGNIN_ARROW = "var(--oc-signin-arrow, inline)";
1317
+ var signinRoleSize = (role, fallback) => `var(--oc-signin-${role}-size, ${fallback})`;
1296
1318
  var DEFAULT_AUTH_ORIGIN = "https://ochk.io";
1297
1319
  async function fetchOcLinkedIdentities(opts) {
1298
1320
  const authOrigin = opts?.authOrigin ?? DEFAULT_AUTH_ORIGIN;
@@ -2403,7 +2425,7 @@ function OcSignIn({
2403
2425
  borderRadius: signinRadius(6),
2404
2426
  color: "var(--destructive, #ef4444)",
2405
2427
  fontFamily: SIGNIN_FONT,
2406
- fontSize: signinSize(11)
2428
+ fontSize: signinRoleSize("text", signinSize(11))
2407
2429
  },
2408
2430
  children: "That sign-in didn't finish. Try again, or use another way below."
2409
2431
  }
@@ -2421,7 +2443,7 @@ function OcSignIn({
2421
2443
  background: "color-mix(in srgb, var(--primary, #f97316) 8%, transparent)",
2422
2444
  color: "var(--foreground, #fafafa)",
2423
2445
  fontFamily: SIGNIN_FONT,
2424
- fontSize: signinSize(11),
2446
+ fontSize: signinRoleSize("text", signinSize(11)),
2425
2447
  lineHeight: 1.6
2426
2448
  },
2427
2449
  children: [
@@ -2577,7 +2599,7 @@ function SigninTab({
2577
2599
  borderBottom: active ? "2px solid var(--primary, #f97316)" : "2px solid transparent",
2578
2600
  color: active ? "var(--foreground, #fafafa)" : "var(--muted-foreground, #a1a1aa)",
2579
2601
  fontFamily: SIGNIN_FONT,
2580
- fontSize: signinSize(11),
2602
+ fontSize: signinRoleSize("label", signinSize(11)),
2581
2603
  letterSpacing: signinTracking("0.12em"),
2582
2604
  textTransform: SIGNIN_CASE,
2583
2605
  cursor: "pointer",
@@ -2650,7 +2672,7 @@ function ProviderSignIn({
2650
2672
  margin: first ? `${BLOCK_GAP}px 0` : `0 0 ${BLOCK_GAP}px`,
2651
2673
  color: "var(--muted-foreground, #a1a1aa)",
2652
2674
  fontFamily: SIGNIN_FONT,
2653
- fontSize: signinSize(10),
2675
+ fontSize: signinRoleSize("hint", signinSize(10)),
2654
2676
  letterSpacing: signinTracking("0.16em"),
2655
2677
  textTransform: SIGNIN_CASE
2656
2678
  },
@@ -3181,7 +3203,7 @@ function FlowHeader({
3181
3203
  {
3182
3204
  style: {
3183
3205
  color: "var(--muted-foreground, #a1a1aa)",
3184
- fontSize: 13,
3206
+ fontSize: signinRoleSize("text", "13px"),
3185
3207
  lineHeight: 1.55,
3186
3208
  margin: 0
3187
3209
  },
@@ -3200,7 +3222,7 @@ var linkButtonStyle = {
3200
3222
  border: "none",
3201
3223
  color: "var(--muted-foreground, #a1a1aa)",
3202
3224
  fontFamily: SIGNIN_FONT,
3203
- fontSize: signinSize(11),
3225
+ fontSize: signinRoleSize("button", signinSize(11)),
3204
3226
  letterSpacing: signinTracking("0.12em"),
3205
3227
  textTransform: SIGNIN_CASE,
3206
3228
  cursor: "pointer",
@@ -3218,7 +3240,7 @@ function Label({
3218
3240
  display: "block",
3219
3241
  color: "var(--foreground, #fafafa)",
3220
3242
  fontFamily: SIGNIN_FONT,
3221
- fontSize: signinSize(11),
3243
+ fontSize: signinRoleSize("label", signinSize(11)),
3222
3244
  letterSpacing: signinTracking("0.12em"),
3223
3245
  textTransform: SIGNIN_CASE,
3224
3246
  marginBottom: 6
@@ -3252,7 +3274,7 @@ var linkAlsoStyle = {
3252
3274
  borderTop: "1px solid var(--border, #27272a)",
3253
3275
  color: "var(--muted-foreground, #a1a1aa)",
3254
3276
  fontFamily: SIGNIN_FONT,
3255
- fontSize: signinSize(12),
3277
+ fontSize: signinRoleSize("text", signinSize(12)),
3256
3278
  lineHeight: 1.5,
3257
3279
  cursor: "pointer"
3258
3280
  };
@@ -3265,7 +3287,7 @@ function submitStyle(disabled) {
3265
3287
  border: "none",
3266
3288
  borderRadius: SIGNIN_BUTTON_RADIUS,
3267
3289
  fontFamily: SIGNIN_FONT,
3268
- fontSize: signinSize(11),
3290
+ fontSize: signinRoleSize("button", signinSize(11)),
3269
3291
  letterSpacing: signinTracking("0.14em"),
3270
3292
  textTransform: SIGNIN_CASE,
3271
3293
  fontWeight: SIGNIN_STRONG,
@@ -3284,7 +3306,7 @@ function ErrorLine2({ children }) {
3284
3306
  marginBottom: 0,
3285
3307
  color: "var(--destructive, #ef4444)",
3286
3308
  fontFamily: SIGNIN_FONT,
3287
- fontSize: signinSize(11),
3309
+ fontSize: signinRoleSize("hint", signinSize(11)),
3288
3310
  letterSpacing: "0.04em"
3289
3311
  },
3290
3312
  children
@@ -3300,7 +3322,7 @@ function Hint({ children }) {
3300
3322
  marginBottom: 0,
3301
3323
  color: "var(--muted-foreground, #a1a1aa)",
3302
3324
  fontFamily: SIGNIN_FONT,
3303
- fontSize: 10.5,
3325
+ fontSize: signinRoleSize("hint", "10.5px"),
3304
3326
  lineHeight: 1.55
3305
3327
  },
3306
3328
  children