@fctc/interface-logic 1.7.5 → 1.7.7

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/services.mjs CHANGED
@@ -28,6 +28,626 @@ var UriConstants = /* @__PURE__ */ ((UriConstants2) => {
28
28
  return UriConstants2;
29
29
  })(UriConstants || {});
30
30
 
31
+ // src/store/index.ts
32
+ import { useDispatch, useSelector } from "react-redux";
33
+
34
+ // src/store/reducers/breadcrums-slice/index.ts
35
+ import { createSlice } from "@reduxjs/toolkit";
36
+ var initialState = {
37
+ breadCrumbs: []
38
+ };
39
+ var breadcrumbsSlice = createSlice({
40
+ name: "breadcrumbs",
41
+ initialState,
42
+ reducers: {
43
+ setBreadCrumbs: (state, action) => {
44
+ state.breadCrumbs = [...state.breadCrumbs, action.payload];
45
+ }
46
+ }
47
+ });
48
+ var { setBreadCrumbs } = breadcrumbsSlice.actions;
49
+ var breadcrums_slice_default = breadcrumbsSlice.reducer;
50
+
51
+ // src/store/reducers/env-slice/index.ts
52
+ import { createSlice as createSlice2 } from "@reduxjs/toolkit";
53
+ var initialState2 = {
54
+ baseUrl: "",
55
+ companies: [],
56
+ user: {},
57
+ db: "",
58
+ refreshTokenEndpoint: "",
59
+ config: {
60
+ grantType: "",
61
+ clientId: "",
62
+ clientSecret: "",
63
+ redirectUri: ""
64
+ },
65
+ envFile: null,
66
+ defaultCompany: {
67
+ id: null,
68
+ logo: "",
69
+ secondary_color: "",
70
+ primary_color: ""
71
+ },
72
+ context: {
73
+ uid: null,
74
+ allowed_company_ids: [],
75
+ lang: "vi_VN",
76
+ tz: "Asia/Saigon"
77
+ }
78
+ };
79
+ var envSlice = createSlice2({
80
+ name: "env",
81
+ initialState: initialState2,
82
+ reducers: {
83
+ setEnv: (state, action) => {
84
+ Object.assign(state, action.payload);
85
+ },
86
+ setUid: (state, action) => {
87
+ state.context.uid = action.payload;
88
+ },
89
+ setAllowCompanies: (state, action) => {
90
+ state.context.allowed_company_ids = action.payload;
91
+ },
92
+ setCompanies: (state, action) => {
93
+ state.companies = action.payload;
94
+ },
95
+ setDefaultCompany: (state, action) => {
96
+ state.defaultCompany = action.payload;
97
+ },
98
+ setLang: (state, action) => {
99
+ state.context.lang = action.payload;
100
+ },
101
+ setUser: (state, action) => {
102
+ state.user = action.payload;
103
+ },
104
+ setConfig: (state, action) => {
105
+ state.config = action.payload;
106
+ },
107
+ setEnvFile: (state, action) => {
108
+ state.envFile = action.payload;
109
+ }
110
+ }
111
+ });
112
+ var {
113
+ setEnv,
114
+ setUid,
115
+ setLang,
116
+ setAllowCompanies,
117
+ setCompanies,
118
+ setDefaultCompany,
119
+ setUser,
120
+ setConfig,
121
+ setEnvFile
122
+ } = envSlice.actions;
123
+ var env_slice_default = envSlice.reducer;
124
+
125
+ // src/store/reducers/excel-slice/index.ts
126
+ import { createSlice as createSlice3 } from "@reduxjs/toolkit";
127
+ var initialState3 = {
128
+ dataParse: null,
129
+ idFile: null,
130
+ isFileLoaded: false,
131
+ loadingImport: false,
132
+ selectedFile: null,
133
+ errorData: null
134
+ };
135
+ var excelSlice = createSlice3({
136
+ name: "excel",
137
+ initialState: initialState3,
138
+ reducers: {
139
+ setDataParse: (state, action) => {
140
+ state.dataParse = action.payload;
141
+ },
142
+ setIdFile: (state, action) => {
143
+ state.idFile = action.payload;
144
+ },
145
+ setIsFileLoaded: (state, action) => {
146
+ state.isFileLoaded = action.payload;
147
+ },
148
+ setLoadingImport: (state, action) => {
149
+ state.loadingImport = action.payload;
150
+ },
151
+ setSelectedFile: (state, action) => {
152
+ state.selectedFile = action.payload;
153
+ },
154
+ setErrorData: (state, action) => {
155
+ state.errorData = action.payload;
156
+ }
157
+ }
158
+ });
159
+ var {
160
+ setDataParse,
161
+ setIdFile,
162
+ setIsFileLoaded,
163
+ setLoadingImport,
164
+ setSelectedFile,
165
+ setErrorData
166
+ } = excelSlice.actions;
167
+ var excel_slice_default = excelSlice.reducer;
168
+
169
+ // src/store/reducers/form-slice/index.ts
170
+ import { createSlice as createSlice4 } from "@reduxjs/toolkit";
171
+ var initialState4 = {
172
+ viewDataStore: {},
173
+ isShowingModalDetail: false,
174
+ isShowModalTranslate: false,
175
+ formSubmitComponent: {},
176
+ fieldTranslation: null,
177
+ listSubject: {},
178
+ dataUser: {}
179
+ };
180
+ var formSlice = createSlice4({
181
+ name: "form",
182
+ initialState: initialState4,
183
+ reducers: {
184
+ setViewDataStore: (state, action) => {
185
+ state.viewDataStore = action.payload;
186
+ },
187
+ setIsShowingModalDetail: (state, action) => {
188
+ state.isShowingModalDetail = action.payload;
189
+ },
190
+ setIsShowModalTranslate: (state, action) => {
191
+ state.isShowModalTranslate = action.payload;
192
+ },
193
+ setFormSubmitComponent: (state, action) => {
194
+ state.formSubmitComponent[action.payload.key] = action.payload.component;
195
+ },
196
+ setFieldTranslate: (state, action) => {
197
+ state.fieldTranslation = action.payload;
198
+ },
199
+ setListSubject: (state, action) => {
200
+ state.listSubject = action.payload;
201
+ },
202
+ setDataUser: (state, action) => {
203
+ state.dataUser = action.payload;
204
+ }
205
+ }
206
+ });
207
+ var {
208
+ setViewDataStore,
209
+ setIsShowingModalDetail,
210
+ setIsShowModalTranslate,
211
+ setFormSubmitComponent,
212
+ setFieldTranslate,
213
+ setListSubject,
214
+ setDataUser
215
+ } = formSlice.actions;
216
+ var form_slice_default = formSlice.reducer;
217
+
218
+ // src/store/reducers/header-slice/index.ts
219
+ import { createSlice as createSlice5 } from "@reduxjs/toolkit";
220
+ var headerSlice = createSlice5({
221
+ name: "header",
222
+ initialState: {
223
+ value: { allowedCompanyIds: [] }
224
+ },
225
+ reducers: {
226
+ setHeader: (state, action) => {
227
+ state.value = { ...state.value, ...action.payload };
228
+ },
229
+ setAllowedCompanyIds: (state, action) => {
230
+ state.value.allowedCompanyIds = action.payload;
231
+ }
232
+ }
233
+ });
234
+ var { setAllowedCompanyIds, setHeader } = headerSlice.actions;
235
+ var header_slice_default = headerSlice.reducer;
236
+
237
+ // src/store/reducers/list-slice/index.ts
238
+ import { createSlice as createSlice6 } from "@reduxjs/toolkit";
239
+ var initialState5 = {
240
+ pageLimit: 10,
241
+ fields: {},
242
+ order: "",
243
+ selectedRowKeys: [],
244
+ selectedRadioKey: 0,
245
+ indexRowTableModal: -2,
246
+ isUpdateTableModal: false,
247
+ footerGroupTable: {},
248
+ transferDetail: null,
249
+ page: 0,
250
+ domainTable: []
251
+ };
252
+ var listSlice = createSlice6({
253
+ name: "list",
254
+ initialState: initialState5,
255
+ reducers: {
256
+ setPageLimit: (state, action) => {
257
+ state.pageLimit = action.payload;
258
+ },
259
+ setFields: (state, action) => {
260
+ state.fields = action.payload;
261
+ },
262
+ setOrder: (state, action) => {
263
+ state.order = action.payload;
264
+ },
265
+ setSelectedRowKeys: (state, action) => {
266
+ state.selectedRowKeys = action.payload;
267
+ },
268
+ setSelectedRadioKey: (state, action) => {
269
+ state.selectedRadioKey = action.payload;
270
+ },
271
+ setIndexRowTableModal: (state, action) => {
272
+ state.indexRowTableModal = action.payload;
273
+ },
274
+ setTransferDetail: (state, action) => {
275
+ state.transferDetail = action.payload;
276
+ },
277
+ setIsUpdateTableModal: (state, action) => {
278
+ state.isUpdateTableModal = action.payload;
279
+ },
280
+ setPage: (state, action) => {
281
+ state.page = action.payload;
282
+ },
283
+ setDomainTable: (state, action) => {
284
+ state.domainTable = action.payload;
285
+ }
286
+ }
287
+ });
288
+ var {
289
+ setPageLimit,
290
+ setFields,
291
+ setOrder,
292
+ setSelectedRowKeys,
293
+ setIndexRowTableModal,
294
+ setIsUpdateTableModal,
295
+ setPage,
296
+ setSelectedRadioKey,
297
+ setTransferDetail,
298
+ setDomainTable
299
+ } = listSlice.actions;
300
+ var list_slice_default = listSlice.reducer;
301
+
302
+ // src/store/reducers/login-slice/index.ts
303
+ import { createSlice as createSlice7 } from "@reduxjs/toolkit";
304
+ var initialState6 = {
305
+ db: "",
306
+ redirectTo: "/",
307
+ forgotPasswordUrl: "/"
308
+ };
309
+ var loginSlice = createSlice7({
310
+ name: "login",
311
+ initialState: initialState6,
312
+ reducers: {
313
+ setDb: (state, action) => {
314
+ state.db = action.payload;
315
+ },
316
+ setRedirectTo: (state, action) => {
317
+ state.redirectTo = action.payload;
318
+ },
319
+ setForgotPasswordUrl: (state, action) => {
320
+ state.forgotPasswordUrl = action.payload;
321
+ }
322
+ }
323
+ });
324
+ var { setDb, setRedirectTo, setForgotPasswordUrl } = loginSlice.actions;
325
+ var login_slice_default = loginSlice.reducer;
326
+
327
+ // src/store/reducers/navbar-slice/index.ts
328
+ import { createSlice as createSlice8 } from "@reduxjs/toolkit";
329
+ var initialState7 = {
330
+ menuFocus: {},
331
+ menuAction: {},
332
+ navbarWidth: 250,
333
+ menuList: []
334
+ };
335
+ var navbarSlice = createSlice8({
336
+ name: "navbar",
337
+ initialState: initialState7,
338
+ reducers: {
339
+ setMenuFocus: (state, action) => {
340
+ state.menuFocus = action.payload;
341
+ },
342
+ setMenuFocusAction: (state, action) => {
343
+ state.menuAction = action.payload;
344
+ },
345
+ setNavbarWidth: (state, action) => {
346
+ state.navbarWidth = action.payload;
347
+ },
348
+ setMenuList: (state, action) => {
349
+ state.menuList = action.payload;
350
+ }
351
+ }
352
+ });
353
+ var { setMenuFocus, setMenuFocusAction, setNavbarWidth, setMenuList } = navbarSlice.actions;
354
+ var navbar_slice_default = navbarSlice.reducer;
355
+
356
+ // src/store/reducers/profile-slice/index.ts
357
+ import { createSlice as createSlice9 } from "@reduxjs/toolkit";
358
+ var initialState8 = {
359
+ profile: {}
360
+ };
361
+ var profileSlice = createSlice9({
362
+ name: "profile",
363
+ initialState: initialState8,
364
+ reducers: {
365
+ setProfile: (state, action) => {
366
+ state.profile = action.payload;
367
+ }
368
+ }
369
+ });
370
+ var { setProfile } = profileSlice.actions;
371
+ var profile_slice_default = profileSlice.reducer;
372
+
373
+ // src/store/reducers/search-slice/index.ts
374
+ import { createSlice as createSlice10 } from "@reduxjs/toolkit";
375
+ var initialState9 = {
376
+ groupByDomain: null,
377
+ searchBy: [],
378
+ searchString: "",
379
+ hoveredIndexSearchList: null,
380
+ selectedTags: [],
381
+ firstDomain: null,
382
+ searchMap: {},
383
+ filterBy: [],
384
+ groupBy: []
385
+ };
386
+ var searchSlice = createSlice10({
387
+ name: "search",
388
+ initialState: initialState9,
389
+ reducers: {
390
+ setGroupByDomain: (state, action) => {
391
+ state.groupByDomain = action.payload;
392
+ },
393
+ setSearchBy: (state, action) => {
394
+ state.searchBy = action.payload;
395
+ },
396
+ setSearchString: (state, action) => {
397
+ state.searchString = action.payload;
398
+ },
399
+ setHoveredIndexSearchList: (state, action) => {
400
+ state.hoveredIndexSearchList = action.payload;
401
+ },
402
+ setSelectedTags: (state, action) => {
403
+ state.selectedTags = action.payload;
404
+ },
405
+ setFirstDomain: (state, action) => {
406
+ state.firstDomain = action.payload;
407
+ },
408
+ setFilterBy: (state, action) => {
409
+ state.filterBy = action.payload;
410
+ },
411
+ setGroupBy: (state, action) => {
412
+ state.groupBy = action.payload;
413
+ },
414
+ setSearchMap: (state, action) => {
415
+ state.searchMap = action.payload;
416
+ },
417
+ updateSearchMap: (state, action) => {
418
+ if (!state.searchMap[action.payload.key]) {
419
+ state.searchMap[action.payload.key] = [];
420
+ }
421
+ state.searchMap[action.payload.key].push(action.payload.value);
422
+ },
423
+ removeKeyFromSearchMap: (state, action) => {
424
+ const { key, item } = action.payload;
425
+ const values = state.searchMap[key];
426
+ if (!values) return;
427
+ if (item) {
428
+ const filtered = values.filter((value) => value.name !== item.name);
429
+ if (filtered.length > 0) {
430
+ state.searchMap[key] = filtered;
431
+ } else {
432
+ delete state.searchMap[key];
433
+ }
434
+ } else {
435
+ delete state.searchMap[key];
436
+ }
437
+ },
438
+ clearSearchMap: (state) => {
439
+ state.searchMap = {};
440
+ }
441
+ }
442
+ });
443
+ var {
444
+ setGroupByDomain,
445
+ setSelectedTags,
446
+ setSearchString,
447
+ setHoveredIndexSearchList,
448
+ setFirstDomain,
449
+ setSearchBy,
450
+ setFilterBy,
451
+ setSearchMap,
452
+ updateSearchMap,
453
+ removeKeyFromSearchMap,
454
+ setGroupBy,
455
+ clearSearchMap
456
+ } = searchSlice.actions;
457
+ var search_slice_default = searchSlice.reducer;
458
+
459
+ // src/store/store.ts
460
+ import { configureStore } from "@reduxjs/toolkit";
461
+
462
+ // node_modules/redux/dist/redux.mjs
463
+ function formatProdErrorMessage(code) {
464
+ 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. `;
465
+ }
466
+ var randomString = () => Math.random().toString(36).substring(7).split("").join(".");
467
+ var ActionTypes = {
468
+ INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`,
469
+ REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
470
+ PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
471
+ };
472
+ var actionTypes_default = ActionTypes;
473
+ function isPlainObject(obj) {
474
+ if (typeof obj !== "object" || obj === null)
475
+ return false;
476
+ let proto = obj;
477
+ while (Object.getPrototypeOf(proto) !== null) {
478
+ proto = Object.getPrototypeOf(proto);
479
+ }
480
+ return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
481
+ }
482
+ function miniKindOf(val) {
483
+ if (val === void 0)
484
+ return "undefined";
485
+ if (val === null)
486
+ return "null";
487
+ const type = typeof val;
488
+ switch (type) {
489
+ case "boolean":
490
+ case "string":
491
+ case "number":
492
+ case "symbol":
493
+ case "function": {
494
+ return type;
495
+ }
496
+ }
497
+ if (Array.isArray(val))
498
+ return "array";
499
+ if (isDate(val))
500
+ return "date";
501
+ if (isError(val))
502
+ return "error";
503
+ const constructorName = ctorName(val);
504
+ switch (constructorName) {
505
+ case "Symbol":
506
+ case "Promise":
507
+ case "WeakMap":
508
+ case "WeakSet":
509
+ case "Map":
510
+ case "Set":
511
+ return constructorName;
512
+ }
513
+ return Object.prototype.toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, "");
514
+ }
515
+ function ctorName(val) {
516
+ return typeof val.constructor === "function" ? val.constructor.name : null;
517
+ }
518
+ function isError(val) {
519
+ return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
520
+ }
521
+ function isDate(val) {
522
+ if (val instanceof Date)
523
+ return true;
524
+ return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
525
+ }
526
+ function kindOf(val) {
527
+ let typeOfVal = typeof val;
528
+ if (process.env.NODE_ENV !== "production") {
529
+ typeOfVal = miniKindOf(val);
530
+ }
531
+ return typeOfVal;
532
+ }
533
+ function warning(message) {
534
+ if (typeof console !== "undefined" && typeof console.error === "function") {
535
+ console.error(message);
536
+ }
537
+ try {
538
+ throw new Error(message);
539
+ } catch (e) {
540
+ }
541
+ }
542
+ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
543
+ const reducerKeys = Object.keys(reducers);
544
+ const argumentName = action && action.type === actionTypes_default.INIT ? "preloadedState argument passed to createStore" : "previous state received by the reducer";
545
+ if (reducerKeys.length === 0) {
546
+ return "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.";
547
+ }
548
+ if (!isPlainObject(inputState)) {
549
+ return `The ${argumentName} has unexpected type of "${kindOf(inputState)}". Expected argument to be an object with the following keys: "${reducerKeys.join('", "')}"`;
550
+ }
551
+ const unexpectedKeys = Object.keys(inputState).filter((key) => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]);
552
+ unexpectedKeys.forEach((key) => {
553
+ unexpectedKeyCache[key] = true;
554
+ });
555
+ if (action && action.type === actionTypes_default.REPLACE)
556
+ return;
557
+ if (unexpectedKeys.length > 0) {
558
+ 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.`;
559
+ }
560
+ }
561
+ function assertReducerShape(reducers) {
562
+ Object.keys(reducers).forEach((key) => {
563
+ const reducer = reducers[key];
564
+ const initialState10 = reducer(void 0, {
565
+ type: actionTypes_default.INIT
566
+ });
567
+ if (typeof initialState10 === "undefined") {
568
+ 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.`);
569
+ }
570
+ if (typeof reducer(void 0, {
571
+ type: actionTypes_default.PROBE_UNKNOWN_ACTION()
572
+ }) === "undefined") {
573
+ 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.`);
574
+ }
575
+ });
576
+ }
577
+ function combineReducers(reducers) {
578
+ const reducerKeys = Object.keys(reducers);
579
+ const finalReducers = {};
580
+ for (let i = 0; i < reducerKeys.length; i++) {
581
+ const key = reducerKeys[i];
582
+ if (process.env.NODE_ENV !== "production") {
583
+ if (typeof reducers[key] === "undefined") {
584
+ warning(`No reducer provided for key "${key}"`);
585
+ }
586
+ }
587
+ if (typeof reducers[key] === "function") {
588
+ finalReducers[key] = reducers[key];
589
+ }
590
+ }
591
+ const finalReducerKeys = Object.keys(finalReducers);
592
+ let unexpectedKeyCache;
593
+ if (process.env.NODE_ENV !== "production") {
594
+ unexpectedKeyCache = {};
595
+ }
596
+ let shapeAssertionError;
597
+ try {
598
+ assertReducerShape(finalReducers);
599
+ } catch (e) {
600
+ shapeAssertionError = e;
601
+ }
602
+ return function combination(state = {}, action) {
603
+ if (shapeAssertionError) {
604
+ throw shapeAssertionError;
605
+ }
606
+ if (process.env.NODE_ENV !== "production") {
607
+ const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
608
+ if (warningMessage) {
609
+ warning(warningMessage);
610
+ }
611
+ }
612
+ let hasChanged = false;
613
+ const nextState = {};
614
+ for (let i = 0; i < finalReducerKeys.length; i++) {
615
+ const key = finalReducerKeys[i];
616
+ const reducer = finalReducers[key];
617
+ const previousStateForKey = state[key];
618
+ const nextStateForKey = reducer(previousStateForKey, action);
619
+ if (typeof nextStateForKey === "undefined") {
620
+ const actionType = action && action.type;
621
+ 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.`);
622
+ }
623
+ nextState[key] = nextStateForKey;
624
+ hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
625
+ }
626
+ hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
627
+ return hasChanged ? nextState : state;
628
+ };
629
+ }
630
+
631
+ // src/store/store.ts
632
+ var rootReducer = combineReducers({
633
+ env: env_slice_default,
634
+ header: header_slice_default,
635
+ navbar: navbar_slice_default,
636
+ list: list_slice_default,
637
+ search: search_slice_default,
638
+ form: form_slice_default,
639
+ breadcrumbs: breadcrums_slice_default,
640
+ login: login_slice_default,
641
+ excel: excel_slice_default,
642
+ profile: profile_slice_default
643
+ });
644
+ var envStore = configureStore({
645
+ reducer: rootReducer,
646
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware({
647
+ serializableCheck: false
648
+ })
649
+ });
650
+
31
651
  // src/configs/axios-client.ts
32
652
  import axios from "axios";
33
653
 
@@ -2147,331 +2767,19 @@ var toQueryString = (params) => {
2147
2767
  (key) => encodeURIComponent(key) + "=" + encodeURIComponent(params[key].toString())
2148
2768
  ).join("&");
2149
2769
  };
2150
- var updateTokenParamInOriginalRequest = (originalRequest, newAccessToken) => {
2151
- if (!originalRequest.data) return originalRequest.data;
2152
- if (typeof originalRequest.data === "string") {
2153
- try {
2154
- const parsedData = JSON.parse(originalRequest.data);
2155
- if (parsedData.with_context && typeof parsedData.with_context === "object") {
2156
- parsedData.with_context.token = newAccessToken;
2157
- }
2158
- return JSON.stringify(parsedData);
2159
- } catch (e) {
2160
- console.warn("Failed to parse originalRequest.data", e);
2161
- return originalRequest.data;
2162
- }
2163
- }
2164
- if (typeof originalRequest.data === "object" && originalRequest.data.with_context) {
2165
- originalRequest.data.with_context.token = newAccessToken;
2166
- }
2167
- return originalRequest.data;
2168
- };
2169
-
2170
- // src/utils/storage/local-storage.ts
2171
- var localStorageUtils = () => {
2172
- const setToken = async (access_token) => {
2173
- localStorage.setItem("accessToken", access_token);
2174
- };
2175
- const setRefreshToken = async (refresh_token) => {
2176
- localStorage.setItem("refreshToken", refresh_token);
2177
- };
2178
- const getAccessToken = async () => {
2179
- return localStorage.getItem("accessToken");
2180
- };
2181
- const getRefreshToken = async () => {
2182
- return localStorage.getItem("refreshToken");
2183
- };
2184
- const clearToken = async () => {
2185
- localStorage.removeItem("accessToken");
2186
- localStorage.removeItem("refreshToken");
2187
- };
2188
- return {
2189
- setToken,
2190
- setRefreshToken,
2191
- getAccessToken,
2192
- getRefreshToken,
2193
- clearToken
2194
- };
2195
- };
2196
-
2197
- // src/utils/storage/session-storage.ts
2198
- var sessionStorageUtils = () => {
2199
- const getBrowserSession = async () => {
2200
- return sessionStorage.getItem("browserSession");
2201
- };
2202
- return {
2203
- getBrowserSession
2204
- };
2205
- };
2206
-
2207
- // src/configs/axios-client.ts
2208
- var axiosClient = {
2209
- init(config) {
2210
- const localStorage2 = config.localStorageUtils ?? localStorageUtils();
2211
- const sessionStorage2 = config.sessionStorageUtils ?? sessionStorageUtils();
2212
- const db = config.db;
2213
- let isRefreshing = false;
2214
- let failedQueue = [];
2215
- const processQueue = (error, token = null) => {
2216
- failedQueue?.forEach((prom) => {
2217
- if (error) {
2218
- prom.reject(error);
2219
- } else {
2220
- prom.resolve(token);
2221
- }
2222
- });
2223
- failedQueue = [];
2224
- };
2225
- const instance = axios.create({
2226
- adapter: axios.defaults.adapter,
2227
- baseURL: config.baseUrl,
2228
- timeout: 5e4,
2229
- paramsSerializer: (params) => new URLSearchParams(params).toString()
2230
- });
2231
- instance.interceptors.request.use(
2232
- async (config2) => {
2233
- const useRefreshToken = config2.useRefreshToken;
2234
- const token = useRefreshToken ? await localStorage2.getRefreshToken() : await localStorage2.getAccessToken();
2235
- if (token) {
2236
- config2.headers["Authorization"] = "Bearer " + token;
2237
- }
2238
- return config2;
2239
- },
2240
- (error) => {
2241
- Promise.reject(error);
2242
- }
2243
- );
2244
- instance.interceptors.response.use(
2245
- (response) => {
2246
- return handleResponse(response);
2247
- },
2248
- async (error) => {
2249
- const handleError3 = async (error2) => {
2250
- if (!error2.response) {
2251
- return error2;
2252
- }
2253
- const { data } = error2.response;
2254
- if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
2255
- await clearAuthToken();
2256
- }
2257
- return data;
2258
- };
2259
- const originalRequest = error.config;
2260
- if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401, "ERR_2FA_006"].includes(
2261
- error.response.data.code
2262
- )) {
2263
- if (isRefreshing) {
2264
- return new Promise(function(resolve, reject) {
2265
- failedQueue.push({ resolve, reject });
2266
- }).then((token) => {
2267
- originalRequest.headers["Authorization"] = "Bearer " + token;
2268
- originalRequest.data = updateTokenParamInOriginalRequest(
2269
- originalRequest,
2270
- token
2271
- );
2272
- return instance.request(originalRequest);
2273
- }).catch(async (err) => {
2274
- if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
2275
- await clearAuthToken();
2276
- }
2277
- });
2278
- }
2279
- const browserSession = await sessionStorage2.getBrowserSession();
2280
- const refreshToken = await localStorage2.getRefreshToken();
2281
- const accessTokenExp = await localStorage2.getAccessToken();
2282
- isRefreshing = true;
2283
- if (!refreshToken && (!browserSession || browserSession == "unActive")) {
2284
- await clearAuthToken();
2285
- } else {
2286
- const payload = Object.fromEntries(
2287
- Object.entries({
2288
- refresh_token: refreshToken,
2289
- grant_type: "refresh_token",
2290
- client_id: config.config.clientId,
2291
- client_secret: config.config.clientSecret
2292
- }).filter(([_, value]) => !!value)
2293
- );
2294
- return new Promise(function(resolve) {
2295
- axios.post(
2296
- `${config.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
2297
- payload,
2298
- {
2299
- headers: {
2300
- "Content-Type": config.refreshTokenEndpoint ? "application/x-www-form-urlencoded" : "multipart/form-data",
2301
- Authorization: `Bearer ${accessTokenExp}`
2302
- }
2303
- }
2304
- ).then(async (res) => {
2305
- const data = res.data;
2306
- await localStorage2.setToken(data.access_token);
2307
- await localStorage2.setRefreshToken(data.refresh_token);
2308
- axios.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
2309
- originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
2310
- originalRequest.data = updateTokenParamInOriginalRequest(
2311
- originalRequest,
2312
- data.access_token
2313
- );
2314
- processQueue(null, data.access_token);
2315
- resolve(instance.request(originalRequest));
2316
- }).catch(async (err) => {
2317
- if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST") || err?.error_code === "ERR_2FA_006") {
2318
- await clearAuthToken();
2319
- }
2320
- if (err && err.response) {
2321
- const { error_code } = err.response?.data || {};
2322
- if (error_code === "AUTHEN_FAIL") {
2323
- await clearAuthToken();
2324
- }
2325
- }
2326
- processQueue(err, null);
2327
- }).finally(() => {
2328
- isRefreshing = false;
2329
- });
2330
- });
2331
- }
2332
- }
2333
- return Promise.reject(await handleError3(error));
2334
- }
2335
- );
2336
- const handleResponse = (res) => {
2337
- if (res && res.data) {
2338
- return res.data;
2339
- }
2340
- return res;
2341
- };
2342
- const handleError2 = (error) => {
2343
- if (error.isAxiosError && error.code === "ECONNABORTED") {
2344
- console.error("Request Timeout Error:", error);
2345
- return "Request Timeout Error";
2346
- } else if (error.isAxiosError && !error.response) {
2347
- console.error("Network Error:", error);
2348
- return "Network Error";
2349
- } else {
2350
- console.error("Other Error:", error?.response);
2351
- const errorMessage = error?.response?.data?.message || "An error occurred";
2352
- return { message: errorMessage, status: error?.response?.status };
2353
- }
2354
- };
2355
- const clearAuthToken = async () => {
2356
- await localStorage2.clearToken();
2357
- if (typeof window !== "undefined") {
2358
- window.location.href = `/login`;
2359
- }
2360
- };
2361
- function formatUrl(url, db2) {
2362
- return url + (db2 ? "?db=" + db2 : "");
2363
- }
2364
- const responseBody = (response) => response;
2365
- const requests = {
2366
- get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
2367
- post: (url, body, headers) => instance.post(formatUrl(url, db), body, headers).then(responseBody),
2368
- post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
2369
- responseType: "arraybuffer",
2370
- headers: {
2371
- "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
2372
- Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
2373
- }
2374
- }).then(responseBody),
2375
- put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
2376
- patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
2377
- delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
2378
- };
2379
- return requests;
2380
- }
2381
- };
2382
2770
 
2383
2771
  // src/environment/EnvStore.ts
2384
- var EnvStore = class _EnvStore {
2385
- static instance = null;
2386
- state = {};
2387
- localStorageUtils;
2388
- sessionStorageUtils;
2389
- constructor(localStorageUtils2, sessionStorageUtils2) {
2390
- this.localStorageUtils = localStorageUtils2;
2391
- this.sessionStorageUtils = sessionStorageUtils2;
2392
- }
2393
- static getInstance(localStorageUtils2, sessionStorageUtils2) {
2394
- if (!_EnvStore.instance) {
2395
- console.log("Creating new EnvStore instance");
2396
- _EnvStore.instance = new _EnvStore(localStorageUtils2, sessionStorageUtils2);
2397
- } else {
2398
- console.log("Returning existing EnvStore instance");
2399
- }
2400
- return _EnvStore.instance;
2401
- }
2402
- setupEnv(envConfig) {
2403
- this.state = {
2404
- ...this.state,
2405
- ...envConfig,
2406
- localStorageUtils: this.localStorageUtils,
2407
- sessionStorageUtils: this.sessionStorageUtils
2408
- };
2409
- console.log("Setting up env with config:", envConfig);
2410
- this.state.requests = axiosClient.init(this.state);
2411
- console.log("axiosClient.init result:", this.state.requests);
2412
- }
2413
- setUid(uid) {
2414
- this.state.uid = uid;
2415
- }
2416
- setLang(lang) {
2417
- this.state.lang = lang;
2418
- }
2419
- setAllowCompanies(allowCompanies) {
2420
- this.state.allowCompanies = allowCompanies;
2421
- }
2422
- setCompanies(companies) {
2423
- this.state.companies = companies;
2424
- }
2425
- setDefaultCompany(company) {
2426
- this.state.defaultCompany = company;
2427
- }
2428
- setUserInfo(userInfo) {
2429
- this.state.user = userInfo;
2430
- }
2431
- // Getters để truy cập trạng thái
2432
- get baseUrl() {
2433
- return this.state.baseUrl;
2434
- }
2435
- get requests() {
2436
- return this.state.requests;
2437
- }
2438
- get context() {
2439
- return this.state.context;
2440
- }
2441
- get defaultCompany() {
2442
- return this.state.defaultCompany;
2443
- }
2444
- get config() {
2445
- return this.state.config;
2446
- }
2447
- get companies() {
2448
- return this.state.companies;
2449
- }
2450
- get user() {
2451
- return this.state.user;
2452
- }
2453
- get db() {
2454
- return this.state.db;
2455
- }
2456
- get refreshTokenEndpoint() {
2457
- return this.state.refreshTokenEndpoint;
2458
- }
2459
- get uid() {
2460
- return this.state.uid;
2461
- }
2462
- get lang() {
2463
- return this.state.lang;
2464
- }
2465
- get allowCompanies() {
2466
- return this.state.allowCompanies;
2467
- }
2772
+ var requests = {
2773
+ get: async (url, headers) => ({}),
2774
+ post: async (url, body, headers) => ({}),
2775
+ post_excel: async (url, body, headers) => ({}),
2776
+ put: async (url, body, headers) => ({}),
2777
+ patch: async (url, body) => ({}),
2778
+ delete: async (url, body) => ({})
2468
2779
  };
2469
2780
  function getEnv() {
2470
- const instance = EnvStore.getInstance();
2471
- if (!instance) {
2472
- throw new Error("EnvStore has not been initialized \u2014 call initEnv() first");
2473
- }
2474
- return instance;
2781
+ const env = envStore.getState().env;
2782
+ return { ...env, requests };
2475
2783
  }
2476
2784
 
2477
2785
  // src/services/action-service/index.ts
@@ -2639,7 +2947,7 @@ var AuthService = {
2639
2947
  }).filter(([_, value]) => !!value)
2640
2948
  );
2641
2949
  const encodedData = new URLSearchParams(payload).toString();
2642
- return env?.requests?.post(body.path, encodedData, {
2950
+ return env?.requests?.post(body?.path ?? "", encodedData, {
2643
2951
  headers: {
2644
2952
  "Content-Type": "application/x-www-form-urlencoded"
2645
2953
  }
@@ -2736,6 +3044,20 @@ var AuthService = {
2736
3044
  }
2737
3045
  });
2738
3046
  },
3047
+ async isValidActionToken(actionToken, path) {
3048
+ const env = getEnv();
3049
+ return env?.requests?.post(
3050
+ path,
3051
+ {},
3052
+ {
3053
+ headers: {
3054
+ "Content-Type": "application/json"
3055
+ },
3056
+ useActionToken: true,
3057
+ actionToken
3058
+ }
3059
+ );
3060
+ },
2739
3061
  async loginSocial({
2740
3062
  db,
2741
3063
  state,
@@ -3500,7 +3822,7 @@ var model_service_default = ModelService;
3500
3822
  var UserService = {
3501
3823
  async getProfile(path) {
3502
3824
  const env = getEnv();
3503
- return env.requests.get(path ?? "/userinfo" /* PROFILE_PATH */, {
3825
+ return env?.requests?.get(path ?? "/userinfo" /* PROFILE_PATH */, {
3504
3826
  headers: {
3505
3827
  "Content-Type": "application/x-www-form-urlencoded"
3506
3828
  }
@@ -3819,8 +4141,7 @@ var ViewService = {
3819
4141
  },
3820
4142
  async getVersion() {
3821
4143
  const env = getEnv();
3822
- console.log("env?.requests", env, env?.requests);
3823
- return env?.requests?.get("", {
4144
+ return env?.requests.get("", {
3824
4145
  headers: {
3825
4146
  "Content-Type": "application/json"
3826
4147
  }