datastake-daf 0.6.493 → 0.6.495

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.
@@ -6146,7 +6146,18 @@ class BaseHTTPService {
6146
6146
  // Init
6147
6147
  this.cancelToken = {};
6148
6148
  this.token = this.getToken();
6149
- this.setupAxios();
6149
+
6150
+ // 🔥 NEW: Don't setup axios immediately, do it lazily
6151
+ this.api = null;
6152
+ this._axiosInitialized = false;
6153
+ }
6154
+
6155
+ // 🔥 NEW: Lazy initialization method
6156
+ _ensureAxiosInitialized() {
6157
+ if (!this._axiosInitialized) {
6158
+ this.setupAxios();
6159
+ this._axiosInitialized = true;
6160
+ }
6150
6161
  }
6151
6162
  setupAxios() {
6152
6163
  const headers = {
@@ -6164,8 +6175,6 @@ class BaseHTTPService {
6164
6175
  }
6165
6176
  setupInterceptors() {
6166
6177
  this.api.interceptors.response.use(response => response, error => Promise.reject(error));
6167
-
6168
- // Request interceptor - clean JSON data
6169
6178
  this.api.interceptors.request.use(config => {
6170
6179
  if (['post', 'put', 'patch'].includes(config.method)) {
6171
6180
  config.data = this.cleanJSON(config.data);
@@ -6190,6 +6199,7 @@ class BaseHTTPService {
6190
6199
  }
6191
6200
  this.api = axios$1.create(options);
6192
6201
  this.setupInterceptors();
6202
+ this._axiosInitialized = true; // 🔥 Mark as initialized
6193
6203
  }
6194
6204
  async formatResponse(call) {
6195
6205
  try {
@@ -6210,6 +6220,8 @@ class BaseHTTPService {
6210
6220
  }
6211
6221
  }
6212
6222
  apiPost(options) {
6223
+ this._ensureAxiosInitialized(); // 🔥 Ensure initialized
6224
+
6213
6225
  // Check if there are any previous pending requests
6214
6226
  if (typeof this.cancelToken[options.url] != typeof undefined) {
6215
6227
  try {
@@ -6235,6 +6247,8 @@ class BaseHTTPService {
6235
6247
  }).catch(err => this.onError(err)));
6236
6248
  }
6237
6249
  apiGet(options) {
6250
+ this._ensureAxiosInitialized(); // 🔥 Ensure initialized
6251
+
6238
6252
  const token = this.getToken();
6239
6253
  if (token !== this.token || !token) {
6240
6254
  this.reloadAxios();
@@ -6254,6 +6268,8 @@ class BaseHTTPService {
6254
6268
  }).catch(err => this.onError(err)));
6255
6269
  }
6256
6270
  apiDelete(options) {
6271
+ this._ensureAxiosInitialized(); // 🔥 Ensure initialized
6272
+
6257
6273
  const token = this.getToken();
6258
6274
  if (token !== this.token || !token) {
6259
6275
  this.reloadAxios();
@@ -6273,6 +6289,8 @@ class BaseHTTPService {
6273
6289
  }).catch(err => this.onError(err)));
6274
6290
  }
6275
6291
  apiPut(options) {
6292
+ this._ensureAxiosInitialized(); // 🔥 Ensure initialized
6293
+
6276
6294
  if (typeof this.cancelToken[options.url] != typeof undefined) {
6277
6295
  try {
6278
6296
  this.cancelToken[options.url].cancel("Operation canceled due to new request.");
@@ -6297,6 +6315,8 @@ class BaseHTTPService {
6297
6315
  }).catch(err => this.onError(err, options.onUnauthorized)));
6298
6316
  }
6299
6317
  apiPatch(options) {
6318
+ this._ensureAxiosInitialized(); // 🔥 Ensure initialized
6319
+
6300
6320
  const token = this.getToken();
6301
6321
  if (token !== this.token || !token) {
6302
6322
  this.reloadAxios();
@@ -6378,8 +6398,16 @@ const configureServices = config => {
6378
6398
  ...globalConfig,
6379
6399
  ...config
6380
6400
  };
6401
+ console.log({
6402
+ configureServices: globalConfig
6403
+ });
6404
+ };
6405
+ const getConfig = () => {
6406
+ console.log({
6407
+ getConfig: globalConfig
6408
+ });
6409
+ return globalConfig;
6381
6410
  };
6382
- const getConfig = () => globalConfig;
6383
6411
 
6384
6412
  /**
6385
6413
  * Generic error handler factory for axios requests
@@ -6475,46 +6503,53 @@ class ErrorService {
6475
6503
  }
6476
6504
  }
6477
6505
 
6506
+ // In datastake-daf - src/services/BaseService.js
6478
6507
  class BaseService extends BaseHTTPService {
6479
6508
  constructor() {
6480
- const config = getConfig();
6481
- const onError = createErrorHandler({
6482
- getStorageManager: () => StorageManager,
6483
- handleError: ({
6484
- status,
6485
- statusText,
6486
- data
6487
- }) => {
6488
- ErrorService.handle({
6489
- status,
6490
- statusText,
6491
- data
6492
- });
6493
- },
6494
- tokenStorageKey: 'token',
6495
- unauthorizedRedirect: '/',
6496
- checkTokenValidity: true,
6497
- handleNetworkError: true
6498
- });
6509
+ // Call super with lazy getters that fetch config at runtime
6499
6510
  super({
6500
6511
  getToken: () => getToken(),
6501
- getHeaders: () => ({
6502
- Language: config.language || StorageManager.get('datastakeLng') || 'en',
6503
- 'ngrok-skip-browser-warning': true,
6504
- Application: config.application
6505
- }),
6512
+ getHeaders: () => {
6513
+ const config = getConfig();
6514
+ return {
6515
+ Language: config.language || StorageManager.get('datastakeLng') || 'en',
6516
+ 'ngrok-skip-browser-warning': true,
6517
+ Application: config.application
6518
+ };
6519
+ },
6506
6520
  getBaseURL: options => {
6521
+ const config = getConfig();
6507
6522
  if (options?.isStore) return config.storeUrl;
6508
6523
  return config.mainApiUrl;
6509
6524
  },
6510
- onError: onError,
6525
+ onError: error => {
6526
+ // Create error handler lazily
6527
+ const errorHandler = createErrorHandler({
6528
+ getStorageManager: () => StorageManager,
6529
+ handleError: ({
6530
+ status,
6531
+ statusText,
6532
+ data
6533
+ }) => {
6534
+ ErrorService.handle({
6535
+ status,
6536
+ statusText,
6537
+ data
6538
+ });
6539
+ },
6540
+ tokenStorageKey: 'token',
6541
+ unauthorizedRedirect: '/',
6542
+ checkTokenValidity: true,
6543
+ handleNetworkError: true
6544
+ });
6545
+ return errorHandler(error);
6546
+ },
6511
6547
  timeout: 300000
6512
6548
  });
6513
- this.config = config;
6514
6549
  }
6515
6550
  apiGet(options) {
6516
6551
  const token = getToken();
6517
- const config = this.config;
6552
+ const config = getConfig();
6518
6553
  if (token !== this.token || !token) {
6519
6554
  this.reloadAxios();
6520
6555
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.493",
3
+ "version": "0.6.495",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -1,3 +1,4 @@
1
+ // In datastake-daf - src/services/BaseService.js
1
2
  import { BaseHTTPService } from './helpers/BaseHTTPService.js';
2
3
  import { getToken } from '../../helpers/Token.js';
3
4
  import { createErrorHandler } from '../../helpers/errorHandling.js';
@@ -7,40 +8,43 @@ import { ErrorService } from './ErrorService.js';
7
8
 
8
9
  export class BaseService extends BaseHTTPService {
9
10
  constructor() {
10
- const config = getConfig();
11
-
12
- const onError = createErrorHandler({
13
- getStorageManager: () => StorageManager,
14
- handleError: ({ status, statusText, data }) => {
15
- ErrorService.handle({ status, statusText, data });
16
- },
17
- tokenStorageKey: 'token',
18
- unauthorizedRedirect: '/',
19
- checkTokenValidity: true,
20
- handleNetworkError: true,
21
- });
22
-
11
+ // Call super with lazy getters that fetch config at runtime
23
12
  super({
24
13
  getToken: () => getToken(),
25
- getHeaders: () => ({
26
- Language: config.language || StorageManager.get('datastakeLng') || 'en',
27
- 'ngrok-skip-browser-warning': true,
28
- Application: config.application,
29
- }),
14
+ getHeaders: () => {
15
+ const config = getConfig();
16
+ return {
17
+ Language: config.language || StorageManager.get('datastakeLng') || 'en',
18
+ 'ngrok-skip-browser-warning': true,
19
+ Application: config.application,
20
+ };
21
+ },
30
22
  getBaseURL: (options) => {
23
+ const config = getConfig();
31
24
  if (options?.isStore) return config.storeUrl;
32
25
  return config.mainApiUrl;
33
26
  },
34
- onError: onError,
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
+ },
35
41
  timeout: 300000,
36
42
  });
37
-
38
- this.config = config;
39
43
  }
40
44
 
41
45
  apiGet(options) {
42
46
  const token = getToken();
43
- const config = this.config;
47
+ const config = getConfig();
44
48
 
45
49
  if (token !== this.token || !token) {
46
50
  this.reloadAxios();
@@ -34,224 +34,243 @@ const paramsSerializer = (params) => {
34
34
  * Provides axios wrapper with token management, cancel tokens, and interceptors
35
35
  */
36
36
  export class BaseHTTPService {
37
- constructor(config = {}) {
38
- const {getHeaders, getBaseURL, onError, timeout = 300000, customAxiosConfig = {}} = config;
37
+ constructor(config = {}) {
38
+ const {getHeaders, getBaseURL, onError, timeout = 300000, customAxiosConfig = {}} = config;
39
39
 
40
- this.getToken = getToken || (() => null);
41
- this.getHeaders = getHeaders || (() => ({}));
42
- this.getBaseURL = getBaseURL || (() => null);
43
- this.onError = onError || (() => null);
44
- this.cleanJSON = cleanJSON;
45
- this.timeout = timeout;
46
- this.customAxiosConfig = customAxiosConfig;
40
+ this.getToken = getToken || (() => null);
41
+ this.getHeaders = getHeaders || (() => ({}));
42
+ this.getBaseURL = getBaseURL || (() => null);
43
+ this.onError = onError || (() => null);
44
+ this.cleanJSON = cleanJSON;
45
+ this.timeout = timeout;
46
+ this.customAxiosConfig = customAxiosConfig;
47
47
 
48
- // Init
49
- this.cancelToken = {}
50
- this.token = this.getToken();
48
+ // Init
49
+ this.cancelToken = {}
50
+ this.token = this.getToken();
51
+
52
+ // 🔥 NEW: Don't setup axios immediately, do it lazily
53
+ this.api = null;
54
+ this._axiosInitialized = false;
55
+ }
51
56
 
52
- this.setupAxios();
53
- }
57
+ // 🔥 NEW: Lazy initialization method
58
+ _ensureAxiosInitialized() {
59
+ if (!this._axiosInitialized) {
60
+ this.setupAxios();
61
+ this._axiosInitialized = true;
62
+ }
63
+ }
54
64
 
55
- setupAxios() {
56
- const headers = {
57
- Authorization: `Bearer ${this.token}`,
58
- ...this.getHeaders(),
59
- };
65
+ setupAxios() {
66
+ const headers = {
67
+ Authorization: `Bearer ${this.token}`,
68
+ ...this.getHeaders(),
69
+ };
60
70
 
61
- this.api = axios.create({
62
- baseURL: this.getBaseURL(),
63
- headers,
64
- timeout: this.timeout,
65
- paramsSerializer: paramsSerializer,
66
- ...this.customAxiosConfig,
67
- });
71
+ this.api = axios.create({
72
+ baseURL: this.getBaseURL(),
73
+ headers,
74
+ timeout: this.timeout,
75
+ paramsSerializer: paramsSerializer,
76
+ ...this.customAxiosConfig,
77
+ });
68
78
 
69
- this.setupInterceptors();
70
- }
79
+ this.setupInterceptors();
80
+ }
71
81
 
72
- setupInterceptors() {
73
- this.api.interceptors.response.use(
74
- (response) => response,
75
- (error) => Promise.reject(error)
76
- );
82
+ setupInterceptors() {
83
+ this.api.interceptors.response.use(
84
+ (response) => response,
85
+ (error) => Promise.reject(error)
86
+ );
77
87
 
78
- // Request interceptor - clean JSON data
79
- this.api.interceptors.request.use(
80
- (config) => {
81
- if (['post', 'put', 'patch'].includes(config.method)) {
82
- config.data = this.cleanJSON(config.data);
83
- }
84
-
85
- return config;
86
- },
87
- (error) => Promise.reject(error)
88
- );
89
- }
90
-
91
- reloadAxios() {
92
- const token = this.getToken();
93
- this.token = token;
88
+ this.api.interceptors.request.use(
89
+ (config) => {
90
+ if (['post', 'put', 'patch'].includes(config.method)) {
91
+ config.data = this.cleanJSON(config.data);
92
+ }
93
+ return config;
94
+ },
95
+ (error) => Promise.reject(error)
96
+ );
97
+ }
98
+
99
+ reloadAxios() {
100
+ const token = this.getToken();
101
+ this.token = token;
94
102
 
95
- const options = {
96
- baseURL: this.getBaseURL(),
97
- timeout: this.timeout,
98
- paramsSerializer: paramsSerializer,
99
- ...this.customAxiosConfig,
100
- };
103
+ const options = {
104
+ baseURL: this.getBaseURL(),
105
+ timeout: this.timeout,
106
+ paramsSerializer: paramsSerializer,
107
+ ...this.customAxiosConfig,
108
+ };
101
109
 
102
- if (token) {
103
- options.headers = {
104
- Authorization: `Bearer ${token}`,
105
- ...this.getHeaders(),
106
- };
107
- }
110
+ if (token) {
111
+ options.headers = {
112
+ Authorization: `Bearer ${token}`,
113
+ ...this.getHeaders(),
114
+ };
115
+ }
116
+
117
+ this.api = axios.create(options);
118
+ this.setupInterceptors();
119
+ this._axiosInitialized = true; // 🔥 Mark as initialized
120
+ }
108
121
 
109
- this.api = axios.create(options);
110
- this.setupInterceptors();
111
- }
122
+ async formatResponse(call) {
123
+ try {
124
+ const res = await call;
125
+ const { data, status, statusText } = res || {};
126
+ this.cancelToken = {};
127
+ return { data, status, statusText };
128
+ } catch (error) {
129
+ return Promise.reject(error);
130
+ }
131
+ }
112
132
 
113
- async formatResponse(call) {
133
+ apiPost(options) {
134
+ this._ensureAxiosInitialized(); // 🔥 Ensure initialized
135
+
136
+ // Check if there are any previous pending requests
137
+ if (typeof this.cancelToken[options.url] != typeof undefined) {
114
138
  try {
115
- const res = await call;
116
- const { data, status, statusText } = res || {};
117
- this.cancelToken = {};
118
- return { data, status, statusText };
119
- } catch (error) {
120
- return Promise.reject(error);
139
+ this.cancelToken[options.url].cancel("Operation canceled due to new request.");
140
+ } catch (e) {
141
+ console.log(e);
142
+ return {};
121
143
  }
122
- }
144
+ }
145
+
146
+ this.cancelToken[options.url] = axios.CancelToken.source();
147
+ const token = this.getToken();
148
+
149
+ if (token !== this.token || !token) {
150
+ this.reloadAxios();
151
+ }
152
+
153
+ return this.formatResponse(
154
+ this.api.post(options.url, options.data, {
155
+ baseURL: options.baseURL || this.getBaseURL(options),
156
+ cancelToken: this.cancelToken[options.url].token,
157
+ headers: {
158
+ Authorization: `Bearer ${this.getToken()}`,
159
+ ...this.getHeaders(),
160
+ ...(options?.headers || {}),
161
+ }
162
+ })
163
+ .catch((err) => this.onError(err))
164
+ );
165
+ }
123
166
 
124
- apiPost(options) {
125
- // Check if there are any previous pending requests
126
- if (typeof this.cancelToken[options.url] != typeof undefined) {
127
- try {
128
- this.cancelToken[options.url].cancel("Operation canceled due to new request.");
129
- } catch (e) {
130
- console.log(e);
131
- return {};
167
+ apiGet(options) {
168
+ this._ensureAxiosInitialized(); // 🔥 Ensure initialized
169
+
170
+ const token = this.getToken();
171
+
172
+ if (token !== this.token || !token) {
173
+ this.reloadAxios();
174
+ }
175
+
176
+ const { url, ...config } = options;
177
+
178
+ return this.formatResponse(
179
+ this.api.get(url, {
180
+ ...config,
181
+ baseURL: options.baseURL || this.getBaseURL(options),
182
+ headers: {
183
+ Authorization: `Bearer ${this.getToken()}`,
184
+ ...this.getHeaders(),
185
+ ...(config?.headers || {}),
132
186
  }
133
- }
134
-
135
- this.cancelToken[options.url] = axios.CancelToken.source();
136
- const token = this.getToken();
137
-
138
- if (token !== this.token || !token) {
139
- this.reloadAxios();
140
- }
141
-
142
- return this.formatResponse(
143
- this.api.post(options.url, options.data, {
144
- baseURL: options.baseURL || this.getBaseURL(options),
145
- cancelToken: this.cancelToken[options.url].token,
146
- headers: {
147
- Authorization: `Bearer ${this.getToken()}`,
148
- ...this.getHeaders(),
149
- ...(options?.headers || {}),
150
- }
151
- })
152
- .catch((err) => this.onError(err))
153
- );
154
- }
187
+ })
188
+ .catch((err) => this.onError(err))
189
+ );
190
+ }
155
191
 
156
- apiGet(options) {
157
- const token = this.getToken();
158
-
159
- if (token !== this.token || !token) {
160
- this.reloadAxios();
161
- }
162
-
163
- const { url, ...config } = options;
164
-
165
- return this.formatResponse(
166
- this.api.get(url, {
167
- ...config,
168
- baseURL: options.baseURL || this.getBaseURL(options),
169
- headers: {
170
- Authorization: `Bearer ${this.getToken()}`,
171
- ...this.getHeaders(),
172
- ...(config?.headers || {}),
173
- }
174
- })
175
- .catch((err) => this.onError(err))
176
- );
177
- }
192
+ apiDelete(options) {
193
+ this._ensureAxiosInitialized(); // 🔥 Ensure initialized
194
+
195
+ const token = this.getToken();
196
+
197
+ if (token !== this.token || !token) {
198
+ this.reloadAxios();
199
+ }
200
+
201
+ const { url, ...config } = options;
202
+
203
+ return this.formatResponse(
204
+ this.api.delete(url, {
205
+ ...config,
206
+ baseURL: options.baseURL || this.getBaseURL(options),
207
+ headers: {
208
+ Authorization: `Bearer ${this.getToken()}`,
209
+ ...this.getHeaders(),
210
+ ...(config?.headers || {}),
211
+ }
212
+ })
213
+ .catch((err) => this.onError(err))
214
+ );
215
+ }
178
216
 
179
- apiDelete(options) {
180
- const token = this.getToken();
181
-
182
- if (token !== this.token || !token) {
183
- this.reloadAxios();
217
+ apiPut(options) {
218
+ this._ensureAxiosInitialized(); // 🔥 Ensure initialized
219
+
220
+ if (typeof this.cancelToken[options.url] != typeof undefined) {
221
+ try {
222
+ this.cancelToken[options.url].cancel("Operation canceled due to new request.");
223
+ } catch (e) {
224
+ console.log(e);
225
+ return {};
184
226
  }
185
-
186
- const { url, ...config } = options;
187
-
188
- return this.formatResponse(
189
- this.api.delete(url, {
190
- ...config,
191
- baseURL: options.baseURL || this.getBaseURL(options),
192
- headers: {
193
- Authorization: `Bearer ${this.getToken()}`,
194
- ...this.getHeaders(),
195
- ...(config?.headers || {}),
196
- }
197
- })
198
- .catch((err) => this.onError(err))
199
- );
200
- }
201
-
202
- apiPut(options) {
203
- if (typeof this.cancelToken[options.url] != typeof undefined) {
204
- try {
205
- this.cancelToken[options.url].cancel("Operation canceled due to new request.");
206
- } catch (e) {
207
- console.log(e);
208
- return {};
227
+ }
228
+
229
+ this.cancelToken[options.url] = axios.CancelToken.source();
230
+ const token = this.getToken();
231
+
232
+ if (token !== this.token || !token) {
233
+ this.reloadAxios();
234
+ }
235
+
236
+ return this.formatResponse(
237
+ this.api.put(options.url, options.data, {
238
+ cancelToken: this.cancelToken[options.url].token,
239
+ baseURL: options.baseURL || this.getBaseURL(options),
240
+ headers: {
241
+ Authorization: `Bearer ${this.getToken()}`,
242
+ ...this.getHeaders(),
243
+ ...(options?.headers || {}),
209
244
  }
210
- }
211
-
212
- this.cancelToken[options.url] = axios.CancelToken.source();
213
- const token = this.getToken();
214
-
215
- if (token !== this.token || !token) {
216
- this.reloadAxios();
217
- }
218
-
219
- return this.formatResponse(
220
- this.api.put(options.url, options.data, {
221
- cancelToken: this.cancelToken[options.url].token,
222
- baseURL: options.baseURL || this.getBaseURL(options),
223
- headers: {
224
- Authorization: `Bearer ${this.getToken()}`,
225
- ...this.getHeaders(),
226
- ...(options?.headers || {}),
227
- }
228
- })
229
- .catch((err) => this.onError(err, options.onUnauthorized))
230
- );
231
- }
245
+ })
246
+ .catch((err) => this.onError(err, options.onUnauthorized))
247
+ );
248
+ }
232
249
 
233
- apiPatch(options) {
234
- const token = this.getToken();
235
-
236
- if (token !== this.token || !token) {
237
- this.reloadAxios();
238
- }
239
-
240
- return this.formatResponse(
241
- this.api.patch(options.url, options.data, {
242
- baseURL: options.baseURL || this.getBaseURL(options),
243
- headers: {
244
- Authorization: `Bearer ${this.getToken()}`,
245
- ...this.getHeaders(),
246
- ...(options?.headers || {}),
247
- }
248
- })
249
- .catch((err) => this.onError(err))
250
- );
251
- }
252
-
253
- // Utility method
254
- assignParamsToUrl(path, params) {
255
- return assignParamsToUrl(path, params);
256
- }
250
+ apiPatch(options) {
251
+ this._ensureAxiosInitialized(); // 🔥 Ensure initialized
252
+
253
+ const token = this.getToken();
254
+
255
+ if (token !== this.token || !token) {
256
+ this.reloadAxios();
257
+ }
258
+
259
+ return this.formatResponse(
260
+ this.api.patch(options.url, options.data, {
261
+ baseURL: options.baseURL || this.getBaseURL(options),
262
+ headers: {
263
+ Authorization: `Bearer ${this.getToken()}`,
264
+ ...this.getHeaders(),
265
+ ...(options?.headers || {}),
266
+ }
267
+ })
268
+ .catch((err) => this.onError(err))
269
+ );
270
+ }
271
+
272
+ // Utility method
273
+ assignParamsToUrl(path, params) {
274
+ return assignParamsToUrl(path, params);
275
+ }
257
276
  }
@@ -11,6 +11,10 @@ let globalConfig = {
11
11
 
12
12
  export const configureServices = (config) => {
13
13
  globalConfig = { ...globalConfig, ...config };
14
+ console.log({configureServices: globalConfig})
14
15
  };
15
16
 
16
- export const getConfig = () => globalConfig;
17
+ export const getConfig = () => {
18
+ console.log({getConfig: globalConfig})
19
+ return globalConfig;
20
+ };