datastake-daf 0.6.497 → 0.6.499

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.
@@ -6540,6 +6540,39 @@ class ErrorService {
6540
6540
  // In datastake-daf - src/services/BaseService.js
6541
6541
  class BaseService extends BaseHTTPService {
6542
6542
  constructor() {
6543
+ getConfig();
6544
+ const errorHandler = createErrorHandler({
6545
+ getStorageManager: () => StorageManager,
6546
+ handleError: ({
6547
+ status,
6548
+ statusText,
6549
+ data
6550
+ }) => {
6551
+ console.error('[BaseService] Error:', {
6552
+ status,
6553
+ statusText,
6554
+ data
6555
+ });
6556
+ ErrorService.handle({
6557
+ status,
6558
+ statusText,
6559
+ data
6560
+ });
6561
+ },
6562
+ onUnauthorized: () => {
6563
+ console.warn('[BaseService] 401 Unauthorized - Token cleared, redirecting to /');
6564
+ console.trace('[BaseService] Unauthorized call stack:');
6565
+ StorageManager.clearOne('token');
6566
+ if (typeof window !== 'undefined') {
6567
+ window.location.href = '/';
6568
+ }
6569
+ },
6570
+ tokenStorageKey: 'token',
6571
+ unauthorizedRedirect: '/',
6572
+ checkTokenValidity: true,
6573
+ handleNetworkError: true
6574
+ });
6575
+
6543
6576
  // Call super with lazy getters that fetch config at runtime
6544
6577
  super({
6545
6578
  getToken: () => getToken(),
@@ -6556,55 +6589,20 @@ class BaseService extends BaseHTTPService {
6556
6589
  if (options?.isStore) return config.storeUrl;
6557
6590
  return config.mainApiUrl;
6558
6591
  },
6559
- onError: error => {
6560
- // Create error handler lazily
6561
- const errorHandler = createErrorHandler({
6562
- getStorageManager: () => StorageManager,
6563
- handleError: ({
6564
- status,
6565
- statusText,
6566
- data
6567
- }) => {
6568
- ErrorService.handle({
6569
- status,
6570
- statusText,
6571
- data
6572
- });
6573
- },
6574
- tokenStorageKey: 'token',
6575
- unauthorizedRedirect: '/',
6576
- checkTokenValidity: true,
6577
- handleNetworkError: true
6578
- });
6579
- return errorHandler(error);
6580
- },
6592
+ onError: errorHandler,
6581
6593
  timeout: 300000
6582
6594
  });
6583
6595
  }
6584
6596
  apiGet(options) {
6585
- const token = getToken();
6586
6597
  const config = getConfig();
6587
- if (token !== this.token || !token) {
6588
- this.reloadAxios();
6598
+
6599
+ // Add custom baseURL handling for isStore
6600
+ if (options.isStore) {
6601
+ options.baseURL = config.storeUrl;
6589
6602
  }
6590
- const {
6591
- url,
6592
- ...restConfig
6593
- } = options;
6594
- const baseURL = options.isStore ? config.storeUrl : config.mainApiUrl;
6595
- return this.formatResponse(this.api.get(url, {
6596
- ...restConfig,
6597
- baseURL,
6598
- headers: options.isStore ? {
6599
- Authorization: `Bearer ${getToken()}`,
6600
- ...(restConfig?.headers || {})
6601
- } : {
6602
- Authorization: `Bearer ${getToken()}`,
6603
- Language: config.language || StorageManager.get('datastakeLng') || 'en',
6604
- Application: config.application,
6605
- ...(restConfig?.headers || {})
6606
- }
6607
- }).catch(err => this.onError(err)));
6603
+
6604
+ // Call parent's apiGet
6605
+ return super.apiGet(options);
6608
6606
  }
6609
6607
  }
6610
6608
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.497",
3
+ "version": "0.6.499",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -8,6 +8,28 @@ import { ErrorService } from './ErrorService.js';
8
8
 
9
9
  export class BaseService extends BaseHTTPService {
10
10
  constructor() {
11
+ const config = getConfig();
12
+
13
+ const errorHandler = createErrorHandler({
14
+ getStorageManager: () => StorageManager,
15
+ handleError: ({ status, statusText, data }) => {
16
+ console.error('[BaseService] Error:', { status, statusText, data });
17
+ ErrorService.handle({ status, statusText, data });
18
+ },
19
+ onUnauthorized: () => {
20
+ console.warn('[BaseService] 401 Unauthorized - Token cleared, redirecting to /');
21
+ console.trace('[BaseService] Unauthorized call stack:');
22
+ StorageManager.clearOne('token');
23
+ if (typeof window !== 'undefined') {
24
+ window.location.href = '/';
25
+ }
26
+ },
27
+ tokenStorageKey: 'token',
28
+ unauthorizedRedirect: '/',
29
+ checkTokenValidity: true,
30
+ handleNetworkError: true,
31
+ });
32
+
11
33
  // Call super with lazy getters that fetch config at runtime
12
34
  super({
13
35
  getToken: () => getToken(),
@@ -24,50 +46,20 @@ export class BaseService extends BaseHTTPService {
24
46
  if (options?.isStore) return config.storeUrl;
25
47
  return config.mainApiUrl;
26
48
  },
27
- onError: (error) => {
28
- // Create error handler lazily
29
- const errorHandler = createErrorHandler({
30
- getStorageManager: () => StorageManager,
31
- handleError: ({ status, statusText, data }) => {
32
- ErrorService.handle({ status, statusText, data });
33
- },
34
- tokenStorageKey: 'token',
35
- unauthorizedRedirect: '/',
36
- checkTokenValidity: true,
37
- handleNetworkError: true,
38
- });
39
- return errorHandler(error);
40
- },
49
+ onError: errorHandler,
41
50
  timeout: 300000,
42
51
  });
43
52
  }
44
53
 
45
54
  apiGet(options) {
46
- const token = getToken();
47
55
  const config = getConfig();
48
56
 
49
- if (token !== this.token || !token) {
50
- this.reloadAxios();
57
+ // Add custom baseURL handling for isStore
58
+ if (options.isStore) {
59
+ options.baseURL = config.storeUrl;
51
60
  }
52
61
 
53
- const { url, ...restConfig } = options;
54
- const baseURL = options.isStore ? config.storeUrl : config.mainApiUrl;
55
-
56
- return this.formatResponse(
57
- this.api.get(url, {
58
- ...restConfig,
59
- baseURL,
60
- headers: options.isStore ? {
61
- Authorization: `Bearer ${getToken()}`,
62
- ...(restConfig?.headers || {}),
63
- } : {
64
- Authorization: `Bearer ${getToken()}`,
65
- Language: config.language || StorageManager.get('datastakeLng') || 'en',
66
- Application: config.application,
67
- ...(restConfig?.headers || {}),
68
- }
69
- })
70
- .catch((err) => this.onError(err))
71
- );
62
+ // Call parent's apiGet
63
+ return super.apiGet(options);
72
64
  }
73
65
  }