@versini/auth-provider 5.1.2 → 5.1.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.
Files changed (2) hide show
  1. package/dist/index.js +172 -167
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -4,13 +4,13 @@ var L = (e, t, r) => Be(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { jsx as Fe } from "react/jsx-runtime";
5
5
  import { useSyncExternalStore as Ge, useCallback as H, useEffect as ve, createContext as qe, useRef as ze, useState as Xe, useContext as Qe } from "react";
6
6
  /*!
7
- @versini/auth-provider v5.1.2
7
+ @versini/auth-provider v5.1.3
8
8
  © 2024 gizmette.com
9
9
  */
10
10
  try {
11
11
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
12
- version: "5.1.2",
13
- buildTime: "07/09/2024 11:15 AM EDT",
12
+ version: "5.1.3",
13
+ buildTime: "07/09/2024 03:32 PM EDT",
14
14
  homepage: "https://github.com/aversini/auth-client",
15
15
  license: "MIT"
16
16
  });
@@ -23,7 +23,7 @@ try {
23
23
  try {
24
24
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
25
25
  version: "2.11.0",
26
- buildTime: "07/09/2024 11:15 AM EDT",
26
+ buildTime: "07/09/2024 03:32 PM EDT",
27
27
  homepage: "https://github.com/aversini/auth-client",
28
28
  license: "MIT"
29
29
  });
@@ -58,7 +58,7 @@ awIDAQAB
58
58
  LOGOUT: "logout"
59
59
  }, X = crypto, be = (e) => e instanceof CryptoKey, $ = new TextEncoder(), Q = new TextDecoder();
60
60
  function tt(...e) {
61
- const t = e.reduce((n, { length: s }) => n + s, 0), r = new Uint8Array(t);
61
+ const t = e.reduce((n, { length: o }) => n + o, 0), r = new Uint8Array(t);
62
62
  let a = 0;
63
63
  for (const n of e)
64
64
  r.set(n, a), a += n.length;
@@ -78,7 +78,7 @@ const rt = (e) => {
78
78
  throw new TypeError("The input to be decoded is not correctly encoded.");
79
79
  }
80
80
  };
81
- class C extends Error {
81
+ class P extends Error {
82
82
  static get code() {
83
83
  return "ERR_JOSE_GENERIC";
84
84
  }
@@ -87,7 +87,7 @@ class C extends Error {
87
87
  super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) == null || r.call(Error, this, this.constructor);
88
88
  }
89
89
  }
90
- class A extends C {
90
+ class T extends P {
91
91
  static get code() {
92
92
  return "ERR_JWT_CLAIM_VALIDATION_FAILED";
93
93
  }
@@ -95,7 +95,7 @@ class A extends C {
95
95
  super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = a, this.reason = n, this.payload = r;
96
96
  }
97
97
  }
98
- class le extends C {
98
+ class le extends P {
99
99
  static get code() {
100
100
  return "ERR_JWT_EXPIRED";
101
101
  }
@@ -103,7 +103,7 @@ class le extends C {
103
103
  super(t), this.code = "ERR_JWT_EXPIRED", this.claim = a, this.reason = n, this.payload = r;
104
104
  }
105
105
  }
106
- class at extends C {
106
+ class at extends P {
107
107
  constructor() {
108
108
  super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
109
109
  }
@@ -111,7 +111,7 @@ class at extends C {
111
111
  return "ERR_JOSE_ALG_NOT_ALLOWED";
112
112
  }
113
113
  }
114
- class b extends C {
114
+ class b extends P {
115
115
  constructor() {
116
116
  super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
117
117
  }
@@ -119,7 +119,7 @@ class b extends C {
119
119
  return "ERR_JOSE_NOT_SUPPORTED";
120
120
  }
121
121
  }
122
- class f extends C {
122
+ class f extends P {
123
123
  constructor() {
124
124
  super(...arguments), this.code = "ERR_JWS_INVALID";
125
125
  }
@@ -127,7 +127,7 @@ class f extends C {
127
127
  return "ERR_JWS_INVALID";
128
128
  }
129
129
  }
130
- let Re = class extends C {
130
+ let Re = class extends P {
131
131
  constructor() {
132
132
  super(...arguments), this.code = "ERR_JWT_INVALID";
133
133
  }
@@ -135,7 +135,7 @@ let Re = class extends C {
135
135
  return "ERR_JWT_INVALID";
136
136
  }
137
137
  };
138
- class nt extends C {
138
+ class nt extends P {
139
139
  constructor() {
140
140
  super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
141
141
  }
@@ -143,7 +143,7 @@ class nt extends C {
143
143
  return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
144
144
  }
145
145
  }
146
- function k(e, t = "algorithm.name") {
146
+ function _(e, t = "algorithm.name") {
147
147
  return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
148
148
  }
149
149
  function W(e, t) {
@@ -180,45 +180,45 @@ function it(e, t, ...r) {
180
180
  case "HS384":
181
181
  case "HS512": {
182
182
  if (!W(e.algorithm, "HMAC"))
183
- throw k("HMAC");
183
+ throw _("HMAC");
184
184
  const a = parseInt(t.slice(2), 10);
185
185
  if (te(e.algorithm.hash) !== a)
186
- throw k(`SHA-${a}`, "algorithm.hash");
186
+ throw _(`SHA-${a}`, "algorithm.hash");
187
187
  break;
188
188
  }
189
189
  case "RS256":
190
190
  case "RS384":
191
191
  case "RS512": {
192
192
  if (!W(e.algorithm, "RSASSA-PKCS1-v1_5"))
193
- throw k("RSASSA-PKCS1-v1_5");
193
+ throw _("RSASSA-PKCS1-v1_5");
194
194
  const a = parseInt(t.slice(2), 10);
195
195
  if (te(e.algorithm.hash) !== a)
196
- throw k(`SHA-${a}`, "algorithm.hash");
196
+ throw _(`SHA-${a}`, "algorithm.hash");
197
197
  break;
198
198
  }
199
199
  case "PS256":
200
200
  case "PS384":
201
201
  case "PS512": {
202
202
  if (!W(e.algorithm, "RSA-PSS"))
203
- throw k("RSA-PSS");
203
+ throw _("RSA-PSS");
204
204
  const a = parseInt(t.slice(2), 10);
205
205
  if (te(e.algorithm.hash) !== a)
206
- throw k(`SHA-${a}`, "algorithm.hash");
206
+ throw _(`SHA-${a}`, "algorithm.hash");
207
207
  break;
208
208
  }
209
209
  case "EdDSA": {
210
210
  if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
211
- throw k("Ed25519 or Ed448");
211
+ throw _("Ed25519 or Ed448");
212
212
  break;
213
213
  }
214
214
  case "ES256":
215
215
  case "ES384":
216
216
  case "ES512": {
217
217
  if (!W(e.algorithm, "ECDSA"))
218
- throw k("ECDSA");
218
+ throw _("ECDSA");
219
219
  const a = st(t);
220
220
  if (e.algorithm.namedCurve !== a)
221
- throw k(a, "algorithm.namedCurve");
221
+ throw _(a, "algorithm.namedCurve");
222
222
  break;
223
223
  }
224
224
  default:
@@ -249,10 +249,10 @@ const Pe = (e) => be(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) ===
249
249
  r = new Set(n);
250
250
  continue;
251
251
  }
252
- for (const s of n) {
253
- if (r.has(s))
252
+ for (const o of n) {
253
+ if (r.has(o))
254
254
  return !1;
255
- r.add(s);
255
+ r.add(o);
256
256
  }
257
257
  }
258
258
  return !0;
@@ -364,8 +364,8 @@ const De = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
364
364
  let n = e.get(t);
365
365
  if (n != null && n[a])
366
366
  return n[a];
367
- const s = await ht({ ...r, alg: a });
368
- return n ? n[a] = s : e.set(t, { [a]: s }), s;
367
+ const o = await ht({ ...r, alg: a });
368
+ return n ? n[a] = o : e.set(t, { [a]: o }), o;
369
369
  }, ft = (e, t) => {
370
370
  if (De(e)) {
371
371
  let r = e.export({ format: "jwk" });
@@ -384,7 +384,7 @@ const De = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
384
384
  if (a === -1)
385
385
  return !1;
386
386
  const n = e.subarray(a, a + t.length);
387
- return n.length !== t.length ? !1 : n.every((s, o) => s === t[o]) || v(e, t, a + 1);
387
+ return n.length !== t.length ? !1 : n.every((o, s) => o === t[s]) || v(e, t, a + 1);
388
388
  }, fe = (e) => {
389
389
  switch (!0) {
390
390
  case v(e, [42, 134, 72, 206, 61, 3, 1, 7]):
@@ -405,52 +405,52 @@ const De = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
405
405
  throw new b("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
406
406
  }
407
407
  }, wt = async (e, t, r, a, n) => {
408
- let s, o;
408
+ let o, s;
409
409
  const i = new Uint8Array(atob(r.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
410
410
  switch (a) {
411
411
  case "PS256":
412
412
  case "PS384":
413
413
  case "PS512":
414
- s = { name: "RSA-PSS", hash: `SHA-${a.slice(-3)}` }, o = ["verify"];
414
+ o = { name: "RSA-PSS", hash: `SHA-${a.slice(-3)}` }, s = ["verify"];
415
415
  break;
416
416
  case "RS256":
417
417
  case "RS384":
418
418
  case "RS512":
419
- s = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${a.slice(-3)}` }, o = ["verify"];
419
+ o = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${a.slice(-3)}` }, s = ["verify"];
420
420
  break;
421
421
  case "RSA-OAEP":
422
422
  case "RSA-OAEP-256":
423
423
  case "RSA-OAEP-384":
424
424
  case "RSA-OAEP-512":
425
- s = {
425
+ o = {
426
426
  name: "RSA-OAEP",
427
427
  hash: `SHA-${parseInt(a.slice(-3), 10) || 1}`
428
- }, o = ["encrypt", "wrapKey"];
428
+ }, s = ["encrypt", "wrapKey"];
429
429
  break;
430
430
  case "ES256":
431
- s = { name: "ECDSA", namedCurve: "P-256" }, o = ["verify"];
431
+ o = { name: "ECDSA", namedCurve: "P-256" }, s = ["verify"];
432
432
  break;
433
433
  case "ES384":
434
- s = { name: "ECDSA", namedCurve: "P-384" }, o = ["verify"];
434
+ o = { name: "ECDSA", namedCurve: "P-384" }, s = ["verify"];
435
435
  break;
436
436
  case "ES512":
437
- s = { name: "ECDSA", namedCurve: "P-521" }, o = ["verify"];
437
+ o = { name: "ECDSA", namedCurve: "P-521" }, s = ["verify"];
438
438
  break;
439
439
  case "ECDH-ES":
440
440
  case "ECDH-ES+A128KW":
441
441
  case "ECDH-ES+A192KW":
442
442
  case "ECDH-ES+A256KW": {
443
443
  const c = fe(i);
444
- s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, o = [];
444
+ o = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, s = [];
445
445
  break;
446
446
  }
447
447
  case "EdDSA":
448
- s = { name: fe(i) }, o = ["verify"];
448
+ o = { name: fe(i) }, s = ["verify"];
449
449
  break;
450
450
  default:
451
451
  throw new b('Invalid or unsupported "alg" (Algorithm) value');
452
452
  }
453
- return X.subtle.importKey(t, i, s, !1, o);
453
+ return X.subtle.importKey(t, i, o, !1, s);
454
454
  }, mt = (e, t, r) => wt(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
455
455
  async function Et(e, t, r) {
456
456
  if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
@@ -481,17 +481,17 @@ function Tt(e, t, r, a, n) {
481
481
  throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
482
482
  if (!a || a.crit === void 0)
483
483
  return /* @__PURE__ */ new Set();
484
- if (!Array.isArray(a.crit) || a.crit.length === 0 || a.crit.some((o) => typeof o != "string" || o.length === 0))
484
+ if (!Array.isArray(a.crit) || a.crit.length === 0 || a.crit.some((s) => typeof s != "string" || s.length === 0))
485
485
  throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
486
- let s;
487
- r !== void 0 ? s = new Map([...Object.entries(r), ...t.entries()]) : s = t;
488
- for (const o of a.crit) {
489
- if (!s.has(o))
490
- throw new b(`Extension Header Parameter "${o}" is not recognized`);
491
- if (n[o] === void 0)
492
- throw new e(`Extension Header Parameter "${o}" is missing`);
493
- if (s.get(o) && a[o] === void 0)
494
- throw new e(`Extension Header Parameter "${o}" MUST be integrity protected`);
486
+ let o;
487
+ r !== void 0 ? o = new Map([...Object.entries(r), ...t.entries()]) : o = t;
488
+ for (const s of a.crit) {
489
+ if (!o.has(s))
490
+ throw new b(`Extension Header Parameter "${s}" is not recognized`);
491
+ if (n[s] === void 0)
492
+ throw new e(`Extension Header Parameter "${s}" is missing`);
493
+ if (o.get(s) && a[s] === void 0)
494
+ throw new e(`Extension Header Parameter "${s}" MUST be integrity protected`);
495
495
  }
496
496
  return new Set(a.crit);
497
497
  }
@@ -539,9 +539,9 @@ async function vt(e, t, r) {
539
539
  const bt = async (e, t, r, a) => {
540
540
  const n = await vt(e, t, "verify");
541
541
  dt(e, n);
542
- const s = _t(e, n.algorithm);
542
+ const o = _t(e, n.algorithm);
543
543
  try {
544
- return await X.subtle.verify(s, n, r, a);
544
+ return await X.subtle.verify(o, n, r, a);
545
545
  } catch {
546
546
  return !1;
547
547
  }
@@ -562,8 +562,8 @@ async function Rt(e, t, r) {
562
562
  let a = {};
563
563
  if (e.protected)
564
564
  try {
565
- const S = B(e.protected);
566
- a = JSON.parse(Q.decode(S));
565
+ const g = B(e.protected);
566
+ a = JSON.parse(Q.decode(g));
567
567
  } catch {
568
568
  throw new f("JWS Protected Header is invalid");
569
569
  }
@@ -572,9 +572,9 @@ async function Rt(e, t, r) {
572
572
  const n = {
573
573
  ...a,
574
574
  ...e.header
575
- }, s = Tt(f, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, a, n);
576
- let o = !0;
577
- if (s.has("b64") && (o = a.b64, typeof o != "boolean"))
575
+ }, o = Tt(f, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, a, n);
576
+ let s = !0;
577
+ if (o.has("b64") && (s = a.b64, typeof s != "boolean"))
578
578
  throw new f('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
579
579
  const { alg: i } = n;
580
580
  if (typeof i != "string" || !i)
@@ -582,7 +582,7 @@ async function Rt(e, t, r) {
582
582
  const c = r && kt("algorithms", r.algorithms);
583
583
  if (c && !c.has(i))
584
584
  throw new at('"alg" (Algorithm) Header Parameter value not allowed');
585
- if (o) {
585
+ if (s) {
586
586
  if (typeof e.payload != "string")
587
587
  throw new f("JWS Payload must be a string");
588
588
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
@@ -598,24 +598,24 @@ async function Rt(e, t, r) {
598
598
  }
599
599
  if (!await bt(i, t, y, p))
600
600
  throw new nt();
601
- let E;
602
- if (o)
601
+ let S;
602
+ if (s)
603
603
  try {
604
- E = B(e.payload);
604
+ S = B(e.payload);
605
605
  } catch {
606
606
  throw new f("Failed to base64url decode the payload");
607
607
  }
608
- else typeof e.payload == "string" ? E = $.encode(e.payload) : E = e.payload;
609
- const m = { payload: E };
608
+ else typeof e.payload == "string" ? S = $.encode(e.payload) : S = e.payload;
609
+ const m = { payload: S };
610
610
  return e.protected !== void 0 && (m.protectedHeader = a), e.header !== void 0 && (m.unprotectedHeader = e.header), d ? { ...m, key: t } : m;
611
611
  }
612
612
  async function It(e, t, r) {
613
613
  if (e instanceof Uint8Array && (e = Q.decode(e)), typeof e != "string")
614
614
  throw new f("Compact JWS must be a string or Uint8Array");
615
- const { 0: a, 1: n, 2: s, length: o } = e.split(".");
616
- if (o !== 3)
615
+ const { 0: a, 1: n, 2: o, length: s } = e.split(".");
616
+ if (s !== 3)
617
617
  throw new f("Invalid Compact JWS");
618
- const i = await Rt({ payload: n, protected: a, signature: s }, t, r), c = { payload: i.payload, protectedHeader: i.protectedHeader };
618
+ const i = await Rt({ payload: n, protected: a, signature: o }, t, r), c = { payload: i.payload, protectedHeader: i.protectedHeader };
619
619
  return typeof t == "function" ? { ...c, key: i.key } : c;
620
620
  }
621
621
  const Ct = (e) => Math.floor(e.getTime() / 1e3), He = 60, Ke = He * 60, ce = Ke * 24, Pt = ce * 7, Ot = ce * 365.25, Dt = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, pe = (e) => {
@@ -671,18 +671,18 @@ const Ct = (e) => Math.floor(e.getTime() / 1e3), He = 60, Ke = He * 60, ce = Ke
671
671
  throw new Re("JWT Claims Set must be a top-level JSON object");
672
672
  const { typ: n } = r;
673
673
  if (n && (typeof e.typ != "string" || ye(e.typ) !== ye(n)))
674
- throw new A('unexpected "typ" JWT header value', a, "typ", "check_failed");
675
- const { requiredClaims: s = [], issuer: o, subject: i, audience: c, maxTokenAge: d } = r, p = [...s];
676
- d !== void 0 && p.push("iat"), c !== void 0 && p.push("aud"), i !== void 0 && p.push("sub"), o !== void 0 && p.push("iss");
677
- for (const S of new Set(p.reverse()))
678
- if (!(S in a))
679
- throw new A(`missing required "${S}" claim`, a, S, "missing");
680
- if (o && !(Array.isArray(o) ? o : [o]).includes(a.iss))
681
- throw new A('unexpected "iss" claim value', a, "iss", "check_failed");
674
+ throw new T('unexpected "typ" JWT header value', a, "typ", "check_failed");
675
+ const { requiredClaims: o = [], issuer: s, subject: i, audience: c, maxTokenAge: d } = r, p = [...o];
676
+ d !== void 0 && p.push("iat"), c !== void 0 && p.push("aud"), i !== void 0 && p.push("sub"), s !== void 0 && p.push("iss");
677
+ for (const g of new Set(p.reverse()))
678
+ if (!(g in a))
679
+ throw new T(`missing required "${g}" claim`, a, g, "missing");
680
+ if (s && !(Array.isArray(s) ? s : [s]).includes(a.iss))
681
+ throw new T('unexpected "iss" claim value', a, "iss", "check_failed");
682
682
  if (i && a.sub !== i)
683
- throw new A('unexpected "sub" claim value', a, "sub", "check_failed");
683
+ throw new T('unexpected "sub" claim value', a, "sub", "check_failed");
684
684
  if (c && !Ut(a.aud, typeof c == "string" ? [c] : c))
685
- throw new A('unexpected "aud" claim value', a, "aud", "check_failed");
685
+ throw new T('unexpected "aud" claim value', a, "aud", "check_failed");
686
686
  let y;
687
687
  switch (typeof r.clockTolerance) {
688
688
  case "string":
@@ -697,27 +697,27 @@ const Ct = (e) => Math.floor(e.getTime() / 1e3), He = 60, Ke = He * 60, ce = Ke
697
697
  default:
698
698
  throw new TypeError("Invalid clockTolerance option type");
699
699
  }
700
- const { currentDate: E } = r, m = Ct(E || /* @__PURE__ */ new Date());
700
+ const { currentDate: S } = r, m = Ct(S || /* @__PURE__ */ new Date());
701
701
  if ((a.iat !== void 0 || d) && typeof a.iat != "number")
702
- throw new A('"iat" claim must be a number', a, "iat", "invalid");
702
+ throw new T('"iat" claim must be a number', a, "iat", "invalid");
703
703
  if (a.nbf !== void 0) {
704
704
  if (typeof a.nbf != "number")
705
- throw new A('"nbf" claim must be a number', a, "nbf", "invalid");
705
+ throw new T('"nbf" claim must be a number', a, "nbf", "invalid");
706
706
  if (a.nbf > m + y)
707
- throw new A('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
707
+ throw new T('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
708
708
  }
709
709
  if (a.exp !== void 0) {
710
710
  if (typeof a.exp != "number")
711
- throw new A('"exp" claim must be a number', a, "exp", "invalid");
711
+ throw new T('"exp" claim must be a number', a, "exp", "invalid");
712
712
  if (a.exp <= m - y)
713
713
  throw new le('"exp" claim timestamp check failed', a, "exp", "check_failed");
714
714
  }
715
715
  if (d) {
716
- const S = m - a.iat, ee = typeof d == "number" ? d : pe(d);
717
- if (S - y > ee)
716
+ const g = m - a.iat, ee = typeof d == "number" ? d : pe(d);
717
+ if (g - y > ee)
718
718
  throw new le('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
719
- if (S < 0 - y)
720
- throw new A('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
719
+ if (g < 0 - y)
720
+ throw new T('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
721
721
  }
722
722
  return a;
723
723
  };
@@ -726,8 +726,8 @@ async function Kt(e, t, r) {
726
726
  const n = await It(e, t, r);
727
727
  if ((a = n.protectedHeader.crit) != null && a.includes("b64") && n.protectedHeader.b64 === !1)
728
728
  throw new Re("JWTs MUST NOT use unencoded payload");
729
- const s = { payload: Ht(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
730
- return typeof t == "function" ? { ...s, key: n.key } : s;
729
+ const o = { payload: Ht(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
730
+ return typeof t == "function" ? { ...o, key: n.key } : o;
731
731
  }
732
732
  const K = async (e) => {
733
733
  try {
@@ -796,9 +796,9 @@ function x({
796
796
  initialValue: t
797
797
  }) {
798
798
  const r = Ge(Yt, () => ge(e)), a = H(
799
- (o) => {
799
+ (s) => {
800
800
  try {
801
- const i = typeof o == "function" ? o(JSON.parse(r)) : o;
801
+ const i = typeof s == "function" ? s(JSON.parse(r)) : s;
802
802
  i == null ? Vt(e) : Se(e, i);
803
803
  } catch (i) {
804
804
  console.warn(i);
@@ -807,16 +807,16 @@ function x({
807
807
  [e, r]
808
808
  ), n = H(() => {
809
809
  a(t);
810
- }, [t, a]), s = H(() => {
810
+ }, [t, a]), o = H(() => {
811
811
  a(null);
812
812
  }, [a]);
813
813
  return ve(() => {
814
814
  try {
815
815
  ge(e) === null && typeof t < "u" && Se(e, t);
816
- } catch (o) {
817
- console.warn(o);
816
+ } catch (s) {
817
+ console.warn(s);
818
818
  }
819
- }, [e, t]), [r ? JSON.parse(r) : null, a, n, s];
819
+ }, [e, t]), [r ? JSON.parse(r) : null, a, n, o];
820
820
  }
821
821
  var h = [];
822
822
  for (var se = 0; se < 256; ++se)
@@ -864,32 +864,34 @@ const M = "Oops! It looks like your session has expired. For your security, plea
864
864
  );
865
865
  if (a.status !== 200)
866
866
  return { status: a.status, data: [] };
867
- const { data: n, errors: s } = await a.json();
867
+ const { data: n, errors: o } = await a.json();
868
868
  return {
869
869
  status: a.status,
870
870
  data: n,
871
- errors: s
871
+ errors: o
872
872
  };
873
873
  } catch (a) {
874
874
  return console.error(a), { status: 500, data: [] };
875
875
  }
876
876
  }, tr = async ({
877
- idToken: e,
878
- accessToken: t,
879
- refreshToken: r,
880
- clientId: a,
881
- domain: n
877
+ userId: e,
878
+ idToken: t,
879
+ accessToken: r,
880
+ refreshToken: a,
881
+ clientId: n,
882
+ domain: o
882
883
  }) => {
883
884
  try {
884
885
  return {
885
886
  status: (await Z({
886
887
  type: z.LOGOUT,
887
- clientId: a,
888
+ clientId: n,
888
889
  params: {
889
- idToken: e,
890
- accessToken: t,
891
- refreshToken: r,
892
- domain: n
890
+ userId: e,
891
+ idToken: t,
892
+ accessToken: r,
893
+ refreshToken: a,
894
+ domain: o
893
895
  }
894
896
  })).status === 200
895
897
  };
@@ -904,8 +906,8 @@ const M = "Oops! It looks like your session has expired. For your security, plea
904
906
  clientId: r,
905
907
  nonce: a,
906
908
  type: n,
907
- sessionExpiration: s,
908
- code: o,
909
+ sessionExpiration: o,
910
+ code: s,
909
911
  code_verifier: i,
910
912
  domain: c
911
913
  }) => {
@@ -917,9 +919,9 @@ const M = "Oops! It looks like your session has expired. For your security, plea
917
919
  type: n || q.ID_AND_ACCESS_TOKEN,
918
920
  username: e,
919
921
  password: t,
920
- sessionExpiration: s,
922
+ sessionExpiration: o,
921
923
  nonce: a,
922
- code: o,
924
+ code: s,
923
925
  code_verifier: i,
924
926
  domain: c
925
927
  }
@@ -970,10 +972,10 @@ const M = "Oops! It looks like your session has expired. For your security, plea
970
972
  nonce: r,
971
973
  refreshToken: a,
972
974
  accessToken: n,
973
- domain: s
975
+ domain: o
974
976
  }) => {
975
977
  try {
976
- const o = await Z({
978
+ const s = await Z({
977
979
  type: z.AUTHENTICATE,
978
980
  clientId: e,
979
981
  params: {
@@ -982,12 +984,12 @@ const M = "Oops! It looks like your session has expired. For your security, plea
982
984
  nonce: r,
983
985
  refreshToken: a,
984
986
  accessToken: n,
985
- domain: s
987
+ domain: o
986
988
  }
987
- }), i = await K(o.data.accessToken);
989
+ }), i = await K(s.data.accessToken);
988
990
  return i && i.payload[w.USER_ID_KEY] !== "" && i.payload[w.NONCE_KEY] === r ? {
989
- accessToken: o.data.accessToken,
990
- refreshToken: o.data.refreshToken,
991
+ accessToken: s.data.accessToken,
992
+ refreshToken: s.data.refreshToken,
991
993
  userId: i.payload[w.USER_ID_KEY],
992
994
  status: !0
993
995
  } : {
@@ -1030,9 +1032,9 @@ class nr {
1030
1032
  nonce: a,
1031
1033
  domain: n
1032
1034
  }) {
1033
- const s = await K(this.refreshToken);
1034
- if (s && s.payload[w.USER_ID_KEY] !== "") {
1035
- const o = await ar({
1035
+ const o = await K(this.refreshToken);
1036
+ if (o && o.payload[w.USER_ID_KEY] !== "") {
1037
+ const s = await ar({
1036
1038
  clientId: t,
1037
1039
  userId: r,
1038
1040
  nonce: a,
@@ -1040,10 +1042,10 @@ class nr {
1040
1042
  accessToken: this.accessToken,
1041
1043
  domain: n
1042
1044
  });
1043
- return o.status ? (this.accessToken = o.accessToken, this.refreshToken = o.refreshToken, {
1045
+ return s.status ? (this.accessToken = s.accessToken, this.refreshToken = s.refreshToken, {
1044
1046
  status: "success",
1045
- newAccessToken: o.accessToken,
1046
- newRefreshToken: o.refreshToken
1047
+ newAccessToken: s.accessToken,
1048
+ newRefreshToken: s.refreshToken
1047
1049
  }) : {
1048
1050
  status: "failure"
1049
1051
  };
@@ -1069,24 +1071,24 @@ const Y = () => {
1069
1071
  clientId: r,
1070
1072
  domain: a = ""
1071
1073
  }) => {
1072
- const n = ze(!1), [s, o, , i] = x({
1074
+ const n = ze(!1), [o, s, , i] = x({
1073
1075
  key: `${V}::${r}::@@user@@`
1074
1076
  }), [c, d, , p] = x({
1075
1077
  key: `${V}::${r}::@@access@@`
1076
- }), [y, E, , m] = x(
1078
+ }), [y, S, , m] = x(
1077
1079
  {
1078
1080
  key: `${V}::${r}::@@refresh@@`
1079
1081
  }
1080
- ), [S, ee, , ue] = x({
1082
+ ), [g, ee, , ue] = x({
1081
1083
  key: `${V}::${r}::@@nonce@@`
1082
- }), $e = new nr(c, y), [P, T] = Xe({
1084
+ }), $e = new nr(c, y), [R, k] = Xe({
1083
1085
  isLoading: !0,
1084
1086
  isAuthenticated: !1,
1085
1087
  user: void 0,
1086
1088
  logoutReason: ""
1087
1089
  }), N = H(
1088
1090
  (u) => {
1089
- console.warn(u), T({
1091
+ console.warn(u), k({
1090
1092
  isLoading: !0,
1091
1093
  isAuthenticated: !1,
1092
1094
  user: void 0,
@@ -1094,34 +1096,37 @@ const Y = () => {
1094
1096
  }), i(), p(), m(), ue();
1095
1097
  },
1096
1098
  [p, i, ue, m]
1097
- ), R = H(
1099
+ ), I = H(
1098
1100
  async (u) => {
1101
+ const { user: A } = R;
1099
1102
  N(u || M), await tr({
1100
- idToken: s,
1103
+ userId: (A == null ? void 0 : A.userId) || "",
1104
+ idToken: o,
1101
1105
  accessToken: c,
1102
1106
  refreshToken: y,
1103
1107
  clientId: r,
1104
1108
  domain: a
1105
- }), T((_) => ({
1106
- ..._,
1109
+ }), k((E) => ({
1110
+ ...E,
1107
1111
  isLoading: !1
1108
1112
  }));
1109
1113
  },
1110
1114
  [
1111
1115
  c,
1116
+ R,
1112
1117
  r,
1113
1118
  a,
1114
- s,
1119
+ o,
1115
1120
  y,
1116
1121
  N
1117
1122
  ]
1118
1123
  );
1119
1124
  ve(() => {
1120
1125
  if (!n.current)
1121
- return P.isLoading && s !== null ? (async () => {
1126
+ return R.isLoading && o !== null ? (async () => {
1122
1127
  try {
1123
- const u = await K(s);
1124
- u && u.payload[w.USER_ID_KEY] !== "" ? T({
1128
+ const u = await K(o);
1129
+ u && u.payload[w.USER_ID_KEY] !== "" ? k({
1125
1130
  isLoading: !1,
1126
1131
  isAuthenticated: !0,
1127
1132
  user: {
@@ -1129,41 +1134,41 @@ const Y = () => {
1129
1134
  username: u.payload[w.USERNAME_KEY]
1130
1135
  },
1131
1136
  logoutReason: ""
1132
- }) : await R(M);
1137
+ }) : await I(M);
1133
1138
  } catch {
1134
- await R(M);
1139
+ await I(M);
1135
1140
  }
1136
- })() : T((u) => ({
1141
+ })() : k((u) => ({
1137
1142
  ...u,
1138
1143
  isLoading: !1
1139
1144
  })), () => {
1140
1145
  n.current = !0;
1141
1146
  };
1142
- }, [P.isLoading, s, R]);
1143
- const We = async (u, _, g) => {
1144
- const I = zt();
1145
- if (ee(I), T((D) => ({
1147
+ }, [R.isLoading, o, I]);
1148
+ const We = async (u, A, E) => {
1149
+ const C = zt();
1150
+ if (ee(C), k((D) => ({
1146
1151
  ...D,
1147
1152
  isLoading: !0
1148
- })), i(), p(), m(), g === q.CODE) {
1153
+ })), i(), p(), m(), E === q.CODE) {
1149
1154
  const { code_verifier: D, code_challenge: Me } = await Mt(), de = await rr({
1150
- nonce: I,
1155
+ nonce: C,
1151
1156
  clientId: r,
1152
1157
  code_challenge: Me
1153
1158
  });
1154
1159
  if (de.status) {
1155
1160
  const U = await _e({
1156
1161
  username: u,
1157
- password: _,
1162
+ password: A,
1158
1163
  clientId: r,
1159
1164
  sessionExpiration: t,
1160
- nonce: I,
1161
- type: g,
1165
+ nonce: C,
1166
+ type: E,
1162
1167
  code: de.code,
1163
1168
  code_verifier: D,
1164
1169
  domain: a
1165
1170
  });
1166
- return U.status ? (o(U.idToken), d(U.accessToken), E(U.refreshToken), T({
1171
+ return U.status ? (s(U.idToken), d(U.accessToken), S(U.refreshToken), k({
1167
1172
  isLoading: !1,
1168
1173
  isAuthenticated: !0,
1169
1174
  user: {
@@ -1171,7 +1176,7 @@ const Y = () => {
1171
1176
  username: u
1172
1177
  },
1173
1178
  logoutReason: ""
1174
- }), !0) : (N(Te), T((Ve) => ({
1179
+ }), !0) : (N(Te), k((Ve) => ({
1175
1180
  ...Ve,
1176
1181
  isLoading: !1
1177
1182
  })), !1);
@@ -1180,55 +1185,55 @@ const Y = () => {
1180
1185
  }
1181
1186
  const O = await _e({
1182
1187
  username: u,
1183
- password: _,
1188
+ password: A,
1184
1189
  clientId: r,
1185
1190
  sessionExpiration: t,
1186
- nonce: I,
1187
- type: g,
1191
+ nonce: C,
1192
+ type: E,
1188
1193
  domain: a
1189
1194
  });
1190
- return O.status ? (o(O.idToken), d(O.accessToken), E(O.refreshToken), T({
1195
+ return O.status ? (s(O.idToken), d(O.accessToken), S(O.refreshToken), k({
1191
1196
  isLoading: !1,
1192
1197
  isAuthenticated: !0,
1193
1198
  user: {
1194
1199
  userId: O.userId,
1195
1200
  username: u
1196
1201
  }
1197
- }), !0) : (N(Te), T((D) => ({
1202
+ }), !0) : (N(Te), k((D) => ({
1198
1203
  ...D,
1199
1204
  isLoading: !1
1200
1205
  })), !1);
1201
1206
  }, Je = async (u) => {
1202
- u == null || u.preventDefault(), await R(Xt);
1207
+ u == null || u.preventDefault(), await I(Xt);
1203
1208
  }, xe = async () => {
1204
- const { isAuthenticated: u, user: _ } = P;
1209
+ const { isAuthenticated: u, user: A } = R;
1205
1210
  try {
1206
- if (u && _ && _.userId) {
1211
+ if (u && A && A.userId) {
1207
1212
  if (c) {
1208
- const I = await K(c);
1209
- if (I && I.payload[w.USER_ID_KEY] !== "")
1213
+ const C = await K(c);
1214
+ if (C && C.payload[w.USER_ID_KEY] !== "")
1210
1215
  return c;
1211
1216
  }
1212
- const g = await $e.refreshtoken({
1217
+ const E = await $e.refreshtoken({
1213
1218
  clientId: r,
1214
- userId: _.userId,
1215
- nonce: S,
1219
+ userId: A.userId,
1220
+ nonce: g,
1216
1221
  domain: a
1217
1222
  });
1218
- return g.status && g.status === "success" ? (d(g.newAccessToken), E(g.newRefreshToken), g.newAccessToken) : (await R(oe), "");
1223
+ return E.status && E.status === "success" ? (d(E.newAccessToken), S(E.newRefreshToken), E.newAccessToken) : (await I(oe), "");
1219
1224
  }
1220
- return await R(oe), "";
1225
+ return await I(oe), "";
1221
1226
  } catch {
1222
- return await R(oe), "";
1227
+ return await I(oe), "";
1223
1228
  }
1224
1229
  }, je = () => {
1225
- if (P.isAuthenticated && s)
1226
- return s;
1230
+ if (R.isAuthenticated && o)
1231
+ return o;
1227
1232
  };
1228
1233
  return /* @__PURE__ */ Fe(
1229
1234
  Le.Provider,
1230
1235
  {
1231
- value: { ...P, login: We, logout: Je, getAccessToken: xe, getIdToken: je },
1236
+ value: { ...R, login: We, logout: Je, getAccessToken: xe, getIdToken: je },
1232
1237
  children: e
1233
1238
  }
1234
1239
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-provider",
3
- "version": "5.1.2",
3
+ "version": "5.1.3",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -49,5 +49,5 @@
49
49
  "jose": "5.6.3",
50
50
  "uuid": "10.0.0"
51
51
  },
52
- "gitHead": "b422f26798753972e8db4e33c6168245aa53a1e0"
52
+ "gitHead": "7e11120613639298318e8075445b3e56f7e01404"
53
53
  }