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