@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.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;
|