@versini/auth-provider 5.0.3 → 5.0.5

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 +252 -270
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,17 +1,17 @@
1
- var je = Object.defineProperty;
2
- var Me = (e, t, r) => t in e ? je(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var N = (e, t, r) => (Me(e, typeof t != "symbol" ? t + "" : t, r), r);
4
- import { jsx as Ve } from "react/jsx-runtime";
1
+ var Me = Object.defineProperty;
2
+ var Ve = (e, t, r) => t in e ? Me(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var L = (e, t, r) => (Ve(e, typeof t != "symbol" ? t + "" : t, r), r);
4
+ import { jsx as Ye } from "react/jsx-runtime";
5
5
  import * as U from "react";
6
- import { createContext as Ye, useRef as Be, useState as Fe, useCallback as Ge, useEffect as qe, useContext as ze } from "react";
6
+ import { createContext as Be, useRef as Fe, useState as Ge, useCallback as de, useEffect as qe, useContext as ze } from "react";
7
7
  /*!
8
- @versini/auth-provider v5.0.3
8
+ @versini/auth-provider v5.0.5
9
9
  © 2024 gizmette.com
10
10
  */
11
11
  try {
12
12
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
13
- version: "5.0.3",
14
- buildTime: "07/05/2024 10:27 AM EDT",
13
+ version: "5.0.5",
14
+ buildTime: "07/05/2024 02:22 PM EDT",
15
15
  homepage: "https://github.com/aversini/auth-client",
16
16
  license: "MIT"
17
17
  });
@@ -24,13 +24,13 @@ try {
24
24
  try {
25
25
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
26
26
  version: "2.10.1",
27
- buildTime: "07/05/2024 10:27 AM EDT",
27
+ buildTime: "07/05/2024 02:22 PM EDT",
28
28
  homepage: "https://github.com/aversini/auth-client",
29
29
  license: "MIT"
30
30
  });
31
31
  } catch {
32
32
  }
33
- const F = {
33
+ const q = {
34
34
  ID_TOKEN: "id_token",
35
35
  ACCESS_TOKEN: "token",
36
36
  ID_AND_ACCESS_TOKEN: "id_token token",
@@ -38,7 +38,7 @@ const F = {
38
38
  REFRESH_TOKEN: "refresh_token"
39
39
  }, Xe = {
40
40
  CLIENT_ID: "X-Auth-ClientId"
41
- }, m = {
41
+ }, y = {
42
42
  ALG: "RS256",
43
43
  USER_ID_KEY: "sub",
44
44
  TOKEN_ID_KEY: "__raw",
@@ -53,11 +53,11 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
53
53
  l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
54
54
  sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
55
55
  awIDAQAB
56
- -----END PUBLIC KEY-----`, G = {
56
+ -----END PUBLIC KEY-----`, z = {
57
57
  AUTHENTICATE: "authenticate",
58
58
  CODE: "code",
59
59
  LOGOUT: "logout"
60
- }, q = crypto, be = (e) => e instanceof CryptoKey, L = new TextEncoder(), z = new TextDecoder();
60
+ }, X = crypto, _e = (e) => e instanceof CryptoKey, $ = new TextEncoder(), Q = new TextDecoder();
61
61
  function Ze(...e) {
62
62
  const t = e.reduce((n, { length: s }) => n + s, 0), r = new Uint8Array(t);
63
63
  let a = 0;
@@ -70,9 +70,9 @@ const et = (e) => {
70
70
  for (let a = 0; a < t.length; a++)
71
71
  r[a] = t.charCodeAt(a);
72
72
  return r;
73
- }, V = (e) => {
73
+ }, B = (e) => {
74
74
  let t = e;
75
- t instanceof Uint8Array && (t = z.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
75
+ t instanceof Uint8Array && (t = Q.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
76
76
  try {
77
77
  return et(t);
78
78
  } catch {
@@ -96,7 +96,7 @@ class g extends C {
96
96
  super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = a, this.reason = n, this.payload = r;
97
97
  }
98
98
  }
99
- class de extends C {
99
+ class le extends C {
100
100
  static get code() {
101
101
  return "ERR_JWT_EXPIRED";
102
102
  }
@@ -112,7 +112,7 @@ class tt extends C {
112
112
  return "ERR_JOSE_ALG_NOT_ALLOWED";
113
113
  }
114
114
  }
115
- let R = class extends C {
115
+ let _ = class extends C {
116
116
  constructor() {
117
117
  super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
118
118
  }
@@ -127,7 +127,7 @@ let R = class extends C {
127
127
  return "ERR_JWS_INVALID";
128
128
  }
129
129
  };
130
- class _e extends C {
130
+ class ve extends C {
131
131
  constructor() {
132
132
  super(...arguments), this.code = "ERR_JWT_INVALID";
133
133
  }
@@ -143,13 +143,13 @@ class rt extends C {
143
143
  return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
144
144
  }
145
145
  }
146
- function _(e, t = "algorithm.name") {
146
+ function T(e, t = "algorithm.name") {
147
147
  return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
148
148
  }
149
- function $(e, t) {
149
+ function W(e, t) {
150
150
  return e.name === t;
151
151
  }
152
- function Z(e) {
152
+ function te(e) {
153
153
  return parseInt(e.name.slice(4), 10);
154
154
  }
155
155
  function at(e) {
@@ -180,46 +180,46 @@ function st(e, t, ...r) {
180
180
  case "HS256":
181
181
  case "HS384":
182
182
  case "HS512": {
183
- if (!$(e.algorithm, "HMAC"))
184
- throw _("HMAC");
183
+ if (!W(e.algorithm, "HMAC"))
184
+ throw T("HMAC");
185
185
  const a = parseInt(t.slice(2), 10);
186
- if (Z(e.algorithm.hash) !== a)
187
- throw _(`SHA-${a}`, "algorithm.hash");
186
+ if (te(e.algorithm.hash) !== a)
187
+ throw T(`SHA-${a}`, "algorithm.hash");
188
188
  break;
189
189
  }
190
190
  case "RS256":
191
191
  case "RS384":
192
192
  case "RS512": {
193
- if (!$(e.algorithm, "RSASSA-PKCS1-v1_5"))
194
- throw _("RSASSA-PKCS1-v1_5");
193
+ if (!W(e.algorithm, "RSASSA-PKCS1-v1_5"))
194
+ throw T("RSASSA-PKCS1-v1_5");
195
195
  const a = parseInt(t.slice(2), 10);
196
- if (Z(e.algorithm.hash) !== a)
197
- throw _(`SHA-${a}`, "algorithm.hash");
196
+ if (te(e.algorithm.hash) !== a)
197
+ throw T(`SHA-${a}`, "algorithm.hash");
198
198
  break;
199
199
  }
200
200
  case "PS256":
201
201
  case "PS384":
202
202
  case "PS512": {
203
- if (!$(e.algorithm, "RSA-PSS"))
204
- throw _("RSA-PSS");
203
+ if (!W(e.algorithm, "RSA-PSS"))
204
+ throw T("RSA-PSS");
205
205
  const a = parseInt(t.slice(2), 10);
206
- if (Z(e.algorithm.hash) !== a)
207
- throw _(`SHA-${a}`, "algorithm.hash");
206
+ if (te(e.algorithm.hash) !== a)
207
+ throw T(`SHA-${a}`, "algorithm.hash");
208
208
  break;
209
209
  }
210
210
  case "EdDSA": {
211
211
  if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
212
- throw _("Ed25519 or Ed448");
212
+ throw T("Ed25519 or Ed448");
213
213
  break;
214
214
  }
215
215
  case "ES256":
216
216
  case "ES384":
217
217
  case "ES512": {
218
- if (!$(e.algorithm, "ECDSA"))
219
- throw _("ECDSA");
218
+ if (!W(e.algorithm, "ECDSA"))
219
+ throw T("ECDSA");
220
220
  const a = at(t);
221
221
  if (e.algorithm.namedCurve !== a)
222
- throw _(a, "algorithm.namedCurve");
222
+ throw T(a, "algorithm.namedCurve");
223
223
  break;
224
224
  }
225
225
  default:
@@ -227,7 +227,7 @@ function st(e, t, ...r) {
227
227
  }
228
228
  nt(e, r);
229
229
  }
230
- function ve(e, t, ...r) {
230
+ function Re(e, t, ...r) {
231
231
  var a;
232
232
  if (r.length > 2) {
233
233
  const n = r.pop();
@@ -236,11 +236,11 @@ function ve(e, t, ...r) {
236
236
  r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
237
237
  return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (a = t.constructor) != null && a.name && (e += ` Received an instance of ${t.constructor.name}`), e;
238
238
  }
239
- const le = (e, ...t) => ve("Key must be ", e, ...t);
240
- function Re(e, t, ...r) {
241
- return ve(`Key for the ${e} algorithm must be `, t, ...r);
239
+ const he = (e, ...t) => Re("Key must be ", e, ...t);
240
+ function Ie(e, t, ...r) {
241
+ return Re(`Key for the ${e} algorithm must be `, t, ...r);
242
242
  }
243
- const Ie = (e) => be(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", B = ["CryptoKey"], ot = (...e) => {
243
+ const Ce = (e) => _e(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", G = ["CryptoKey"], ot = (...e) => {
244
244
  const t = e.filter(Boolean);
245
245
  if (t.length === 0 || t.length === 1)
246
246
  return !0;
@@ -304,7 +304,7 @@ function ut(e) {
304
304
  }, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
305
305
  break;
306
306
  default:
307
- throw new R('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
307
+ throw new _('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
308
308
  }
309
309
  break;
310
310
  }
@@ -326,7 +326,7 @@ function ut(e) {
326
326
  t = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
327
327
  break;
328
328
  default:
329
- throw new R('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
329
+ throw new _('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
330
330
  }
331
331
  break;
332
332
  }
@@ -342,12 +342,12 @@ function ut(e) {
342
342
  t = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
343
343
  break;
344
344
  default:
345
- throw new R('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
345
+ throw new _('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
346
346
  }
347
347
  break;
348
348
  }
349
349
  default:
350
- throw new R('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
350
+ throw new _('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
351
351
  }
352
352
  return { algorithm: t, keyUsages: r };
353
353
  }
@@ -359,52 +359,52 @@ const dt = async (e) => {
359
359
  e.ext ?? !1,
360
360
  e.key_ops ?? r
361
361
  ], n = { ...e };
362
- return delete n.alg, delete n.use, q.subtle.importKey("jwk", n, ...a);
363
- }, Ce = (e) => V(e);
364
- let ee, te;
365
- const Pe = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", Oe = async (e, t, r, a) => {
362
+ return delete n.alg, delete n.use, X.subtle.importKey("jwk", n, ...a);
363
+ }, Pe = (e) => B(e);
364
+ let re, ae;
365
+ const Oe = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", De = async (e, t, r, a) => {
366
366
  let n = e.get(t);
367
367
  if (n != null && n[a])
368
368
  return n[a];
369
369
  const s = await dt({ ...r, alg: a });
370
370
  return n ? n[a] = s : e.set(t, { [a]: s }), s;
371
371
  }, lt = (e, t) => {
372
- if (Pe(e)) {
372
+ if (Oe(e)) {
373
373
  let r = e.export({ format: "jwk" });
374
- return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Ce(r.k) : (te || (te = /* @__PURE__ */ new WeakMap()), Oe(te, e, r, t));
374
+ return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Pe(r.k) : (ae || (ae = /* @__PURE__ */ new WeakMap()), De(ae, e, r, t));
375
375
  }
376
376
  return e;
377
377
  }, ht = (e, t) => {
378
- if (Pe(e)) {
378
+ if (Oe(e)) {
379
379
  let r = e.export({ format: "jwk" });
380
- return r.k ? Ce(r.k) : (ee || (ee = /* @__PURE__ */ new WeakMap()), Oe(ee, e, r, t));
380
+ return r.k ? Pe(r.k) : (re || (re = /* @__PURE__ */ new WeakMap()), De(re, e, r, t));
381
381
  }
382
382
  return e;
383
- }, ft = { normalizePublicKey: lt, normalizePrivateKey: ht }, v = (e, t, r = 0) => {
383
+ }, ft = { normalizePublicKey: lt, normalizePrivateKey: ht }, b = (e, t, r = 0) => {
384
384
  r === 0 && (t.unshift(t.length), t.unshift(6));
385
385
  const a = e.indexOf(t[0], r);
386
386
  if (a === -1)
387
387
  return !1;
388
388
  const n = e.subarray(a, a + t.length);
389
- return n.length !== t.length ? !1 : n.every((s, o) => s === t[o]) || v(e, t, a + 1);
390
- }, he = (e) => {
389
+ return n.length !== t.length ? !1 : n.every((s, o) => s === t[o]) || b(e, t, a + 1);
390
+ }, fe = (e) => {
391
391
  switch (!0) {
392
- case v(e, [42, 134, 72, 206, 61, 3, 1, 7]):
392
+ case b(e, [42, 134, 72, 206, 61, 3, 1, 7]):
393
393
  return "P-256";
394
- case v(e, [43, 129, 4, 0, 34]):
394
+ case b(e, [43, 129, 4, 0, 34]):
395
395
  return "P-384";
396
- case v(e, [43, 129, 4, 0, 35]):
396
+ case b(e, [43, 129, 4, 0, 35]):
397
397
  return "P-521";
398
- case v(e, [43, 101, 110]):
398
+ case b(e, [43, 101, 110]):
399
399
  return "X25519";
400
- case v(e, [43, 101, 111]):
400
+ case b(e, [43, 101, 111]):
401
401
  return "X448";
402
- case v(e, [43, 101, 112]):
402
+ case b(e, [43, 101, 112]):
403
403
  return "Ed25519";
404
- case v(e, [43, 101, 113]):
404
+ case b(e, [43, 101, 113]):
405
405
  return "Ed448";
406
406
  default:
407
- throw new R("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
407
+ throw new _("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
408
408
  }
409
409
  }, pt = async (e, t, r, a, n) => {
410
410
  let s, o;
@@ -442,39 +442,39 @@ const Pe = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
442
442
  case "ECDH-ES+A128KW":
443
443
  case "ECDH-ES+A192KW":
444
444
  case "ECDH-ES+A256KW": {
445
- const c = he(i);
445
+ const c = fe(i);
446
446
  s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, o = [];
447
447
  break;
448
448
  }
449
449
  case "EdDSA":
450
- s = { name: he(i) }, o = ["verify"];
450
+ s = { name: fe(i) }, o = ["verify"];
451
451
  break;
452
452
  default:
453
- throw new R('Invalid or unsupported "alg" (Algorithm) value');
453
+ throw new _('Invalid or unsupported "alg" (Algorithm) value');
454
454
  }
455
- return q.subtle.importKey(t, i, s, !1, o);
455
+ return X.subtle.importKey(t, i, s, !1, o);
456
456
  }, yt = (e, t, r) => pt(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
457
457
  async function mt(e, t, r) {
458
458
  if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
459
459
  throw new TypeError('"spki" must be SPKI formatted string');
460
460
  return yt(e, t);
461
461
  }
462
- const Y = (e) => e == null ? void 0 : e[Symbol.toStringTag], wt = (e, t) => {
462
+ const F = (e) => e == null ? void 0 : e[Symbol.toStringTag], wt = (e, t) => {
463
463
  if (!(t instanceof Uint8Array)) {
464
- if (!Ie(t))
465
- throw new TypeError(Re(e, t, ...B, "Uint8Array"));
464
+ if (!Ce(t))
465
+ throw new TypeError(Ie(e, t, ...G, "Uint8Array"));
466
466
  if (t.type !== "secret")
467
- throw new TypeError(`${Y(t)} instances for symmetric algorithms must be of type "secret"`);
467
+ throw new TypeError(`${F(t)} instances for symmetric algorithms must be of type "secret"`);
468
468
  }
469
469
  }, Et = (e, t, r) => {
470
- if (!Ie(t))
471
- throw new TypeError(Re(e, t, ...B));
470
+ if (!Ce(t))
471
+ throw new TypeError(Ie(e, t, ...G));
472
472
  if (t.type === "secret")
473
- throw new TypeError(`${Y(t)} instances for asymmetric algorithms must not be of type "secret"`);
473
+ throw new TypeError(`${F(t)} instances for asymmetric algorithms must not be of type "secret"`);
474
474
  if (t.algorithm && r === "verify" && t.type === "private")
475
- throw new TypeError(`${Y(t)} instances for asymmetric algorithm verifying must be of type "public"`);
475
+ throw new TypeError(`${F(t)} instances for asymmetric algorithm verifying must be of type "public"`);
476
476
  if (t.algorithm && r === "encrypt" && t.type === "private")
477
- throw new TypeError(`${Y(t)} instances for asymmetric algorithm encryption must be of type "public"`);
477
+ throw new TypeError(`${F(t)} instances for asymmetric algorithm encryption must be of type "public"`);
478
478
  }, St = (e, t, r) => {
479
479
  e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? wt(e, t) : Et(e, t, r);
480
480
  };
@@ -489,7 +489,7 @@ function gt(e, t, r, a, n) {
489
489
  r !== void 0 ? s = new Map([...Object.entries(r), ...t.entries()]) : s = t;
490
490
  for (const o of a.crit) {
491
491
  if (!s.has(o))
492
- throw new R(`Extension Header Parameter "${o}" is not recognized`);
492
+ throw new _(`Extension Header Parameter "${o}" is not recognized`);
493
493
  if (n[o] === void 0)
494
494
  throw new e(`Extension Header Parameter "${o}" is missing`);
495
495
  if (s.get(o) && a[o] === void 0)
@@ -525,25 +525,25 @@ function Tt(e, t) {
525
525
  case "EdDSA":
526
526
  return { name: t.name };
527
527
  default:
528
- throw new R(`alg ${e} is not supported either by JOSE or your javascript runtime`);
528
+ throw new _(`alg ${e} is not supported either by JOSE or your javascript runtime`);
529
529
  }
530
530
  }
531
531
  async function kt(e, t, r) {
532
- if (t = await ft.normalizePublicKey(t, e), be(t))
532
+ if (t = await ft.normalizePublicKey(t, e), _e(t))
533
533
  return st(t, e, r), t;
534
534
  if (t instanceof Uint8Array) {
535
535
  if (!e.startsWith("HS"))
536
- throw new TypeError(le(t, ...B));
537
- return q.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
536
+ throw new TypeError(he(t, ...G));
537
+ return X.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
538
538
  }
539
- throw new TypeError(le(t, ...B, "Uint8Array"));
539
+ throw new TypeError(he(t, ...G, "Uint8Array"));
540
540
  }
541
541
  const bt = async (e, t, r, a) => {
542
542
  const n = await kt(e, t, "verify");
543
543
  ct(e, n);
544
544
  const s = Tt(e, n.algorithm);
545
545
  try {
546
- return await q.subtle.verify(s, n, r, a);
546
+ return await X.subtle.verify(s, n, r, a);
547
547
  } catch {
548
548
  return !1;
549
549
  }
@@ -564,8 +564,8 @@ async function _t(e, t, r) {
564
564
  let a = {};
565
565
  if (e.protected)
566
566
  try {
567
- const S = V(e.protected);
568
- a = JSON.parse(z.decode(S));
567
+ const E = B(e.protected);
568
+ a = JSON.parse(Q.decode(E));
569
569
  } catch {
570
570
  throw new f("JWS Protected Header is invalid");
571
571
  }
@@ -591,29 +591,29 @@ async function _t(e, t, r) {
591
591
  throw new f("JWS Payload must be a string or an Uint8Array instance");
592
592
  let d = !1;
593
593
  typeof t == "function" && (t = await t(a, e), d = !0), St(i, t, "verify");
594
- const y = Ze(L.encode(e.protected ?? ""), L.encode("."), typeof e.payload == "string" ? L.encode(e.payload) : e.payload);
594
+ const m = Ze($.encode(e.protected ?? ""), $.encode("."), typeof e.payload == "string" ? $.encode(e.payload) : e.payload);
595
595
  let p;
596
596
  try {
597
- p = V(e.signature);
597
+ p = B(e.signature);
598
598
  } catch {
599
599
  throw new f("Failed to base64url decode the signature");
600
600
  }
601
- if (!await bt(i, t, p, y))
601
+ if (!await bt(i, t, p, m))
602
602
  throw new rt();
603
603
  let A;
604
604
  if (o)
605
605
  try {
606
- A = V(e.payload);
606
+ A = B(e.payload);
607
607
  } catch {
608
608
  throw new f("Failed to base64url decode the payload");
609
609
  }
610
610
  else
611
- typeof e.payload == "string" ? A = L.encode(e.payload) : A = e.payload;
612
- const E = { payload: A };
613
- return e.protected !== void 0 && (E.protectedHeader = a), e.header !== void 0 && (E.unprotectedHeader = e.header), d ? { ...E, key: t } : E;
611
+ typeof e.payload == "string" ? A = $.encode(e.payload) : A = e.payload;
612
+ const w = { payload: A };
613
+ return e.protected !== void 0 && (w.protectedHeader = a), e.header !== void 0 && (w.unprotectedHeader = e.header), d ? { ...w, key: t } : w;
614
614
  }
615
615
  async function vt(e, t, r) {
616
- if (e instanceof Uint8Array && (e = z.decode(e)), typeof e != "string")
616
+ if (e instanceof Uint8Array && (e = Q.decode(e)), typeof e != "string")
617
617
  throw new f("Compact JWS must be a string or Uint8Array");
618
618
  const { 0: a, 1: n, 2: s, length: o } = e.split(".");
619
619
  if (o !== 3)
@@ -621,7 +621,7 @@ async function vt(e, t, r) {
621
621
  const i = await _t({ payload: n, protected: a, signature: s }, t, r), c = { payload: i.payload, protectedHeader: i.protectedHeader };
622
622
  return typeof t == "function" ? { ...c, key: i.key } : c;
623
623
  }
624
- const Rt = (e) => Math.floor(e.getTime() / 1e3), De = 60, Ue = De * 60, ce = Ue * 24, It = ce * 7, Ct = ce * 365.25, Pt = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, fe = (e) => {
624
+ const Rt = (e) => Math.floor(e.getTime() / 1e3), Ue = 60, He = Ue * 60, ce = He * 24, It = ce * 7, Ct = ce * 365.25, Pt = /^(\+|\-)? ?(\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) => {
625
625
  const t = Pt.exec(e);
626
626
  if (!t || t[4] && t[1])
627
627
  throw new TypeError("Invalid time period format");
@@ -640,14 +640,14 @@ const Rt = (e) => Math.floor(e.getTime() / 1e3), De = 60, Ue = De * 60, ce = Ue
640
640
  case "min":
641
641
  case "mins":
642
642
  case "m":
643
- n = Math.round(r * De);
643
+ n = Math.round(r * Ue);
644
644
  break;
645
645
  case "hour":
646
646
  case "hours":
647
647
  case "hr":
648
648
  case "hrs":
649
649
  case "h":
650
- n = Math.round(r * Ue);
650
+ n = Math.round(r * He);
651
651
  break;
652
652
  case "day":
653
653
  case "days":
@@ -664,22 +664,22 @@ const Rt = (e) => Math.floor(e.getTime() / 1e3), De = 60, Ue = De * 60, ce = Ue
664
664
  break;
665
665
  }
666
666
  return t[1] === "-" || t[4] === "ago" ? -n : n;
667
- }, pe = (e) => e.toLowerCase().replace(/^application\//, ""), Ot = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Dt = (e, t, r = {}) => {
667
+ }, ye = (e) => e.toLowerCase().replace(/^application\//, ""), Ot = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Dt = (e, t, r = {}) => {
668
668
  let a;
669
669
  try {
670
- a = JSON.parse(z.decode(t));
670
+ a = JSON.parse(Q.decode(t));
671
671
  } catch {
672
672
  }
673
673
  if (!ie(a))
674
- throw new _e("JWT Claims Set must be a top-level JSON object");
674
+ throw new ve("JWT Claims Set must be a top-level JSON object");
675
675
  const { typ: n } = r;
676
- if (n && (typeof e.typ != "string" || pe(e.typ) !== pe(n)))
676
+ if (n && (typeof e.typ != "string" || ye(e.typ) !== ye(n)))
677
677
  throw new g('unexpected "typ" JWT header value', a, "typ", "check_failed");
678
- const { requiredClaims: s = [], issuer: o, subject: i, audience: c, maxTokenAge: d } = r, y = [...s];
679
- d !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"), o !== void 0 && y.push("iss");
680
- for (const S of new Set(y.reverse()))
681
- if (!(S in a))
682
- throw new g(`missing required "${S}" claim`, a, S, "missing");
678
+ const { requiredClaims: s = [], issuer: o, subject: i, audience: c, maxTokenAge: d } = r, m = [...s];
679
+ d !== void 0 && m.push("iat"), c !== void 0 && m.push("aud"), i !== void 0 && m.push("sub"), o !== void 0 && m.push("iss");
680
+ for (const E of new Set(m.reverse()))
681
+ if (!(E in a))
682
+ throw new g(`missing required "${E}" claim`, a, E, "missing");
683
683
  if (o && !(Array.isArray(o) ? o : [o]).includes(a.iss))
684
684
  throw new g('unexpected "iss" claim value', a, "iss", "check_failed");
685
685
  if (i && a.sub !== i)
@@ -689,7 +689,7 @@ const Rt = (e) => Math.floor(e.getTime() / 1e3), De = 60, Ue = De * 60, ce = Ue
689
689
  let p;
690
690
  switch (typeof r.clockTolerance) {
691
691
  case "string":
692
- p = fe(r.clockTolerance);
692
+ p = pe(r.clockTolerance);
693
693
  break;
694
694
  case "number":
695
695
  p = r.clockTolerance;
@@ -700,26 +700,26 @@ const Rt = (e) => Math.floor(e.getTime() / 1e3), De = 60, Ue = De * 60, ce = Ue
700
700
  default:
701
701
  throw new TypeError("Invalid clockTolerance option type");
702
702
  }
703
- const { currentDate: A } = r, E = Rt(A || /* @__PURE__ */ new Date());
703
+ const { currentDate: A } = r, w = Rt(A || /* @__PURE__ */ new Date());
704
704
  if ((a.iat !== void 0 || d) && typeof a.iat != "number")
705
705
  throw new g('"iat" claim must be a number', a, "iat", "invalid");
706
706
  if (a.nbf !== void 0) {
707
707
  if (typeof a.nbf != "number")
708
708
  throw new g('"nbf" claim must be a number', a, "nbf", "invalid");
709
- if (a.nbf > E + p)
709
+ if (a.nbf > w + p)
710
710
  throw new g('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
711
711
  }
712
712
  if (a.exp !== void 0) {
713
713
  if (typeof a.exp != "number")
714
714
  throw new g('"exp" claim must be a number', a, "exp", "invalid");
715
- if (a.exp <= E - p)
716
- throw new de('"exp" claim timestamp check failed', a, "exp", "check_failed");
715
+ if (a.exp <= w - p)
716
+ throw new le('"exp" claim timestamp check failed', a, "exp", "check_failed");
717
717
  }
718
718
  if (d) {
719
- const S = E - a.iat, K = typeof d == "number" ? d : fe(d);
720
- if (S - p > K)
721
- throw new de('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
722
- if (S < 0 - p)
719
+ const E = w - a.iat, K = typeof d == "number" ? d : pe(d);
720
+ if (E - p > K)
721
+ throw new le('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
722
+ if (E < 0 - p)
723
723
  throw new g('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
724
724
  }
725
725
  return a;
@@ -728,52 +728,52 @@ async function Ut(e, t, r) {
728
728
  var a;
729
729
  const n = await vt(e, t, r);
730
730
  if ((a = n.protectedHeader.crit) != null && a.includes("b64") && n.protectedHeader.b64 === !1)
731
- throw new _e("JWTs MUST NOT use unencoded payload");
731
+ throw new ve("JWTs MUST NOT use unencoded payload");
732
732
  const s = { payload: Dt(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
733
733
  return typeof t == "function" ? { ...s, key: n.key } : s;
734
734
  }
735
735
  const H = async (e) => {
736
736
  try {
737
- const t = m.ALG, r = await mt(Qe, t);
737
+ const t = y.ALG, r = await mt(Qe, t);
738
738
  return await Ut(e, r, {
739
- issuer: m.ISSUER
739
+ issuer: y.ISSUER
740
740
  });
741
741
  } catch {
742
742
  return;
743
743
  }
744
744
  };
745
745
  var l = [];
746
- for (var re = 0; re < 256; ++re)
747
- l.push((re + 256).toString(16).slice(1));
746
+ for (var ne = 0; ne < 256; ++ne)
747
+ l.push((ne + 256).toString(16).slice(1));
748
748
  function Ht(e, t = 0) {
749
749
  return (l[e[t + 0]] + l[e[t + 1]] + l[e[t + 2]] + l[e[t + 3]] + "-" + l[e[t + 4]] + l[e[t + 5]] + "-" + l[e[t + 6]] + l[e[t + 7]] + "-" + l[e[t + 8]] + l[e[t + 9]] + "-" + l[e[t + 10]] + l[e[t + 11]] + l[e[t + 12]] + l[e[t + 13]] + l[e[t + 14]] + l[e[t + 15]]).toLowerCase();
750
750
  }
751
- var W, Kt = new Uint8Array(16);
751
+ var J, Kt = new Uint8Array(16);
752
752
  function Nt() {
753
- if (!W && (W = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !W))
753
+ if (!J && (J = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !J))
754
754
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
755
- return W(Kt);
755
+ return J(Kt);
756
756
  }
757
757
  var Lt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
758
- const ye = {
758
+ const me = {
759
759
  randomUUID: Lt
760
760
  };
761
- function me(e, t, r) {
762
- if (ye.randomUUID && !t && !e)
763
- return ye.randomUUID();
761
+ function we(e, t, r) {
762
+ if (me.randomUUID && !t && !e)
763
+ return me.randomUUID();
764
764
  e = e || {};
765
765
  var a = e.random || (e.rng || Nt)();
766
766
  return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, Ht(a);
767
767
  }
768
- const we = globalThis.crypto, $t = (e) => `${me()}${me()}`.slice(0, e), Wt = (e) => btoa(
768
+ const Ee = globalThis.crypto, $t = (e) => `${we()}${we()}`.slice(0, e), Wt = (e) => btoa(
769
769
  [...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
770
770
  );
771
771
  async function Jt(e) {
772
- if (!we.subtle)
772
+ if (!Ee.subtle)
773
773
  throw new Error(
774
774
  "crypto.subtle is available only in secure contexts (HTTPS)."
775
775
  );
776
- const t = new TextEncoder().encode(e), r = await we.subtle.digest("SHA-256", t);
776
+ const t = new TextEncoder().encode(e), r = await Ee.subtle.digest("SHA-256", t);
777
777
  return Wt(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
778
778
  }
779
779
  async function xt(e) {
@@ -783,29 +783,29 @@ async function xt(e) {
783
783
  code_challenge: a
784
784
  };
785
785
  }
786
- function He(e, t) {
786
+ function Ke(e, t) {
787
787
  window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
788
788
  }
789
- const Ee = (e, t) => {
789
+ const Se = (e, t) => {
790
790
  const r = JSON.stringify(
791
791
  typeof t == "function" ? t() : t
792
792
  );
793
- window.localStorage.setItem(e, r), He(e, r);
793
+ window.localStorage.setItem(e, r), Ke(e, r);
794
794
  }, jt = (e) => {
795
- window.localStorage.removeItem(e), He(e, null);
796
- }, Se = (e) => window.localStorage.getItem(e), Mt = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
797
- function J({
795
+ window.localStorage.removeItem(e), Ke(e, null);
796
+ }, ge = (e) => window.localStorage.getItem(e), Mt = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
797
+ function x({
798
798
  key: e,
799
799
  initialValue: t
800
800
  }) {
801
- const r = () => Se(e), a = U.useSyncExternalStore(
801
+ const r = () => ge(e), a = U.useSyncExternalStore(
802
802
  Mt,
803
803
  r
804
804
  ), n = U.useCallback(
805
805
  (i) => {
806
806
  try {
807
807
  const c = typeof i == "function" ? i(JSON.parse(a)) : i;
808
- c == null ? jt(e) : Ee(e, c);
808
+ c == null ? jt(e) : Se(e, c);
809
809
  } catch (c) {
810
810
  console.warn(c);
811
811
  }
@@ -818,46 +818,46 @@ function J({
818
818
  }, [n]);
819
819
  return U.useEffect(() => {
820
820
  try {
821
- Se(e) === null && typeof t < "u" && Ee(e, t);
821
+ ge(e) === null && typeof t < "u" && Se(e, t);
822
822
  } catch (i) {
823
823
  console.warn(i);
824
824
  }
825
825
  }, [e, t]), [a ? JSON.parse(a) : null, n, s, o];
826
826
  }
827
827
  var h = [];
828
- for (var ae = 0; ae < 256; ++ae)
829
- h.push((ae + 256).toString(16).slice(1));
828
+ for (var se = 0; se < 256; ++se)
829
+ h.push((se + 256).toString(16).slice(1));
830
830
  function Vt(e, t = 0) {
831
831
  return (h[e[t + 0]] + h[e[t + 1]] + h[e[t + 2]] + h[e[t + 3]] + "-" + h[e[t + 4]] + h[e[t + 5]] + "-" + h[e[t + 6]] + h[e[t + 7]] + "-" + h[e[t + 8]] + h[e[t + 9]] + "-" + h[e[t + 10]] + h[e[t + 11]] + h[e[t + 12]] + h[e[t + 13]] + h[e[t + 14]] + h[e[t + 15]]).toLowerCase();
832
832
  }
833
- var x, Yt = new Uint8Array(16);
833
+ var j, Yt = new Uint8Array(16);
834
834
  function Bt() {
835
- if (!x && (x = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !x))
835
+ if (!j && (j = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !j))
836
836
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
837
- return x(Yt);
837
+ return j(Yt);
838
838
  }
839
839
  var Ft = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
840
- const ge = {
840
+ const Ae = {
841
841
  randomUUID: Ft
842
842
  };
843
843
  function Gt(e, t, r) {
844
- if (ge.randomUUID && !t && !e)
845
- return ge.randomUUID();
844
+ if (Ae.randomUUID && !t && !e)
845
+ return Ae.randomUUID();
846
846
  e = e || {};
847
847
  var a = e.random || (e.rng || Bt)();
848
848
  return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, Vt(a);
849
849
  }
850
- const ne = "Oops! It looks like your session has expired. For your security, please log in again to continue.", qt = "Your session has been successfully terminated.", Ae = "Login failed. Please try again.", se = "Error getting access token, please re-authenticate.", zt = "You forgot to wrap your component in <AuthProvider>.", Te = {
850
+ const M = "Oops! It looks like your session has expired. For your security, please log in again to continue.", qt = "Your session has been successfully terminated.", Te = "Login failed. Please try again.", oe = "Error getting access token, please re-authenticate.", zt = "You forgot to wrap your component in <AuthProvider>.", ke = {
851
851
  dev: "https://auth.gizmette.local.com:3003",
852
852
  prod: "https://mylogin.gizmette.com"
853
- }, j = "@@auth@@", Xt = process.env.NODE_ENV === "production", Qt = !Xt, X = async ({
853
+ }, V = "@@auth@@", Xt = process.env.NODE_ENV === "production", Qt = !Xt, Z = async ({
854
854
  type: e,
855
855
  clientId: t,
856
856
  params: r = {}
857
857
  }) => {
858
858
  try {
859
859
  const a = await fetch(
860
- Qt ? `${Te.dev}/${e}` : `${Te.prod}/${e}`,
860
+ Qt ? `${ke.dev}/${e}` : `${ke.prod}/${e}`,
861
861
  {
862
862
  credentials: "include",
863
863
  method: "POST",
@@ -879,7 +879,7 @@ const ne = "Oops! It looks like your session has expired. For your security, ple
879
879
  } catch (a) {
880
880
  return console.error(a), { status: 500, data: [] };
881
881
  }
882
- }, oe = async ({
882
+ }, Zt = async ({
883
883
  idToken: e,
884
884
  accessToken: t,
885
885
  refreshToken: r,
@@ -887,8 +887,8 @@ const ne = "Oops! It looks like your session has expired. For your security, ple
887
887
  }) => {
888
888
  try {
889
889
  return {
890
- status: (await X({
891
- type: G.LOGOUT,
890
+ status: (await Z({
891
+ type: z.LOGOUT,
892
892
  clientId: a,
893
893
  params: {
894
894
  idToken: e,
@@ -902,7 +902,7 @@ const ne = "Oops! It looks like your session has expired. For your security, ple
902
902
  status: !1
903
903
  };
904
904
  }
905
- }, ke = async ({
905
+ }, be = async ({
906
906
  username: e,
907
907
  password: t,
908
908
  clientId: r,
@@ -913,11 +913,11 @@ const ne = "Oops! It looks like your session has expired. For your security, ple
913
913
  code_verifier: i
914
914
  }) => {
915
915
  try {
916
- const c = await X({
917
- type: G.AUTHENTICATE,
916
+ const c = await Z({
917
+ type: z.AUTHENTICATE,
918
918
  clientId: r,
919
919
  params: {
920
- type: n || F.ID_AND_ACCESS_TOKEN,
920
+ type: n || q.ID_AND_ACCESS_TOKEN,
921
921
  username: e,
922
922
  password: t,
923
923
  sessionExpiration: s,
@@ -926,11 +926,11 @@ const ne = "Oops! It looks like your session has expired. For your security, ple
926
926
  code_verifier: i
927
927
  }
928
928
  }), d = await H(c.data.idToken);
929
- return d && d.payload[m.USER_ID_KEY] !== "" && d.payload[m.NONCE_KEY] === a ? {
929
+ return d && d.payload[y.USER_ID_KEY] !== "" && d.payload[y.NONCE_KEY] === a ? {
930
930
  idToken: c.data.idToken,
931
931
  accessToken: c.data.accessToken,
932
932
  refreshToken: c.data.refreshToken,
933
- userId: d.payload[m.USER_ID_KEY],
933
+ userId: d.payload[y.USER_ID_KEY],
934
934
  status: !0
935
935
  } : {
936
936
  status: !1
@@ -940,17 +940,17 @@ const ne = "Oops! It looks like your session has expired. For your security, ple
940
940
  status: !1
941
941
  };
942
942
  }
943
- }, Zt = async ({
943
+ }, er = async ({
944
944
  nonce: e,
945
945
  clientId: t,
946
946
  code_challenge: r
947
947
  }) => {
948
948
  try {
949
- const a = await X({
950
- type: G.CODE,
949
+ const a = await Z({
950
+ type: z.CODE,
951
951
  clientId: t,
952
952
  params: {
953
- type: F.CODE,
953
+ type: q.CODE,
954
954
  nonce: e,
955
955
  code_challenge: r
956
956
  }
@@ -966,7 +966,7 @@ const ne = "Oops! It looks like your session has expired. For your security, ple
966
966
  status: !1
967
967
  };
968
968
  }
969
- }, er = async ({
969
+ }, tr = async ({
970
970
  clientId: e,
971
971
  userId: t,
972
972
  nonce: r,
@@ -974,21 +974,21 @@ const ne = "Oops! It looks like your session has expired. For your security, ple
974
974
  accessToken: n
975
975
  }) => {
976
976
  try {
977
- const s = await X({
978
- type: G.AUTHENTICATE,
977
+ const s = await Z({
978
+ type: z.AUTHENTICATE,
979
979
  clientId: e,
980
980
  params: {
981
- type: F.REFRESH_TOKEN,
981
+ type: q.REFRESH_TOKEN,
982
982
  userId: t,
983
983
  nonce: r,
984
984
  refreshToken: a,
985
985
  accessToken: n
986
986
  }
987
987
  }), o = await H(s.data.accessToken);
988
- return o && o.payload[m.USER_ID_KEY] !== "" && o.payload[m.NONCE_KEY] === r ? {
988
+ return o && o.payload[y.USER_ID_KEY] !== "" && o.payload[y.NONCE_KEY] === r ? {
989
989
  accessToken: s.data.accessToken,
990
990
  refreshToken: s.data.refreshToken,
991
- userId: o.payload[m.USER_ID_KEY],
991
+ userId: o.payload[y.USER_ID_KEY],
992
992
  status: !0
993
993
  } : {
994
994
  status: !1
@@ -999,11 +999,11 @@ const ne = "Oops! It looks like your session has expired. For your security, ple
999
999
  };
1000
1000
  }
1001
1001
  };
1002
- class tr {
1002
+ class rr {
1003
1003
  constructor(t = null, r = null) {
1004
- N(this, "refreshTokenPromise", null);
1005
- N(this, "accessToken");
1006
- N(this, "refreshToken");
1004
+ L(this, "refreshTokenPromise", null);
1005
+ L(this, "accessToken");
1006
+ L(this, "refreshToken");
1007
1007
  this.accessToken = t || "", this.refreshToken = r || "";
1008
1008
  }
1009
1009
  async refreshtoken({
@@ -1028,8 +1028,8 @@ class tr {
1028
1028
  nonce: a
1029
1029
  }) {
1030
1030
  const n = await H(this.refreshToken);
1031
- if (n && n.payload[m.USER_ID_KEY] !== "") {
1032
- const s = await er({
1031
+ if (n && n.payload[y.USER_ID_KEY] !== "") {
1032
+ const s = await tr({
1033
1033
  clientId: t,
1034
1034
  userId: r,
1035
1035
  nonce: a,
@@ -1049,117 +1049,107 @@ class tr {
1049
1049
  };
1050
1050
  }
1051
1051
  }
1052
- const M = () => {
1052
+ const Y = () => {
1053
1053
  throw new Error(zt);
1054
- }, Ke = Ye({
1054
+ }, Ne = Be({
1055
1055
  isAuthenticated: !1,
1056
1056
  isLoading: !1,
1057
- login: M,
1058
- logout: M,
1059
- getAccessToken: M,
1060
- getIdToken: M,
1057
+ login: Y,
1058
+ logout: Y,
1059
+ getAccessToken: Y,
1060
+ getIdToken: Y,
1061
1061
  logoutReason: ""
1062
- }), ir = ({
1062
+ }), cr = ({
1063
1063
  children: e,
1064
1064
  sessionExpiration: t,
1065
1065
  clientId: r
1066
1066
  }) => {
1067
- const a = Be(!1), [n, s, , o] = J({
1068
- key: `${j}::${r}::@@user@@`
1069
- }), [i, c, , d] = J({
1070
- key: `${j}::${r}::@@access@@`
1071
- }), [y, p, , A] = J(
1067
+ const a = Fe(!1), [n, s, , o] = x({
1068
+ key: `${V}::${r}::@@user@@`
1069
+ }), [i, c, , d] = x({
1070
+ key: `${V}::${r}::@@access@@`
1071
+ }), [m, p, , A] = x(
1072
1072
  {
1073
- key: `${j}::${r}::@@refresh@@`
1073
+ key: `${V}::${r}::@@refresh@@`
1074
1074
  }
1075
- ), [E, S, , K] = J({
1076
- key: `${j}::${r}::@@nonce@@`
1077
- }), Ne = new tr(i, y), [P, T] = Fe({
1075
+ ), [w, E, , K] = x({
1076
+ key: `${V}::${r}::@@nonce@@`
1077
+ }), Le = new rr(i, m), [P, v] = Ge({
1078
1078
  isLoading: !0,
1079
1079
  isAuthenticated: !1,
1080
1080
  user: void 0,
1081
1081
  logoutReason: ""
1082
- }), k = Ge(
1082
+ }), N = de(
1083
1083
  (u) => {
1084
- console.warn(u), T({
1084
+ console.warn(u), v({
1085
1085
  isLoading: !0,
1086
1086
  isAuthenticated: !1,
1087
1087
  user: void 0,
1088
- logoutReason: u || ne
1088
+ logoutReason: u || M
1089
1089
  }), o(), d(), A(), K();
1090
1090
  },
1091
1091
  [o, d, K, A]
1092
+ ), R = de(
1093
+ async (u) => {
1094
+ N(u || M), await Zt({
1095
+ idToken: n,
1096
+ accessToken: i,
1097
+ refreshToken: m,
1098
+ clientId: r
1099
+ }), v((k) => ({
1100
+ ...k,
1101
+ isLoading: !1
1102
+ }));
1103
+ },
1104
+ [i, r, n, N, m]
1092
1105
  );
1093
1106
  qe(() => {
1094
1107
  if (!a.current)
1095
1108
  return P.isLoading && n !== null ? (async () => {
1096
1109
  try {
1097
1110
  const u = await H(n);
1098
- u && u.payload[m.USER_ID_KEY] !== "" ? T({
1111
+ u && u.payload[y.USER_ID_KEY] !== "" ? v({
1099
1112
  isLoading: !1,
1100
1113
  isAuthenticated: !0,
1101
1114
  user: {
1102
- userId: u.payload[m.USER_ID_KEY],
1103
- username: u.payload[m.USERNAME_KEY]
1115
+ userId: u.payload[y.USER_ID_KEY],
1116
+ username: u.payload[y.USERNAME_KEY]
1104
1117
  },
1105
1118
  logoutReason: ""
1106
- }) : (k(ne), await oe({
1107
- idToken: n,
1108
- accessToken: i,
1109
- refreshToken: y,
1110
- clientId: r
1111
- }), T((w) => ({
1112
- ...w,
1113
- isLoading: !1
1114
- })));
1119
+ }) : await R(M);
1115
1120
  } catch {
1116
- k(ne), await oe({
1117
- idToken: n,
1118
- accessToken: i,
1119
- refreshToken: y,
1120
- clientId: r
1121
- }), T((w) => ({
1122
- ...w,
1123
- isLoading: !1
1124
- }));
1121
+ await R(M);
1125
1122
  }
1126
- })() : T((u) => ({
1123
+ })() : v((u) => ({
1127
1124
  ...u,
1128
1125
  isLoading: !1
1129
1126
  })), () => {
1130
1127
  a.current = !0;
1131
1128
  };
1132
- }, [
1133
- P,
1134
- i,
1135
- n,
1136
- y,
1137
- r,
1138
- k
1139
- ]);
1140
- const Le = async (u, w, b) => {
1129
+ }, [P.isLoading, n, R]);
1130
+ const $e = async (u, k, S) => {
1141
1131
  const I = Gt();
1142
- if (S(I), T((Q) => ({
1143
- ...Q,
1132
+ if (E(I), v((ee) => ({
1133
+ ...ee,
1144
1134
  isLoading: !0
1145
- })), b === F.CODE) {
1146
- const { code_verifier: Q, code_challenge: xe } = await xt(), ue = await Zt({
1135
+ })), S === q.CODE) {
1136
+ const { code_verifier: ee, code_challenge: je } = await xt(), ue = await er({
1147
1137
  nonce: I,
1148
1138
  clientId: r,
1149
- code_challenge: xe
1139
+ code_challenge: je
1150
1140
  });
1151
1141
  if (ue.status) {
1152
- const D = await ke({
1142
+ const D = await be({
1153
1143
  username: u,
1154
- password: w,
1144
+ password: k,
1155
1145
  clientId: r,
1156
1146
  sessionExpiration: t,
1157
1147
  nonce: I,
1158
- type: b,
1148
+ type: S,
1159
1149
  code: ue.code,
1160
- code_verifier: Q
1150
+ code_verifier: ee
1161
1151
  });
1162
- return D.status ? (s(D.idToken), c(D.accessToken), p(D.refreshToken), T({
1152
+ return D.status ? (s(D.idToken), c(D.accessToken), p(D.refreshToken), v({
1163
1153
  isLoading: !1,
1164
1154
  isAuthenticated: !0,
1165
1155
  user: {
@@ -1167,70 +1157,62 @@ const M = () => {
1167
1157
  username: u
1168
1158
  },
1169
1159
  logoutReason: ""
1170
- }), !0) : (k(Ae), !1);
1160
+ }), !0) : (N(Te), !1);
1171
1161
  }
1172
1162
  return !1;
1173
1163
  }
1174
- const O = await ke({
1164
+ const O = await be({
1175
1165
  username: u,
1176
- password: w,
1166
+ password: k,
1177
1167
  clientId: r,
1178
1168
  sessionExpiration: t,
1179
1169
  nonce: I,
1180
- type: b
1170
+ type: S
1181
1171
  });
1182
- return O.status ? (s(O.idToken), c(O.accessToken), p(O.refreshToken), T({
1172
+ return O.status ? (s(O.idToken), c(O.accessToken), p(O.refreshToken), v({
1183
1173
  isLoading: !1,
1184
1174
  isAuthenticated: !0,
1185
1175
  user: {
1186
1176
  userId: O.userId,
1187
1177
  username: u
1188
1178
  }
1189
- }), !0) : (k(Ae), !1);
1190
- }, $e = async (u) => {
1191
- u == null || u.preventDefault(), k(qt), await oe({
1192
- idToken: n,
1193
- accessToken: i,
1194
- refreshToken: y,
1195
- clientId: r
1196
- }), T((w) => ({
1197
- ...w,
1198
- isLoading: !1
1199
- }));
1200
- }, We = async () => {
1201
- const { isAuthenticated: u, user: w } = P;
1179
+ }), !0) : (N(Te), !1);
1180
+ }, We = async (u) => {
1181
+ u == null || u.preventDefault(), await R(qt);
1182
+ }, Je = async () => {
1183
+ const { isAuthenticated: u, user: k } = P;
1202
1184
  try {
1203
- if (u && w && w.userId) {
1185
+ if (u && k && k.userId) {
1204
1186
  if (i) {
1205
1187
  const I = await H(i);
1206
- if (I && I.payload[m.USER_ID_KEY] !== "")
1188
+ if (I && I.payload[y.USER_ID_KEY] !== "")
1207
1189
  return i;
1208
1190
  }
1209
- const b = await Ne.refreshtoken({
1191
+ const S = await Le.refreshtoken({
1210
1192
  clientId: r,
1211
- userId: w.userId,
1212
- nonce: E
1193
+ userId: k.userId,
1194
+ nonce: w
1213
1195
  });
1214
- return b.status ? (c(b.newAccessToken), p(b.newRefreshToken), b.newAccessToken) : (k(se), "");
1196
+ return S.status && S.status === "success" ? (c(S.newAccessToken), p(S.newRefreshToken), S.newAccessToken) : (await R(oe), "");
1215
1197
  }
1216
- return k(se), "";
1198
+ return await R(oe), "";
1217
1199
  } catch {
1218
- return k(se), "";
1200
+ return await R(oe), "";
1219
1201
  }
1220
- }, Je = () => {
1202
+ }, xe = () => {
1221
1203
  if (P.isAuthenticated && n)
1222
1204
  return n;
1223
1205
  };
1224
- return /* @__PURE__ */ Ve(
1225
- Ke.Provider,
1206
+ return /* @__PURE__ */ Ye(
1207
+ Ne.Provider,
1226
1208
  {
1227
- value: { ...P, login: Le, logout: $e, getAccessToken: We, getIdToken: Je },
1209
+ value: { ...P, login: $e, logout: We, getAccessToken: Je, getIdToken: xe },
1228
1210
  children: e
1229
1211
  }
1230
1212
  );
1231
- }, cr = (e = Ke) => ze(e);
1213
+ }, ur = (e = Ne) => ze(e);
1232
1214
  export {
1233
- F as AUTH_TYPES,
1234
- ir as AuthProvider,
1235
- cr as useAuth
1215
+ q as AUTH_TYPES,
1216
+ cr as AuthProvider,
1217
+ ur as useAuth
1236
1218
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-provider",
3
- "version": "5.0.3",
3
+ "version": "5.0.5",
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": "9701c63e8ac76af08e748b921c0d69c37cded915"
52
+ "gitHead": "4a2ce0cc03567f791e235375cad30177adb6b15e"
53
53
  }