@versini/auth-provider 4.2.0 → 4.3.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.
package/dist/index.js CHANGED
@@ -1,46 +1,47 @@
1
- import { jsx as Pe } from "react/jsx-runtime";
2
- import * as C from "react";
3
- import { createContext as De, useState as Ue, useCallback as Ne, useEffect as He, useContext as Le } from "react";
1
+ import { jsx as Ue } from "react/jsx-runtime";
2
+ import * as D from "react";
3
+ import { createContext as Ne, useState as He, useCallback as Le, useEffect as $e, useContext as Ke } from "react";
4
4
  /*!
5
- @versini/auth-provider v4.2.0
5
+ @versini/auth-provider v4.3.0
6
6
  © 2024 gizmette.com
7
7
  */
8
8
  try {
9
9
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
10
- version: "4.2.0",
11
- buildTime: "06/27/2024 06:57 PM EDT",
10
+ version: "4.3.0",
11
+ buildTime: "06/28/2024 11:03 AM EDT",
12
12
  homepage: "https://github.com/aversini/auth-client",
13
13
  license: "MIT"
14
14
  });
15
15
  } catch {
16
16
  }
17
17
  /*!
18
- @versini/auth-common v2.8.0
18
+ @versini/auth-common v2.9.0
19
19
  © 2024 gizmette.com
20
20
  */
21
21
  try {
22
22
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
23
- version: "2.8.0",
24
- buildTime: "06/27/2024 06:57 PM EDT",
23
+ version: "2.9.0",
24
+ buildTime: "06/28/2024 11:03 AM EDT",
25
25
  homepage: "https://github.com/aversini/auth-client",
26
26
  license: "MIT"
27
27
  });
28
28
  } catch {
29
29
  }
30
- const F = {
30
+ const M = {
31
31
  ID_TOKEN: "id_token",
32
32
  ACCESS_TOKEN: "token",
33
33
  ID_AND_ACCESS_TOKEN: "id_token token",
34
- CODE: "code"
35
- }, $e = {
34
+ CODE: "code",
35
+ REFRESH_TOKEN: "refresh_token"
36
+ }, Je = {
36
37
  CLIENT_ID: "X-Auth-ClientId"
37
- }, _ = {
38
+ }, f = {
38
39
  ALG: "RS256",
39
40
  USER_ID_KEY: "sub",
40
41
  TOKEN_ID_KEY: "__raw",
41
42
  NONCE_KEY: "_nonce",
42
43
  ISSUER: "gizmette.com"
43
- }, Je = `-----BEGIN PUBLIC KEY-----
44
+ }, We = `-----BEGIN PUBLIC KEY-----
44
45
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
45
46
  w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
46
47
  i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
@@ -48,33 +49,33 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
48
49
  l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
49
50
  sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
50
51
  awIDAQAB
51
- -----END PUBLIC KEY-----`, q = {
52
+ -----END PUBLIC KEY-----`, V = {
52
53
  AUTHENTICATE: "authenticate",
53
54
  CODE: "code",
54
55
  LOGOUT: "logout"
55
- }, z = crypto, ye = (e) => e instanceof CryptoKey, P = new TextEncoder(), J = new TextDecoder();
56
- function Ke(...e) {
57
- const t = e.reduce((n, { length: s }) => n + s, 0), o = new Uint8Array(t);
56
+ }, te = crypto, Ee = (e) => e instanceof CryptoKey, L = new TextEncoder(), Y = new TextDecoder();
57
+ function xe(...e) {
58
+ const t = e.reduce((a, { length: s }) => a + s, 0), o = new Uint8Array(t);
58
59
  let r = 0;
59
- for (const n of e)
60
- o.set(n, r), r += n.length;
60
+ for (const a of e)
61
+ o.set(a, r), r += a.length;
61
62
  return o;
62
63
  }
63
- const We = (e) => {
64
+ const je = (e) => {
64
65
  const t = atob(e), o = new Uint8Array(t.length);
65
66
  for (let r = 0; r < t.length; r++)
66
67
  o[r] = t.charCodeAt(r);
67
68
  return o;
68
- }, x = (e) => {
69
+ }, B = (e) => {
69
70
  let t = e;
70
- t instanceof Uint8Array && (t = J.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
71
+ t instanceof Uint8Array && (t = Y.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
71
72
  try {
72
- return We(t);
73
+ return je(t);
73
74
  } catch {
74
75
  throw new TypeError("The input to be decoded is not correctly encoded.");
75
76
  }
76
77
  };
77
- class T extends Error {
78
+ class C extends Error {
78
79
  static get code() {
79
80
  return "ERR_JOSE_GENERIC";
80
81
  }
@@ -83,23 +84,23 @@ class T extends Error {
83
84
  super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (o = Error.captureStackTrace) == null || o.call(Error, this, this.constructor);
84
85
  }
85
86
  }
86
- class w extends T {
87
+ class g extends C {
87
88
  static get code() {
88
89
  return "ERR_JWT_CLAIM_VALIDATION_FAILED";
89
90
  }
90
- constructor(t, o, r = "unspecified", n = "unspecified") {
91
- super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = n, this.payload = o;
91
+ constructor(t, o, r = "unspecified", a = "unspecified") {
92
+ super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = a, this.payload = o;
92
93
  }
93
94
  }
94
- class te extends T {
95
+ class ae extends C {
95
96
  static get code() {
96
97
  return "ERR_JWT_EXPIRED";
97
98
  }
98
- constructor(t, o, r = "unspecified", n = "unspecified") {
99
- super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = n, this.payload = o;
99
+ constructor(t, o, r = "unspecified", a = "unspecified") {
100
+ super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = a, this.payload = o;
100
101
  }
101
102
  }
102
- class xe extends T {
103
+ class Me extends C {
103
104
  constructor() {
104
105
  super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
105
106
  }
@@ -107,7 +108,7 @@ class xe extends T {
107
108
  return "ERR_JOSE_ALG_NOT_ALLOWED";
108
109
  }
109
110
  }
110
- class K extends T {
111
+ class F extends C {
111
112
  constructor() {
112
113
  super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
113
114
  }
@@ -115,7 +116,7 @@ class K extends T {
115
116
  return "ERR_JOSE_NOT_SUPPORTED";
116
117
  }
117
118
  }
118
- let h = class extends T {
119
+ let h = class extends C {
119
120
  constructor() {
120
121
  super(...arguments), this.code = "ERR_JWS_INVALID";
121
122
  }
@@ -123,7 +124,7 @@ let h = class extends T {
123
124
  return "ERR_JWS_INVALID";
124
125
  }
125
126
  };
126
- class me extends T {
127
+ class Se extends C {
127
128
  constructor() {
128
129
  super(...arguments), this.code = "ERR_JWT_INVALID";
129
130
  }
@@ -131,7 +132,7 @@ class me extends T {
131
132
  return "ERR_JWT_INVALID";
132
133
  }
133
134
  }
134
- class je extends T {
135
+ class Ve extends C {
135
136
  constructor() {
136
137
  super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
137
138
  }
@@ -139,16 +140,16 @@ class je extends T {
139
140
  return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
140
141
  }
141
142
  }
142
- function S(e, t = "algorithm.name") {
143
+ function _(e, t = "algorithm.name") {
143
144
  return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
144
145
  }
145
- function D(e, t) {
146
+ function $(e, t) {
146
147
  return e.name === t;
147
148
  }
148
- function j(e) {
149
+ function q(e) {
149
150
  return parseInt(e.name.slice(4), 10);
150
151
  }
151
- function Me(e) {
152
+ function Ye(e) {
152
153
  switch (e) {
153
154
  case "ES256":
154
155
  return "P-256";
@@ -160,7 +161,7 @@ function Me(e) {
160
161
  throw new Error("unreachable");
161
162
  }
162
163
  }
163
- function Ve(e, t) {
164
+ function Fe(e, t) {
164
165
  if (t.length && !t.some((o) => e.usages.includes(o))) {
165
166
  let o = "CryptoKey does not support this operation, its usages must include ";
166
167
  if (t.length > 2) {
@@ -176,78 +177,78 @@ function Ge(e, t, ...o) {
176
177
  case "HS256":
177
178
  case "HS384":
178
179
  case "HS512": {
179
- if (!D(e.algorithm, "HMAC"))
180
- throw S("HMAC");
180
+ if (!$(e.algorithm, "HMAC"))
181
+ throw _("HMAC");
181
182
  const r = parseInt(t.slice(2), 10);
182
- if (j(e.algorithm.hash) !== r)
183
- throw S(`SHA-${r}`, "algorithm.hash");
183
+ if (q(e.algorithm.hash) !== r)
184
+ throw _(`SHA-${r}`, "algorithm.hash");
184
185
  break;
185
186
  }
186
187
  case "RS256":
187
188
  case "RS384":
188
189
  case "RS512": {
189
- if (!D(e.algorithm, "RSASSA-PKCS1-v1_5"))
190
- throw S("RSASSA-PKCS1-v1_5");
190
+ if (!$(e.algorithm, "RSASSA-PKCS1-v1_5"))
191
+ throw _("RSASSA-PKCS1-v1_5");
191
192
  const r = parseInt(t.slice(2), 10);
192
- if (j(e.algorithm.hash) !== r)
193
- throw S(`SHA-${r}`, "algorithm.hash");
193
+ if (q(e.algorithm.hash) !== r)
194
+ throw _(`SHA-${r}`, "algorithm.hash");
194
195
  break;
195
196
  }
196
197
  case "PS256":
197
198
  case "PS384":
198
199
  case "PS512": {
199
- if (!D(e.algorithm, "RSA-PSS"))
200
- throw S("RSA-PSS");
200
+ if (!$(e.algorithm, "RSA-PSS"))
201
+ throw _("RSA-PSS");
201
202
  const r = parseInt(t.slice(2), 10);
202
- if (j(e.algorithm.hash) !== r)
203
- throw S(`SHA-${r}`, "algorithm.hash");
203
+ if (q(e.algorithm.hash) !== r)
204
+ throw _(`SHA-${r}`, "algorithm.hash");
204
205
  break;
205
206
  }
206
207
  case "EdDSA": {
207
208
  if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
208
- throw S("Ed25519 or Ed448");
209
+ throw _("Ed25519 or Ed448");
209
210
  break;
210
211
  }
211
212
  case "ES256":
212
213
  case "ES384":
213
214
  case "ES512": {
214
- if (!D(e.algorithm, "ECDSA"))
215
- throw S("ECDSA");
216
- const r = Me(t);
215
+ if (!$(e.algorithm, "ECDSA"))
216
+ throw _("ECDSA");
217
+ const r = Ye(t);
217
218
  if (e.algorithm.namedCurve !== r)
218
- throw S(r, "algorithm.namedCurve");
219
+ throw _(r, "algorithm.namedCurve");
219
220
  break;
220
221
  }
221
222
  default:
222
223
  throw new TypeError("CryptoKey does not support this operation");
223
224
  }
224
- Ve(e, o);
225
+ Fe(e, o);
225
226
  }
226
- function we(e, t, ...o) {
227
+ function ge(e, t, ...o) {
227
228
  var r;
228
229
  if (o.length > 2) {
229
- const n = o.pop();
230
- e += `one of type ${o.join(", ")}, or ${n}.`;
230
+ const a = o.pop();
231
+ e += `one of type ${o.join(", ")}, or ${a}.`;
231
232
  } else
232
233
  o.length === 2 ? e += `one of type ${o[0]} or ${o[1]}.` : e += `of type ${o[0]}.`;
233
234
  return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (r = t.constructor) != null && r.name && (e += ` Received an instance of ${t.constructor.name}`), e;
234
235
  }
235
- const re = (e, ...t) => we("Key must be ", e, ...t);
236
- function ge(e, t, ...o) {
237
- return we(`Key for the ${e} algorithm must be `, t, ...o);
236
+ const ne = (e, ...t) => ge("Key must be ", e, ...t);
237
+ function Ae(e, t, ...o) {
238
+ return ge(`Key for the ${e} algorithm must be `, t, ...o);
238
239
  }
239
- const Se = (e) => ye(e), b = ["CryptoKey"], Ye = (...e) => {
240
+ const _e = (e) => Ee(e), I = ["CryptoKey"], Be = (...e) => {
240
241
  const t = e.filter(Boolean);
241
242
  if (t.length === 0 || t.length === 1)
242
243
  return !0;
243
244
  let o;
244
245
  for (const r of t) {
245
- const n = Object.keys(r);
246
+ const a = Object.keys(r);
246
247
  if (!o || o.size === 0) {
247
- o = new Set(n);
248
+ o = new Set(a);
248
249
  continue;
249
250
  }
250
- for (const s of n) {
251
+ for (const s of a) {
251
252
  if (o.has(s))
252
253
  return !1;
253
254
  o.add(s);
@@ -255,11 +256,11 @@ const Se = (e) => ye(e), b = ["CryptoKey"], Ye = (...e) => {
255
256
  }
256
257
  return !0;
257
258
  };
258
- function Be(e) {
259
+ function qe(e) {
259
260
  return typeof e == "object" && e !== null;
260
261
  }
261
- function B(e) {
262
- if (!Be(e) || Object.prototype.toString.call(e) !== "[object Object]")
262
+ function ee(e) {
263
+ if (!qe(e) || Object.prototype.toString.call(e) !== "[object Object]")
263
264
  return !1;
264
265
  if (Object.getPrototypeOf(e) === null)
265
266
  return !0;
@@ -268,51 +269,51 @@ function B(e) {
268
269
  t = Object.getPrototypeOf(t);
269
270
  return Object.getPrototypeOf(e) === t;
270
271
  }
271
- const Fe = (e, t) => {
272
+ const ze = (e, t) => {
272
273
  if (e.startsWith("RS") || e.startsWith("PS")) {
273
274
  const { modulusLength: o } = t.algorithm;
274
275
  if (typeof o != "number" || o < 2048)
275
276
  throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
276
277
  }
277
- }, A = (e, t, o = 0) => {
278
+ }, b = (e, t, o = 0) => {
278
279
  o === 0 && (t.unshift(t.length), t.unshift(6));
279
280
  const r = e.indexOf(t[0], o);
280
281
  if (r === -1)
281
282
  return !1;
282
- const n = e.subarray(r, r + t.length);
283
- return n.length !== t.length ? !1 : n.every((s, a) => s === t[a]) || A(e, t, r + 1);
284
- }, oe = (e) => {
283
+ const a = e.subarray(r, r + t.length);
284
+ return a.length !== t.length ? !1 : a.every((s, n) => s === t[n]) || b(e, t, r + 1);
285
+ }, se = (e) => {
285
286
  switch (!0) {
286
- case A(e, [42, 134, 72, 206, 61, 3, 1, 7]):
287
+ case b(e, [42, 134, 72, 206, 61, 3, 1, 7]):
287
288
  return "P-256";
288
- case A(e, [43, 129, 4, 0, 34]):
289
+ case b(e, [43, 129, 4, 0, 34]):
289
290
  return "P-384";
290
- case A(e, [43, 129, 4, 0, 35]):
291
+ case b(e, [43, 129, 4, 0, 35]):
291
292
  return "P-521";
292
- case A(e, [43, 101, 110]):
293
+ case b(e, [43, 101, 110]):
293
294
  return "X25519";
294
- case A(e, [43, 101, 111]):
295
+ case b(e, [43, 101, 111]):
295
296
  return "X448";
296
- case A(e, [43, 101, 112]):
297
+ case b(e, [43, 101, 112]):
297
298
  return "Ed25519";
298
- case A(e, [43, 101, 113]):
299
+ case b(e, [43, 101, 113]):
299
300
  return "Ed448";
300
301
  default:
301
- throw new K("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
302
+ throw new F("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
302
303
  }
303
- }, qe = async (e, t, o, r, n) => {
304
- let s, a;
305
- const c = new Uint8Array(atob(o.replace(e, "")).split("").map((i) => i.charCodeAt(0)));
304
+ }, Xe = async (e, t, o, r, a) => {
305
+ let s, n;
306
+ const i = new Uint8Array(atob(o.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
306
307
  switch (r) {
307
308
  case "PS256":
308
309
  case "PS384":
309
310
  case "PS512":
310
- s = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` }, a = ["verify"];
311
+ s = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` }, n = ["verify"];
311
312
  break;
312
313
  case "RS256":
313
314
  case "RS384":
314
315
  case "RS512":
315
- s = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` }, a = ["verify"];
316
+ s = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` }, n = ["verify"];
316
317
  break;
317
318
  case "RSA-OAEP":
318
319
  case "RSA-OAEP-256":
@@ -321,83 +322,83 @@ const Fe = (e, t) => {
321
322
  s = {
322
323
  name: "RSA-OAEP",
323
324
  hash: `SHA-${parseInt(r.slice(-3), 10) || 1}`
324
- }, a = ["encrypt", "wrapKey"];
325
+ }, n = ["encrypt", "wrapKey"];
325
326
  break;
326
327
  case "ES256":
327
- s = { name: "ECDSA", namedCurve: "P-256" }, a = ["verify"];
328
+ s = { name: "ECDSA", namedCurve: "P-256" }, n = ["verify"];
328
329
  break;
329
330
  case "ES384":
330
- s = { name: "ECDSA", namedCurve: "P-384" }, a = ["verify"];
331
+ s = { name: "ECDSA", namedCurve: "P-384" }, n = ["verify"];
331
332
  break;
332
333
  case "ES512":
333
- s = { name: "ECDSA", namedCurve: "P-521" }, a = ["verify"];
334
+ s = { name: "ECDSA", namedCurve: "P-521" }, n = ["verify"];
334
335
  break;
335
336
  case "ECDH-ES":
336
337
  case "ECDH-ES+A128KW":
337
338
  case "ECDH-ES+A192KW":
338
339
  case "ECDH-ES+A256KW": {
339
- const i = oe(c);
340
- s = i.startsWith("P-") ? { name: "ECDH", namedCurve: i } : { name: i }, a = [];
340
+ const c = se(i);
341
+ s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, n = [];
341
342
  break;
342
343
  }
343
344
  case "EdDSA":
344
- s = { name: oe(c) }, a = ["verify"];
345
+ s = { name: se(i) }, n = ["verify"];
345
346
  break;
346
347
  default:
347
- throw new K('Invalid or unsupported "alg" (Algorithm) value');
348
+ throw new F('Invalid or unsupported "alg" (Algorithm) value');
348
349
  }
349
- return z.subtle.importKey(t, c, s, !1, a);
350
- }, ze = (e, t, o) => qe(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
351
- async function Xe(e, t, o) {
350
+ return te.subtle.importKey(t, i, s, !1, n);
351
+ }, Qe = (e, t, o) => Xe(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
352
+ async function Ze(e, t, o) {
352
353
  if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
353
354
  throw new TypeError('"spki" must be SPKI formatted string');
354
- return ze(e, t);
355
+ return Qe(e, t);
355
356
  }
356
- const Qe = (e, t) => {
357
+ const et = (e, t) => {
357
358
  if (!(t instanceof Uint8Array)) {
358
- if (!Se(t))
359
- throw new TypeError(ge(e, t, ...b, "Uint8Array"));
359
+ if (!_e(t))
360
+ throw new TypeError(Ae(e, t, ...I, "Uint8Array"));
360
361
  if (t.type !== "secret")
361
- throw new TypeError(`${b.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
362
+ throw new TypeError(`${I.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
362
363
  }
363
- }, Ze = (e, t, o) => {
364
- if (!Se(t))
365
- throw new TypeError(ge(e, t, ...b));
364
+ }, tt = (e, t, o) => {
365
+ if (!_e(t))
366
+ throw new TypeError(Ae(e, t, ...I));
366
367
  if (t.type === "secret")
367
- throw new TypeError(`${b.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
368
+ throw new TypeError(`${I.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
368
369
  if (t.algorithm && o === "verify" && t.type === "private")
369
- throw new TypeError(`${b.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
370
+ throw new TypeError(`${I.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
370
371
  if (t.algorithm && o === "encrypt" && t.type === "private")
371
- throw new TypeError(`${b.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
372
- }, et = (e, t, o) => {
373
- e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Qe(e, t) : Ze(e, t, o);
372
+ throw new TypeError(`${I.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
373
+ }, rt = (e, t, o) => {
374
+ e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? et(e, t) : tt(e, t, o);
374
375
  };
375
- function tt(e, t, o, r, n) {
376
- if (n.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
376
+ function ot(e, t, o, r, a) {
377
+ if (a.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
377
378
  throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
378
379
  if (!r || r.crit === void 0)
379
380
  return /* @__PURE__ */ new Set();
380
- if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((a) => typeof a != "string" || a.length === 0))
381
+ if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((n) => typeof n != "string" || n.length === 0))
381
382
  throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
382
383
  let s;
383
384
  o !== void 0 ? s = new Map([...Object.entries(o), ...t.entries()]) : s = t;
384
- for (const a of r.crit) {
385
- if (!s.has(a))
386
- throw new K(`Extension Header Parameter "${a}" is not recognized`);
387
- if (n[a] === void 0)
388
- throw new e(`Extension Header Parameter "${a}" is missing`);
389
- if (s.get(a) && r[a] === void 0)
390
- throw new e(`Extension Header Parameter "${a}" MUST be integrity protected`);
385
+ for (const n of r.crit) {
386
+ if (!s.has(n))
387
+ throw new F(`Extension Header Parameter "${n}" is not recognized`);
388
+ if (a[n] === void 0)
389
+ throw new e(`Extension Header Parameter "${n}" is missing`);
390
+ if (s.get(n) && r[n] === void 0)
391
+ throw new e(`Extension Header Parameter "${n}" MUST be integrity protected`);
391
392
  }
392
393
  return new Set(r.crit);
393
394
  }
394
- const rt = (e, t) => {
395
+ const at = (e, t) => {
395
396
  if (t !== void 0 && (!Array.isArray(t) || t.some((o) => typeof o != "string")))
396
397
  throw new TypeError(`"${e}" option must be an array of strings`);
397
398
  if (t)
398
399
  return new Set(t);
399
400
  };
400
- function ot(e, t) {
401
+ function nt(e, t) {
401
402
  const o = `SHA-${e.slice(-3)}`;
402
403
  switch (e) {
403
404
  case "HS256":
@@ -419,31 +420,31 @@ function ot(e, t) {
419
420
  case "EdDSA":
420
421
  return { name: t.name };
421
422
  default:
422
- throw new K(`alg ${e} is not supported either by JOSE or your javascript runtime`);
423
+ throw new F(`alg ${e} is not supported either by JOSE or your javascript runtime`);
423
424
  }
424
425
  }
425
- function nt(e, t, o) {
426
- if (ye(t))
426
+ function st(e, t, o) {
427
+ if (Ee(t))
427
428
  return Ge(t, e, o), t;
428
429
  if (t instanceof Uint8Array) {
429
430
  if (!e.startsWith("HS"))
430
- throw new TypeError(re(t, ...b));
431
- return z.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [o]);
431
+ throw new TypeError(ne(t, ...I));
432
+ return te.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [o]);
432
433
  }
433
- throw new TypeError(re(t, ...b, "Uint8Array"));
434
+ throw new TypeError(ne(t, ...I, "Uint8Array"));
434
435
  }
435
- const at = async (e, t, o, r) => {
436
- const n = await nt(e, t, "verify");
437
- Fe(e, n);
438
- const s = ot(e, n.algorithm);
436
+ const ct = async (e, t, o, r) => {
437
+ const a = await st(e, t, "verify");
438
+ ze(e, a);
439
+ const s = nt(e, a.algorithm);
439
440
  try {
440
- return await z.subtle.verify(s, n, o, r);
441
+ return await te.subtle.verify(s, a, o, r);
441
442
  } catch {
442
443
  return !1;
443
444
  }
444
445
  };
445
- async function st(e, t, o) {
446
- if (!B(e))
446
+ async function it(e, t, o) {
447
+ if (!ee(e))
447
448
  throw new h("Flattened JWS must be an object");
448
449
  if (e.protected === void 0 && e.header === void 0)
449
450
  throw new h('Flattened JWS must have either of the "protected" or "header" members');
@@ -453,327 +454,327 @@ async function st(e, t, o) {
453
454
  throw new h("JWS Payload missing");
454
455
  if (typeof e.signature != "string")
455
456
  throw new h("JWS Signature missing or incorrect type");
456
- if (e.header !== void 0 && !B(e.header))
457
+ if (e.header !== void 0 && !ee(e.header))
457
458
  throw new h("JWS Unprotected Header incorrect type");
458
459
  let r = {};
459
460
  if (e.protected)
460
461
  try {
461
- const p = x(e.protected);
462
- r = JSON.parse(J.decode(p));
462
+ const m = B(e.protected);
463
+ r = JSON.parse(Y.decode(m));
463
464
  } catch {
464
465
  throw new h("JWS Protected Header is invalid");
465
466
  }
466
- if (!Ye(r, e.header))
467
+ if (!Be(r, e.header))
467
468
  throw new h("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
468
- const n = {
469
+ const a = {
469
470
  ...r,
470
471
  ...e.header
471
- }, s = tt(h, /* @__PURE__ */ new Map([["b64", !0]]), o == null ? void 0 : o.crit, r, n);
472
- let a = !0;
473
- if (s.has("b64") && (a = r.b64, typeof a != "boolean"))
472
+ }, s = ot(h, /* @__PURE__ */ new Map([["b64", !0]]), o == null ? void 0 : o.crit, r, a);
473
+ let n = !0;
474
+ if (s.has("b64") && (n = r.b64, typeof n != "boolean"))
474
475
  throw new h('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
475
- const { alg: c } = n;
476
- if (typeof c != "string" || !c)
476
+ const { alg: i } = a;
477
+ if (typeof i != "string" || !i)
477
478
  throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');
478
- const i = o && rt("algorithms", o.algorithms);
479
- if (i && !i.has(c))
480
- throw new xe('"alg" (Algorithm) Header Parameter value not allowed');
481
- if (a) {
479
+ const c = o && at("algorithms", o.algorithms);
480
+ if (c && !c.has(i))
481
+ throw new Me('"alg" (Algorithm) Header Parameter value not allowed');
482
+ if (n) {
482
483
  if (typeof e.payload != "string")
483
484
  throw new h("JWS Payload must be a string");
484
485
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
485
486
  throw new h("JWS Payload must be a string or an Uint8Array instance");
486
487
  let u = !1;
487
- typeof t == "function" && (t = await t(r, e), u = !0), et(c, t, "verify");
488
- const m = Ke(P.encode(e.protected ?? ""), P.encode("."), typeof e.payload == "string" ? P.encode(e.payload) : e.payload);
489
- let f;
488
+ typeof t == "function" && (t = await t(r, e), u = !0), rt(i, t, "verify");
489
+ const y = xe(L.encode(e.protected ?? ""), L.encode("."), typeof e.payload == "string" ? L.encode(e.payload) : e.payload);
490
+ let p;
490
491
  try {
491
- f = x(e.signature);
492
+ p = B(e.signature);
492
493
  } catch {
493
494
  throw new h("Failed to base64url decode the signature");
494
495
  }
495
- if (!await at(c, t, f, m))
496
- throw new je();
497
- let E;
498
- if (a)
496
+ if (!await ct(i, t, p, y))
497
+ throw new Ve();
498
+ let T;
499
+ if (n)
499
500
  try {
500
- E = x(e.payload);
501
+ T = B(e.payload);
501
502
  } catch {
502
503
  throw new h("Failed to base64url decode the payload");
503
504
  }
504
505
  else
505
- typeof e.payload == "string" ? E = P.encode(e.payload) : E = e.payload;
506
- const y = { payload: E };
507
- return e.protected !== void 0 && (y.protectedHeader = r), e.header !== void 0 && (y.unprotectedHeader = e.header), u ? { ...y, key: t } : y;
506
+ typeof e.payload == "string" ? T = L.encode(e.payload) : T = e.payload;
507
+ const E = { payload: T };
508
+ return e.protected !== void 0 && (E.protectedHeader = r), e.header !== void 0 && (E.unprotectedHeader = e.header), u ? { ...E, key: t } : E;
508
509
  }
509
- async function it(e, t, o) {
510
- if (e instanceof Uint8Array && (e = J.decode(e)), typeof e != "string")
510
+ async function ut(e, t, o) {
511
+ if (e instanceof Uint8Array && (e = Y.decode(e)), typeof e != "string")
511
512
  throw new h("Compact JWS must be a string or Uint8Array");
512
- const { 0: r, 1: n, 2: s, length: a } = e.split(".");
513
- if (a !== 3)
513
+ const { 0: r, 1: a, 2: s, length: n } = e.split(".");
514
+ if (n !== 3)
514
515
  throw new h("Invalid Compact JWS");
515
- const c = await st({ payload: n, protected: r, signature: s }, t, o), i = { payload: c.payload, protectedHeader: c.protectedHeader };
516
- return typeof t == "function" ? { ...i, key: c.key } : i;
516
+ const i = await it({ payload: a, protected: r, signature: s }, t, o), c = { payload: i.payload, protectedHeader: i.protectedHeader };
517
+ return typeof t == "function" ? { ...c, key: i.key } : c;
517
518
  }
518
- const ct = (e) => Math.floor(e.getTime() / 1e3), Ee = 60, Ae = Ee * 60, X = Ae * 24, ut = X * 7, dt = X * 365.25, lt = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, ne = (e) => {
519
- const t = lt.exec(e);
519
+ const dt = (e) => Math.floor(e.getTime() / 1e3), Te = 60, be = Te * 60, re = be * 24, lt = re * 7, ht = re * 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, ce = (e) => {
520
+ const t = pt.exec(e);
520
521
  if (!t || t[4] && t[1])
521
522
  throw new TypeError("Invalid time period format");
522
523
  const o = parseFloat(t[2]), r = t[3].toLowerCase();
523
- let n;
524
+ let a;
524
525
  switch (r) {
525
526
  case "sec":
526
527
  case "secs":
527
528
  case "second":
528
529
  case "seconds":
529
530
  case "s":
530
- n = Math.round(o);
531
+ a = Math.round(o);
531
532
  break;
532
533
  case "minute":
533
534
  case "minutes":
534
535
  case "min":
535
536
  case "mins":
536
537
  case "m":
537
- n = Math.round(o * Ee);
538
+ a = Math.round(o * Te);
538
539
  break;
539
540
  case "hour":
540
541
  case "hours":
541
542
  case "hr":
542
543
  case "hrs":
543
544
  case "h":
544
- n = Math.round(o * Ae);
545
+ a = Math.round(o * be);
545
546
  break;
546
547
  case "day":
547
548
  case "days":
548
549
  case "d":
549
- n = Math.round(o * X);
550
+ a = Math.round(o * re);
550
551
  break;
551
552
  case "week":
552
553
  case "weeks":
553
554
  case "w":
554
- n = Math.round(o * ut);
555
+ a = Math.round(o * lt);
555
556
  break;
556
557
  default:
557
- n = Math.round(o * dt);
558
+ a = Math.round(o * ht);
558
559
  break;
559
560
  }
560
- return t[1] === "-" || t[4] === "ago" ? -n : n;
561
- }, ae = (e) => e.toLowerCase().replace(/^application\//, ""), ht = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, pt = (e, t, o = {}) => {
561
+ return t[1] === "-" || t[4] === "ago" ? -a : a;
562
+ }, ie = (e) => e.toLowerCase().replace(/^application\//, ""), ft = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, yt = (e, t, o = {}) => {
562
563
  let r;
563
564
  try {
564
- r = JSON.parse(J.decode(t));
565
+ r = JSON.parse(Y.decode(t));
565
566
  } catch {
566
567
  }
567
- if (!B(r))
568
- throw new me("JWT Claims Set must be a top-level JSON object");
569
- const { typ: n } = o;
570
- if (n && (typeof e.typ != "string" || ae(e.typ) !== ae(n)))
571
- throw new w('unexpected "typ" JWT header value', r, "typ", "check_failed");
572
- const { requiredClaims: s = [], issuer: a, subject: c, audience: i, maxTokenAge: u } = o, m = [...s];
573
- u !== void 0 && m.push("iat"), i !== void 0 && m.push("aud"), c !== void 0 && m.push("sub"), a !== void 0 && m.push("iss");
574
- for (const p of new Set(m.reverse()))
575
- if (!(p in r))
576
- throw new w(`missing required "${p}" claim`, r, p, "missing");
577
- if (a && !(Array.isArray(a) ? a : [a]).includes(r.iss))
578
- throw new w('unexpected "iss" claim value', r, "iss", "check_failed");
579
- if (c && r.sub !== c)
580
- throw new w('unexpected "sub" claim value', r, "sub", "check_failed");
581
- if (i && !ht(r.aud, typeof i == "string" ? [i] : i))
582
- throw new w('unexpected "aud" claim value', r, "aud", "check_failed");
583
- let f;
568
+ if (!ee(r))
569
+ throw new Se("JWT Claims Set must be a top-level JSON object");
570
+ const { typ: a } = o;
571
+ if (a && (typeof e.typ != "string" || ie(e.typ) !== ie(a)))
572
+ throw new g('unexpected "typ" JWT header value', r, "typ", "check_failed");
573
+ const { requiredClaims: s = [], issuer: n, subject: i, audience: c, maxTokenAge: u } = o, y = [...s];
574
+ u !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"), n !== void 0 && y.push("iss");
575
+ for (const m of new Set(y.reverse()))
576
+ if (!(m in r))
577
+ throw new g(`missing required "${m}" claim`, r, m, "missing");
578
+ if (n && !(Array.isArray(n) ? n : [n]).includes(r.iss))
579
+ throw new g('unexpected "iss" claim value', r, "iss", "check_failed");
580
+ if (i && r.sub !== i)
581
+ throw new g('unexpected "sub" claim value', r, "sub", "check_failed");
582
+ if (c && !ft(r.aud, typeof c == "string" ? [c] : c))
583
+ throw new g('unexpected "aud" claim value', r, "aud", "check_failed");
584
+ let p;
584
585
  switch (typeof o.clockTolerance) {
585
586
  case "string":
586
- f = ne(o.clockTolerance);
587
+ p = ce(o.clockTolerance);
587
588
  break;
588
589
  case "number":
589
- f = o.clockTolerance;
590
+ p = o.clockTolerance;
590
591
  break;
591
592
  case "undefined":
592
- f = 0;
593
+ p = 0;
593
594
  break;
594
595
  default:
595
596
  throw new TypeError("Invalid clockTolerance option type");
596
597
  }
597
- const { currentDate: E } = o, y = ct(E || /* @__PURE__ */ new Date());
598
+ const { currentDate: T } = o, E = dt(T || /* @__PURE__ */ new Date());
598
599
  if ((r.iat !== void 0 || u) && typeof r.iat != "number")
599
- throw new w('"iat" claim must be a number', r, "iat", "invalid");
600
+ throw new g('"iat" claim must be a number', r, "iat", "invalid");
600
601
  if (r.nbf !== void 0) {
601
602
  if (typeof r.nbf != "number")
602
- throw new w('"nbf" claim must be a number', r, "nbf", "invalid");
603
- if (r.nbf > y + f)
604
- throw new w('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
603
+ throw new g('"nbf" claim must be a number', r, "nbf", "invalid");
604
+ if (r.nbf > E + p)
605
+ throw new g('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
605
606
  }
606
607
  if (r.exp !== void 0) {
607
608
  if (typeof r.exp != "number")
608
- throw new w('"exp" claim must be a number', r, "exp", "invalid");
609
- if (r.exp <= y - f)
610
- throw new te('"exp" claim timestamp check failed', r, "exp", "check_failed");
609
+ throw new g('"exp" claim must be a number', r, "exp", "invalid");
610
+ if (r.exp <= E - p)
611
+ throw new ae('"exp" claim timestamp check failed', r, "exp", "check_failed");
611
612
  }
612
613
  if (u) {
613
- const p = y - r.iat, v = typeof u == "number" ? u : ne(u);
614
- if (p - f > v)
615
- throw new te('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
616
- if (p < 0 - f)
617
- throw new w('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
614
+ const m = E - r.iat, v = typeof u == "number" ? u : ce(u);
615
+ if (m - p > v)
616
+ throw new ae('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
617
+ if (m < 0 - p)
618
+ throw new g('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
618
619
  }
619
620
  return r;
620
621
  };
621
- async function ft(e, t, o) {
622
+ async function mt(e, t, o) {
622
623
  var r;
623
- const n = await it(e, t, o);
624
- if ((r = n.protectedHeader.crit) != null && r.includes("b64") && n.protectedHeader.b64 === !1)
625
- throw new me("JWTs MUST NOT use unencoded payload");
626
- const s = { payload: pt(n.protectedHeader, n.payload, o), protectedHeader: n.protectedHeader };
627
- return typeof t == "function" ? { ...s, key: n.key } : s;
624
+ const a = await ut(e, t, o);
625
+ if ((r = a.protectedHeader.crit) != null && r.includes("b64") && a.protectedHeader.b64 === !1)
626
+ throw new Se("JWTs MUST NOT use unencoded payload");
627
+ const s = { payload: yt(a.protectedHeader, a.payload, o), protectedHeader: a.protectedHeader };
628
+ return typeof t == "function" ? { ...s, key: a.key } : s;
628
629
  }
629
- const be = async (e) => {
630
+ const N = async (e) => {
630
631
  try {
631
- const t = _.ALG, o = await Xe(Je, t);
632
- return await ft(e, o, {
633
- issuer: _.ISSUER
632
+ const t = f.ALG, o = await Ze(We, t);
633
+ return await mt(e, o, {
634
+ issuer: f.ISSUER
634
635
  });
635
636
  } catch {
636
637
  return;
637
638
  }
638
639
  };
639
640
  var d = [];
640
- for (var M = 0; M < 256; ++M)
641
- d.push((M + 256).toString(16).slice(1));
642
- function yt(e, t = 0) {
641
+ for (var z = 0; z < 256; ++z)
642
+ d.push((z + 256).toString(16).slice(1));
643
+ function wt(e, t = 0) {
643
644
  return (d[e[t + 0]] + d[e[t + 1]] + d[e[t + 2]] + d[e[t + 3]] + "-" + d[e[t + 4]] + d[e[t + 5]] + "-" + d[e[t + 6]] + d[e[t + 7]] + "-" + d[e[t + 8]] + d[e[t + 9]] + "-" + d[e[t + 10]] + d[e[t + 11]] + d[e[t + 12]] + d[e[t + 13]] + d[e[t + 14]] + d[e[t + 15]]).toLowerCase();
644
645
  }
645
- var U, mt = new Uint8Array(16);
646
- function wt() {
647
- if (!U && (U = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !U))
646
+ var K, Et = new Uint8Array(16);
647
+ function St() {
648
+ if (!K && (K = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !K))
648
649
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
649
- return U(mt);
650
+ return K(Et);
650
651
  }
651
652
  var gt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
652
- const se = {
653
+ const ue = {
653
654
  randomUUID: gt
654
655
  };
655
- function ie(e, t, o) {
656
- if (se.randomUUID && !t && !e)
657
- return se.randomUUID();
656
+ function de(e, t, o) {
657
+ if (ue.randomUUID && !t && !e)
658
+ return ue.randomUUID();
658
659
  e = e || {};
659
- var r = e.random || (e.rng || wt)();
660
- return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, yt(r);
660
+ var r = e.random || (e.rng || St)();
661
+ return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, wt(r);
661
662
  }
662
- const ce = globalThis.crypto, St = (e) => `${ie()}${ie()}`.slice(0, e), Et = (e) => btoa(
663
+ const le = globalThis.crypto, At = (e) => `${de()}${de()}`.slice(0, e), _t = (e) => btoa(
663
664
  [...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
664
665
  );
665
- async function At(e) {
666
- if (!ce.subtle)
666
+ async function Tt(e) {
667
+ if (!le.subtle)
667
668
  throw new Error(
668
669
  "crypto.subtle is available only in secure contexts (HTTPS)."
669
670
  );
670
- const t = new TextEncoder().encode(e), o = await ce.subtle.digest("SHA-256", t);
671
- return Et(o).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
671
+ const t = new TextEncoder().encode(e), o = await le.subtle.digest("SHA-256", t);
672
+ return _t(o).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
672
673
  }
673
674
  async function bt(e) {
674
- const o = St(43), r = await At(o);
675
+ const o = At(43), r = await Tt(o);
675
676
  return {
676
677
  code_verifier: o,
677
678
  code_challenge: r
678
679
  };
679
680
  }
680
- function _e(e, t) {
681
+ function Ie(e, t) {
681
682
  window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
682
683
  }
683
- const ue = (e, t) => {
684
+ const he = (e, t) => {
684
685
  const o = JSON.stringify(
685
686
  typeof t == "function" ? t() : t
686
687
  );
687
- window.localStorage.setItem(e, o), _e(e, o);
688
- }, _t = (e) => {
689
- window.localStorage.removeItem(e), _e(e, null);
690
- }, de = (e) => window.localStorage.getItem(e), Tt = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
691
- function N({
688
+ window.localStorage.setItem(e, o), Ie(e, o);
689
+ }, It = (e) => {
690
+ window.localStorage.removeItem(e), Ie(e, null);
691
+ }, pe = (e) => window.localStorage.getItem(e), vt = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
692
+ function J({
692
693
  key: e,
693
694
  initialValue: t
694
695
  }) {
695
- const o = () => de(e), r = C.useSyncExternalStore(
696
- Tt,
696
+ const o = () => pe(e), r = D.useSyncExternalStore(
697
+ vt,
697
698
  o
698
- ), n = C.useCallback(
699
- (c) => {
699
+ ), a = D.useCallback(
700
+ (i) => {
700
701
  try {
701
- const i = typeof c == "function" ? c(JSON.parse(r)) : c;
702
- i == null ? _t(e) : ue(e, i);
703
- } catch (i) {
704
- console.warn(i);
702
+ const c = typeof i == "function" ? i(JSON.parse(r)) : i;
703
+ c == null ? It(e) : he(e, c);
704
+ } catch (c) {
705
+ console.warn(c);
705
706
  }
706
707
  },
707
708
  [e, r]
708
- ), s = C.useCallback(() => {
709
- n(t);
710
- }, [t, n]), a = C.useCallback(() => {
711
- n(null);
712
- }, [n]);
713
- return C.useEffect(() => {
709
+ ), s = D.useCallback(() => {
710
+ a(t);
711
+ }, [t, a]), n = D.useCallback(() => {
712
+ a(null);
713
+ }, [a]);
714
+ return D.useEffect(() => {
714
715
  try {
715
- de(e) === null && typeof t < "u" && ue(e, t);
716
- } catch (c) {
717
- console.warn(c);
716
+ pe(e) === null && typeof t < "u" && he(e, t);
717
+ } catch (i) {
718
+ console.warn(i);
718
719
  }
719
- }, [e, t]), [r ? JSON.parse(r) : null, n, s, a];
720
+ }, [e, t]), [r ? JSON.parse(r) : null, a, s, n];
720
721
  }
721
722
  var l = [];
722
- for (var V = 0; V < 256; ++V)
723
- l.push((V + 256).toString(16).slice(1));
724
- function vt(e, t = 0) {
723
+ for (var X = 0; X < 256; ++X)
724
+ l.push((X + 256).toString(16).slice(1));
725
+ function Rt(e, t = 0) {
725
726
  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();
726
727
  }
727
- var H, It = new Uint8Array(16);
728
- function Rt() {
729
- if (!H && (H = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !H))
728
+ var W, kt = new Uint8Array(16);
729
+ function Ct() {
730
+ if (!W && (W = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !W))
730
731
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
731
- return H(It);
732
+ return W(kt);
732
733
  }
733
- var kt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
734
- const le = {
735
- randomUUID: kt
734
+ var Ot = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
735
+ const fe = {
736
+ randomUUID: Ot
736
737
  };
737
- function Ct(e, t, o) {
738
- if (le.randomUUID && !t && !e)
739
- return le.randomUUID();
738
+ function Pt(e, t, o) {
739
+ if (fe.randomUUID && !t && !e)
740
+ return fe.randomUUID();
740
741
  e = e || {};
741
- var r = e.random || (e.rng || Rt)();
742
- return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, vt(r);
742
+ var r = e.random || (e.rng || Ct)();
743
+ return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Rt(r);
743
744
  }
744
- const G = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Ot = "Your session has been successfully terminated.", he = "Login failed. Please try again.", Pt = "You forgot to wrap your component in <AuthProvider>.", pe = {
745
+ const Q = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Dt = "Your session has been successfully terminated.", ye = "Login failed. Please try again.", U = "Error getting access token, please re-authenticate.", Ut = "You forgot to wrap your component in <AuthProvider>.", me = {
745
746
  dev: "https://auth.gizmette.local.com:3003",
746
747
  prod: "https://mylogin.gizmette.com"
747
- }, L = "@@auth@@", Dt = process.env.NODE_ENV === "production", Ut = !Dt, Q = async ({
748
+ }, x = "@@auth@@", Nt = process.env.NODE_ENV === "production", Ht = !Nt, G = async ({
748
749
  type: e,
749
750
  clientId: t,
750
751
  params: o = {}
751
752
  }) => {
752
753
  try {
753
754
  const r = await fetch(
754
- Ut ? `${pe.dev}/${e}` : `${pe.prod}/${e}`,
755
+ Ht ? `${me.dev}/${e}` : `${me.prod}/${e}`,
755
756
  {
756
757
  credentials: "include",
757
758
  method: "POST",
758
759
  headers: {
759
760
  "Content-Type": "application/json",
760
- [$e.CLIENT_ID]: `${t}`
761
+ [Je.CLIENT_ID]: `${t}`
761
762
  },
762
763
  body: JSON.stringify(o)
763
764
  }
764
765
  );
765
766
  if (r.status !== 200)
766
767
  return { status: r.status, data: [] };
767
- const { data: n, errors: s } = await r.json();
768
+ const { data: a, errors: s } = await r.json();
768
769
  return {
769
770
  status: r.status,
770
- data: n,
771
+ data: a,
771
772
  errors: s
772
773
  };
773
774
  } catch (r) {
774
775
  return console.error(r), { status: 500, data: [] };
775
776
  }
776
- }, Y = async ({
777
+ }, Z = async ({
777
778
  idToken: e,
778
779
  accessToken: t,
779
780
  refreshToken: o,
@@ -781,8 +782,8 @@ const G = "Oops! It looks like your session has expired. For your security, plea
781
782
  }) => {
782
783
  try {
783
784
  return {
784
- status: (await Q({
785
- type: q.LOGOUT,
785
+ status: (await G({
786
+ type: V.LOGOUT,
786
787
  clientId: r,
787
788
  params: {
788
789
  idToken: e,
@@ -796,35 +797,35 @@ const G = "Oops! It looks like your session has expired. For your security, plea
796
797
  status: !1
797
798
  };
798
799
  }
799
- }, fe = async ({
800
+ }, we = async ({
800
801
  username: e,
801
802
  password: t,
802
803
  clientId: o,
803
804
  nonce: r,
804
- type: n,
805
+ type: a,
805
806
  sessionExpiration: s,
806
- code: a,
807
- code_verifier: c
807
+ code: n,
808
+ code_verifier: i
808
809
  }) => {
809
810
  try {
810
- const i = await Q({
811
- type: q.AUTHENTICATE,
811
+ const c = await G({
812
+ type: V.AUTHENTICATE,
812
813
  clientId: o,
813
814
  params: {
814
- type: n || F.ID_AND_ACCESS_TOKEN,
815
+ type: a || M.ID_AND_ACCESS_TOKEN,
815
816
  username: e,
816
817
  password: t,
817
818
  sessionExpiration: s,
818
819
  nonce: r,
819
- code: a,
820
- code_verifier: c
820
+ code: n,
821
+ code_verifier: i
821
822
  }
822
- }), u = await be(i.data.idToken);
823
- return u && u.payload[_.USER_ID_KEY] !== "" && u.payload[_.NONCE_KEY] === r ? {
824
- idToken: i.data.idToken,
825
- accessToken: i.data.accessToken,
826
- refreshToken: i.data.refreshToken,
827
- userId: u.payload[_.USER_ID_KEY],
823
+ }), u = await N(c.data.idToken);
824
+ return u && u.payload[f.USER_ID_KEY] !== "" && u.payload[f.NONCE_KEY] === r ? {
825
+ idToken: c.data.idToken,
826
+ accessToken: c.data.accessToken,
827
+ refreshToken: c.data.refreshToken,
828
+ userId: u.payload[f.USER_ID_KEY],
828
829
  status: !0
829
830
  } : {
830
831
  status: !1
@@ -834,17 +835,17 @@ const G = "Oops! It looks like your session has expired. For your security, plea
834
835
  status: !1
835
836
  };
836
837
  }
837
- }, Nt = async ({
838
+ }, Lt = async ({
838
839
  nonce: e,
839
840
  clientId: t,
840
841
  code_challenge: o
841
842
  }) => {
842
843
  try {
843
- const r = await Q({
844
- type: q.CODE,
844
+ const r = await G({
845
+ type: V.CODE,
845
846
  clientId: t,
846
847
  params: {
847
- type: F.CODE,
848
+ type: M.CODE,
848
849
  nonce: e,
849
850
  code_challenge: o
850
851
  }
@@ -860,144 +861,198 @@ const G = "Oops! It looks like your session has expired. For your security, plea
860
861
  status: !1
861
862
  };
862
863
  }
863
- }, $ = () => {
864
- throw new Error(Pt);
865
- }, Te = De({
864
+ }, $t = async ({
865
+ clientId: e,
866
+ userId: t,
867
+ nonce: o,
868
+ refreshToken: r,
869
+ accessToken: a
870
+ }) => {
871
+ try {
872
+ const s = await G({
873
+ type: V.AUTHENTICATE,
874
+ clientId: e,
875
+ params: {
876
+ type: M.REFRESH_TOKEN,
877
+ userId: t,
878
+ nonce: o,
879
+ refreshToken: r,
880
+ accessToken: a
881
+ }
882
+ }), n = await N(s.data.accessToken);
883
+ return n && n.payload[f.USER_ID_KEY] !== "" && n.payload[f.NONCE_KEY] === o ? {
884
+ accessToken: s.data.accessToken,
885
+ refreshToken: s.data.refreshToken,
886
+ userId: n.payload[f.USER_ID_KEY],
887
+ status: !0
888
+ } : {
889
+ status: !1
890
+ };
891
+ } catch {
892
+ return {
893
+ status: !1
894
+ };
895
+ }
896
+ }, j = () => {
897
+ throw new Error(Ut);
898
+ }, ve = Ne({
866
899
  isAuthenticated: !1,
867
900
  isLoading: !1,
868
- login: $,
869
- logout: $,
870
- getAccessToken: $,
871
- getIdToken: $,
901
+ login: j,
902
+ logout: j,
903
+ getAccessToken: j,
904
+ getIdToken: j,
872
905
  logoutReason: ""
873
- }), Jt = ({
906
+ }), xt = ({
874
907
  children: e,
875
908
  sessionExpiration: t,
876
909
  clientId: o
877
910
  }) => {
878
- const [r, n, , s] = N({
879
- key: `${L}::${o}::@@user@@`
880
- }), [a, c, , i] = N({
881
- key: `${L}::${o}::@@access@@`
882
- }), [u, m, , f] = N(
911
+ const [r, a, , s] = J({
912
+ key: `${x}::${o}::@@user@@`
913
+ }), [n, i, , c] = J({
914
+ key: `${x}::${o}::@@access@@`
915
+ }), [u, y, , p] = J(
883
916
  {
884
- key: `${L}::${o}::@@refresh@@`
917
+ key: `${x}::${o}::@@refresh@@`
885
918
  }
886
- ), [, E, , y] = N({
887
- key: `${L}::${o}::@@nonce@@`
888
- }), [p, v] = Ue({
919
+ ), [T, E, , m] = J({
920
+ key: `${x}::${o}::@@nonce@@`
921
+ }), [v, H] = He({
889
922
  isLoading: !0,
890
923
  isAuthenticated: !1,
891
924
  userId: "",
892
925
  logoutReason: ""
893
- }), I = Ne(
894
- (g) => {
895
- v({
926
+ }), A = Le(
927
+ (w) => {
928
+ H({
896
929
  isLoading: !1,
897
930
  isAuthenticated: !1,
898
931
  userId: "",
899
- logoutReason: g || G
900
- }), s(), i(), f(), y();
932
+ logoutReason: w || Q
933
+ }), s(), c(), p(), m();
901
934
  },
902
- [s, i, y, f]
935
+ [s, c, m, p]
903
936
  );
904
- He(() => {
905
- p.isLoading && r !== null && (async () => {
937
+ $e(() => {
938
+ v.isLoading && r !== null && (async () => {
906
939
  try {
907
- const g = await be(r);
908
- g && g.payload[_.USER_ID_KEY] !== "" ? v({
940
+ const w = await N(r);
941
+ w && w.payload[f.USER_ID_KEY] !== "" ? H({
909
942
  isLoading: !1,
910
943
  isAuthenticated: !0,
911
- userId: g.payload[_.USER_ID_KEY],
944
+ userId: w.payload[f.USER_ID_KEY],
912
945
  logoutReason: ""
913
- }) : (I(G), await Y({
946
+ }) : (A(Q), await Z({
914
947
  idToken: r,
915
- accessToken: a,
948
+ accessToken: n,
916
949
  refreshToken: u,
917
950
  clientId: o
918
951
  }));
919
952
  } catch {
920
- I(G), await Y({
953
+ A(Q), await Z({
921
954
  idToken: r,
922
- accessToken: a,
955
+ accessToken: n,
923
956
  refreshToken: u,
924
957
  clientId: o
925
958
  });
926
959
  }
927
960
  })();
928
961
  }, [
929
- p.isLoading,
930
- a,
962
+ v.isLoading,
963
+ n,
931
964
  r,
932
965
  u,
933
966
  o,
934
- I
967
+ A
935
968
  ]);
936
- const ve = async (g, Z, W) => {
937
- const O = Ct();
938
- if (E(O), W === F.CODE) {
939
- const { code_verifier: Ce, code_challenge: Oe } = await bt(), ee = await Nt({
940
- nonce: O,
969
+ const Re = async (w, O, R) => {
970
+ const k = Pt();
971
+ if (E(k), R === M.CODE) {
972
+ const { code_verifier: Pe, code_challenge: De } = await bt(), oe = await Lt({
973
+ nonce: k,
941
974
  clientId: o,
942
- code_challenge: Oe
975
+ code_challenge: De
943
976
  });
944
- if (ee.status) {
945
- const k = await fe({
946
- username: g,
947
- password: Z,
977
+ if (oe.status) {
978
+ const P = await we({
979
+ username: w,
980
+ password: O,
948
981
  clientId: o,
949
982
  sessionExpiration: t,
950
- nonce: O,
951
- type: W,
952
- code: ee.code,
953
- code_verifier: Ce
983
+ nonce: k,
984
+ type: R,
985
+ code: oe.code,
986
+ code_verifier: Pe
954
987
  });
955
- return k.status ? (n(k.idToken), c(k.accessToken), m(k.refreshToken), v({
988
+ return P.status ? (a(P.idToken), i(P.accessToken), y(P.refreshToken), H({
956
989
  isLoading: !1,
957
990
  isAuthenticated: !0,
958
- userId: k.userId,
991
+ userId: P.userId,
959
992
  logoutReason: ""
960
- }), !0) : (I(he), !1);
993
+ }), !0) : (A(ye), !1);
961
994
  }
962
995
  return !1;
963
996
  }
964
- const R = await fe({
965
- username: g,
966
- password: Z,
997
+ const S = await we({
998
+ username: w,
999
+ password: O,
967
1000
  clientId: o,
968
1001
  sessionExpiration: t,
969
- nonce: O,
970
- type: W
1002
+ nonce: k,
1003
+ type: R
971
1004
  });
972
- return R.status ? (n(R.idToken), c(R.accessToken), m(R.refreshToken), v({
1005
+ return S.status ? (a(S.idToken), i(S.accessToken), y(S.refreshToken), H({
973
1006
  isLoading: !1,
974
1007
  isAuthenticated: !0,
975
- userId: R.userId
976
- }), !0) : (I(he), !1);
977
- }, Ie = async () => {
978
- I(Ot), await Y({
1008
+ userId: S.userId
1009
+ }), !0) : (A(ye), !1);
1010
+ }, ke = async () => {
1011
+ A(Dt), await Z({
979
1012
  idToken: r,
980
- accessToken: a,
1013
+ accessToken: n,
981
1014
  refreshToken: u,
982
1015
  clientId: o
983
1016
  });
984
- }, Re = () => {
985
- if (p.isAuthenticated && a)
986
- return a;
987
- }, ke = () => {
988
- if (p.isAuthenticated && r)
1017
+ }, Ce = async () => {
1018
+ const { isAuthenticated: w, userId: O } = v;
1019
+ try {
1020
+ if (w && O && n) {
1021
+ const R = await N(n);
1022
+ if (R && R.payload[f.USER_ID_KEY] !== "")
1023
+ return n;
1024
+ const k = await N(u);
1025
+ if (k && k.payload[f.USER_ID_KEY] !== "") {
1026
+ const S = await $t({
1027
+ clientId: o,
1028
+ userId: O,
1029
+ nonce: T,
1030
+ refreshToken: u,
1031
+ accessToken: n
1032
+ });
1033
+ if (S.status)
1034
+ return i(S.accessToken), y(S.refreshToken), S.accessToken;
1035
+ A(U);
1036
+ }
1037
+ return A(U), console.error(U), "";
1038
+ }
1039
+ } catch {
1040
+ return A(U), console.error(U), "";
1041
+ }
1042
+ }, Oe = () => {
1043
+ if (v.isAuthenticated && r)
989
1044
  return r;
990
1045
  };
991
- return /* @__PURE__ */ Pe(
992
- Te.Provider,
1046
+ return /* @__PURE__ */ Ue(
1047
+ ve.Provider,
993
1048
  {
994
- value: { ...p, login: ve, logout: Ie, getAccessToken: Re, getIdToken: ke },
1049
+ value: { ...v, login: Re, logout: ke, getAccessToken: Ce, getIdToken: Oe },
995
1050
  children: e
996
1051
  }
997
1052
  );
998
- }, Kt = (e = Te) => Le(e);
1053
+ }, jt = (e = ve) => Ke(e);
999
1054
  export {
1000
- F as AUTH_TYPES,
1001
- Jt as AuthProvider,
1002
- Kt as useAuth
1055
+ M as AUTH_TYPES,
1056
+ xt as AuthProvider,
1057
+ jt as useAuth
1003
1058
  };