@fctc/edu-logic-lib 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/config.js +257 -6
  2. package/dist/config.mjs +256 -2
  3. package/dist/constants.js +152 -53
  4. package/dist/constants.mjs +141 -2
  5. package/dist/environment.js +839 -16
  6. package/dist/environment.mjs +840 -4
  7. package/dist/hooks.js +4850 -180
  8. package/dist/hooks.mjs +4813 -9
  9. package/dist/index.js +5320 -626
  10. package/dist/index.mjs +5165 -12
  11. package/dist/models.js +1107 -18
  12. package/dist/models.mjs +1107 -9
  13. package/dist/provider.js +1115 -17
  14. package/dist/provider.mjs +1115 -8
  15. package/dist/services.js +1922 -31
  16. package/dist/services.mjs +1922 -7
  17. package/dist/store.js +576 -248
  18. package/dist/store.mjs +519 -1
  19. package/dist/types.js +0 -2
  20. package/dist/types.mjs +1 -1
  21. package/dist/utils.js +2355 -61
  22. package/dist/utils.mjs +2344 -1
  23. package/package.json +2 -1
  24. package/dist/chunk-4K3QAEZ6.js +0 -90
  25. package/dist/chunk-6BLY7NZ6.mjs +0 -120
  26. package/dist/chunk-6QXB3XX7.mjs +0 -256
  27. package/dist/chunk-7JD5GMIZ.js +0 -2
  28. package/dist/chunk-AYUH66EE.mjs +0 -62
  29. package/dist/chunk-CZHZLKNA.mjs +0 -585
  30. package/dist/chunk-EK43MEN4.js +0 -635
  31. package/dist/chunk-ELARQVCE.mjs +0 -2344
  32. package/dist/chunk-FVGPSTJ7.js +0 -122
  33. package/dist/chunk-GGOFXFSX.js +0 -2362
  34. package/dist/chunk-IXDDYGKE.js +0 -61
  35. package/dist/chunk-MLJQPO4Q.mjs +0 -57
  36. package/dist/chunk-OADBRQ4A.js +0 -32
  37. package/dist/chunk-OBR6UTC5.mjs +0 -1
  38. package/dist/chunk-OFUXC2LA.mjs +0 -86
  39. package/dist/chunk-P2IGWJDZ.js +0 -1068
  40. package/dist/chunk-QLUONJPQ.mjs +0 -519
  41. package/dist/chunk-RWRHCIQI.mjs +0 -1059
  42. package/dist/chunk-RZBHZYXG.js +0 -582
  43. package/dist/chunk-S7B3VKMJ.mjs +0 -85
  44. package/dist/chunk-S7YF2I23.js +0 -95
  45. package/dist/chunk-UY6GNZNB.js +0 -262
  46. package/dist/chunk-XYVK476U.mjs +0 -29
  47. package/dist/chunk-YOV6KAT2.js +0 -66
@@ -1,25 +1,848 @@
1
1
  'use strict';
2
2
 
3
- var chunk4K3QAEZ6_js = require('./chunk-4K3QAEZ6.js');
4
- require('./chunk-RZBHZYXG.js');
5
- require('./chunk-UY6GNZNB.js');
6
- require('./chunk-IXDDYGKE.js');
3
+ var toolkit = require('@reduxjs/toolkit');
4
+ var axios = require('axios');
7
5
 
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
7
 
8
+ var axios__default = /*#__PURE__*/_interopDefault(axios);
9
9
 
10
- Object.defineProperty(exports, "EnvStore", {
11
- enumerable: true,
12
- get: function () { return chunk4K3QAEZ6_js.EnvStore; }
10
+ // src/store/reducers/env-slice/index.ts
11
+ var initialState = {
12
+ baseUrl: "",
13
+ requests: null,
14
+ companies: [],
15
+ user: {},
16
+ envFile: null,
17
+ defaultCompany: {
18
+ id: null,
19
+ logo: "",
20
+ secondary_color: "",
21
+ primary_color: ""
22
+ },
23
+ context: {
24
+ uid: null,
25
+ allowed_company_ids: [],
26
+ lang: "vi_VN",
27
+ tz: "Asia/Saigon"
28
+ }
29
+ };
30
+ var envSlice = toolkit.createSlice({
31
+ name: "env",
32
+ initialState,
33
+ reducers: {
34
+ setEnv: (state, action) => {
35
+ Object.assign(state, action.payload);
36
+ },
37
+ setUid: (state, action) => {
38
+ state.context.uid = action.payload;
39
+ },
40
+ setAllowCompanies: (state, action) => {
41
+ state.context.allowed_company_ids = action.payload;
42
+ },
43
+ setCompanies: (state, action) => {
44
+ state.companies = action.payload;
45
+ },
46
+ setDefaultCompany: (state, action) => {
47
+ state.defaultCompany = action.payload;
48
+ },
49
+ setLang: (state, action) => {
50
+ state.context.lang = action.payload;
51
+ },
52
+ setUser: (state, action) => {
53
+ state.user = action.payload;
54
+ },
55
+ setEnvFile: (state, action) => {
56
+ state.envFile = action.payload;
57
+ }
58
+ }
13
59
  });
14
- Object.defineProperty(exports, "env", {
15
- enumerable: true,
16
- get: function () { return chunk4K3QAEZ6_js.env; }
60
+ var {
61
+ setEnv,
62
+ setUid,
63
+ setLang,
64
+ setAllowCompanies,
65
+ setCompanies,
66
+ setDefaultCompany,
67
+ setUser,
68
+ setEnvFile
69
+ } = envSlice.actions;
70
+ var env_slice_default = envSlice.reducer;
71
+ var initialState2 = {
72
+ dataParse: null,
73
+ idFile: null,
74
+ isFileLoaded: false,
75
+ loadingImport: false,
76
+ selectedFile: null,
77
+ errorData: null
78
+ };
79
+ var excelSlice = toolkit.createSlice({
80
+ name: "excel",
81
+ initialState: initialState2,
82
+ reducers: {
83
+ setDataParse: (state, action) => {
84
+ state.dataParse = action.payload;
85
+ },
86
+ setIdFile: (state, action) => {
87
+ state.idFile = action.payload;
88
+ },
89
+ setIsFileLoaded: (state, action) => {
90
+ state.isFileLoaded = action.payload;
91
+ },
92
+ setLoadingImport: (state, action) => {
93
+ state.loadingImport = action.payload;
94
+ },
95
+ setSelectedFile: (state, action) => {
96
+ state.selectedFile = action.payload;
97
+ },
98
+ setErrorData: (state, action) => {
99
+ state.errorData = action.payload;
100
+ }
101
+ }
17
102
  });
18
- Object.defineProperty(exports, "getEnv", {
19
- enumerable: true,
20
- get: function () { return chunk4K3QAEZ6_js.getEnv; }
103
+ var {
104
+ setDataParse,
105
+ setIdFile,
106
+ setIsFileLoaded,
107
+ setLoadingImport,
108
+ setSelectedFile,
109
+ setErrorData
110
+ } = excelSlice.actions;
111
+ var excel_slice_default = excelSlice.reducer;
112
+ var initialState3 = {
113
+ viewDataStore: {},
114
+ isShowingModalDetail: false,
115
+ isShowModalTranslate: false,
116
+ formSubmitComponent: {},
117
+ fieldTranslation: null,
118
+ listSubject: {},
119
+ dataUser: {}
120
+ };
121
+ var formSlice = toolkit.createSlice({
122
+ name: "form",
123
+ initialState: initialState3,
124
+ reducers: {
125
+ setViewDataStore: (state, action) => {
126
+ state.viewDataStore = action.payload;
127
+ },
128
+ setIsShowingModalDetail: (state, action) => {
129
+ state.isShowingModalDetail = action.payload;
130
+ },
131
+ setIsShowModalTranslate: (state, action) => {
132
+ state.isShowModalTranslate = action.payload;
133
+ },
134
+ setFormSubmitComponent: (state, action) => {
135
+ state.formSubmitComponent[action.payload.key] = action.payload.component;
136
+ },
137
+ setFieldTranslate: (state, action) => {
138
+ state.fieldTranslation = action.payload;
139
+ },
140
+ setListSubject: (state, action) => {
141
+ state.listSubject = action.payload;
142
+ },
143
+ setDataUser: (state, action) => {
144
+ state.dataUser = action.payload;
145
+ }
146
+ }
21
147
  });
22
- Object.defineProperty(exports, "initEnv", {
23
- enumerable: true,
24
- get: function () { return chunk4K3QAEZ6_js.initEnv; }
148
+ var {
149
+ setViewDataStore,
150
+ setIsShowingModalDetail,
151
+ setIsShowModalTranslate,
152
+ setFormSubmitComponent,
153
+ setFieldTranslate,
154
+ setListSubject,
155
+ setDataUser
156
+ } = formSlice.actions;
157
+ var form_slice_default = formSlice.reducer;
158
+ var initialState4 = {
159
+ pageLimit: 10,
160
+ fields: {},
161
+ order: "",
162
+ selectedRowKeys: [],
163
+ indexRowTableModal: -2,
164
+ footerGroupTable: {},
165
+ page: 0,
166
+ domainTable: []
167
+ };
168
+ var listSlice = toolkit.createSlice({
169
+ name: "list",
170
+ initialState: initialState4,
171
+ reducers: {
172
+ setPageLimit: (state, action) => {
173
+ state.pageLimit = action.payload;
174
+ },
175
+ setFields: (state, action) => {
176
+ state.fields = action.payload;
177
+ },
178
+ setOrder: (state, action) => {
179
+ state.order = action.payload;
180
+ },
181
+ setSelectedRowKeys: (state, action) => {
182
+ state.selectedRowKeys = action.payload;
183
+ },
184
+ setIndexRowTableModal: (state, action) => {
185
+ state.indexRowTableModal = action.payload;
186
+ },
187
+ setPage: (state, action) => {
188
+ state.page = action.payload;
189
+ },
190
+ setDomainTable: (state, action) => {
191
+ state.domainTable = action.payload;
192
+ }
193
+ }
25
194
  });
195
+ var {
196
+ setPageLimit,
197
+ setFields,
198
+ setOrder,
199
+ setSelectedRowKeys,
200
+ setIndexRowTableModal,
201
+ setPage,
202
+ setDomainTable
203
+ } = listSlice.actions;
204
+ var list_slice_default = listSlice.reducer;
205
+ var initialState5 = {
206
+ menuList: []
207
+ };
208
+ var navbarSlice = toolkit.createSlice({
209
+ name: "navbar",
210
+ initialState: initialState5,
211
+ reducers: {
212
+ setMenuList: (state, action) => {
213
+ state.menuList = action.payload;
214
+ }
215
+ }
216
+ });
217
+ var { setMenuList } = navbarSlice.actions;
218
+ var navbar_slice_default = navbarSlice.reducer;
219
+ var initialState6 = {
220
+ profile: {}
221
+ };
222
+ var profileSlice = toolkit.createSlice({
223
+ name: "profile",
224
+ initialState: initialState6,
225
+ reducers: {
226
+ setProfile: (state, action) => {
227
+ state.profile = action.payload;
228
+ }
229
+ }
230
+ });
231
+ var { setProfile } = profileSlice.actions;
232
+ var profile_slice_default = profileSlice.reducer;
233
+ var initialState7 = {
234
+ groupByDomain: null,
235
+ tableHead: [],
236
+ searchString: "",
237
+ hoveredIndexSearchList: null,
238
+ selectedTags: [],
239
+ firstDomain: null,
240
+ searchMap: {},
241
+ typeFieldsSearch: "",
242
+ modelSearch: "",
243
+ filterBy: [],
244
+ groupBy: []
245
+ };
246
+ var searchSlice = toolkit.createSlice({
247
+ name: "search",
248
+ initialState: initialState7,
249
+ reducers: {
250
+ setGroupByDomain: (state, action) => {
251
+ state.groupByDomain = action.payload;
252
+ },
253
+ setTableHead: (state, action) => {
254
+ state.tableHead = action.payload;
255
+ },
256
+ setSearchString: (state, action) => {
257
+ state.searchString = action.payload;
258
+ },
259
+ setHoveredIndexSearchList: (state, action) => {
260
+ state.hoveredIndexSearchList = action.payload;
261
+ },
262
+ setSelectedTags: (state, action) => {
263
+ state.selectedTags = action.payload;
264
+ },
265
+ setFirstDomain: (state, action) => {
266
+ state.firstDomain = action.payload;
267
+ },
268
+ setTypeFieldsSearch: (state, action) => {
269
+ state.typeFieldsSearch = action.payload;
270
+ },
271
+ setModelSearch: (state, action) => {
272
+ state.modelSearch = action.payload;
273
+ },
274
+ setFilterBy: (state, action) => {
275
+ state.filterBy = action.payload;
276
+ },
277
+ setGroupBy: (state, action) => {
278
+ state.groupBy = action.payload;
279
+ },
280
+ setSearchMap: (state, action) => {
281
+ state.searchMap = action.payload;
282
+ },
283
+ updateSearchMap: (state, action) => {
284
+ if (!state.searchMap[action.payload.key]) {
285
+ state.searchMap[action.payload.key] = [];
286
+ }
287
+ state.searchMap[action.payload.key].push(action.payload.value);
288
+ },
289
+ removeKeyFromSearchMap: (state, action) => {
290
+ const { key, item } = action.payload;
291
+ const values = state.searchMap[key];
292
+ if (!values) return;
293
+ if (item) {
294
+ const filtered = values.filter((value) => value.name !== item.name);
295
+ if (filtered.length > 0) {
296
+ state.searchMap[key] = filtered;
297
+ } else {
298
+ delete state.searchMap[key];
299
+ }
300
+ } else {
301
+ delete state.searchMap[key];
302
+ }
303
+ },
304
+ clearSearchMap: (state) => {
305
+ state.searchMap = {};
306
+ }
307
+ }
308
+ });
309
+ var {
310
+ setGroupByDomain,
311
+ setSelectedTags,
312
+ setSearchString,
313
+ setHoveredIndexSearchList,
314
+ setFirstDomain,
315
+ setTableHead,
316
+ setFilterBy,
317
+ setTypeFieldsSearch,
318
+ setModelSearch,
319
+ setSearchMap,
320
+ updateSearchMap,
321
+ removeKeyFromSearchMap,
322
+ setGroupBy,
323
+ clearSearchMap
324
+ } = searchSlice.actions;
325
+ var search_slice_default = searchSlice.reducer;
326
+
327
+ // node_modules/redux/dist/redux.mjs
328
+ function formatProdErrorMessage(code) {
329
+ return `Minified Redux error #${code}; visit https://redux.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
330
+ }
331
+ var randomString = () => Math.random().toString(36).substring(7).split("").join(".");
332
+ var ActionTypes = {
333
+ INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`,
334
+ REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
335
+ PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
336
+ };
337
+ var actionTypes_default = ActionTypes;
338
+ function isPlainObject(obj) {
339
+ if (typeof obj !== "object" || obj === null)
340
+ return false;
341
+ let proto = obj;
342
+ while (Object.getPrototypeOf(proto) !== null) {
343
+ proto = Object.getPrototypeOf(proto);
344
+ }
345
+ return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
346
+ }
347
+ function miniKindOf(val) {
348
+ if (val === void 0)
349
+ return "undefined";
350
+ if (val === null)
351
+ return "null";
352
+ const type = typeof val;
353
+ switch (type) {
354
+ case "boolean":
355
+ case "string":
356
+ case "number":
357
+ case "symbol":
358
+ case "function": {
359
+ return type;
360
+ }
361
+ }
362
+ if (Array.isArray(val))
363
+ return "array";
364
+ if (isDate(val))
365
+ return "date";
366
+ if (isError(val))
367
+ return "error";
368
+ const constructorName = ctorName(val);
369
+ switch (constructorName) {
370
+ case "Symbol":
371
+ case "Promise":
372
+ case "WeakMap":
373
+ case "WeakSet":
374
+ case "Map":
375
+ case "Set":
376
+ return constructorName;
377
+ }
378
+ return Object.prototype.toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, "");
379
+ }
380
+ function ctorName(val) {
381
+ return typeof val.constructor === "function" ? val.constructor.name : null;
382
+ }
383
+ function isError(val) {
384
+ return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
385
+ }
386
+ function isDate(val) {
387
+ if (val instanceof Date)
388
+ return true;
389
+ return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
390
+ }
391
+ function kindOf(val) {
392
+ let typeOfVal = typeof val;
393
+ if (process.env.NODE_ENV !== "production") {
394
+ typeOfVal = miniKindOf(val);
395
+ }
396
+ return typeOfVal;
397
+ }
398
+ function warning(message) {
399
+ if (typeof console !== "undefined" && typeof console.error === "function") {
400
+ console.error(message);
401
+ }
402
+ try {
403
+ throw new Error(message);
404
+ } catch (e) {
405
+ }
406
+ }
407
+ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
408
+ const reducerKeys = Object.keys(reducers);
409
+ const argumentName = action && action.type === actionTypes_default.INIT ? "preloadedState argument passed to createStore" : "previous state received by the reducer";
410
+ if (reducerKeys.length === 0) {
411
+ return "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.";
412
+ }
413
+ if (!isPlainObject(inputState)) {
414
+ return `The ${argumentName} has unexpected type of "${kindOf(inputState)}". Expected argument to be an object with the following keys: "${reducerKeys.join('", "')}"`;
415
+ }
416
+ const unexpectedKeys = Object.keys(inputState).filter((key) => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]);
417
+ unexpectedKeys.forEach((key) => {
418
+ unexpectedKeyCache[key] = true;
419
+ });
420
+ if (action && action.type === actionTypes_default.REPLACE)
421
+ return;
422
+ if (unexpectedKeys.length > 0) {
423
+ 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.`;
424
+ }
425
+ }
426
+ function assertReducerShape(reducers) {
427
+ Object.keys(reducers).forEach((key) => {
428
+ const reducer = reducers[key];
429
+ const initialState8 = reducer(void 0, {
430
+ type: actionTypes_default.INIT
431
+ });
432
+ if (typeof initialState8 === "undefined") {
433
+ 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.`);
434
+ }
435
+ if (typeof reducer(void 0, {
436
+ type: actionTypes_default.PROBE_UNKNOWN_ACTION()
437
+ }) === "undefined") {
438
+ 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.`);
439
+ }
440
+ });
441
+ }
442
+ function combineReducers(reducers) {
443
+ const reducerKeys = Object.keys(reducers);
444
+ const finalReducers = {};
445
+ for (let i = 0; i < reducerKeys.length; i++) {
446
+ const key = reducerKeys[i];
447
+ if (process.env.NODE_ENV !== "production") {
448
+ if (typeof reducers[key] === "undefined") {
449
+ warning(`No reducer provided for key "${key}"`);
450
+ }
451
+ }
452
+ if (typeof reducers[key] === "function") {
453
+ finalReducers[key] = reducers[key];
454
+ }
455
+ }
456
+ const finalReducerKeys = Object.keys(finalReducers);
457
+ let unexpectedKeyCache;
458
+ if (process.env.NODE_ENV !== "production") {
459
+ unexpectedKeyCache = {};
460
+ }
461
+ let shapeAssertionError;
462
+ try {
463
+ assertReducerShape(finalReducers);
464
+ } catch (e) {
465
+ shapeAssertionError = e;
466
+ }
467
+ return function combination(state = {}, action) {
468
+ if (shapeAssertionError) {
469
+ throw shapeAssertionError;
470
+ }
471
+ if (process.env.NODE_ENV !== "production") {
472
+ const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
473
+ if (warningMessage) {
474
+ warning(warningMessage);
475
+ }
476
+ }
477
+ let hasChanged = false;
478
+ const nextState = {};
479
+ for (let i = 0; i < finalReducerKeys.length; i++) {
480
+ const key = finalReducerKeys[i];
481
+ const reducer = finalReducers[key];
482
+ const previousStateForKey = state[key];
483
+ const nextStateForKey = reducer(previousStateForKey, action);
484
+ if (typeof nextStateForKey === "undefined") {
485
+ const actionType = action && action.type;
486
+ 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.`);
487
+ }
488
+ nextState[key] = nextStateForKey;
489
+ hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
490
+ }
491
+ hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
492
+ return hasChanged ? nextState : state;
493
+ };
494
+ }
495
+
496
+ // src/store/store.ts
497
+ var rootReducer = combineReducers({
498
+ env: env_slice_default,
499
+ navbar: navbar_slice_default,
500
+ list: list_slice_default,
501
+ search: search_slice_default,
502
+ form: form_slice_default,
503
+ excel: excel_slice_default,
504
+ profile: profile_slice_default
505
+ });
506
+ var envStore = toolkit.configureStore({
507
+ reducer: rootReducer,
508
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware({
509
+ serializableCheck: false
510
+ })
511
+ });
512
+ var MAINT_KEY = "MAINTENANCE_ACTIVE";
513
+ var MAINT_AT = "MAINTENANCE_AT";
514
+ var MAINT_LAST_PATH = "MAINTENANCE_LAST_PATH";
515
+ var hasRedirectedToMaintenance = false;
516
+ function setMaintenanceFlags() {
517
+ if (typeof window === "undefined") return;
518
+ const { pathname, search } = window.location;
519
+ const lastPath = pathname + (search || "");
520
+ if (pathname !== "/maintenance" && !window.localStorage.getItem(MAINT_LAST_PATH)) {
521
+ window.localStorage.setItem(MAINT_LAST_PATH, lastPath);
522
+ }
523
+ window.localStorage.setItem(MAINT_KEY, "true");
524
+ window.localStorage.setItem(MAINT_AT, String(Date.now()));
525
+ }
526
+ async function clearMaintenanceAndExit(getToken, opts) {
527
+ if (typeof window === "undefined") return;
528
+ const forceLogin = opts?.forceLogin === true;
529
+ const clearTokenOnForce = opts?.clearTokenOnForce !== false;
530
+ window.localStorage.removeItem(MAINT_KEY);
531
+ window.localStorage.removeItem(MAINT_AT);
532
+ const lastPath = window.localStorage.getItem(MAINT_LAST_PATH);
533
+ window.localStorage.removeItem(MAINT_LAST_PATH);
534
+ try {
535
+ if (forceLogin) {
536
+ if (clearTokenOnForce) {
537
+ try {
538
+ await opts?.clearToken?.();
539
+ } catch {
540
+ }
541
+ }
542
+ window.location.replace("/login");
543
+ return;
544
+ }
545
+ const token = await getToken();
546
+ if (token) {
547
+ const target = lastPath && lastPath !== "/maintenance" ? lastPath : "/";
548
+ window.location.replace(target);
549
+ } else {
550
+ window.location.replace("/login");
551
+ }
552
+ } catch {
553
+ window.location.replace("/login");
554
+ }
555
+ }
556
+ var axiosClient = {
557
+ init(config) {
558
+ const localStorage = config.localStorageUtils;
559
+ const sessionStorage = config.sessionStorageUtils;
560
+ const db = config.db;
561
+ let isRefreshing = false;
562
+ let failedQueue = [];
563
+ const processQueue = (error, token = null) => {
564
+ failedQueue?.forEach((prom) => {
565
+ if (error) {
566
+ prom.reject(error);
567
+ } else {
568
+ prom.resolve(token);
569
+ }
570
+ });
571
+ failedQueue = [];
572
+ };
573
+ const instance = axios__default.default.create({
574
+ adapter: axios__default.default.defaults.adapter,
575
+ baseURL: config.baseUrl,
576
+ timeout: 5e4,
577
+ paramsSerializer: (params) => new URLSearchParams(params).toString()
578
+ });
579
+ if (typeof window !== "undefined") {
580
+ const isMaint = window.localStorage.getItem(MAINT_KEY) === "true";
581
+ const onMaintenancePage = window.location.pathname === "/maintenance";
582
+ if (isMaint && !onMaintenancePage) {
583
+ hasRedirectedToMaintenance = true;
584
+ window.location.replace("/maintenance");
585
+ }
586
+ if (isMaint && onMaintenancePage) {
587
+ const healthUrl = config.healthUrl || `${(config.baseUrl || "").replace(/\/+$/, "")}/health`;
588
+ (async () => {
589
+ try {
590
+ await axios__default.default.get(healthUrl, { timeout: 8e3 });
591
+ await clearMaintenanceAndExit(() => localStorage.getAccessToken(), {
592
+ forceLogin: true,
593
+ clearTokenOnForce: true,
594
+ clearToken: () => localStorage.clearToken()
595
+ });
596
+ } catch {
597
+ }
598
+ })();
599
+ }
600
+ }
601
+ instance.interceptors.request.use(
602
+ async (configReq) => {
603
+ const token = await localStorage.getAccessToken();
604
+ if (token) {
605
+ configReq.headers["Authorization"] = "Bearer " + token;
606
+ }
607
+ return configReq;
608
+ },
609
+ (error) => Promise.reject(error)
610
+ );
611
+ instance.interceptors.response.use(
612
+ (response) => {
613
+ if (typeof window !== "undefined") {
614
+ const isMaint = window.localStorage.getItem(MAINT_KEY) === "true";
615
+ const onMaintenancePage = window.location.pathname === "/maintenance";
616
+ if (isMaint && onMaintenancePage) {
617
+ (async () => {
618
+ await clearMaintenanceAndExit(
619
+ () => localStorage.getAccessToken(),
620
+ {
621
+ forceLogin: true,
622
+ clearTokenOnForce: true,
623
+ clearToken: () => localStorage.clearToken()
624
+ }
625
+ );
626
+ })();
627
+ } else if (isMaint) {
628
+ window.localStorage.removeItem(MAINT_KEY);
629
+ window.localStorage.removeItem(MAINT_AT);
630
+ window.localStorage.removeItem(MAINT_LAST_PATH);
631
+ }
632
+ }
633
+ return handleResponse(response);
634
+ },
635
+ async (error) => {
636
+ const status = error?.response?.status;
637
+ if (status === 503) {
638
+ if (typeof window !== "undefined") {
639
+ setMaintenanceFlags();
640
+ if (!hasRedirectedToMaintenance && window.location.pathname !== "/maintenance") {
641
+ hasRedirectedToMaintenance = true;
642
+ window.location.replace("/maintenance");
643
+ }
644
+ }
645
+ return Promise.reject({
646
+ code: 503,
647
+ message: "SERVICE_UNAVAILABLE",
648
+ original: error?.response?.data
649
+ });
650
+ }
651
+ const handleError = async (err) => {
652
+ if (!err.response) {
653
+ return err;
654
+ }
655
+ const { data } = err.response;
656
+ if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
657
+ await clearAuthToken();
658
+ }
659
+ return data;
660
+ };
661
+ const originalRequest = error.config;
662
+ if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401].includes(
663
+ error.response.data.code
664
+ )) {
665
+ if (isRefreshing) {
666
+ return new Promise(function(resolve, reject) {
667
+ failedQueue.push({ resolve, reject });
668
+ }).then((token) => {
669
+ originalRequest.headers["Authorization"] = "Bearer " + token;
670
+ return instance.request(originalRequest);
671
+ }).catch(async (err) => {
672
+ if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
673
+ await clearAuthToken();
674
+ }
675
+ });
676
+ }
677
+ const browserSession = await sessionStorage.getBrowserSession();
678
+ const refreshToken = await localStorage.getRefreshToken();
679
+ const accessTokenExp = await localStorage.getAccessToken();
680
+ isRefreshing = true;
681
+ if (!refreshToken && (!browserSession || browserSession == "unActive")) {
682
+ await clearAuthToken();
683
+ } else {
684
+ const payload = Object.fromEntries(
685
+ Object.entries({
686
+ refresh_token: refreshToken,
687
+ grant_type: "refresh_token",
688
+ client_id: config.config.clientId,
689
+ client_secret: config.config.clientSecret
690
+ }).filter(([_, value]) => !!value)
691
+ );
692
+ return new Promise(function(resolve) {
693
+ axios__default.default.post(
694
+ `${config.baseUrl}${"/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
695
+ payload,
696
+ {
697
+ headers: {
698
+ "Content-Type": "multipart/form-data",
699
+ Authorization: `Bearer ${accessTokenExp}`
700
+ }
701
+ }
702
+ ).then(async (res) => {
703
+ const data = res.data;
704
+ await localStorage.setToken(data.access_token);
705
+ await localStorage.setRefreshToken(data.refresh_token);
706
+ axios__default.default.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
707
+ originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
708
+ processQueue(null, data.access_token);
709
+ resolve(instance.request(originalRequest));
710
+ }).catch(async (err) => {
711
+ if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST")) {
712
+ await clearAuthToken();
713
+ }
714
+ if (err && err.response) {
715
+ const { error_code } = err.response?.data || {};
716
+ if (error_code === "AUTHEN_FAIL") {
717
+ await clearAuthToken();
718
+ }
719
+ }
720
+ processQueue(err, null);
721
+ }).finally(() => {
722
+ isRefreshing = false;
723
+ });
724
+ });
725
+ }
726
+ }
727
+ return Promise.reject(await handleError(error));
728
+ }
729
+ );
730
+ const handleResponse = (res) => {
731
+ if (res && res.data) {
732
+ return res.data;
733
+ }
734
+ return res;
735
+ };
736
+ const clearAuthToken = async () => {
737
+ await localStorage.clearToken();
738
+ if (typeof window !== "undefined") {
739
+ window.location.href = `/login`;
740
+ }
741
+ };
742
+ function formatUrl(url, db2) {
743
+ return url + (db2 ? "?db=" + db2 : "");
744
+ }
745
+ const responseBody = (response) => response;
746
+ const requests = {
747
+ get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
748
+ post: (url, body, headers) => instance.post(formatUrl(url, db), body, { headers }).then(responseBody),
749
+ post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
750
+ responseType: "arraybuffer",
751
+ headers: {
752
+ "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
753
+ Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
754
+ }
755
+ }).then(responseBody),
756
+ put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
757
+ patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
758
+ delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
759
+ };
760
+ return requests;
761
+ }
762
+ };
763
+
764
+ // src/environment/EnvStore.ts
765
+ var EnvStore = class {
766
+ envStore;
767
+ baseUrl;
768
+ requests;
769
+ context;
770
+ defaultCompany;
771
+ config;
772
+ companies;
773
+ user;
774
+ db;
775
+ localStorageUtils;
776
+ sessionStorageUtils;
777
+ constructor(envStore2, localStorageUtils, sessionStorageUtils) {
778
+ this.envStore = envStore2;
779
+ this.localStorageUtils = localStorageUtils;
780
+ this.sessionStorageUtils = sessionStorageUtils;
781
+ this.setup();
782
+ }
783
+ setup() {
784
+ const env2 = this.envStore.getState().env;
785
+ this.baseUrl = env2?.baseUrl;
786
+ this.requests = env2?.requests;
787
+ this.context = env2?.context;
788
+ this.defaultCompany = env2?.defaultCompany;
789
+ this.config = env2?.config;
790
+ this.companies = env2?.companies || [];
791
+ this.user = env2?.user;
792
+ this.db = env2?.db;
793
+ }
794
+ setupEnv(envConfig) {
795
+ const dispatch = this.envStore.dispatch;
796
+ const env2 = {
797
+ ...envConfig,
798
+ localStorageUtils: this.localStorageUtils,
799
+ sessionStorageUtils: this.sessionStorageUtils
800
+ };
801
+ const requests = axiosClient.init(env2);
802
+ dispatch(setEnv({ ...env2, requests }));
803
+ this.setup();
804
+ }
805
+ setUid(uid) {
806
+ const dispatch = this.envStore.dispatch;
807
+ dispatch(setUid(uid));
808
+ this.setup();
809
+ }
810
+ setLang(lang) {
811
+ const dispatch = this.envStore.dispatch;
812
+ dispatch(setLang(lang));
813
+ this.setup();
814
+ }
815
+ setAllowCompanies(allowCompanies) {
816
+ const dispatch = this.envStore.dispatch;
817
+ dispatch(setAllowCompanies(allowCompanies));
818
+ this.setup();
819
+ }
820
+ setCompanies(companies) {
821
+ const dispatch = this.envStore.dispatch;
822
+ dispatch(setCompanies(companies));
823
+ this.setup();
824
+ }
825
+ setDefaultCompany(company) {
826
+ const dispatch = this.envStore.dispatch;
827
+ dispatch(setDefaultCompany(company));
828
+ this.setup();
829
+ }
830
+ setUserInfo(userInfo) {
831
+ const dispatch = this.envStore.dispatch;
832
+ dispatch(setUser(userInfo));
833
+ this.setup();
834
+ }
835
+ };
836
+ exports.env = null;
837
+ function initEnv({}) {
838
+ exports.env = new EnvStore(envStore);
839
+ return exports.env;
840
+ }
841
+ function getEnv() {
842
+ if (!exports.env) exports.env = new EnvStore(envStore);
843
+ return exports.env;
844
+ }
845
+
846
+ exports.EnvStore = EnvStore;
847
+ exports.getEnv = getEnv;
848
+ exports.initEnv = initEnv;