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