@fctc/edu-logic-lib 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ var axios = require('axios');
3
4
  var reactRedux = require('react-redux');
4
5
  var toolkit = require('@reduxjs/toolkit');
5
- var axios = require('axios');
6
6
  var reactQuery = require('@tanstack/react-query');
7
7
  var React = require('react');
8
8
  var jsxRuntime = require('react/jsx-runtime');
@@ -12,6 +12,8 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
12
  var axios__default = /*#__PURE__*/_interopDefault(axios);
13
13
  var React__default = /*#__PURE__*/_interopDefault(React);
14
14
 
15
+ // src/config/axios-client.ts
16
+
15
17
  // src/constants/api/key-constant.ts
16
18
  var KeyConstants = /* @__PURE__ */ ((KeyConstants2) => {
17
19
  KeyConstants2["PROFILE"] = "userinfo";
@@ -68,6 +70,259 @@ var UriConstants = /* @__PURE__ */ ((UriConstants2) => {
68
70
  return UriConstants2;
69
71
  })(UriConstants || {});
70
72
 
73
+ // src/config/axios-client.ts
74
+ var MAINT_KEY = "MAINTENANCE_ACTIVE";
75
+ var MAINT_AT = "MAINTENANCE_AT";
76
+ var MAINT_LAST_PATH = "MAINTENANCE_LAST_PATH";
77
+ var hasRedirectedToMaintenance = false;
78
+ function setMaintenanceFlags() {
79
+ if (typeof window === "undefined") return;
80
+ const { pathname, search } = window.location;
81
+ const lastPath = pathname + (search || "");
82
+ if (pathname !== "/maintenance" && !window.localStorage.getItem(MAINT_LAST_PATH)) {
83
+ window.localStorage.setItem(MAINT_LAST_PATH, lastPath);
84
+ }
85
+ window.localStorage.setItem(MAINT_KEY, "true");
86
+ window.localStorage.setItem(MAINT_AT, String(Date.now()));
87
+ }
88
+ async function clearMaintenanceAndExit(getToken, opts) {
89
+ if (typeof window === "undefined") return;
90
+ const forceLogin = opts?.forceLogin === true;
91
+ const clearTokenOnForce = opts?.clearTokenOnForce !== false;
92
+ window.localStorage.removeItem(MAINT_KEY);
93
+ window.localStorage.removeItem(MAINT_AT);
94
+ const lastPath = window.localStorage.getItem(MAINT_LAST_PATH);
95
+ window.localStorage.removeItem(MAINT_LAST_PATH);
96
+ try {
97
+ if (forceLogin) {
98
+ if (clearTokenOnForce) {
99
+ try {
100
+ await opts?.clearToken?.();
101
+ } catch {
102
+ }
103
+ }
104
+ window.location.replace("/login");
105
+ return;
106
+ }
107
+ const token = await getToken();
108
+ if (token) {
109
+ const target = lastPath && lastPath !== "/maintenance" ? lastPath : "/";
110
+ window.location.replace(target);
111
+ } else {
112
+ window.location.replace("/login");
113
+ }
114
+ } catch {
115
+ window.location.replace("/login");
116
+ }
117
+ }
118
+ var axiosClient = {
119
+ init(config) {
120
+ const localStorage2 = config.localStorageUtils;
121
+ const sessionStorage = config.sessionStorageUtils;
122
+ const db = config.db;
123
+ let isRefreshing = false;
124
+ let failedQueue = [];
125
+ const processQueue = (error, token = null) => {
126
+ failedQueue?.forEach((prom) => {
127
+ if (error) {
128
+ prom.reject(error);
129
+ } else {
130
+ prom.resolve(token);
131
+ }
132
+ });
133
+ failedQueue = [];
134
+ };
135
+ const instance = axios__default.default.create({
136
+ adapter: axios__default.default.defaults.adapter,
137
+ baseURL: config.baseUrl,
138
+ timeout: 5e4,
139
+ paramsSerializer: (params) => new URLSearchParams(params).toString()
140
+ });
141
+ if (typeof window !== "undefined") {
142
+ const isMaint = window.localStorage.getItem(MAINT_KEY) === "true";
143
+ const onMaintenancePage = window.location.pathname === "/maintenance";
144
+ if (isMaint && !onMaintenancePage) {
145
+ hasRedirectedToMaintenance = true;
146
+ window.location.replace("/maintenance");
147
+ }
148
+ if (isMaint && onMaintenancePage) {
149
+ const healthUrl = config.healthUrl || `${(config.baseUrl || "").replace(/\/+$/, "")}/health`;
150
+ (async () => {
151
+ try {
152
+ await axios__default.default.get(healthUrl, { timeout: 8e3 });
153
+ await clearMaintenanceAndExit(() => localStorage2.getAccessToken(), {
154
+ forceLogin: true,
155
+ clearTokenOnForce: true,
156
+ clearToken: () => localStorage2.clearToken()
157
+ });
158
+ } catch {
159
+ }
160
+ })();
161
+ }
162
+ }
163
+ instance.interceptors.request.use(
164
+ async (configReq) => {
165
+ const token = await localStorage2.getAccessToken();
166
+ if (token) {
167
+ configReq.headers["Authorization"] = "Bearer " + token;
168
+ }
169
+ return configReq;
170
+ },
171
+ (error) => Promise.reject(error)
172
+ );
173
+ instance.interceptors.response.use(
174
+ (response) => {
175
+ if (typeof window !== "undefined") {
176
+ const isMaint = window.localStorage.getItem(MAINT_KEY) === "true";
177
+ const onMaintenancePage = window.location.pathname === "/maintenance";
178
+ if (isMaint && onMaintenancePage) {
179
+ (async () => {
180
+ await clearMaintenanceAndExit(
181
+ () => localStorage2.getAccessToken(),
182
+ {
183
+ forceLogin: true,
184
+ clearTokenOnForce: true,
185
+ clearToken: () => localStorage2.clearToken()
186
+ }
187
+ );
188
+ })();
189
+ } else if (isMaint) {
190
+ window.localStorage.removeItem(MAINT_KEY);
191
+ window.localStorage.removeItem(MAINT_AT);
192
+ window.localStorage.removeItem(MAINT_LAST_PATH);
193
+ }
194
+ }
195
+ return handleResponse(response);
196
+ },
197
+ async (error) => {
198
+ const status = error?.response?.status;
199
+ if (status === 503) {
200
+ if (typeof window !== "undefined") {
201
+ setMaintenanceFlags();
202
+ if (!hasRedirectedToMaintenance && window.location.pathname !== "/maintenance") {
203
+ hasRedirectedToMaintenance = true;
204
+ window.location.replace("/maintenance");
205
+ }
206
+ }
207
+ return Promise.reject({
208
+ code: 503,
209
+ message: "SERVICE_UNAVAILABLE",
210
+ original: error?.response?.data
211
+ });
212
+ }
213
+ const handleError = async (err) => {
214
+ if (!err.response) {
215
+ return err;
216
+ }
217
+ const { data } = err.response;
218
+ if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
219
+ await clearAuthToken();
220
+ }
221
+ return data;
222
+ };
223
+ const originalRequest = error.config;
224
+ if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401].includes(
225
+ error.response.data.code
226
+ )) {
227
+ if (isRefreshing) {
228
+ return new Promise(function(resolve, reject) {
229
+ failedQueue.push({ resolve, reject });
230
+ }).then((token) => {
231
+ originalRequest.headers["Authorization"] = "Bearer " + token;
232
+ return instance.request(originalRequest);
233
+ }).catch(async (err) => {
234
+ if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
235
+ await clearAuthToken();
236
+ }
237
+ });
238
+ }
239
+ const browserSession = await sessionStorage.getBrowserSession();
240
+ const refreshToken = await localStorage2.getRefreshToken();
241
+ const accessTokenExp = await localStorage2.getAccessToken();
242
+ isRefreshing = true;
243
+ if (!refreshToken && (!browserSession || browserSession == "unActive")) {
244
+ await clearAuthToken();
245
+ } else {
246
+ const payload = Object.fromEntries(
247
+ Object.entries({
248
+ refresh_token: refreshToken,
249
+ grant_type: "refresh_token",
250
+ client_id: config.config.clientId,
251
+ client_secret: config.config.clientSecret
252
+ }).filter(([_, value]) => !!value)
253
+ );
254
+ return new Promise(function(resolve) {
255
+ axios__default.default.post(
256
+ `${config.baseUrl}${"/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
257
+ payload,
258
+ {
259
+ headers: {
260
+ "Content-Type": "multipart/form-data",
261
+ Authorization: `Bearer ${accessTokenExp}`
262
+ }
263
+ }
264
+ ).then(async (res) => {
265
+ const data = res.data;
266
+ await localStorage2.setToken(data.access_token);
267
+ await localStorage2.setRefreshToken(data.refresh_token);
268
+ axios__default.default.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
269
+ originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
270
+ processQueue(null, data.access_token);
271
+ resolve(instance.request(originalRequest));
272
+ }).catch(async (err) => {
273
+ if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST")) {
274
+ await clearAuthToken();
275
+ }
276
+ if (err && err.response) {
277
+ const { error_code } = err.response?.data || {};
278
+ if (error_code === "AUTHEN_FAIL") {
279
+ await clearAuthToken();
280
+ }
281
+ }
282
+ processQueue(err, null);
283
+ }).finally(() => {
284
+ isRefreshing = false;
285
+ });
286
+ });
287
+ }
288
+ }
289
+ return Promise.reject(await handleError(error));
290
+ }
291
+ );
292
+ const handleResponse = (res) => {
293
+ if (res && res.data) {
294
+ return res.data;
295
+ }
296
+ return res;
297
+ };
298
+ const clearAuthToken = async () => {
299
+ await localStorage2.clearToken();
300
+ if (typeof window !== "undefined") {
301
+ window.location.href = `/login`;
302
+ }
303
+ };
304
+ function formatUrl(url, db2) {
305
+ return url + (db2 ? "?db=" + db2 : "");
306
+ }
307
+ const responseBody = (response) => response;
308
+ const requests = {
309
+ get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
310
+ post: (url, body, headers) => instance.post(formatUrl(url, db), body, { headers }).then(responseBody),
311
+ post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
312
+ responseType: "arraybuffer",
313
+ headers: {
314
+ "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
315
+ Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
316
+ }
317
+ }).then(responseBody),
318
+ put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
319
+ patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
320
+ delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
321
+ };
322
+ return requests;
323
+ }
324
+ };
325
+
71
326
  // src/constants/field/field-type-constant.ts
72
327
  var FieldTypeConstants = /* @__PURE__ */ ((FieldTypeConstants2) => {
73
328
  FieldTypeConstants2["CHAR"] = "char";
@@ -485,436 +740,185 @@ var ActionTypes = {
485
740
  REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
486
741
  PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
487
742
  };
488
- var actionTypes_default = ActionTypes;
489
- function isPlainObject(obj) {
490
- if (typeof obj !== "object" || obj === null)
491
- return false;
492
- let proto = obj;
493
- while (Object.getPrototypeOf(proto) !== null) {
494
- proto = Object.getPrototypeOf(proto);
495
- }
496
- return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
497
- }
498
- function miniKindOf(val) {
499
- if (val === void 0)
500
- return "undefined";
501
- if (val === null)
502
- return "null";
503
- const type = typeof val;
504
- switch (type) {
505
- case "boolean":
506
- case "string":
507
- case "number":
508
- case "symbol":
509
- case "function": {
510
- return type;
511
- }
512
- }
513
- if (Array.isArray(val))
514
- return "array";
515
- if (isDate(val))
516
- return "date";
517
- if (isError(val))
518
- return "error";
519
- const constructorName = ctorName(val);
520
- switch (constructorName) {
521
- case "Symbol":
522
- case "Promise":
523
- case "WeakMap":
524
- case "WeakSet":
525
- case "Map":
526
- case "Set":
527
- return constructorName;
528
- }
529
- return Object.prototype.toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, "");
530
- }
531
- function ctorName(val) {
532
- return typeof val.constructor === "function" ? val.constructor.name : null;
533
- }
534
- function isError(val) {
535
- return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
536
- }
537
- function isDate(val) {
538
- if (val instanceof Date)
539
- return true;
540
- return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
541
- }
542
- function kindOf(val) {
543
- let typeOfVal = typeof val;
544
- if (process.env.NODE_ENV !== "production") {
545
- typeOfVal = miniKindOf(val);
546
- }
547
- return typeOfVal;
548
- }
549
- function warning(message) {
550
- if (typeof console !== "undefined" && typeof console.error === "function") {
551
- console.error(message);
552
- }
553
- try {
554
- throw new Error(message);
555
- } catch (e) {
556
- }
557
- }
558
- function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
559
- const reducerKeys = Object.keys(reducers);
560
- const argumentName = action && action.type === actionTypes_default.INIT ? "preloadedState argument passed to createStore" : "previous state received by the reducer";
561
- if (reducerKeys.length === 0) {
562
- return "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.";
563
- }
564
- if (!isPlainObject(inputState)) {
565
- return `The ${argumentName} has unexpected type of "${kindOf(inputState)}". Expected argument to be an object with the following keys: "${reducerKeys.join('", "')}"`;
566
- }
567
- const unexpectedKeys = Object.keys(inputState).filter((key) => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]);
568
- unexpectedKeys.forEach((key) => {
569
- unexpectedKeyCache[key] = true;
570
- });
571
- if (action && action.type === actionTypes_default.REPLACE)
572
- return;
573
- if (unexpectedKeys.length > 0) {
574
- return `Unexpected ${unexpectedKeys.length > 1 ? "keys" : "key"} "${unexpectedKeys.join('", "')}" found in ${argumentName}. Expected to find one of the known reducer keys instead: "${reducerKeys.join('", "')}". Unexpected keys will be ignored.`;
575
- }
576
- }
577
- function assertReducerShape(reducers) {
578
- Object.keys(reducers).forEach((key) => {
579
- const reducer = reducers[key];
580
- const initialState8 = reducer(void 0, {
581
- type: actionTypes_default.INIT
582
- });
583
- if (typeof initialState8 === "undefined") {
584
- throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : `The slice reducer for key "${key}" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.`);
585
- }
586
- if (typeof reducer(void 0, {
587
- type: actionTypes_default.PROBE_UNKNOWN_ACTION()
588
- }) === "undefined") {
589
- throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : `The slice reducer for key "${key}" returned undefined when probed with a random type. Don't try to handle '${actionTypes_default.INIT}' or other actions in "redux/*" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.`);
590
- }
591
- });
592
- }
593
- function combineReducers(reducers) {
594
- const reducerKeys = Object.keys(reducers);
595
- const finalReducers = {};
596
- for (let i = 0; i < reducerKeys.length; i++) {
597
- const key = reducerKeys[i];
598
- if (process.env.NODE_ENV !== "production") {
599
- if (typeof reducers[key] === "undefined") {
600
- warning(`No reducer provided for key "${key}"`);
601
- }
602
- }
603
- if (typeof reducers[key] === "function") {
604
- finalReducers[key] = reducers[key];
605
- }
606
- }
607
- const finalReducerKeys = Object.keys(finalReducers);
608
- let unexpectedKeyCache;
609
- if (process.env.NODE_ENV !== "production") {
610
- unexpectedKeyCache = {};
611
- }
612
- let shapeAssertionError;
613
- try {
614
- assertReducerShape(finalReducers);
615
- } catch (e) {
616
- shapeAssertionError = e;
617
- }
618
- return function combination(state = {}, action) {
619
- if (shapeAssertionError) {
620
- throw shapeAssertionError;
621
- }
622
- if (process.env.NODE_ENV !== "production") {
623
- const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
624
- if (warningMessage) {
625
- warning(warningMessage);
626
- }
627
- }
628
- let hasChanged = false;
629
- const nextState = {};
630
- for (let i = 0; i < finalReducerKeys.length; i++) {
631
- const key = finalReducerKeys[i];
632
- const reducer = finalReducers[key];
633
- const previousStateForKey = state[key];
634
- const nextStateForKey = reducer(previousStateForKey, action);
635
- if (typeof nextStateForKey === "undefined") {
636
- const actionType = action && action.type;
637
- throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : `When called with an action of type ${actionType ? `"${String(actionType)}"` : "(unknown type)"}, the slice reducer for key "${key}" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.`);
638
- }
639
- nextState[key] = nextStateForKey;
640
- hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
641
- }
642
- hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
643
- return hasChanged ? nextState : state;
644
- };
645
- }
646
-
647
- // src/store/store.ts
648
- var rootReducer = combineReducers({
649
- env: env_slice_default,
650
- navbar: navbar_slice_default,
651
- list: list_slice_default,
652
- search: search_slice_default,
653
- form: form_slice_default,
654
- excel: excel_slice_default,
655
- profile: profile_slice_default
656
- });
657
- var envStore = toolkit.configureStore({
658
- reducer: rootReducer,
659
- middleware: (getDefaultMiddleware) => getDefaultMiddleware({
660
- serializableCheck: false
661
- })
662
- });
663
-
664
- // src/store/index.ts
665
- var useAppDispatch = reactRedux.useDispatch;
666
- var useAppSelector = reactRedux.useSelector;
667
- var MAINT_KEY = "MAINTENANCE_ACTIVE";
668
- var MAINT_AT = "MAINTENANCE_AT";
669
- var MAINT_LAST_PATH = "MAINTENANCE_LAST_PATH";
670
- var hasRedirectedToMaintenance = false;
671
- function setMaintenanceFlags() {
672
- if (typeof window === "undefined") return;
673
- const { pathname, search } = window.location;
674
- const lastPath = pathname + (search || "");
675
- if (pathname !== "/maintenance" && !window.localStorage.getItem(MAINT_LAST_PATH)) {
676
- window.localStorage.setItem(MAINT_LAST_PATH, lastPath);
677
- }
678
- window.localStorage.setItem(MAINT_KEY, "true");
679
- window.localStorage.setItem(MAINT_AT, String(Date.now()));
680
- }
681
- async function clearMaintenanceAndExit(getToken, opts) {
682
- if (typeof window === "undefined") return;
683
- const forceLogin = opts?.forceLogin === true;
684
- const clearTokenOnForce = opts?.clearTokenOnForce !== false;
685
- window.localStorage.removeItem(MAINT_KEY);
686
- window.localStorage.removeItem(MAINT_AT);
687
- const lastPath = window.localStorage.getItem(MAINT_LAST_PATH);
688
- window.localStorage.removeItem(MAINT_LAST_PATH);
689
- try {
690
- if (forceLogin) {
691
- if (clearTokenOnForce) {
692
- try {
693
- await opts?.clearToken?.();
694
- } catch {
695
- }
696
- }
697
- window.location.replace("/login");
698
- return;
699
- }
700
- const token = await getToken();
701
- if (token) {
702
- const target = lastPath && lastPath !== "/maintenance" ? lastPath : "/";
703
- window.location.replace(target);
704
- } else {
705
- window.location.replace("/login");
706
- }
707
- } catch {
708
- window.location.replace("/login");
709
- }
710
- }
711
- var axiosClient = {
712
- init(config) {
713
- const localStorage2 = config.localStorageUtils;
714
- const sessionStorage = config.sessionStorageUtils;
715
- const db = config.db;
716
- let isRefreshing = false;
717
- let failedQueue = [];
718
- const processQueue = (error, token = null) => {
719
- failedQueue?.forEach((prom) => {
720
- if (error) {
721
- prom.reject(error);
722
- } else {
723
- prom.resolve(token);
724
- }
725
- });
726
- failedQueue = [];
727
- };
728
- const instance = axios__default.default.create({
729
- adapter: axios__default.default.defaults.adapter,
730
- baseURL: config.baseUrl,
731
- timeout: 5e4,
732
- paramsSerializer: (params) => new URLSearchParams(params).toString()
733
- });
734
- if (typeof window !== "undefined") {
735
- const isMaint = window.localStorage.getItem(MAINT_KEY) === "true";
736
- const onMaintenancePage = window.location.pathname === "/maintenance";
737
- if (isMaint && !onMaintenancePage) {
738
- hasRedirectedToMaintenance = true;
739
- window.location.replace("/maintenance");
740
- }
741
- if (isMaint && onMaintenancePage) {
742
- const healthUrl = config.healthUrl || `${(config.baseUrl || "").replace(/\/+$/, "")}/health`;
743
- (async () => {
744
- try {
745
- await axios__default.default.get(healthUrl, { timeout: 8e3 });
746
- await clearMaintenanceAndExit(() => localStorage2.getAccessToken(), {
747
- forceLogin: true,
748
- clearTokenOnForce: true,
749
- clearToken: () => localStorage2.clearToken()
750
- });
751
- } catch {
752
- }
753
- })();
754
- }
755
- }
756
- instance.interceptors.request.use(
757
- async (configReq) => {
758
- const token = await localStorage2.getAccessToken();
759
- if (token) {
760
- configReq.headers["Authorization"] = "Bearer " + token;
761
- }
762
- return configReq;
763
- },
764
- (error) => Promise.reject(error)
765
- );
766
- instance.interceptors.response.use(
767
- (response) => {
768
- if (typeof window !== "undefined") {
769
- const isMaint = window.localStorage.getItem(MAINT_KEY) === "true";
770
- const onMaintenancePage = window.location.pathname === "/maintenance";
771
- if (isMaint && onMaintenancePage) {
772
- (async () => {
773
- await clearMaintenanceAndExit(
774
- () => localStorage2.getAccessToken(),
775
- {
776
- forceLogin: true,
777
- clearTokenOnForce: true,
778
- clearToken: () => localStorage2.clearToken()
779
- }
780
- );
781
- })();
782
- } else if (isMaint) {
783
- window.localStorage.removeItem(MAINT_KEY);
784
- window.localStorage.removeItem(MAINT_AT);
785
- window.localStorage.removeItem(MAINT_LAST_PATH);
786
- }
787
- }
788
- return handleResponse(response);
789
- },
790
- async (error) => {
791
- const status = error?.response?.status;
792
- if (status === 503) {
793
- if (typeof window !== "undefined") {
794
- setMaintenanceFlags();
795
- if (!hasRedirectedToMaintenance && window.location.pathname !== "/maintenance") {
796
- hasRedirectedToMaintenance = true;
797
- window.location.replace("/maintenance");
798
- }
799
- }
800
- return Promise.reject({
801
- code: 503,
802
- message: "SERVICE_UNAVAILABLE",
803
- original: error?.response?.data
804
- });
805
- }
806
- const handleError = async (err) => {
807
- if (!err.response) {
808
- return err;
809
- }
810
- const { data } = err.response;
811
- if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
812
- await clearAuthToken();
813
- }
814
- return data;
815
- };
816
- const originalRequest = error.config;
817
- if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401].includes(
818
- error.response.data.code
819
- )) {
820
- if (isRefreshing) {
821
- return new Promise(function(resolve, reject) {
822
- failedQueue.push({ resolve, reject });
823
- }).then((token) => {
824
- originalRequest.headers["Authorization"] = "Bearer " + token;
825
- return instance.request(originalRequest);
826
- }).catch(async (err) => {
827
- if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
828
- await clearAuthToken();
829
- }
830
- });
831
- }
832
- const browserSession = await sessionStorage.getBrowserSession();
833
- const refreshToken = await localStorage2.getRefreshToken();
834
- const accessTokenExp = await localStorage2.getAccessToken();
835
- isRefreshing = true;
836
- if (!refreshToken && (!browserSession || browserSession == "unActive")) {
837
- await clearAuthToken();
838
- } else {
839
- const payload = Object.fromEntries(
840
- Object.entries({
841
- refresh_token: refreshToken,
842
- grant_type: "refresh_token",
843
- client_id: config.config.clientId,
844
- client_secret: config.config.clientSecret
845
- }).filter(([_, value]) => !!value)
846
- );
847
- return new Promise(function(resolve) {
848
- axios__default.default.post(
849
- `${config.baseUrl}${"/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
850
- payload,
851
- {
852
- headers: {
853
- "Content-Type": "multipart/form-data",
854
- Authorization: `Bearer ${accessTokenExp}`
855
- }
856
- }
857
- ).then(async (res) => {
858
- const data = res.data;
859
- await localStorage2.setToken(data.access_token);
860
- await localStorage2.setRefreshToken(data.refresh_token);
861
- axios__default.default.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
862
- originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
863
- processQueue(null, data.access_token);
864
- resolve(instance.request(originalRequest));
865
- }).catch(async (err) => {
866
- if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST")) {
867
- await clearAuthToken();
868
- }
869
- if (err && err.response) {
870
- const { error_code } = err.response?.data || {};
871
- if (error_code === "AUTHEN_FAIL") {
872
- await clearAuthToken();
873
- }
874
- }
875
- processQueue(err, null);
876
- }).finally(() => {
877
- isRefreshing = false;
878
- });
879
- });
880
- }
881
- }
882
- return Promise.reject(await handleError(error));
743
+ var actionTypes_default = ActionTypes;
744
+ function isPlainObject(obj) {
745
+ if (typeof obj !== "object" || obj === null)
746
+ return false;
747
+ let proto = obj;
748
+ while (Object.getPrototypeOf(proto) !== null) {
749
+ proto = Object.getPrototypeOf(proto);
750
+ }
751
+ return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
752
+ }
753
+ function miniKindOf(val) {
754
+ if (val === void 0)
755
+ return "undefined";
756
+ if (val === null)
757
+ return "null";
758
+ const type = typeof val;
759
+ switch (type) {
760
+ case "boolean":
761
+ case "string":
762
+ case "number":
763
+ case "symbol":
764
+ case "function": {
765
+ return type;
766
+ }
767
+ }
768
+ if (Array.isArray(val))
769
+ return "array";
770
+ if (isDate(val))
771
+ return "date";
772
+ if (isError(val))
773
+ return "error";
774
+ const constructorName = ctorName(val);
775
+ switch (constructorName) {
776
+ case "Symbol":
777
+ case "Promise":
778
+ case "WeakMap":
779
+ case "WeakSet":
780
+ case "Map":
781
+ case "Set":
782
+ return constructorName;
783
+ }
784
+ return Object.prototype.toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, "");
785
+ }
786
+ function ctorName(val) {
787
+ return typeof val.constructor === "function" ? val.constructor.name : null;
788
+ }
789
+ function isError(val) {
790
+ return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
791
+ }
792
+ function isDate(val) {
793
+ if (val instanceof Date)
794
+ return true;
795
+ return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
796
+ }
797
+ function kindOf(val) {
798
+ let typeOfVal = typeof val;
799
+ if (process.env.NODE_ENV !== "production") {
800
+ typeOfVal = miniKindOf(val);
801
+ }
802
+ return typeOfVal;
803
+ }
804
+ function warning(message) {
805
+ if (typeof console !== "undefined" && typeof console.error === "function") {
806
+ console.error(message);
807
+ }
808
+ try {
809
+ throw new Error(message);
810
+ } catch (e) {
811
+ }
812
+ }
813
+ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
814
+ const reducerKeys = Object.keys(reducers);
815
+ const argumentName = action && action.type === actionTypes_default.INIT ? "preloadedState argument passed to createStore" : "previous state received by the reducer";
816
+ if (reducerKeys.length === 0) {
817
+ return "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.";
818
+ }
819
+ if (!isPlainObject(inputState)) {
820
+ return `The ${argumentName} has unexpected type of "${kindOf(inputState)}". Expected argument to be an object with the following keys: "${reducerKeys.join('", "')}"`;
821
+ }
822
+ const unexpectedKeys = Object.keys(inputState).filter((key) => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]);
823
+ unexpectedKeys.forEach((key) => {
824
+ unexpectedKeyCache[key] = true;
825
+ });
826
+ if (action && action.type === actionTypes_default.REPLACE)
827
+ return;
828
+ if (unexpectedKeys.length > 0) {
829
+ return `Unexpected ${unexpectedKeys.length > 1 ? "keys" : "key"} "${unexpectedKeys.join('", "')}" found in ${argumentName}. Expected to find one of the known reducer keys instead: "${reducerKeys.join('", "')}". Unexpected keys will be ignored.`;
830
+ }
831
+ }
832
+ function assertReducerShape(reducers) {
833
+ Object.keys(reducers).forEach((key) => {
834
+ const reducer = reducers[key];
835
+ const initialState8 = reducer(void 0, {
836
+ type: actionTypes_default.INIT
837
+ });
838
+ if (typeof initialState8 === "undefined") {
839
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : `The slice reducer for key "${key}" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.`);
840
+ }
841
+ if (typeof reducer(void 0, {
842
+ type: actionTypes_default.PROBE_UNKNOWN_ACTION()
843
+ }) === "undefined") {
844
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : `The slice reducer for key "${key}" returned undefined when probed with a random type. Don't try to handle '${actionTypes_default.INIT}' or other actions in "redux/*" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.`);
845
+ }
846
+ });
847
+ }
848
+ function combineReducers(reducers) {
849
+ const reducerKeys = Object.keys(reducers);
850
+ const finalReducers = {};
851
+ for (let i = 0; i < reducerKeys.length; i++) {
852
+ const key = reducerKeys[i];
853
+ if (process.env.NODE_ENV !== "production") {
854
+ if (typeof reducers[key] === "undefined") {
855
+ warning(`No reducer provided for key "${key}"`);
883
856
  }
884
- );
885
- const handleResponse = (res) => {
886
- if (res && res.data) {
887
- return res.data;
857
+ }
858
+ if (typeof reducers[key] === "function") {
859
+ finalReducers[key] = reducers[key];
860
+ }
861
+ }
862
+ const finalReducerKeys = Object.keys(finalReducers);
863
+ let unexpectedKeyCache;
864
+ if (process.env.NODE_ENV !== "production") {
865
+ unexpectedKeyCache = {};
866
+ }
867
+ let shapeAssertionError;
868
+ try {
869
+ assertReducerShape(finalReducers);
870
+ } catch (e) {
871
+ shapeAssertionError = e;
872
+ }
873
+ return function combination(state = {}, action) {
874
+ if (shapeAssertionError) {
875
+ throw shapeAssertionError;
876
+ }
877
+ if (process.env.NODE_ENV !== "production") {
878
+ const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
879
+ if (warningMessage) {
880
+ warning(warningMessage);
888
881
  }
889
- return res;
890
- };
891
- const clearAuthToken = async () => {
892
- await localStorage2.clearToken();
893
- if (typeof window !== "undefined") {
894
- window.location.href = `/login`;
882
+ }
883
+ let hasChanged = false;
884
+ const nextState = {};
885
+ for (let i = 0; i < finalReducerKeys.length; i++) {
886
+ const key = finalReducerKeys[i];
887
+ const reducer = finalReducers[key];
888
+ const previousStateForKey = state[key];
889
+ const nextStateForKey = reducer(previousStateForKey, action);
890
+ if (typeof nextStateForKey === "undefined") {
891
+ const actionType = action && action.type;
892
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : `When called with an action of type ${actionType ? `"${String(actionType)}"` : "(unknown type)"}, the slice reducer for key "${key}" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.`);
895
893
  }
896
- };
897
- function formatUrl(url, db2) {
898
- return url + (db2 ? "?db=" + db2 : "");
894
+ nextState[key] = nextStateForKey;
895
+ hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
899
896
  }
900
- const responseBody = (response) => response;
901
- const requests = {
902
- get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
903
- post: (url, body, headers) => instance.post(formatUrl(url, db), body, { headers }).then(responseBody),
904
- post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
905
- responseType: "arraybuffer",
906
- headers: {
907
- "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
908
- Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
909
- }
910
- }).then(responseBody),
911
- put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
912
- patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
913
- delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
914
- };
915
- return requests;
916
- }
917
- };
897
+ hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
898
+ return hasChanged ? nextState : state;
899
+ };
900
+ }
901
+
902
+ // src/store/store.ts
903
+ var rootReducer = combineReducers({
904
+ env: env_slice_default,
905
+ navbar: navbar_slice_default,
906
+ list: list_slice_default,
907
+ search: search_slice_default,
908
+ form: form_slice_default,
909
+ excel: excel_slice_default,
910
+ profile: profile_slice_default
911
+ });
912
+ var envStore = toolkit.configureStore({
913
+ reducer: rootReducer,
914
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware({
915
+ serializableCheck: false
916
+ })
917
+ });
918
+
919
+ // src/store/index.ts
920
+ var useAppDispatch = reactRedux.useDispatch;
921
+ var useAppSelector = reactRedux.useSelector;
918
922
 
919
923
  // src/environment/EnvStore.ts
920
924
  var EnvStore = class {
@@ -5090,6 +5094,31 @@ var useRunAction = ({ idAction, context }) => {
5090
5094
  });
5091
5095
  };
5092
5096
  var use_run_action_default = useRunAction;
5097
+
5098
+ // src/models/company-model/index.ts
5099
+ var CompanyModel = class extends base_model_default {
5100
+ constructor(init) {
5101
+ super(init);
5102
+ }
5103
+ async getCurrentCompany() {
5104
+ return await company_service_default.getCurrentCompany();
5105
+ }
5106
+ async getUserCompany(id) {
5107
+ return await company_service_default.getInfoCompany(id);
5108
+ }
5109
+ };
5110
+ var company_model_default = CompanyModel;
5111
+
5112
+ // src/models/user-model/index.ts
5113
+ var UserModel = class extends base_model_default {
5114
+ constructor(init) {
5115
+ super(init);
5116
+ }
5117
+ async getProfile() {
5118
+ return await user_service_default.getProfile();
5119
+ }
5120
+ };
5121
+ var user_model_default = UserModel;
5093
5122
  var ReactQueryProvider = ({ children }) => {
5094
5123
  const [queryClient] = React.useState(
5095
5124
  () => new reactQuery.QueryClient({
@@ -5144,31 +5173,6 @@ var VersionGate = ({ children }) => {
5144
5173
  return ready ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }) : null;
5145
5174
  };
5146
5175
 
5147
- // src/models/company-model/index.ts
5148
- var CompanyModel = class extends base_model_default {
5149
- constructor(init) {
5150
- super(init);
5151
- }
5152
- async getCurrentCompany() {
5153
- return await company_service_default.getCurrentCompany();
5154
- }
5155
- async getUserCompany(id) {
5156
- return await company_service_default.getInfoCompany(id);
5157
- }
5158
- };
5159
- var company_model_default = CompanyModel;
5160
-
5161
- // src/models/user-model/index.ts
5162
- var UserModel = class extends base_model_default {
5163
- constructor(init) {
5164
- super(init);
5165
- }
5166
- async getProfile() {
5167
- return await user_service_default.getProfile();
5168
- }
5169
- };
5170
- var user_model_default = UserModel;
5171
-
5172
5176
  exports.ActionService = action_service_default;
5173
5177
  exports.AuthService = auth_service_default;
5174
5178
  exports.BaseModel = base_model_default;