alex-evo-sh-auth 0.0.10 → 0.0.12

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.
@@ -1,127 +1,127 @@
1
- import fe, { createContext as de, useState as I, useMemo as me, useCallback as j, useEffect as C, useContext as B } from "react";
2
- import { Outlet as H } from "react-router-dom";
3
- async function he(r) {
4
- const t = await fetch(`${r.authServer}/refresh`, {
1
+ import De, { createContext as Rr, useState as Q, useMemo as Sr, useCallback as Z, useEffect as re, useContext as $e } from "react";
2
+ import { Outlet as Ue } from "react-router-dom";
3
+ async function wr(n) {
4
+ const a = await fetch(`${n.authServer}/refresh`, {
5
5
  method: "POST",
6
6
  headers: {
7
7
  "Content-Type": "application/json"
8
8
  },
9
9
  body: JSON.stringify({
10
10
  grant_type: "refresh_token",
11
- client_id: r.clientId
11
+ client_id: n.clientId
12
12
  })
13
13
  });
14
- if (t.status === 401)
15
- return localStorage.removeItem(r.baseKey + "_access"), null;
16
- const o = await t.json();
17
- return localStorage.setItem(r.baseKey + "_access", o.access), o.access;
14
+ if (a.status === 401)
15
+ return localStorage.removeItem(n.baseKey + "_access"), null;
16
+ const c = await a.json();
17
+ return localStorage.setItem(n.baseKey + "_access", c.access), c.access;
18
18
  }
19
- class ge {
20
- constructor(t, o) {
21
- this.onAuthFail = o, this.config = t;
19
+ class Tr {
20
+ constructor(a, c) {
21
+ this.onAuthFail = c, this.config = a;
22
22
  }
23
23
  refreshPromise = null;
24
24
  config;
25
25
  getToken() {
26
26
  return localStorage.getItem(this.config.baseKey + "_access");
27
27
  }
28
- setToken(t) {
29
- t ? localStorage.setItem(this.config.baseKey + "_access", t) : localStorage.removeItem(this.config.baseKey + "_access");
28
+ setToken(a) {
29
+ a ? localStorage.setItem(this.config.baseKey + "_access", a) : localStorage.removeItem(this.config.baseKey + "_access");
30
30
  }
31
31
  async getValidToken() {
32
- let t = this.getToken();
33
- return t || (this.refreshPromise || (this.refreshPromise = he(this.config).then((o) => (this.setToken(o), o)).finally(() => {
32
+ let a = this.getToken();
33
+ return a || (this.refreshPromise || (this.refreshPromise = wr(this.config).then((c) => (this.setToken(c), c)).finally(() => {
34
34
  this.refreshPromise = null;
35
- })), t = await this.refreshPromise, !t && this.onAuthFail && this.onAuthFail(), t);
35
+ })), a = await this.refreshPromise, !a && this.onAuthFail && this.onAuthFail(), a);
36
36
  }
37
37
  }
38
- class we {
38
+ class Dr {
39
39
  authServer;
40
40
  clientId;
41
41
  redirectUri;
42
42
  homePage;
43
43
  baseKey;
44
- constructor(t, o, a, s, c) {
45
- this.authServer = t, this.clientId = o, this.redirectUri = a, this.homePage = s, this.baseKey = c;
44
+ constructor(a, c, u, d, p) {
45
+ this.authServer = a, this.clientId = c, this.redirectUri = u, this.homePage = d, this.baseKey = p;
46
46
  }
47
47
  }
48
- async function X(r, t, o = {}) {
49
- let a = r.getToken();
50
- const s = (l) => fetch(t, {
51
- ...o,
48
+ async function We(n, a, c = {}) {
49
+ let u = n.getToken();
50
+ const d = (h) => fetch(a, {
51
+ ...c,
52
52
  headers: {
53
- ...o.headers,
54
- Authorization: l ? `Bearer ${l}` : ""
53
+ ...c.headers,
54
+ Authorization: h ? `Bearer ${h}` : ""
55
55
  }
56
56
  });
57
- let c = await s(a);
58
- return c.status !== 401 || (r.setToken(null), a = await r.getValidToken(), !a) ? c : s(a);
57
+ let p = await d(u);
58
+ return p.status !== 401 || (n.setToken(null), u = await n.getValidToken(), !u) ? p : d(u);
59
59
  }
60
- async function z(r) {
61
- const t = new URLSearchParams(window.location.search), o = t.get("code"), a = sessionStorage.getItem("oauth_state"), s = t.get("state");
62
- if (!o) return;
63
- if (!s || s !== a)
60
+ async function je(n) {
61
+ const a = new URLSearchParams(window.location.search), c = a.get("code"), u = sessionStorage.getItem("oauth_state"), d = a.get("state");
62
+ if (!c) return;
63
+ if (!d || d !== u)
64
64
  throw new Error("Invalid OAuth state");
65
- const c = sessionStorage.getItem("pkce_verifier"), d = await (await fetch(`${r.config.authServer}/token`, {
65
+ const p = sessionStorage.getItem("pkce_verifier"), R = await (await fetch(`${n.config.authServer}/token`, {
66
66
  method: "POST",
67
67
  headers: {
68
68
  "Content-Type": "application/json"
69
69
  },
70
70
  body: JSON.stringify({
71
- client_id: r.config.clientId,
72
- code: o,
73
- code_verifier: c
71
+ client_id: n.config.clientId,
72
+ code: c,
73
+ code_verifier: p
74
74
  })
75
75
  })).json();
76
- localStorage.setItem(r.config.baseKey + "_access", d.access), window.history.replaceState({}, document.title, r.config.homePage), window.location.href = r.config.homePage;
76
+ localStorage.setItem(n.config.baseKey + "_access", R.access), window.history.replaceState({}, document.title, n.config.homePage), window.location.href = n.config.homePage;
77
77
  }
78
- function _e(r = 64) {
79
- const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
80
- let o = "";
81
- const a = new Uint8Array(r);
82
- crypto.getRandomValues(a);
83
- for (let s = 0; s < a.length; s++)
84
- o += t[a[s] % t.length];
85
- return o;
78
+ function Pr(n = 64) {
79
+ const a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
80
+ let c = "";
81
+ const u = new Uint8Array(n);
82
+ crypto.getRandomValues(u);
83
+ for (let d = 0; d < u.length; d++)
84
+ c += a[u[d] % a.length];
85
+ return c;
86
86
  }
87
- async function pe(r) {
88
- const o = new TextEncoder().encode(r), a = await crypto.subtle.digest("SHA-256", o);
89
- return new Uint8Array(a);
87
+ async function Or(n) {
88
+ const c = new TextEncoder().encode(n), u = await crypto.subtle.digest("SHA-256", c);
89
+ return new Uint8Array(u);
90
90
  }
91
- function ve(r) {
92
- return btoa(String.fromCharCode(...Array.from(r))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
91
+ function Cr(n) {
92
+ return btoa(String.fromCharCode(...Array.from(n))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
93
93
  }
94
- async function N(r) {
95
- const t = _e(64), o = ve(await pe(t));
96
- sessionStorage.setItem("pkce_verifier", t);
97
- const a = crypto.randomUUID();
98
- sessionStorage.setItem("oauth_state", a);
99
- const s = new URLSearchParams({
94
+ async function ee(n) {
95
+ const a = Pr(64), c = Cr(await Or(a));
96
+ sessionStorage.setItem("pkce_verifier", a);
97
+ const u = crypto.randomUUID();
98
+ sessionStorage.setItem("oauth_state", u);
99
+ const d = new URLSearchParams({
100
100
  response_type: "code",
101
- client_id: r.config.clientId,
102
- redirect_uri: r.config.redirectUri,
103
- code_challenge: o,
101
+ client_id: n.config.clientId,
102
+ redirect_uri: n.config.redirectUri,
103
+ code_challenge: c,
104
104
  code_challenge_method: "S256",
105
- state: a
105
+ state: u
106
106
  });
107
- window.location.href = `${r.config.authServer}/authorize?${s}`;
107
+ window.location.href = `${n.config.authServer}/authorize?${d}`;
108
108
  }
109
- async function M(r) {
109
+ async function xe(n) {
110
110
  try {
111
- await X(r, `${r.config.authServer}/logout`, {
111
+ await We(n, `${n.config.authServer}/logout`, {
112
112
  method: "POST",
113
113
  headers: {
114
114
  "Content-Type": "application/json"
115
115
  },
116
116
  body: JSON.stringify({
117
- client_id: r.config.clientId
117
+ client_id: n.config.clientId
118
118
  })
119
- }), localStorage.removeItem(r.config.baseKey + "_access"), await N(r);
120
- } catch (t) {
121
- console.error(t);
119
+ }), localStorage.removeItem(n.config.baseKey + "_access"), await ee(n);
120
+ } catch (a) {
121
+ console.error(a);
122
122
  }
123
123
  }
124
- const $ = de({
124
+ const te = Rr({
125
125
  login: () => {
126
126
  },
127
127
  logout: () => {
@@ -132,339 +132,690 @@ const $ = de({
132
132
  user: null,
133
133
  loading: !1
134
134
  });
135
- var T = { exports: {} }, b = {};
136
- var q;
137
- function be() {
138
- if (q) return b;
139
- q = 1;
140
- var r = /* @__PURE__ */ Symbol.for("react.transitional.element"), t = /* @__PURE__ */ Symbol.for("react.fragment");
141
- function o(a, s, c) {
142
- var l = null;
143
- if (c !== void 0 && (l = "" + c), s.key !== void 0 && (l = "" + s.key), "key" in s) {
144
- c = {};
145
- for (var d in s)
146
- d !== "key" && (c[d] = s[d]);
147
- } else c = s;
148
- return s = c.ref, {
149
- $$typeof: r,
150
- type: a,
151
- key: l,
152
- ref: s !== void 0 ? s : null,
153
- props: c
154
- };
135
+ var N = { exports: {} }, U = {};
136
+ var Ae;
137
+ function kr() {
138
+ if (Ae) return U;
139
+ Ae = 1;
140
+ var n = De, a = /* @__PURE__ */ Symbol.for("react.element"), c = /* @__PURE__ */ Symbol.for("react.fragment"), u = Object.prototype.hasOwnProperty, d = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
141
+ function h(R, y, P) {
142
+ var m, S = {}, w = null, j = null;
143
+ P !== void 0 && (w = "" + P), y.key !== void 0 && (w = "" + y.key), y.ref !== void 0 && (j = y.ref);
144
+ for (m in y) u.call(y, m) && !p.hasOwnProperty(m) && (S[m] = y[m]);
145
+ if (R && R.defaultProps) for (m in y = R.defaultProps, y) S[m] === void 0 && (S[m] = y[m]);
146
+ return { $$typeof: a, type: R, key: w, ref: j, props: S, _owner: d.current };
155
147
  }
156
- return b.Fragment = t, b.jsx = o, b.jsxs = o, b;
148
+ return U.Fragment = c, U.jsx = h, U.jsxs = h, U;
157
149
  }
158
- var E = {};
159
- var G;
160
- function Ee() {
161
- return G || (G = 1, process.env.NODE_ENV !== "production" && (function() {
162
- function r(e) {
163
- if (e == null) return null;
164
- if (typeof e == "function")
165
- return e.$$typeof === ie ? null : e.displayName || e.name || null;
166
- if (typeof e == "string") return e;
150
+ var W = {};
151
+ var Ie;
152
+ function jr() {
153
+ return Ie || (Ie = 1, process.env.NODE_ENV !== "production" && (function() {
154
+ var n = De, a = /* @__PURE__ */ Symbol.for("react.element"), c = /* @__PURE__ */ Symbol.for("react.portal"), u = /* @__PURE__ */ Symbol.for("react.fragment"), d = /* @__PURE__ */ Symbol.for("react.strict_mode"), p = /* @__PURE__ */ Symbol.for("react.profiler"), h = /* @__PURE__ */ Symbol.for("react.provider"), R = /* @__PURE__ */ Symbol.for("react.context"), y = /* @__PURE__ */ Symbol.for("react.forward_ref"), P = /* @__PURE__ */ Symbol.for("react.suspense"), m = /* @__PURE__ */ Symbol.for("react.suspense_list"), S = /* @__PURE__ */ Symbol.for("react.memo"), w = /* @__PURE__ */ Symbol.for("react.lazy"), j = /* @__PURE__ */ Symbol.for("react.offscreen"), ae = Symbol.iterator, Ye = "@@iterator";
155
+ function Le(e) {
156
+ if (e === null || typeof e != "object")
157
+ return null;
158
+ var r = ae && e[ae] || e[Ye];
159
+ return typeof r == "function" ? r : null;
160
+ }
161
+ var x = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
162
+ function _(e) {
163
+ {
164
+ for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), o = 1; o < r; o++)
165
+ t[o - 1] = arguments[o];
166
+ Ve("error", e, t);
167
+ }
168
+ }
169
+ function Ve(e, r, t) {
170
+ {
171
+ var o = x.ReactDebugCurrentFrame, l = o.getStackAddendum();
172
+ l !== "" && (r += "%s", t = t.concat([l]));
173
+ var f = t.map(function(s) {
174
+ return String(s);
175
+ });
176
+ f.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, f);
177
+ }
178
+ }
179
+ var Ke = !1, Ne = !1, Je = !1, Me = !1, Be = !1, oe;
180
+ oe = /* @__PURE__ */ Symbol.for("react.module.reference");
181
+ function qe(e) {
182
+ return !!(typeof e == "string" || typeof e == "function" || e === u || e === p || Be || e === d || e === P || e === m || Me || e === j || Ke || Ne || Je || typeof e == "object" && e !== null && (e.$$typeof === w || e.$$typeof === S || e.$$typeof === h || e.$$typeof === R || e.$$typeof === y || // This needs to include all possible module reference object
183
+ // types supported by any Flight configuration anywhere since
184
+ // we don't know which Flight build this will end up being used
185
+ // with.
186
+ e.$$typeof === oe || e.getModuleId !== void 0));
187
+ }
188
+ function ze(e, r, t) {
189
+ var o = e.displayName;
190
+ if (o)
191
+ return o;
192
+ var l = r.displayName || r.name || "";
193
+ return l !== "" ? t + "(" + l + ")" : t;
194
+ }
195
+ function ie(e) {
196
+ return e.displayName || "Context";
197
+ }
198
+ function O(e) {
199
+ if (e == null)
200
+ return null;
201
+ if (typeof e.tag == "number" && _("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
202
+ return e.displayName || e.name || null;
203
+ if (typeof e == "string")
204
+ return e;
167
205
  switch (e) {
168
- case w:
206
+ case u:
169
207
  return "Fragment";
170
- case ee:
208
+ case c:
209
+ return "Portal";
210
+ case p:
171
211
  return "Profiler";
172
- case Q:
212
+ case d:
173
213
  return "StrictMode";
174
- case oe:
214
+ case P:
175
215
  return "Suspense";
176
- case ae:
216
+ case m:
177
217
  return "SuspenseList";
178
- case ce:
179
- return "Activity";
180
218
  }
181
219
  if (typeof e == "object")
182
- switch (typeof e.tag == "number" && console.error(
183
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
184
- ), e.$$typeof) {
185
- case Z:
186
- return "Portal";
187
- case te:
188
- return e.displayName || "Context";
189
- case re:
190
- return (e._context.displayName || "Context") + ".Consumer";
191
- case ne:
192
- var n = e.render;
193
- return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
194
- case se:
195
- return n = e.displayName || null, n !== null ? n : r(e.type) || "Memo";
196
- case k:
197
- n = e._payload, e = e._init;
220
+ switch (e.$$typeof) {
221
+ case R:
222
+ var r = e;
223
+ return ie(r) + ".Consumer";
224
+ case h:
225
+ var t = e;
226
+ return ie(t._context) + ".Provider";
227
+ case y:
228
+ return ze(e, e.render, "ForwardRef");
229
+ case S:
230
+ var o = e.displayName || null;
231
+ return o !== null ? o : O(e.type) || "Memo";
232
+ case w: {
233
+ var l = e, f = l._payload, s = l._init;
198
234
  try {
199
- return r(e(n));
235
+ return O(s(f));
200
236
  } catch {
237
+ return null;
201
238
  }
239
+ }
202
240
  }
203
241
  return null;
204
242
  }
205
- function t(e) {
206
- return "" + e;
243
+ var C = Object.assign, D = 0, se, ue, ce, le, fe, de, ve;
244
+ function ge() {
207
245
  }
208
- function o(e) {
246
+ ge.__reactDisabledLog = !0;
247
+ function Ge() {
248
+ {
249
+ if (D === 0) {
250
+ se = console.log, ue = console.info, ce = console.warn, le = console.error, fe = console.group, de = console.groupCollapsed, ve = console.groupEnd;
251
+ var e = {
252
+ configurable: !0,
253
+ enumerable: !0,
254
+ value: ge,
255
+ writable: !0
256
+ };
257
+ Object.defineProperties(console, {
258
+ info: e,
259
+ log: e,
260
+ warn: e,
261
+ error: e,
262
+ group: e,
263
+ groupCollapsed: e,
264
+ groupEnd: e
265
+ });
266
+ }
267
+ D++;
268
+ }
269
+ }
270
+ function He() {
271
+ {
272
+ if (D--, D === 0) {
273
+ var e = {
274
+ configurable: !0,
275
+ enumerable: !0,
276
+ writable: !0
277
+ };
278
+ Object.defineProperties(console, {
279
+ log: C({}, e, {
280
+ value: se
281
+ }),
282
+ info: C({}, e, {
283
+ value: ue
284
+ }),
285
+ warn: C({}, e, {
286
+ value: ce
287
+ }),
288
+ error: C({}, e, {
289
+ value: le
290
+ }),
291
+ group: C({}, e, {
292
+ value: fe
293
+ }),
294
+ groupCollapsed: C({}, e, {
295
+ value: de
296
+ }),
297
+ groupEnd: C({}, e, {
298
+ value: ve
299
+ })
300
+ });
301
+ }
302
+ D < 0 && _("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
303
+ }
304
+ }
305
+ var J = x.ReactCurrentDispatcher, M;
306
+ function Y(e, r, t) {
307
+ {
308
+ if (M === void 0)
309
+ try {
310
+ throw Error();
311
+ } catch (l) {
312
+ var o = l.stack.trim().match(/\n( *(at )?)/);
313
+ M = o && o[1] || "";
314
+ }
315
+ return `
316
+ ` + M + e;
317
+ }
318
+ }
319
+ var B = !1, L;
320
+ {
321
+ var Xe = typeof WeakMap == "function" ? WeakMap : Map;
322
+ L = new Xe();
323
+ }
324
+ function he(e, r) {
325
+ if (!e || B)
326
+ return "";
327
+ {
328
+ var t = L.get(e);
329
+ if (t !== void 0)
330
+ return t;
331
+ }
332
+ var o;
333
+ B = !0;
334
+ var l = Error.prepareStackTrace;
335
+ Error.prepareStackTrace = void 0;
336
+ var f;
337
+ f = J.current, J.current = null, Ge();
209
338
  try {
210
- t(e);
211
- var n = !1;
212
- } catch {
213
- n = !0;
339
+ if (r) {
340
+ var s = function() {
341
+ throw Error();
342
+ };
343
+ if (Object.defineProperty(s.prototype, "props", {
344
+ set: function() {
345
+ throw Error();
346
+ }
347
+ }), typeof Reflect == "object" && Reflect.construct) {
348
+ try {
349
+ Reflect.construct(s, []);
350
+ } catch (E) {
351
+ o = E;
352
+ }
353
+ Reflect.construct(e, [], s);
354
+ } else {
355
+ try {
356
+ s.call();
357
+ } catch (E) {
358
+ o = E;
359
+ }
360
+ e.call(s.prototype);
361
+ }
362
+ } else {
363
+ try {
364
+ throw Error();
365
+ } catch (E) {
366
+ o = E;
367
+ }
368
+ e();
369
+ }
370
+ } catch (E) {
371
+ if (E && o && typeof E.stack == "string") {
372
+ for (var i = E.stack.split(`
373
+ `), b = o.stack.split(`
374
+ `), v = i.length - 1, g = b.length - 1; v >= 1 && g >= 0 && i[v] !== b[g]; )
375
+ g--;
376
+ for (; v >= 1 && g >= 0; v--, g--)
377
+ if (i[v] !== b[g]) {
378
+ if (v !== 1 || g !== 1)
379
+ do
380
+ if (v--, g--, g < 0 || i[v] !== b[g]) {
381
+ var T = `
382
+ ` + i[v].replace(" at new ", " at ");
383
+ return e.displayName && T.includes("<anonymous>") && (T = T.replace("<anonymous>", e.displayName)), typeof e == "function" && L.set(e, T), T;
384
+ }
385
+ while (v >= 1 && g >= 0);
386
+ break;
387
+ }
388
+ }
389
+ } finally {
390
+ B = !1, J.current = f, He(), Error.prepareStackTrace = l;
214
391
  }
215
- if (n) {
216
- n = console;
217
- var i = n.error, u = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
218
- return i.call(
219
- n,
220
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
221
- u
222
- ), t(e);
392
+ var I = e ? e.displayName || e.name : "", k = I ? Y(I) : "";
393
+ return typeof e == "function" && L.set(e, k), k;
394
+ }
395
+ function Ze(e, r, t) {
396
+ return he(e, !1);
397
+ }
398
+ function Qe(e) {
399
+ var r = e.prototype;
400
+ return !!(r && r.isReactComponent);
401
+ }
402
+ function V(e, r, t) {
403
+ if (e == null)
404
+ return "";
405
+ if (typeof e == "function")
406
+ return he(e, Qe(e));
407
+ if (typeof e == "string")
408
+ return Y(e);
409
+ switch (e) {
410
+ case P:
411
+ return Y("Suspense");
412
+ case m:
413
+ return Y("SuspenseList");
223
414
  }
415
+ if (typeof e == "object")
416
+ switch (e.$$typeof) {
417
+ case y:
418
+ return Ze(e.render);
419
+ case S:
420
+ return V(e.type, r, t);
421
+ case w: {
422
+ var o = e, l = o._payload, f = o._init;
423
+ try {
424
+ return V(f(l), r, t);
425
+ } catch {
426
+ }
427
+ }
428
+ }
429
+ return "";
430
+ }
431
+ var $ = Object.prototype.hasOwnProperty, pe = {}, ye = x.ReactDebugCurrentFrame;
432
+ function K(e) {
433
+ if (e) {
434
+ var r = e._owner, t = V(e.type, e._source, r ? r.type : null);
435
+ ye.setExtraStackFrame(t);
436
+ } else
437
+ ye.setExtraStackFrame(null);
438
+ }
439
+ function er(e, r, t, o, l) {
440
+ {
441
+ var f = Function.call.bind($);
442
+ for (var s in e)
443
+ if (f(e, s)) {
444
+ var i = void 0;
445
+ try {
446
+ if (typeof e[s] != "function") {
447
+ var b = Error((o || "React class") + ": " + t + " type `" + s + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[s] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
448
+ throw b.name = "Invariant Violation", b;
449
+ }
450
+ i = e[s](r, s, o, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
451
+ } catch (v) {
452
+ i = v;
453
+ }
454
+ i && !(i instanceof Error) && (K(l), _("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", o || "React class", t, s, typeof i), K(null)), i instanceof Error && !(i.message in pe) && (pe[i.message] = !0, K(l), _("Failed %s type: %s", t, i.message), K(null));
455
+ }
456
+ }
457
+ }
458
+ var rr = Array.isArray;
459
+ function q(e) {
460
+ return rr(e);
224
461
  }
225
- function a(e) {
226
- if (e === w) return "<>";
227
- if (typeof e == "object" && e !== null && e.$$typeof === k)
228
- return "<...>";
462
+ function tr(e) {
463
+ {
464
+ var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
465
+ return t;
466
+ }
467
+ }
468
+ function nr(e) {
229
469
  try {
230
- var n = r(e);
231
- return n ? "<" + n + ">" : "<...>";
470
+ return me(e), !1;
232
471
  } catch {
233
- return "<...>";
472
+ return !0;
234
473
  }
235
474
  }
236
- function s() {
237
- var e = P.A;
238
- return e === null ? null : e.getOwner();
475
+ function me(e) {
476
+ return "" + e;
477
+ }
478
+ function _e(e) {
479
+ if (nr(e))
480
+ return _("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", tr(e)), me(e);
239
481
  }
240
- function c() {
241
- return Error("react-stack-top-frame");
482
+ var be = x.ReactCurrentOwner, ar = {
483
+ key: !0,
484
+ ref: !0,
485
+ __self: !0,
486
+ __source: !0
487
+ }, Ee, Re;
488
+ function or(e) {
489
+ if ($.call(e, "ref")) {
490
+ var r = Object.getOwnPropertyDescriptor(e, "ref").get;
491
+ if (r && r.isReactWarning)
492
+ return !1;
493
+ }
494
+ return e.ref !== void 0;
242
495
  }
243
- function l(e) {
244
- if (F.call(e, "key")) {
245
- var n = Object.getOwnPropertyDescriptor(e, "key").get;
246
- if (n && n.isReactWarning) return !1;
496
+ function ir(e) {
497
+ if ($.call(e, "key")) {
498
+ var r = Object.getOwnPropertyDescriptor(e, "key").get;
499
+ if (r && r.isReactWarning)
500
+ return !1;
247
501
  }
248
502
  return e.key !== void 0;
249
503
  }
250
- function d(e, n) {
251
- function i() {
252
- L || (L = !0, console.error(
253
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
254
- n
255
- ));
504
+ function sr(e, r) {
505
+ typeof e.ref == "string" && be.current;
506
+ }
507
+ function ur(e, r) {
508
+ {
509
+ var t = function() {
510
+ Ee || (Ee = !0, _("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
511
+ };
512
+ t.isReactWarning = !0, Object.defineProperty(e, "key", {
513
+ get: t,
514
+ configurable: !0
515
+ });
256
516
  }
257
- i.isReactWarning = !0, Object.defineProperty(e, "key", {
258
- get: i,
259
- configurable: !0
260
- });
261
517
  }
262
- function S() {
263
- var e = r(this.type);
264
- return D[e] || (D[e] = !0, console.error(
265
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
266
- )), e = this.props.ref, e !== void 0 ? e : null;
518
+ function cr(e, r) {
519
+ {
520
+ var t = function() {
521
+ Re || (Re = !0, _("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
522
+ };
523
+ t.isReactWarning = !0, Object.defineProperty(e, "ref", {
524
+ get: t,
525
+ configurable: !0
526
+ });
527
+ }
267
528
  }
268
- function R(e, n, i, u, y, O) {
269
- var f = i.ref;
270
- return e = {
271
- $$typeof: Y,
529
+ var lr = function(e, r, t, o, l, f, s) {
530
+ var i = {
531
+ // This tag allows us to uniquely identify this as a React Element
532
+ $$typeof: a,
533
+ // Built-in properties that belong on the element
272
534
  type: e,
273
- key: n,
274
- props: i,
275
- _owner: u
276
- }, (f !== void 0 ? f : null) !== null ? Object.defineProperty(e, "ref", {
277
- enumerable: !1,
278
- get: S
279
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
280
- configurable: !1,
281
- enumerable: !1,
282
- writable: !0,
283
- value: 0
284
- }), Object.defineProperty(e, "_debugInfo", {
535
+ key: r,
536
+ ref: t,
537
+ props: s,
538
+ // Record the component responsible for creating this element.
539
+ _owner: f
540
+ };
541
+ return i._store = {}, Object.defineProperty(i._store, "validated", {
285
542
  configurable: !1,
286
543
  enumerable: !1,
287
544
  writable: !0,
288
- value: null
289
- }), Object.defineProperty(e, "_debugStack", {
545
+ value: !1
546
+ }), Object.defineProperty(i, "_self", {
290
547
  configurable: !1,
291
548
  enumerable: !1,
292
- writable: !0,
293
- value: y
294
- }), Object.defineProperty(e, "_debugTask", {
549
+ writable: !1,
550
+ value: o
551
+ }), Object.defineProperty(i, "_source", {
295
552
  configurable: !1,
296
553
  enumerable: !1,
297
- writable: !0,
298
- value: O
299
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
300
- }
301
- function p(e, n, i, u, y, O) {
302
- var f = n.children;
303
- if (f !== void 0)
304
- if (u)
305
- if (le(f)) {
306
- for (u = 0; u < f.length; u++)
307
- v(f[u]);
308
- Object.freeze && Object.freeze(f);
309
- } else
310
- console.error(
311
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
312
- );
313
- else v(f);
314
- if (F.call(n, "key")) {
315
- f = r(e);
316
- var g = Object.keys(n).filter(function(ue) {
317
- return ue !== "key";
318
- });
319
- u = 0 < g.length ? "{key: someKey, " + g.join(": ..., ") + ": ...}" : "{key: someKey}", W[f + u] || (g = 0 < g.length ? "{" + g.join(": ..., ") + ": ...}" : "{}", console.error(
320
- `A props object containing a "key" prop is being spread into JSX:
554
+ writable: !1,
555
+ value: l
556
+ }), Object.freeze && (Object.freeze(i.props), Object.freeze(i)), i;
557
+ };
558
+ function fr(e, r, t, o, l) {
559
+ {
560
+ var f, s = {}, i = null, b = null;
561
+ t !== void 0 && (_e(t), i = "" + t), ir(r) && (_e(r.key), i = "" + r.key), or(r) && (b = r.ref, sr(r, l));
562
+ for (f in r)
563
+ $.call(r, f) && !ar.hasOwnProperty(f) && (s[f] = r[f]);
564
+ if (e && e.defaultProps) {
565
+ var v = e.defaultProps;
566
+ for (f in v)
567
+ s[f] === void 0 && (s[f] = v[f]);
568
+ }
569
+ if (i || b) {
570
+ var g = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
571
+ i && ur(s, g), b && cr(s, g);
572
+ }
573
+ return lr(e, i, b, l, o, be.current, s);
574
+ }
575
+ }
576
+ var z = x.ReactCurrentOwner, Se = x.ReactDebugCurrentFrame;
577
+ function A(e) {
578
+ if (e) {
579
+ var r = e._owner, t = V(e.type, e._source, r ? r.type : null);
580
+ Se.setExtraStackFrame(t);
581
+ } else
582
+ Se.setExtraStackFrame(null);
583
+ }
584
+ var G;
585
+ G = !1;
586
+ function H(e) {
587
+ return typeof e == "object" && e !== null && e.$$typeof === a;
588
+ }
589
+ function we() {
590
+ {
591
+ if (z.current) {
592
+ var e = O(z.current.type);
593
+ if (e)
594
+ return `
595
+
596
+ Check the render method of \`` + e + "`.";
597
+ }
598
+ return "";
599
+ }
600
+ }
601
+ function dr(e) {
602
+ return "";
603
+ }
604
+ var Te = {};
605
+ function vr(e) {
606
+ {
607
+ var r = we();
608
+ if (!r) {
609
+ var t = typeof e == "string" ? e : e.displayName || e.name;
610
+ t && (r = `
611
+
612
+ Check the top-level render call using <` + t + ">.");
613
+ }
614
+ return r;
615
+ }
616
+ }
617
+ function Pe(e, r) {
618
+ {
619
+ if (!e._store || e._store.validated || e.key != null)
620
+ return;
621
+ e._store.validated = !0;
622
+ var t = vr(r);
623
+ if (Te[t])
624
+ return;
625
+ Te[t] = !0;
626
+ var o = "";
627
+ e && e._owner && e._owner !== z.current && (o = " It was passed a child from " + O(e._owner.type) + "."), A(e), _('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, o), A(null);
628
+ }
629
+ }
630
+ function Oe(e, r) {
631
+ {
632
+ if (typeof e != "object")
633
+ return;
634
+ if (q(e))
635
+ for (var t = 0; t < e.length; t++) {
636
+ var o = e[t];
637
+ H(o) && Pe(o, r);
638
+ }
639
+ else if (H(e))
640
+ e._store && (e._store.validated = !0);
641
+ else if (e) {
642
+ var l = Le(e);
643
+ if (typeof l == "function" && l !== e.entries)
644
+ for (var f = l.call(e), s; !(s = f.next()).done; )
645
+ H(s.value) && Pe(s.value, r);
646
+ }
647
+ }
648
+ }
649
+ function gr(e) {
650
+ {
651
+ var r = e.type;
652
+ if (r == null || typeof r == "string")
653
+ return;
654
+ var t;
655
+ if (typeof r == "function")
656
+ t = r.propTypes;
657
+ else if (typeof r == "object" && (r.$$typeof === y || // Note: Memo only checks outer props here.
658
+ // Inner props are checked in the reconciler.
659
+ r.$$typeof === S))
660
+ t = r.propTypes;
661
+ else
662
+ return;
663
+ if (t) {
664
+ var o = O(r);
665
+ er(t, e.props, "prop", o, e);
666
+ } else if (r.PropTypes !== void 0 && !G) {
667
+ G = !0;
668
+ var l = O(r);
669
+ _("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", l || "Unknown");
670
+ }
671
+ typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && _("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
672
+ }
673
+ }
674
+ function hr(e) {
675
+ {
676
+ for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
677
+ var o = r[t];
678
+ if (o !== "children" && o !== "key") {
679
+ A(e), _("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", o), A(null);
680
+ break;
681
+ }
682
+ }
683
+ e.ref !== null && (A(e), _("Invalid attribute `ref` supplied to `React.Fragment`."), A(null));
684
+ }
685
+ }
686
+ var Ce = {};
687
+ function ke(e, r, t, o, l, f) {
688
+ {
689
+ var s = qe(e);
690
+ if (!s) {
691
+ var i = "";
692
+ (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (i += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
693
+ var b = dr();
694
+ b ? i += b : i += we();
695
+ var v;
696
+ e === null ? v = "null" : q(e) ? v = "array" : e !== void 0 && e.$$typeof === a ? (v = "<" + (O(e.type) || "Unknown") + " />", i = " Did you accidentally export a JSX literal instead of a component?") : v = typeof e, _("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", v, i);
697
+ }
698
+ var g = fr(e, r, t, l, f);
699
+ if (g == null)
700
+ return g;
701
+ if (s) {
702
+ var T = r.children;
703
+ if (T !== void 0)
704
+ if (o)
705
+ if (q(T)) {
706
+ for (var I = 0; I < T.length; I++)
707
+ Oe(T[I], e);
708
+ Object.freeze && Object.freeze(T);
709
+ } else
710
+ _("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
711
+ else
712
+ Oe(T, e);
713
+ }
714
+ if ($.call(r, "key")) {
715
+ var k = O(e), E = Object.keys(r).filter(function(Er) {
716
+ return Er !== "key";
717
+ }), X = E.length > 0 ? "{key: someKey, " + E.join(": ..., ") + ": ...}" : "{key: someKey}";
718
+ if (!Ce[k + X]) {
719
+ var br = E.length > 0 ? "{" + E.join(": ..., ") + ": ...}" : "{}";
720
+ _(`A props object containing a "key" prop is being spread into JSX:
321
721
  let props = %s;
322
722
  <%s {...props} />
323
723
  React keys must be passed directly to JSX without using spread:
324
724
  let props = %s;
325
- <%s key={someKey} {...props} />`,
326
- u,
327
- f,
328
- g,
329
- f
330
- ), W[f + u] = !0);
331
- }
332
- if (f = null, i !== void 0 && (o(i), f = "" + i), l(n) && (o(n.key), f = "" + n.key), "key" in n) {
333
- i = {};
334
- for (var x in n)
335
- x !== "key" && (i[x] = n[x]);
336
- } else i = n;
337
- return f && d(
338
- i,
339
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
340
- ), R(
341
- e,
342
- f,
343
- i,
344
- s(),
345
- y,
346
- O
347
- );
348
- }
349
- function v(e) {
350
- m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === k && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
351
- }
352
- function m(e) {
353
- return typeof e == "object" && e !== null && e.$$typeof === Y;
354
- }
355
- var h = fe, Y = /* @__PURE__ */ Symbol.for("react.transitional.element"), Z = /* @__PURE__ */ Symbol.for("react.portal"), w = /* @__PURE__ */ Symbol.for("react.fragment"), Q = /* @__PURE__ */ Symbol.for("react.strict_mode"), ee = /* @__PURE__ */ Symbol.for("react.profiler"), re = /* @__PURE__ */ Symbol.for("react.consumer"), te = /* @__PURE__ */ Symbol.for("react.context"), ne = /* @__PURE__ */ Symbol.for("react.forward_ref"), oe = /* @__PURE__ */ Symbol.for("react.suspense"), ae = /* @__PURE__ */ Symbol.for("react.suspense_list"), se = /* @__PURE__ */ Symbol.for("react.memo"), k = /* @__PURE__ */ Symbol.for("react.lazy"), ce = /* @__PURE__ */ Symbol.for("react.activity"), ie = /* @__PURE__ */ Symbol.for("react.client.reference"), P = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, F = Object.prototype.hasOwnProperty, le = Array.isArray, A = console.createTask ? console.createTask : function() {
356
- return null;
357
- };
358
- h = {
359
- react_stack_bottom_frame: function(e) {
360
- return e();
725
+ <%s key={someKey} {...props} />`, X, k, br, k), Ce[k + X] = !0;
726
+ }
727
+ }
728
+ return e === u ? hr(g) : gr(g), g;
361
729
  }
362
- };
363
- var L, D = {}, J = h.react_stack_bottom_frame.bind(
364
- h,
365
- c
366
- )(), V = A(a(c)), W = {};
367
- E.Fragment = w, E.jsx = function(e, n, i) {
368
- var u = 1e4 > P.recentlyCreatedOwnerStacks++;
369
- return p(
370
- e,
371
- n,
372
- i,
373
- !1,
374
- u ? Error("react-stack-top-frame") : J,
375
- u ? A(a(e)) : V
376
- );
377
- }, E.jsxs = function(e, n, i) {
378
- var u = 1e4 > P.recentlyCreatedOwnerStacks++;
379
- return p(
380
- e,
381
- n,
382
- i,
383
- !0,
384
- u ? Error("react-stack-top-frame") : J,
385
- u ? A(a(e)) : V
386
- );
387
- };
388
- })()), E;
730
+ }
731
+ function pr(e, r, t) {
732
+ return ke(e, r, t, !0);
733
+ }
734
+ function yr(e, r, t) {
735
+ return ke(e, r, t, !1);
736
+ }
737
+ var mr = yr, _r = pr;
738
+ W.Fragment = u, W.jsx = mr, W.jsxs = _r;
739
+ })()), W;
389
740
  }
390
- var K;
391
- function ye() {
392
- return K || (K = 1, process.env.NODE_ENV === "production" ? T.exports = be() : T.exports = Ee()), T.exports;
741
+ var Fe;
742
+ function xr() {
743
+ return Fe || (Fe = 1, process.env.NODE_ENV === "production" ? N.exports = kr() : N.exports = jr()), N.exports;
393
744
  }
394
- var _ = ye();
395
- const ke = ({ children: r, authConfig: t }) => {
396
- const [o, a] = I(null), [s, c] = I(!0), l = me(() => new ge(t), [t]), d = j(async () => {
397
- c(!0);
398
- const p = localStorage.getItem(l.config.baseKey + "_access");
399
- if (!p) {
400
- a(null), c(!1);
745
+ var F = xr();
746
+ const $r = ({ children: n, authConfig: a }) => {
747
+ const [c, u] = Q(null), [d, p] = Q(!0), h = Sr(() => new Tr(a), [a]), R = Z(async () => {
748
+ p(!0);
749
+ const m = localStorage.getItem(h.config.baseKey + "_access");
750
+ if (!m) {
751
+ u(null), p(!1);
401
752
  return;
402
753
  }
403
754
  try {
404
- const v = await X(l, `${l.config.authServer}/me`, {
755
+ const S = await We(h, `${h.config.authServer}/me`, {
405
756
  headers: {
406
- Authorization: `Bearer ${p}`
757
+ Authorization: `Bearer ${m}`
407
758
  }
408
759
  });
409
- if (!v.ok) throw new Error("not found");
410
- const m = await v.json();
411
- a({
412
- role: m.role.role_name,
413
- userId: m.user_id,
414
- userName: m.user_name,
415
- privileges: m.role.privileges.map((h) => h.privilege.trim())
760
+ if (!S.ok) throw new Error("not found");
761
+ const w = await S.json();
762
+ u({
763
+ role: w.role.role_name,
764
+ userId: w.user_id,
765
+ userName: w.user_name,
766
+ privileges: w.role.privileges.map((j) => j.privilege.trim())
416
767
  });
417
768
  } catch {
418
- a(null);
769
+ u(null);
419
770
  }
420
- c(!1);
771
+ p(!1);
421
772
  }, []);
422
- C(() => {
423
- d();
424
- }, [d]);
425
- const S = j(() => {
426
- N(l);
427
- }, [N, l]), R = j(() => {
428
- M(l), a(null);
429
- }, [M, l]);
430
- return /* @__PURE__ */ _.jsx($.Provider, { value: { loadMe: d, loading: s, user: o, login: S, authManager: l, logout: R }, children: r });
431
- }, Pe = () => {
432
- const { authManager: r, loadMe: t } = B($);
433
- return C(() => {
434
- r && (z(r), t());
435
- }, [z, r, t]), /* @__PURE__ */ _.jsx("div", {});
436
- }, U = () => {
437
- const r = B($);
438
- if (!r || !r.authManager) throw new Error("AuthContext not found");
439
- return r;
440
- }, Te = (r) => {
441
- const { user: t } = U();
442
- return !!t?.privileges?.includes(r);
773
+ re(() => {
774
+ R();
775
+ }, [R]);
776
+ const y = Z(() => {
777
+ ee(h);
778
+ }, [ee, h]), P = Z(() => {
779
+ xe(h), u(null);
780
+ }, [xe, h]);
781
+ return /* @__PURE__ */ F.jsx(te.Provider, { value: { loadMe: R, loading: d, user: c, login: y, authManager: h, logout: P }, children: n });
782
+ }, Ur = () => {
783
+ const { authManager: n, loadMe: a } = $e(te);
784
+ return re(() => {
785
+ n && (je(n), a());
786
+ }, [je, n, a]), /* @__PURE__ */ F.jsx("div", {});
787
+ }, ne = () => {
788
+ const n = $e(te);
789
+ if (!n || !n.authManager) throw new Error("AuthContext not found");
790
+ return n;
791
+ }, Ar = (n) => {
792
+ const { user: a } = ne();
793
+ return !!a?.privileges?.includes(n);
443
794
  };
444
- function Ae({ privilege: r, invalidPage: t, loadingPage: o }) {
445
- const { loading: a } = U(), s = Te(r);
446
- return a ? o : s ? /* @__PURE__ */ _.jsx(H, {}) : t;
795
+ function Wr({ privilege: n, invalidPage: a, loadingPage: c }) {
796
+ const { loading: u } = ne(), d = Ar(n);
797
+ return u ? c : d ? /* @__PURE__ */ F.jsx(Ue, {}) : a;
447
798
  }
448
- function Oe({ loadingPage: r }) {
449
- const { authManager: t, login: o, user: a } = U(), [s, c] = I(!0);
450
- return C(() => {
451
- if (!t) return;
452
- t.getToken() ? c(!1) : o();
453
- }, [t, a]), t ? s ? r ?? /* @__PURE__ */ _.jsx("div", { children: "Loading..." }) : /* @__PURE__ */ _.jsx(H, {}) : /* @__PURE__ */ _.jsx("p", { children: "invalud config" });
799
+ function Yr({ loadingPage: n }) {
800
+ const { authManager: a, login: c, user: u } = ne(), [d, p] = Q(!0);
801
+ return re(() => {
802
+ if (!a) return;
803
+ a.getToken() ? p(!1) : c();
804
+ }, [a, u]), a ? d ? n ?? /* @__PURE__ */ F.jsx("div", { children: "Loading..." }) : /* @__PURE__ */ F.jsx(Ue, {}) : /* @__PURE__ */ F.jsx("p", { children: "invalud config" });
454
805
  }
455
806
  export {
456
- $ as AuthContext,
457
- ge as AuthManager,
458
- ke as AuthProvider,
459
- Pe as CallbackPage,
460
- we as Config,
461
- Ae as PrivilegeGate,
462
- Oe as ProtectGate,
463
- X as apiFetch,
464
- z as handleCallback,
465
- N as login,
466
- M as logout,
467
- he as refreshToken,
468
- U as useAuth,
469
- Te as usePrivilege
807
+ te as AuthContext,
808
+ Tr as AuthManager,
809
+ $r as AuthProvider,
810
+ Ur as CallbackPage,
811
+ Dr as Config,
812
+ Wr as PrivilegeGate,
813
+ Yr as ProtectGate,
814
+ We as apiFetch,
815
+ je as handleCallback,
816
+ ee as login,
817
+ xe as logout,
818
+ wr as refreshToken,
819
+ ne as useAuth,
820
+ Ar as usePrivilege
470
821
  };