septor-store 1.2.4 → 1.3.4
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/index.cjs +19 -16
- package/dist/index.d.cts +34 -26
- package/dist/index.d.ts +34 -26
- package/dist/index.js +19 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -77,8 +77,8 @@ var requestHandler = (request) => {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
request.headers = { ...(request == null ? void 0 : request.headers) ?? {} };
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
console.log("default call");
|
|
81
|
+
if (token) request.headers.Authorization = `Bearer ${token}`;
|
|
82
82
|
if (request.data instanceof FormData) {
|
|
83
83
|
const formData = request.data;
|
|
84
84
|
request.data = formData;
|
|
@@ -106,11 +106,10 @@ var custom_axios_default = customAxios;
|
|
|
106
106
|
|
|
107
107
|
// src/utils/useFetch.js
|
|
108
108
|
var axiosSetUps = custom_axios_default;
|
|
109
|
-
function setUpAxiosToUse(setUp) {
|
|
109
|
+
async function setUpAxiosToUse(setUp) {
|
|
110
110
|
axiosSetUps = setUp ?? custom_axios_default;
|
|
111
111
|
}
|
|
112
|
-
var useFetch = async ({ url, method, data = {}, config }) => {
|
|
113
|
-
console.log(method, "------");
|
|
112
|
+
var useFetch = async ({ url, method, data = {}, config, axiosInstance }) => {
|
|
114
113
|
const uniformMethod = `${method}`.toLowerCase();
|
|
115
114
|
const headerC = {
|
|
116
115
|
...config,
|
|
@@ -118,12 +117,14 @@ var useFetch = async ({ url, method, data = {}, config }) => {
|
|
|
118
117
|
...(config == null ? void 0 : config.headers) || {}
|
|
119
118
|
}
|
|
120
119
|
};
|
|
120
|
+
const axiosClient = axiosInstance ?? axiosSetUps;
|
|
121
|
+
console.log(axiosInstance);
|
|
121
122
|
try {
|
|
122
123
|
const axiosMethods = {
|
|
123
|
-
get: () =>
|
|
124
|
-
post: () =>
|
|
125
|
-
put: () =>
|
|
126
|
-
delete: () =>
|
|
124
|
+
get: () => axiosClient.get(`${url}${generateParams(data)}`, headerC),
|
|
125
|
+
post: () => axiosClient.post(url, data, headerC),
|
|
126
|
+
put: () => axiosClient.put(url, data, headerC),
|
|
127
|
+
delete: () => axiosClient.delete(url, { data, ...headerC })
|
|
127
128
|
};
|
|
128
129
|
if (!axiosMethods[uniformMethod]) {
|
|
129
130
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
@@ -221,10 +222,10 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
221
222
|
sleep(timer) {
|
|
222
223
|
return new Promise((r) => setTimeout(r, timer));
|
|
223
224
|
},
|
|
224
|
-
async CallApiData(StateStore, callApi, dataParams, pagnated, mStore = {}, config) {
|
|
225
|
+
async CallApiData(StateStore, callApi, dataParams, pagnated, mStore = {}, config, axiosInstance = null) {
|
|
225
226
|
if (!this.CheckQueriesInQue[callApi]) {
|
|
226
227
|
this.CheckQueriesInQue[callApi] = callApi;
|
|
227
|
-
let [res] = await Promise.all([useFetch({ ...dataParams, config })]);
|
|
228
|
+
let [res] = await Promise.all([useFetch({ ...dataParams, config, axiosInstance })]);
|
|
228
229
|
if (res) {
|
|
229
230
|
this[StateStore] = res;
|
|
230
231
|
if (mStore == null ? void 0 : mStore.mUse) {
|
|
@@ -272,10 +273,11 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
272
273
|
config: {},
|
|
273
274
|
time: 0,
|
|
274
275
|
pagnated: false,
|
|
275
|
-
mStore: { mUse: 0, reset: 0 }
|
|
276
|
+
mStore: { mUse: 0, reset: 0 },
|
|
277
|
+
axiosInstance: null
|
|
276
278
|
}, fasterDataCollection = null) {
|
|
277
279
|
this.Loading = true;
|
|
278
|
-
const { reload, StateStore, reqs, time, pagnated, mStore, config } = dd;
|
|
280
|
+
const { reload, StateStore, reqs, time, pagnated, mStore, config, axiosInstance } = dd;
|
|
279
281
|
const callApi = JSON.stringify(reqs);
|
|
280
282
|
const StateVariable = await this.parseData(StateStore, mStore);
|
|
281
283
|
this[StateStore] = StateVariable ?? [];
|
|
@@ -304,7 +306,6 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
304
306
|
const counters = this.validateObjectLength(StateVariable);
|
|
305
307
|
if (typeof fasterDataCollection == "function")
|
|
306
308
|
fasterDataCollection == null ? void 0 : fasterDataCollection(StateVariable);
|
|
307
|
-
console.log(counters);
|
|
308
309
|
if (counters > 0) {
|
|
309
310
|
if (reload) {
|
|
310
311
|
await this.sleep(1e3 * time);
|
|
@@ -314,7 +315,8 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
314
315
|
reqs,
|
|
315
316
|
pagnated,
|
|
316
317
|
mStore,
|
|
317
|
-
config
|
|
318
|
+
config,
|
|
319
|
+
axiosInstance
|
|
318
320
|
);
|
|
319
321
|
}
|
|
320
322
|
this.Loading = false;
|
|
@@ -328,7 +330,8 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
328
330
|
reqs,
|
|
329
331
|
pagnated,
|
|
330
332
|
mStore,
|
|
331
|
-
config
|
|
333
|
+
config,
|
|
334
|
+
axiosInstance
|
|
332
335
|
);
|
|
333
336
|
} catch (error) {
|
|
334
337
|
console.error(error);
|
package/dist/index.d.cts
CHANGED
|
@@ -4,14 +4,16 @@ import axios from 'axios';
|
|
|
4
4
|
const AbortHandler = {
|
|
5
5
|
abortController: new AbortController()};
|
|
6
6
|
|
|
7
|
-
let baseURL =
|
|
7
|
+
let baseURL =
|
|
8
|
+
typeof import.meta !== "undefined"
|
|
9
|
+
? (import.meta.env.VITE_BACKEND_URL ?? "")
|
|
10
|
+
: "";
|
|
8
11
|
|
|
9
12
|
const customAxios = axios.create({
|
|
10
13
|
baseURL: baseURL,
|
|
11
14
|
signal: AbortHandler.abortController.signal, // Signal that is assiciated with any request to be made with this axios instance
|
|
12
15
|
});
|
|
13
16
|
|
|
14
|
-
|
|
15
17
|
// Request Interceptor
|
|
16
18
|
const requestHandler = (request) => {
|
|
17
19
|
const tokenData = getBearerToken();
|
|
@@ -21,17 +23,17 @@ const requestHandler = (request) => {
|
|
|
21
23
|
if (expiresIn) {
|
|
22
24
|
const timestamp = tokenData?.timestamp ?? null;
|
|
23
25
|
const now = Date.now();
|
|
24
|
-
if (expiresIn &&
|
|
26
|
+
if (expiresIn && now - timestamp > expiresIn * 1000) {
|
|
25
27
|
console.warn("Token has expired.");
|
|
26
|
-
localStorage.removeItem("logginToken");
|
|
28
|
+
localStorage.removeItem("logginToken");
|
|
27
29
|
return null;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
request.headers = {...(request?.headers??{})
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
|
|
33
|
+
request.headers = { ...(request?.headers ?? {}) } || {};
|
|
34
|
+
console.log("default call");
|
|
35
|
+
|
|
36
|
+
if (token) request.headers.Authorization = `Bearer ${token}`;
|
|
35
37
|
// Handle FormData explicitly if needed
|
|
36
38
|
if (request.data instanceof FormData) {
|
|
37
39
|
const formData = request.data;
|
|
@@ -50,22 +52,22 @@ customAxios.interceptors.response.use(
|
|
|
50
52
|
console.log("Error.....", error);
|
|
51
53
|
if (error.response?.status === 401) ;
|
|
52
54
|
return Promise.reject(error); // Reject the error for further handling
|
|
53
|
-
}
|
|
55
|
+
},
|
|
54
56
|
);
|
|
55
57
|
|
|
56
58
|
// Attach Request Interceptor
|
|
57
59
|
customAxios.interceptors.request.use(requestHandler, (error) =>
|
|
58
|
-
Promise.reject(error)
|
|
60
|
+
Promise.reject(error),
|
|
59
61
|
);
|
|
60
62
|
|
|
61
63
|
let axiosSetUps = customAxios;
|
|
62
64
|
|
|
63
|
-
function setUpAxiosToUse(setUp) {
|
|
65
|
+
async function setUpAxiosToUse(setUp) {
|
|
64
66
|
axiosSetUps = setUp??customAxios;
|
|
65
|
-
}
|
|
66
|
-
const useFetch = async ({ url, method, data = {}, config }) => {
|
|
67
|
-
console.log(method,'------');
|
|
68
67
|
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const useFetch = async ({ url, method, data = {}, config,axiosInstance }) => {
|
|
69
71
|
const uniformMethod = `${method}`.toLowerCase();
|
|
70
72
|
const headerC = {
|
|
71
73
|
...config,
|
|
@@ -73,13 +75,17 @@ const useFetch = async ({ url, method, data = {}, config }) => {
|
|
|
73
75
|
...(config?.headers || {}),
|
|
74
76
|
},
|
|
75
77
|
};
|
|
78
|
+
const axiosClient = axiosInstance ?? axiosSetUps;
|
|
79
|
+
console.log(axiosInstance);
|
|
80
|
+
|
|
76
81
|
|
|
82
|
+
|
|
77
83
|
try {
|
|
78
84
|
const axiosMethods = {
|
|
79
|
-
get: () =>
|
|
80
|
-
post: () =>
|
|
81
|
-
put: () =>
|
|
82
|
-
delete: () =>
|
|
85
|
+
get: () => axiosClient.get(`${url}${generateParams(data)}`, headerC),
|
|
86
|
+
post: () => axiosClient.post(url, data, headerC),
|
|
87
|
+
put: () => axiosClient.put(url, data, headerC),
|
|
88
|
+
delete: () => axiosClient.delete(url, { data, ...headerC }),
|
|
83
89
|
};
|
|
84
90
|
|
|
85
91
|
if (!axiosMethods[uniformMethod]) {
|
|
@@ -140,7 +146,7 @@ function getBearerToken() {
|
|
|
140
146
|
}
|
|
141
147
|
}
|
|
142
148
|
|
|
143
|
-
function
|
|
149
|
+
function createPomStore(
|
|
144
150
|
piniaStore = "7286204094",
|
|
145
151
|
callBack = null,
|
|
146
152
|
ds = { StateClean: 0, extenalSetup: null },
|
|
@@ -148,7 +154,7 @@ function createPomStore(
|
|
|
148
154
|
setUpAxiosToUse(ds?.extenalSetup);
|
|
149
155
|
const storeId = "POM" + piniaStore;
|
|
150
156
|
const StateNameUsedSoferList = "septor-store-collection";
|
|
151
|
-
const piniaData= defineStore(storeId, {
|
|
157
|
+
const piniaData = defineStore(storeId, {
|
|
152
158
|
state: () => {
|
|
153
159
|
const StateObjectsContainer = {
|
|
154
160
|
CheckQueriesInQue: {},
|
|
@@ -206,11 +212,11 @@ function createPomStore(
|
|
|
206
212
|
pagnated,
|
|
207
213
|
mStore = {},
|
|
208
214
|
config,
|
|
215
|
+
axiosInstance = null,
|
|
209
216
|
) {
|
|
210
217
|
if (!this.CheckQueriesInQue[callApi]) {
|
|
211
218
|
this.CheckQueriesInQue[callApi] = callApi;
|
|
212
|
-
|
|
213
|
-
let [res] = await Promise.all([useFetch({ ...dataParams, config })]);
|
|
219
|
+
let [res] = await Promise.all([useFetch({ ...dataParams, config,axiosInstance })]);
|
|
214
220
|
// const collection=;
|
|
215
221
|
if (res) {
|
|
216
222
|
this[StateStore] = res;
|
|
@@ -269,11 +275,12 @@ function createPomStore(
|
|
|
269
275
|
time: 0,
|
|
270
276
|
pagnated: false,
|
|
271
277
|
mStore: { mUse: 0, reset: 0 },
|
|
278
|
+
axiosInstance : null,
|
|
272
279
|
},
|
|
273
280
|
fasterDataCollection = null,
|
|
274
281
|
) {
|
|
275
282
|
this.Loading = true;
|
|
276
|
-
const { reload, StateStore, reqs, time, pagnated, mStore, config } = dd;
|
|
283
|
+
const { reload, StateStore, reqs, time, pagnated, mStore, config,axiosInstance } = dd;
|
|
277
284
|
const callApi = JSON.stringify(reqs);
|
|
278
285
|
const StateVariable = await this.parseData(StateStore, mStore);
|
|
279
286
|
this[StateStore] = StateVariable ?? [];
|
|
@@ -310,7 +317,6 @@ function createPomStore(
|
|
|
310
317
|
|
|
311
318
|
if (typeof fasterDataCollection == "function")
|
|
312
319
|
fasterDataCollection?.(StateVariable);
|
|
313
|
-
console.log(counters);
|
|
314
320
|
|
|
315
321
|
if (counters > 0) {
|
|
316
322
|
if (reload) {
|
|
@@ -322,7 +328,8 @@ function createPomStore(
|
|
|
322
328
|
pagnated,
|
|
323
329
|
mStore,
|
|
324
330
|
config,
|
|
325
|
-
|
|
331
|
+
axiosInstance,
|
|
332
|
+
);
|
|
326
333
|
}
|
|
327
334
|
|
|
328
335
|
this.Loading = false;
|
|
@@ -338,6 +345,7 @@ function createPomStore(
|
|
|
338
345
|
pagnated,
|
|
339
346
|
mStore,
|
|
340
347
|
config,
|
|
348
|
+
axiosInstance
|
|
341
349
|
);
|
|
342
350
|
} catch (error) {
|
|
343
351
|
console.error(error);
|
package/dist/index.d.ts
CHANGED
|
@@ -4,14 +4,16 @@ import axios from 'axios';
|
|
|
4
4
|
const AbortHandler = {
|
|
5
5
|
abortController: new AbortController()};
|
|
6
6
|
|
|
7
|
-
let baseURL =
|
|
7
|
+
let baseURL =
|
|
8
|
+
typeof import.meta !== "undefined"
|
|
9
|
+
? (import.meta.env.VITE_BACKEND_URL ?? "")
|
|
10
|
+
: "";
|
|
8
11
|
|
|
9
12
|
const customAxios = axios.create({
|
|
10
13
|
baseURL: baseURL,
|
|
11
14
|
signal: AbortHandler.abortController.signal, // Signal that is assiciated with any request to be made with this axios instance
|
|
12
15
|
});
|
|
13
16
|
|
|
14
|
-
|
|
15
17
|
// Request Interceptor
|
|
16
18
|
const requestHandler = (request) => {
|
|
17
19
|
const tokenData = getBearerToken();
|
|
@@ -21,17 +23,17 @@ const requestHandler = (request) => {
|
|
|
21
23
|
if (expiresIn) {
|
|
22
24
|
const timestamp = tokenData?.timestamp ?? null;
|
|
23
25
|
const now = Date.now();
|
|
24
|
-
if (expiresIn &&
|
|
26
|
+
if (expiresIn && now - timestamp > expiresIn * 1000) {
|
|
25
27
|
console.warn("Token has expired.");
|
|
26
|
-
localStorage.removeItem("logginToken");
|
|
28
|
+
localStorage.removeItem("logginToken");
|
|
27
29
|
return null;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
request.headers = {...(request?.headers??{})
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
|
|
33
|
+
request.headers = { ...(request?.headers ?? {}) } || {};
|
|
34
|
+
console.log("default call");
|
|
35
|
+
|
|
36
|
+
if (token) request.headers.Authorization = `Bearer ${token}`;
|
|
35
37
|
// Handle FormData explicitly if needed
|
|
36
38
|
if (request.data instanceof FormData) {
|
|
37
39
|
const formData = request.data;
|
|
@@ -50,22 +52,22 @@ customAxios.interceptors.response.use(
|
|
|
50
52
|
console.log("Error.....", error);
|
|
51
53
|
if (error.response?.status === 401) ;
|
|
52
54
|
return Promise.reject(error); // Reject the error for further handling
|
|
53
|
-
}
|
|
55
|
+
},
|
|
54
56
|
);
|
|
55
57
|
|
|
56
58
|
// Attach Request Interceptor
|
|
57
59
|
customAxios.interceptors.request.use(requestHandler, (error) =>
|
|
58
|
-
Promise.reject(error)
|
|
60
|
+
Promise.reject(error),
|
|
59
61
|
);
|
|
60
62
|
|
|
61
63
|
let axiosSetUps = customAxios;
|
|
62
64
|
|
|
63
|
-
function setUpAxiosToUse(setUp) {
|
|
65
|
+
async function setUpAxiosToUse(setUp) {
|
|
64
66
|
axiosSetUps = setUp??customAxios;
|
|
65
|
-
}
|
|
66
|
-
const useFetch = async ({ url, method, data = {}, config }) => {
|
|
67
|
-
console.log(method,'------');
|
|
68
67
|
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const useFetch = async ({ url, method, data = {}, config,axiosInstance }) => {
|
|
69
71
|
const uniformMethod = `${method}`.toLowerCase();
|
|
70
72
|
const headerC = {
|
|
71
73
|
...config,
|
|
@@ -73,13 +75,17 @@ const useFetch = async ({ url, method, data = {}, config }) => {
|
|
|
73
75
|
...(config?.headers || {}),
|
|
74
76
|
},
|
|
75
77
|
};
|
|
78
|
+
const axiosClient = axiosInstance ?? axiosSetUps;
|
|
79
|
+
console.log(axiosInstance);
|
|
80
|
+
|
|
76
81
|
|
|
82
|
+
|
|
77
83
|
try {
|
|
78
84
|
const axiosMethods = {
|
|
79
|
-
get: () =>
|
|
80
|
-
post: () =>
|
|
81
|
-
put: () =>
|
|
82
|
-
delete: () =>
|
|
85
|
+
get: () => axiosClient.get(`${url}${generateParams(data)}`, headerC),
|
|
86
|
+
post: () => axiosClient.post(url, data, headerC),
|
|
87
|
+
put: () => axiosClient.put(url, data, headerC),
|
|
88
|
+
delete: () => axiosClient.delete(url, { data, ...headerC }),
|
|
83
89
|
};
|
|
84
90
|
|
|
85
91
|
if (!axiosMethods[uniformMethod]) {
|
|
@@ -140,7 +146,7 @@ function getBearerToken() {
|
|
|
140
146
|
}
|
|
141
147
|
}
|
|
142
148
|
|
|
143
|
-
function
|
|
149
|
+
function createPomStore(
|
|
144
150
|
piniaStore = "7286204094",
|
|
145
151
|
callBack = null,
|
|
146
152
|
ds = { StateClean: 0, extenalSetup: null },
|
|
@@ -148,7 +154,7 @@ function createPomStore(
|
|
|
148
154
|
setUpAxiosToUse(ds?.extenalSetup);
|
|
149
155
|
const storeId = "POM" + piniaStore;
|
|
150
156
|
const StateNameUsedSoferList = "septor-store-collection";
|
|
151
|
-
const piniaData= defineStore(storeId, {
|
|
157
|
+
const piniaData = defineStore(storeId, {
|
|
152
158
|
state: () => {
|
|
153
159
|
const StateObjectsContainer = {
|
|
154
160
|
CheckQueriesInQue: {},
|
|
@@ -206,11 +212,11 @@ function createPomStore(
|
|
|
206
212
|
pagnated,
|
|
207
213
|
mStore = {},
|
|
208
214
|
config,
|
|
215
|
+
axiosInstance = null,
|
|
209
216
|
) {
|
|
210
217
|
if (!this.CheckQueriesInQue[callApi]) {
|
|
211
218
|
this.CheckQueriesInQue[callApi] = callApi;
|
|
212
|
-
|
|
213
|
-
let [res] = await Promise.all([useFetch({ ...dataParams, config })]);
|
|
219
|
+
let [res] = await Promise.all([useFetch({ ...dataParams, config,axiosInstance })]);
|
|
214
220
|
// const collection=;
|
|
215
221
|
if (res) {
|
|
216
222
|
this[StateStore] = res;
|
|
@@ -269,11 +275,12 @@ function createPomStore(
|
|
|
269
275
|
time: 0,
|
|
270
276
|
pagnated: false,
|
|
271
277
|
mStore: { mUse: 0, reset: 0 },
|
|
278
|
+
axiosInstance : null,
|
|
272
279
|
},
|
|
273
280
|
fasterDataCollection = null,
|
|
274
281
|
) {
|
|
275
282
|
this.Loading = true;
|
|
276
|
-
const { reload, StateStore, reqs, time, pagnated, mStore, config } = dd;
|
|
283
|
+
const { reload, StateStore, reqs, time, pagnated, mStore, config,axiosInstance } = dd;
|
|
277
284
|
const callApi = JSON.stringify(reqs);
|
|
278
285
|
const StateVariable = await this.parseData(StateStore, mStore);
|
|
279
286
|
this[StateStore] = StateVariable ?? [];
|
|
@@ -310,7 +317,6 @@ function createPomStore(
|
|
|
310
317
|
|
|
311
318
|
if (typeof fasterDataCollection == "function")
|
|
312
319
|
fasterDataCollection?.(StateVariable);
|
|
313
|
-
console.log(counters);
|
|
314
320
|
|
|
315
321
|
if (counters > 0) {
|
|
316
322
|
if (reload) {
|
|
@@ -322,7 +328,8 @@ function createPomStore(
|
|
|
322
328
|
pagnated,
|
|
323
329
|
mStore,
|
|
324
330
|
config,
|
|
325
|
-
|
|
331
|
+
axiosInstance,
|
|
332
|
+
);
|
|
326
333
|
}
|
|
327
334
|
|
|
328
335
|
this.Loading = false;
|
|
@@ -338,6 +345,7 @@ function createPomStore(
|
|
|
338
345
|
pagnated,
|
|
339
346
|
mStore,
|
|
340
347
|
config,
|
|
348
|
+
axiosInstance
|
|
341
349
|
);
|
|
342
350
|
} catch (error) {
|
|
343
351
|
console.error(error);
|
package/dist/index.js
CHANGED
|
@@ -36,8 +36,8 @@ var requestHandler = (request) => {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
request.headers = { ...(request == null ? void 0 : request.headers) ?? {} };
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
console.log("default call");
|
|
40
|
+
if (token) request.headers.Authorization = `Bearer ${token}`;
|
|
41
41
|
if (request.data instanceof FormData) {
|
|
42
42
|
const formData = request.data;
|
|
43
43
|
request.data = formData;
|
|
@@ -65,11 +65,10 @@ var custom_axios_default = customAxios;
|
|
|
65
65
|
|
|
66
66
|
// src/utils/useFetch.js
|
|
67
67
|
var axiosSetUps = custom_axios_default;
|
|
68
|
-
function setUpAxiosToUse(setUp) {
|
|
68
|
+
async function setUpAxiosToUse(setUp) {
|
|
69
69
|
axiosSetUps = setUp ?? custom_axios_default;
|
|
70
70
|
}
|
|
71
|
-
var useFetch = async ({ url, method, data = {}, config }) => {
|
|
72
|
-
console.log(method, "------");
|
|
71
|
+
var useFetch = async ({ url, method, data = {}, config, axiosInstance }) => {
|
|
73
72
|
const uniformMethod = `${method}`.toLowerCase();
|
|
74
73
|
const headerC = {
|
|
75
74
|
...config,
|
|
@@ -77,12 +76,14 @@ var useFetch = async ({ url, method, data = {}, config }) => {
|
|
|
77
76
|
...(config == null ? void 0 : config.headers) || {}
|
|
78
77
|
}
|
|
79
78
|
};
|
|
79
|
+
const axiosClient = axiosInstance ?? axiosSetUps;
|
|
80
|
+
console.log(axiosInstance);
|
|
80
81
|
try {
|
|
81
82
|
const axiosMethods = {
|
|
82
|
-
get: () =>
|
|
83
|
-
post: () =>
|
|
84
|
-
put: () =>
|
|
85
|
-
delete: () =>
|
|
83
|
+
get: () => axiosClient.get(`${url}${generateParams(data)}`, headerC),
|
|
84
|
+
post: () => axiosClient.post(url, data, headerC),
|
|
85
|
+
put: () => axiosClient.put(url, data, headerC),
|
|
86
|
+
delete: () => axiosClient.delete(url, { data, ...headerC })
|
|
86
87
|
};
|
|
87
88
|
if (!axiosMethods[uniformMethod]) {
|
|
88
89
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
@@ -180,10 +181,10 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
180
181
|
sleep(timer) {
|
|
181
182
|
return new Promise((r) => setTimeout(r, timer));
|
|
182
183
|
},
|
|
183
|
-
async CallApiData(StateStore, callApi, dataParams, pagnated, mStore = {}, config) {
|
|
184
|
+
async CallApiData(StateStore, callApi, dataParams, pagnated, mStore = {}, config, axiosInstance = null) {
|
|
184
185
|
if (!this.CheckQueriesInQue[callApi]) {
|
|
185
186
|
this.CheckQueriesInQue[callApi] = callApi;
|
|
186
|
-
let [res] = await Promise.all([useFetch({ ...dataParams, config })]);
|
|
187
|
+
let [res] = await Promise.all([useFetch({ ...dataParams, config, axiosInstance })]);
|
|
187
188
|
if (res) {
|
|
188
189
|
this[StateStore] = res;
|
|
189
190
|
if (mStore == null ? void 0 : mStore.mUse) {
|
|
@@ -231,10 +232,11 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
231
232
|
config: {},
|
|
232
233
|
time: 0,
|
|
233
234
|
pagnated: false,
|
|
234
|
-
mStore: { mUse: 0, reset: 0 }
|
|
235
|
+
mStore: { mUse: 0, reset: 0 },
|
|
236
|
+
axiosInstance: null
|
|
235
237
|
}, fasterDataCollection = null) {
|
|
236
238
|
this.Loading = true;
|
|
237
|
-
const { reload, StateStore, reqs, time, pagnated, mStore, config } = dd;
|
|
239
|
+
const { reload, StateStore, reqs, time, pagnated, mStore, config, axiosInstance } = dd;
|
|
238
240
|
const callApi = JSON.stringify(reqs);
|
|
239
241
|
const StateVariable = await this.parseData(StateStore, mStore);
|
|
240
242
|
this[StateStore] = StateVariable ?? [];
|
|
@@ -263,7 +265,6 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
263
265
|
const counters = this.validateObjectLength(StateVariable);
|
|
264
266
|
if (typeof fasterDataCollection == "function")
|
|
265
267
|
fasterDataCollection == null ? void 0 : fasterDataCollection(StateVariable);
|
|
266
|
-
console.log(counters);
|
|
267
268
|
if (counters > 0) {
|
|
268
269
|
if (reload) {
|
|
269
270
|
await this.sleep(1e3 * time);
|
|
@@ -273,7 +274,8 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
273
274
|
reqs,
|
|
274
275
|
pagnated,
|
|
275
276
|
mStore,
|
|
276
|
-
config
|
|
277
|
+
config,
|
|
278
|
+
axiosInstance
|
|
277
279
|
);
|
|
278
280
|
}
|
|
279
281
|
this.Loading = false;
|
|
@@ -287,7 +289,8 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
287
289
|
reqs,
|
|
288
290
|
pagnated,
|
|
289
291
|
mStore,
|
|
290
|
-
config
|
|
292
|
+
config,
|
|
293
|
+
axiosInstance
|
|
291
294
|
);
|
|
292
295
|
} catch (error) {
|
|
293
296
|
console.error(error);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A powerful, modular state management solution for Vue 3 applications, built on top of Pinia. Septor Store leverages the Plain Old Module (POM) pattern to provide dynamic store generation, intelligent API request handling, smart caching, and clean separation of concerns—making it ideal for scalable, maintainable, and high-performance frontend development.",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.3.4",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.cjs",
|
|
9
9
|
"module": "dist/index.js",
|