@abyss-project/commons-front-core 5.0.0 → 6.0.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 (55) hide show
  1. package/dist/{CookieConsentSettings.component-Qv7WlFv1.js → CookieConsentSettings.component-Da4l2tFQ.js} +1073 -1038
  2. package/dist/auth/client/abyss-login.d.ts +61 -0
  3. package/dist/auth/client/abyss-login.spec.d.ts +1 -0
  4. package/dist/auth/client/auth-refresh-interceptor.d.ts +41 -0
  5. package/dist/auth/client/auth-refresh-interceptor.spec.d.ts +1 -0
  6. package/dist/auth/client/index.d.ts +2 -0
  7. package/dist/auth/client/web-bridge.d.ts +10 -5
  8. package/dist/auth/components/RequireSession/RequireSession.component.d.ts +17 -0
  9. package/dist/auth/components/RequireSession/RequireSession.component.spec.d.ts +1 -0
  10. package/dist/auth/components/RequireSession/RequireSession.logout.spec.d.ts +1 -0
  11. package/dist/auth/components/SecuritySettings/sections/PasswordSection.component.d.ts +0 -2
  12. package/dist/auth/components/SessionBoundary/AbyssSessionBoundary.component.d.ts +27 -0
  13. package/dist/auth/components/SessionBoundary/AbyssSessionBoundary.component.spec.d.ts +1 -0
  14. package/dist/auth/components/SessionErrorScreen/SessionErrorScreen.component.d.ts +27 -0
  15. package/dist/auth/components/index.d.ts +6 -0
  16. package/dist/auth-client.js +33 -22
  17. package/dist/components/Inputs/CloudImport/CloudImport.component.d.ts +4 -0
  18. package/dist/components/Inputs/CloudImport/CloudImportFile.component.spec.d.ts +1 -0
  19. package/dist/components/Inputs/CloudImport/cloud-accept.d.ts +13 -0
  20. package/dist/components/Inputs/CloudImport/cloud-accept.spec.d.ts +1 -0
  21. package/dist/components/Support/support-status-timeline.logic.d.ts +2 -2
  22. package/dist/cookie-consent.js +1 -1
  23. package/dist/hooks/use-rich-intl.hook.d.ts +28 -2
  24. package/dist/{index-CS_grWE4.js → index-2EY2JNir.js} +4 -4
  25. package/dist/{index-C8PVDVGQ.js → index-B3yNQeWK.js} +2 -2
  26. package/dist/{index-C2RWcbVl.js → index-B7dA6I-R.js} +2 -2
  27. package/dist/{index-CDUED8YP.js → index-B8jAaZFi.js} +2 -2
  28. package/dist/{index-Cl8WUtRw.js → index-BB8-EZF4.js} +2 -2
  29. package/dist/{index-B2u_xNxk.js → index-BI9lpDsi.js} +2 -2
  30. package/dist/{index-BuIwrS34.js → index-BM0yX2Iz.js} +2 -2
  31. package/dist/{index-Y2TnZBi8.js → index-Bw5kKOog.js} +4 -4
  32. package/dist/{index-D5ylhtng.js → index-C8lLApSB.js} +2 -2
  33. package/dist/{index-D1N8_Qim.js → index-CEJ4iiA5.js} +4 -4
  34. package/dist/{index-BFEmh_EV.js → index-CLFBr4MF.js} +2 -2
  35. package/dist/{index-5owlFn6W.js → index-CZRRt2kg.js} +2 -2
  36. package/dist/{index-BsFPvS1n.js → index-Cb-sJiqp.js} +2 -2
  37. package/dist/{index-C_-NoOPN.js → index-CxKeAkSY.js} +2 -2
  38. package/dist/{index-B0h04i9u.js → index-CxfOutZw.js} +3 -3
  39. package/dist/{index-oKfJH01a.js → index-CzlzF3eF.js} +3 -3
  40. package/dist/{index-1CoDaadD.js → index-CzpB9qD9.js} +1 -1
  41. package/dist/{index-CLz2EEY4.js → index-D1QkFZiF.js} +3 -3
  42. package/dist/{index-B4Ff-AfL.js → index-DI9IV0Ew.js} +19209 -18897
  43. package/dist/{index-BG716EPB.js → index-Dc_oDJTw.js} +3 -3
  44. package/dist/{index-DHCXtcI7.js → index-HfP5qfTf.js} +2 -2
  45. package/dist/{index-Ci4SXMFB.js → index-Kbs9OrDN.js} +2 -2
  46. package/dist/index.js +261 -246
  47. package/dist/internal/lazy-value.d.ts +11 -0
  48. package/dist/internal/lazy-value.spec.d.ts +1 -0
  49. package/dist/lazy-value-Co76vxsM.js +7 -0
  50. package/dist/load-safety.spec.d.ts +1 -0
  51. package/dist/translations/en.d.ts +13 -0
  52. package/dist/translations/fr.d.ts +13 -0
  53. package/dist/use-auth.hook-oRxzI95f.js +469 -0
  54. package/package.json +3 -3
  55. package/dist/use-auth.hook-BLaU_u8T.js +0 -391
@@ -1,391 +0,0 @@
1
- import { MfaFactorType as U, SessionPlatform as B, AbyssCore as F, Code as J, AuthResultStatus as X } from "@abyss-project/main";
2
- import { browserSupportsWebAuthn as g, startRegistration as $, browserSupportsWebAuthnAutofill as V, startAuthentication as Q, WebAuthnError as Z } from "@simplewebauthn/browser";
3
- import { a as c, A as d, s as ee } from "./token-storage-CbWrBeIP.js";
4
- import { createContext as te, useState as ne, useEffect as se, useMemo as re, useContext as oe } from "react";
5
- import { jsx as ae } from "react/jsx-runtime";
6
- var ie = /* @__PURE__ */ ((e) => (e.LOADING = "loading", e.ANONYMOUS = "anonymous", e.AUTHENTICATED = "authenticated", e))(ie || {}), ue = /* @__PURE__ */ ((e) => (e.PASSKEY = "passkey", e.TOTP = "totp", e.PASSWORD = "password", e.EMAIL_CODE = "email-code", e))(ue || {});
7
- const le = 6e4, x = 3e4, ce = [
8
- 500,
9
- 1e3,
10
- 2e3
11
- ], de = [
12
- 7500,
13
- 15e3,
14
- 22500,
15
- 27e3
16
- ], G = 3e4, fe = 5e3, pe = "abyss-auth-refresh", he = 2147483647, we = "Token Expired", Ee = (e) => typeof e == "object" && e !== null && e.isAxiosError === !0, H = (e) => {
17
- var r;
18
- if (!Ee(e) || e.code === "ERR_CANCELED")
19
- return { kind: "other" };
20
- if (!e.response)
21
- return { kind: "network" };
22
- const s = (r = e.response.data) == null ? void 0 : r.error;
23
- return {
24
- kind: "http",
25
- status: e.response.status,
26
- code: s == null ? void 0 : s.code,
27
- message: s == null ? void 0 : s.message,
28
- params: s == null ? void 0 : s.params
29
- };
30
- }, me = /* @__PURE__ */ new Map([
31
- [
32
- U.TOTP,
33
- "totp"
34
- /* TOTP */
35
- ],
36
- [
37
- U.PASSKEY,
38
- "passkey"
39
- /* PASSKEY */
40
- ]
41
- ]), Ae = (e) => {
42
- const s = e == null ? void 0 : e.methods;
43
- return Array.isArray(s) ? {
44
- methods: s.flatMap((r) => {
45
- const i = me.get(r);
46
- return i ? [i] : [];
47
- })
48
- } : {};
49
- }, ye = (e) => new Promise((s) => setTimeout(s, e)), Re = () => typeof navigator > "u" || navigator.onLine !== !1, Te = () => typeof navigator > "u" ? null : navigator.locks ?? null, De = (e) => {
50
- const s = e.bridge.platform === B.WEB, r = e.isOnline ?? Re;
51
- let i = {
52
- status: "loading"
53
- /* LOADING */
54
- }, a = null, n = null, E = null, y = null, _ = null, m = null, p = null, l = null, A = 0;
55
- const R = /* @__PURE__ */ new Set(), T = /* @__PURE__ */ new Set(), S = (t) => {
56
- i = t, R.forEach((o) => o(i));
57
- }, D = (t) => {
58
- a = t, e.applyToken(t), T.forEach((o) => o(t));
59
- }, k = () => {
60
- m && (clearTimeout(m), m = null), p && (clearTimeout(p), p = null);
61
- }, K = (t) => {
62
- const o = Date.parse(t);
63
- if (!Number.isFinite(o))
64
- return;
65
- const u = Math.min(
66
- Math.max(o - le - Date.now(), 0),
67
- he
68
- );
69
- m = setTimeout(() => {
70
- m = null, h.refresh();
71
- }, u);
72
- }, P = async (t) => {
73
- var o;
74
- k(), t.refreshToken && await e.storage.setRefreshToken(t.refreshToken), D(t.accessToken), n = t.user, (o = e.onPersistUser) == null || o.call(e, t.user), S({
75
- status: "authenticated",
76
- user: t.user,
77
- mfaEnrollmentRequired: t.mfaEnrollmentRequired,
78
- offline: !1
79
- }), K(t.accessTokenExpiresAt);
80
- }, N = async () => {
81
- var t;
82
- A += 1, k(), l = null, await e.storage.setRefreshToken(null), D(null), n = null, (t = e.onPersistUser) == null || t.call(e, null), S({
83
- status: "anonymous"
84
- /* ANONYMOUS */
85
- });
86
- }, j = () => {
87
- if (l === null)
88
- return G;
89
- const t = Date.now() - l, o = de.find(
90
- (u) => u > t && u < x
91
- );
92
- return o === void 0 ? (l = null, G) : o - t;
93
- }, z = () => {
94
- k();
95
- const t = i.user ?? n;
96
- S(
97
- t ? {
98
- status: "authenticated",
99
- user: t,
100
- mfaEnrollmentRequired: i.mfaEnrollmentRequired,
101
- offline: !0
102
- } : { status: "anonymous", offline: !0 }
103
- ), p = setTimeout(() => {
104
- p = null, h.refresh();
105
- }, j());
106
- }, I = async () => {
107
- const t = s ? null : await e.storage.getRefreshToken();
108
- if (!s && !t)
109
- return { kind: "revoked" };
110
- if (!r())
111
- return { kind: "offline" };
112
- const o = Date.now(), u = new AbortController(), f = setTimeout(
113
- () => u.abort(),
114
- fe
115
- );
116
- try {
117
- const w = await F.sdk.auth.refresh(
118
- t ? { refreshToken: t } : void 0,
119
- { signal: u.signal }
120
- );
121
- return w.error ? { kind: "unreachable", sentAt: o } : { kind: "session", session: w.data };
122
- } catch (w) {
123
- if (u.signal.aborted)
124
- return { kind: "unreachable", sentAt: o };
125
- const L = H(w);
126
- if (L.kind === "other")
127
- throw w;
128
- return L.kind === "http" && L.status === 401 ? { kind: "revoked" } : { kind: "unreachable", sentAt: o };
129
- } finally {
130
- clearTimeout(f);
131
- }
132
- }, O = async () => {
133
- const t = A;
134
- l !== null && Date.now() - l >= x && (l = null);
135
- let o = await I();
136
- const u = l === null ? ce : [];
137
- for (const f of u) {
138
- if (o.kind !== "unreachable" || t !== A || (l = l ?? o.sentAt, await ye(f), t !== A))
139
- break;
140
- o = await I();
141
- }
142
- if (o.kind === "unreachable" ? l = l ?? o.sentAt : o.kind !== "offline" && (l = null), t !== A) {
143
- e.applyToken(a);
144
- return;
145
- }
146
- switch (o.kind) {
147
- case "session":
148
- await P(o.session);
149
- return;
150
- case "revoked":
151
- await N();
152
- return;
153
- case "offline":
154
- case "unreachable":
155
- z();
156
- return;
157
- }
158
- }, b = () => {
159
- i.offline && (p && (clearTimeout(p), p = null), h.refresh());
160
- }, M = () => {
161
- document.visibilityState === "visible" && b();
162
- };
163
- typeof window < "u" && window.addEventListener("online", b), typeof document < "u" && document.addEventListener("visibilitychange", M);
164
- const h = {
165
- bridge: e.bridge,
166
- state: () => i,
167
- subscribe: (t) => (R.add(t), () => {
168
- R.delete(t);
169
- }),
170
- accessToken: () => a,
171
- subscribeToken: (t) => (T.add(t), t(a), () => {
172
- T.delete(t);
173
- }),
174
- bootstrap: () => (_ || (_ = (async () => {
175
- var t;
176
- n = await ((t = e.restoreUser) == null ? void 0 : t.call(e)) ?? null, await h.refresh();
177
- })()), _),
178
- handleResult: async (t) => (t.status === X.AUTHENTICATED && await P(t.session), t),
179
- refresh: () => {
180
- if (!y) {
181
- const t = s ? Te() : null;
182
- y = (t ? t.request(pe, O) : O()).finally(() => {
183
- y = null;
184
- });
185
- }
186
- return y;
187
- },
188
- withAuthRetry: async (t) => {
189
- const o = a;
190
- try {
191
- return await t();
192
- } catch (u) {
193
- const f = H(u);
194
- if (f.kind !== "http")
195
- throw u;
196
- if (f.status === 401 && f.message === we) {
197
- if (a === o && await h.refresh(), i.status !== "authenticated" || a === null || a === o)
198
- throw u;
199
- return t();
200
- }
201
- if (f.status === 403 && f.code === J.reauthRequired && E) {
202
- if (!await E(Ae(f.params)))
203
- throw u;
204
- return t();
205
- }
206
- throw u;
207
- }
208
- },
209
- onReauthRequired: (t) => (E = t, () => {
210
- E === t && (E = null);
211
- }),
212
- logout: async () => {
213
- try {
214
- i.status === "authenticated" && a === null && await h.refresh(), a !== null && await h.withAuthRetry(() => F.sdk.auth.logout());
215
- } finally {
216
- await N();
217
- }
218
- },
219
- dispose: () => {
220
- k(), R.clear(), T.clear(), typeof window < "u" && window.removeEventListener("online", b), typeof document < "u" && document.removeEventListener("visibilitychange", M);
221
- }
222
- };
223
- return h;
224
- }, ke = "https://accounts.google.com/gsi/client", _e = "https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1.0/en_US/appleid.auth.js", v = /* @__PURE__ */ new Map(), W = (e) => {
225
- const s = v.get(e);
226
- if (s)
227
- return s;
228
- const r = new Promise((i, a) => {
229
- const n = document.createElement("script");
230
- n.src = e, n.async = !0, n.onload = () => i(), n.onerror = () => {
231
- v.delete(e), n.remove(), a(
232
- new c(
233
- d.FAILED,
234
- `Could not load ${e}`
235
- )
236
- );
237
- }, document.head.appendChild(n);
238
- });
239
- return v.set(e, r), r;
240
- }, Se = [
241
- "popup_closed_by_user",
242
- "user_cancelled_authorize"
243
- ], Y = (e) => {
244
- const { name: s, message: r } = e ?? {}, i = typeof r == "string" ? r : "Passkey ceremony failed";
245
- return s === "NotAllowedError" || s === "AbortError" || e instanceof Z && e.code === "ERROR_CEREMONY_ABORTED" ? new c(d.CANCELLED, i, e) : new c(d.FAILED, i, e);
246
- }, C = (e) => new c(
247
- d.UNSUPPORTED,
248
- `${e} is not supported by this browser`
249
- ), Pe = (e) => ({
250
- platform: B.WEB,
251
- passkeySupported: async () => g(),
252
- getPasskey: async (s, r = !1) => {
253
- if (!g())
254
- throw C("WebAuthn");
255
- if (r && !await V())
256
- throw C("Passkey autofill");
257
- try {
258
- return await Q({
259
- // abyss-main's options are the WebAuthn JSON this call reads (base64url binary fields).
260
- optionsJSON: s,
261
- useBrowserAutofill: r
262
- });
263
- } catch (i) {
264
- throw Y(i);
265
- }
266
- },
267
- createPasskey: async (s) => {
268
- if (!g())
269
- throw C("WebAuthn");
270
- try {
271
- return await $({
272
- optionsJSON: s
273
- });
274
- } catch (r) {
275
- throw Y(r);
276
- }
277
- },
278
- google: async (s) => {
279
- await W(ke);
280
- const r = window.google;
281
- if (!r)
282
- throw new c(
283
- d.FAILED,
284
- "Google Identity Services missing"
285
- );
286
- return new Promise((i, a) => {
287
- r.accounts.id.initialize({
288
- client_id: e.googleClientId,
289
- // Google copies the raw nonce into the id_token; abyss-main compares it as is.
290
- nonce: s,
291
- callback: (n) => {
292
- if (n.credential) {
293
- i({ idToken: n.credential });
294
- return;
295
- }
296
- a(
297
- new c(
298
- d.FAILED,
299
- "Google returned no credential"
300
- )
301
- );
302
- },
303
- auto_select: !1,
304
- cancel_on_tap_outside: !0,
305
- use_fedcm_for_prompt: !0,
306
- itp_support: !0
307
- }), r.accounts.id.prompt((n) => {
308
- if (n.isSkippedMoment()) {
309
- a(
310
- new c(
311
- d.CANCELLED,
312
- "Google prompt skipped"
313
- )
314
- );
315
- return;
316
- }
317
- n.isDismissedMoment() && n.getDismissedReason() !== "credential_returned" && a(
318
- new c(
319
- d.CANCELLED,
320
- "Google prompt dismissed"
321
- )
322
- );
323
- });
324
- });
325
- },
326
- apple: async (s) => {
327
- var i;
328
- await W(_e);
329
- const r = window.AppleID;
330
- if (!r)
331
- throw new c(
332
- d.FAILED,
333
- "Sign in with Apple JS missing"
334
- );
335
- r.auth.init({
336
- clientId: e.appleServiceId,
337
- scope: "name email",
338
- redirectURI: e.appleRedirectUri,
339
- usePopup: !0,
340
- // Apple carries what it is given; abyss-main compares it with SHA-256(raw nonce) in hex.
341
- nonce: await ee(s)
342
- });
343
- try {
344
- const a = await r.auth.signIn(), n = (i = a.user) == null ? void 0 : i.name;
345
- return {
346
- idToken: a.authorization.id_token,
347
- ...n != null && n.firstName ? { givenName: n.firstName } : {},
348
- ...n != null && n.lastName ? { familyName: n.lastName } : {}
349
- };
350
- } catch (a) {
351
- const n = a == null ? void 0 : a.error;
352
- throw typeof n == "string" && Se.includes(n) ? new c(d.CANCELLED, n, a) : new c(
353
- d.FAILED,
354
- typeof n == "string" ? n : "Sign in with Apple failed",
355
- a
356
- );
357
- }
358
- }
359
- }), q = te(null), Ne = ({ client: e, children: s }) => {
360
- const [r, i] = ne(() => e.state());
361
- se(() => {
362
- i(e.state());
363
- const n = e.subscribe(i);
364
- return e.bootstrap(), n;
365
- }, [e]);
366
- const a = re(() => ({ state: r, client: e }), [r, e]);
367
- return /* @__PURE__ */ ae(q.Provider, { value: a, children: s });
368
- }, Ie = () => {
369
- const e = oe(q);
370
- if (!e)
371
- throw new Error("useAuth() must be called inside <AuthProvider>");
372
- return e;
373
- };
374
- export {
375
- ie as A,
376
- ke as G,
377
- ce as L,
378
- ue as R,
379
- G as U,
380
- le as a,
381
- x as b,
382
- de as c,
383
- fe as d,
384
- pe as e,
385
- De as f,
386
- _e as g,
387
- Pe as h,
388
- q as i,
389
- Ne as j,
390
- Ie as u
391
- };