@orangecheck/auth-client 2.33.2 → 2.33.3
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 +130 -109
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +130 -109
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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;
|