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