septor-store 1.2.4 → 1.3.5
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/README.md +44 -3
- package/dist/index.cjs +35 -17
- package/dist/index.d.cts +56 -30
- package/dist/index.d.ts +56 -30
- package/dist/index.js +35 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -300,12 +300,53 @@ const handleSubmit = async () => {
|
|
|
300
300
|
|
|
301
301
|
```
|
|
302
302
|
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
### Usage
|
|
307
|
+
###### Note: % wish to use your external axios Instance%
|
|
308
|
+
```
|
|
309
|
+
const usePomStore = pomPinia('myCustomStoreId',null,{StateClean:true});
|
|
310
|
+
const pomStore = usePomStore();
|
|
311
|
+
async function fetchTableData({ data, props, Store, saveData = true,}: {
|
|
312
|
+
data: any
|
|
313
|
+
props: any
|
|
314
|
+
Store: any
|
|
315
|
+
saveData?: boolean
|
|
316
|
+
}) {
|
|
317
|
+
const subdomain = getSubdomainName()
|
|
318
|
+
const axiosInstance = subdomain ? Instance1 : Instance2
|
|
319
|
+
|
|
320
|
+
const stateName =props?.state || props?.url.replace(/[^a-z0-9]+/gi, '-')
|
|
321
|
+
const collection = {
|
|
322
|
+
reload: props?.reload ? 0 : 1,
|
|
323
|
+
StateStore: stateName,
|
|
324
|
+
time: props?.time ?? 0,
|
|
325
|
+
reqs: {
|
|
326
|
+
...props,
|
|
327
|
+
url:props.url,
|
|
328
|
+
method: 'post',
|
|
329
|
+
data,
|
|
330
|
+
},
|
|
331
|
+
config: props?.config,
|
|
332
|
+
axiosInstance,// here how to pass it
|
|
333
|
+
mStore: {
|
|
334
|
+
mUse: saveData // not much vital this helps in data persistence
|
|
335
|
+
},
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return Store.stateGenaratorApi(collection)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
```
|
|
303
345
|
🤝 Contributing and Feedback
|
|
304
|
-
|
|
346
|
+
I welcome all contributions and feedback to improve septor-store!
|
|
305
347
|
If you encounter any bugs, have suggestions, or want to contribute,
|
|
306
|
-
please open an issue or submit a pull request:
|
|
348
|
+
please open an issue or submit a pull request: ssenegendonazil@gmail.com
|
|
307
349
|
👉 Report Issues or Suggestions : <https://github.com/ssengedonazil/septor-store-testing>
|
|
308
|
-
|
|
309
350
|
If you find this package useful, consider supporting me:
|
|
310
351
|
|
|
311
352
|
[](https://ko-fi.com/ssengendonazil)
|
package/dist/index.cjs
CHANGED
|
@@ -77,8 +77,7 @@ var requestHandler = (request) => {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
request.headers = { ...(request == null ? void 0 : request.headers) ?? {} };
|
|
80
|
-
if (token)
|
|
81
|
-
request.headers.Authorization = `Bearer ${token}`;
|
|
80
|
+
if (token) request.headers.Authorization = `Bearer ${token}`;
|
|
82
81
|
if (request.data instanceof FormData) {
|
|
83
82
|
const formData = request.data;
|
|
84
83
|
request.data = formData;
|
|
@@ -106,11 +105,10 @@ var custom_axios_default = customAxios;
|
|
|
106
105
|
|
|
107
106
|
// src/utils/useFetch.js
|
|
108
107
|
var axiosSetUps = custom_axios_default;
|
|
109
|
-
function setUpAxiosToUse(setUp) {
|
|
108
|
+
async function setUpAxiosToUse(setUp) {
|
|
110
109
|
axiosSetUps = setUp ?? custom_axios_default;
|
|
111
110
|
}
|
|
112
|
-
var useFetch = async ({ url, method, data = {}, config }) => {
|
|
113
|
-
console.log(method, "------");
|
|
111
|
+
var useFetch = async ({ url, method, data = {}, config, axiosInstance }) => {
|
|
114
112
|
const uniformMethod = `${method}`.toLowerCase();
|
|
115
113
|
const headerC = {
|
|
116
114
|
...config,
|
|
@@ -118,18 +116,19 @@ var useFetch = async ({ url, method, data = {}, config }) => {
|
|
|
118
116
|
...(config == null ? void 0 : config.headers) || {}
|
|
119
117
|
}
|
|
120
118
|
};
|
|
119
|
+
const axiosClient = axiosInstance ?? axiosSetUps;
|
|
121
120
|
try {
|
|
122
121
|
const axiosMethods = {
|
|
123
|
-
get: () =>
|
|
124
|
-
post: () =>
|
|
125
|
-
put: () =>
|
|
126
|
-
delete: () =>
|
|
122
|
+
get: () => axiosClient.get(`${url}${generateParams(data)}`, headerC),
|
|
123
|
+
post: () => axiosClient.post(url, data, headerC),
|
|
124
|
+
put: () => axiosClient.put(url, data, headerC),
|
|
125
|
+
delete: () => axiosClient.delete(url, { data, ...headerC })
|
|
127
126
|
};
|
|
128
127
|
if (!axiosMethods[uniformMethod]) {
|
|
129
128
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
130
129
|
}
|
|
131
130
|
const response = await axiosMethods[uniformMethod]();
|
|
132
|
-
if (response == null ? void 0 : response.
|
|
131
|
+
if (response == null ? void 0 : response.data) {
|
|
133
132
|
return (response == null ? void 0 : response.data) ?? response ?? { Empty: "Empty" };
|
|
134
133
|
}
|
|
135
134
|
return false;
|
|
@@ -221,10 +220,26 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
221
220
|
sleep(timer) {
|
|
222
221
|
return new Promise((r) => setTimeout(r, timer));
|
|
223
222
|
},
|
|
224
|
-
async CallApiData(StateStore, callApi, dataParams, pagnated, mStore = {}, config) {
|
|
223
|
+
async CallApiData(StateStore, callApi, dataParams, pagnated, mStore = {}, config, axiosInstance = null) {
|
|
224
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
225
225
|
if (!this.CheckQueriesInQue[callApi]) {
|
|
226
226
|
this.CheckQueriesInQue[callApi] = callApi;
|
|
227
|
-
let [res] = await Promise.all([useFetch({ ...dataParams, config })]);
|
|
227
|
+
let [res] = await Promise.all([useFetch({ ...dataParams, config, axiosInstance })]);
|
|
228
|
+
if (res == null ? void 0 : res.error) {
|
|
229
|
+
const msg = { msg: "", error: true };
|
|
230
|
+
if ((_b = (_a = res.error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.error) {
|
|
231
|
+
msg.msg = res.error.response.data.error;
|
|
232
|
+
} else if (res.error.message) {
|
|
233
|
+
msg.msg = res.error.message;
|
|
234
|
+
} else if ((_d = (_c = res.error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.errors) {
|
|
235
|
+
const errors = res.error.response.data.errors;
|
|
236
|
+
msg.msg = Object.values(errors)[0][0] || msg.msg;
|
|
237
|
+
}
|
|
238
|
+
if ((_h = (_g = (_f = (_e = res == null ? void 0 : res.error) == null ? void 0 : _e.response) == null ? void 0 : _f.data) == null ? void 0 : _g.payload) == null ? void 0 : _h.message) {
|
|
239
|
+
msg.msg = res.error.response.data.payload.message;
|
|
240
|
+
}
|
|
241
|
+
return res;
|
|
242
|
+
}
|
|
228
243
|
if (res) {
|
|
229
244
|
this[StateStore] = res;
|
|
230
245
|
if (mStore == null ? void 0 : mStore.mUse) {
|
|
@@ -272,10 +287,11 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
272
287
|
config: {},
|
|
273
288
|
time: 0,
|
|
274
289
|
pagnated: false,
|
|
275
|
-
mStore: { mUse: 0, reset: 0 }
|
|
290
|
+
mStore: { mUse: 0, reset: 0 },
|
|
291
|
+
axiosInstance: null
|
|
276
292
|
}, fasterDataCollection = null) {
|
|
277
293
|
this.Loading = true;
|
|
278
|
-
const { reload, StateStore, reqs, time, pagnated, mStore, config } = dd;
|
|
294
|
+
const { reload, StateStore, reqs, time, pagnated, mStore, config, axiosInstance } = dd;
|
|
279
295
|
const callApi = JSON.stringify(reqs);
|
|
280
296
|
const StateVariable = await this.parseData(StateStore, mStore);
|
|
281
297
|
this[StateStore] = StateVariable ?? [];
|
|
@@ -304,7 +320,7 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
304
320
|
const counters = this.validateObjectLength(StateVariable);
|
|
305
321
|
if (typeof fasterDataCollection == "function")
|
|
306
322
|
fasterDataCollection == null ? void 0 : fasterDataCollection(StateVariable);
|
|
307
|
-
console.log(counters);
|
|
323
|
+
console.log({ counters, reload, StateStore });
|
|
308
324
|
if (counters > 0) {
|
|
309
325
|
if (reload) {
|
|
310
326
|
await this.sleep(1e3 * time);
|
|
@@ -314,7 +330,8 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
314
330
|
reqs,
|
|
315
331
|
pagnated,
|
|
316
332
|
mStore,
|
|
317
|
-
config
|
|
333
|
+
config,
|
|
334
|
+
axiosInstance
|
|
318
335
|
);
|
|
319
336
|
}
|
|
320
337
|
this.Loading = false;
|
|
@@ -328,7 +345,8 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
328
345
|
reqs,
|
|
329
346
|
pagnated,
|
|
330
347
|
mStore,
|
|
331
|
-
config
|
|
348
|
+
config,
|
|
349
|
+
axiosInstance
|
|
332
350
|
);
|
|
333
351
|
} catch (error) {
|
|
334
352
|
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,16 @@ 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
|
-
if (token)
|
|
34
|
-
request.headers.Authorization = `Bearer ${token}`;
|
|
32
|
+
|
|
33
|
+
request.headers = { ...(request?.headers ?? {}) } || {};
|
|
34
|
+
|
|
35
|
+
if (token) request.headers.Authorization = `Bearer ${token}`;
|
|
35
36
|
// Handle FormData explicitly if needed
|
|
36
37
|
if (request.data instanceof FormData) {
|
|
37
38
|
const formData = request.data;
|
|
@@ -50,22 +51,22 @@ customAxios.interceptors.response.use(
|
|
|
50
51
|
console.log("Error.....", error);
|
|
51
52
|
if (error.response?.status === 401) ;
|
|
52
53
|
return Promise.reject(error); // Reject the error for further handling
|
|
53
|
-
}
|
|
54
|
+
},
|
|
54
55
|
);
|
|
55
56
|
|
|
56
57
|
// Attach Request Interceptor
|
|
57
58
|
customAxios.interceptors.request.use(requestHandler, (error) =>
|
|
58
|
-
Promise.reject(error)
|
|
59
|
+
Promise.reject(error),
|
|
59
60
|
);
|
|
60
61
|
|
|
61
62
|
let axiosSetUps = customAxios;
|
|
62
63
|
|
|
63
|
-
function setUpAxiosToUse(setUp) {
|
|
64
|
+
async function setUpAxiosToUse(setUp) {
|
|
64
65
|
axiosSetUps = setUp??customAxios;
|
|
65
|
-
}
|
|
66
|
-
const useFetch = async ({ url, method, data = {}, config }) => {
|
|
67
|
-
console.log(method,'------');
|
|
68
66
|
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const useFetch = async ({ url, method, data = {}, config,axiosInstance }) => {
|
|
69
70
|
const uniformMethod = `${method}`.toLowerCase();
|
|
70
71
|
const headerC = {
|
|
71
72
|
...config,
|
|
@@ -73,20 +74,25 @@ const useFetch = async ({ url, method, data = {}, config }) => {
|
|
|
73
74
|
...(config?.headers || {}),
|
|
74
75
|
},
|
|
75
76
|
};
|
|
77
|
+
const axiosClient = axiosInstance ?? axiosSetUps;
|
|
78
|
+
// console.log({headerC,data});
|
|
79
|
+
|
|
76
80
|
|
|
81
|
+
|
|
77
82
|
try {
|
|
78
83
|
const axiosMethods = {
|
|
79
|
-
get: () =>
|
|
80
|
-
post: () =>
|
|
81
|
-
put: () =>
|
|
82
|
-
delete: () =>
|
|
84
|
+
get: () => axiosClient.get(`${url}${generateParams(data)}`, headerC),
|
|
85
|
+
post: () => axiosClient.post(url, data, headerC),
|
|
86
|
+
put: () => axiosClient.put(url, data, headerC),
|
|
87
|
+
delete: () => axiosClient.delete(url, { data, ...headerC }),
|
|
83
88
|
};
|
|
84
89
|
|
|
85
90
|
if (!axiosMethods[uniformMethod]) {
|
|
86
91
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
87
92
|
}
|
|
88
93
|
const response = await axiosMethods[uniformMethod]();
|
|
89
|
-
if(response?.
|
|
94
|
+
if(response?.data){
|
|
95
|
+
// if(response?.status){
|
|
90
96
|
return response?.data ?? response ??{ Empty: "Empty" };
|
|
91
97
|
}
|
|
92
98
|
return false
|
|
@@ -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,20 +212,36 @@ 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=;
|
|
221
|
+
if (res?.error) {
|
|
222
|
+
const msg = { msg: ""};
|
|
223
|
+
if (res.error.response?.data?.error) {
|
|
224
|
+
msg.msg = res.error.response.data.error;
|
|
225
|
+
} else if (res.error.message) {
|
|
226
|
+
msg.msg = res.error.message;
|
|
227
|
+
} else if (res.error.response?.data?.errors) {
|
|
228
|
+
const errors = res.error.response.data.errors;
|
|
229
|
+
msg.msg = Object.values(errors)[0][0] || msg.msg;
|
|
230
|
+
}
|
|
231
|
+
if (res?.error?.response?.data?.payload?.message) {
|
|
232
|
+
msg.msg = res.error.response.data.payload.message;
|
|
233
|
+
}
|
|
234
|
+
return res
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
215
239
|
if (res) {
|
|
216
240
|
this[StateStore] = res;
|
|
217
241
|
if (mStore?.mUse) {
|
|
218
|
-
const checkType =
|
|
219
|
-
typeof res === "object" ? JSON.stringify(res) : res;
|
|
242
|
+
const checkType =typeof res === "object" ? JSON.stringify(res) : res;
|
|
220
243
|
sessionStorage.setItem(StateStore, JSON.stringify(checkType));
|
|
221
244
|
}
|
|
222
|
-
|
|
223
245
|
delete this.CheckQueriesInQue[callApi];
|
|
224
246
|
} else {
|
|
225
247
|
delete this.CheckQueriesInQue[callApi];
|
|
@@ -269,11 +291,12 @@ function createPomStore(
|
|
|
269
291
|
time: 0,
|
|
270
292
|
pagnated: false,
|
|
271
293
|
mStore: { mUse: 0, reset: 0 },
|
|
294
|
+
axiosInstance : null,
|
|
272
295
|
},
|
|
273
296
|
fasterDataCollection = null,
|
|
274
297
|
) {
|
|
275
298
|
this.Loading = true;
|
|
276
|
-
const { reload, StateStore, reqs, time, pagnated, mStore, config } = dd;
|
|
299
|
+
const { reload, StateStore, reqs, time, pagnated, mStore, config,axiosInstance } = dd;
|
|
277
300
|
const callApi = JSON.stringify(reqs);
|
|
278
301
|
const StateVariable = await this.parseData(StateStore, mStore);
|
|
279
302
|
this[StateStore] = StateVariable ?? [];
|
|
@@ -310,9 +333,10 @@ function createPomStore(
|
|
|
310
333
|
|
|
311
334
|
if (typeof fasterDataCollection == "function")
|
|
312
335
|
fasterDataCollection?.(StateVariable);
|
|
313
|
-
console.log(counters);
|
|
314
336
|
|
|
337
|
+
console.log({counters,reload,StateStore});
|
|
315
338
|
if (counters > 0) {
|
|
339
|
+
|
|
316
340
|
if (reload) {
|
|
317
341
|
await this.sleep(1000 * time);
|
|
318
342
|
return await this.CallApiData(
|
|
@@ -322,7 +346,8 @@ function createPomStore(
|
|
|
322
346
|
pagnated,
|
|
323
347
|
mStore,
|
|
324
348
|
config,
|
|
325
|
-
|
|
349
|
+
axiosInstance,
|
|
350
|
+
);
|
|
326
351
|
}
|
|
327
352
|
|
|
328
353
|
this.Loading = false;
|
|
@@ -338,6 +363,7 @@ function createPomStore(
|
|
|
338
363
|
pagnated,
|
|
339
364
|
mStore,
|
|
340
365
|
config,
|
|
366
|
+
axiosInstance
|
|
341
367
|
);
|
|
342
368
|
} catch (error) {
|
|
343
369
|
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,16 @@ 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
|
-
if (token)
|
|
34
|
-
request.headers.Authorization = `Bearer ${token}`;
|
|
32
|
+
|
|
33
|
+
request.headers = { ...(request?.headers ?? {}) } || {};
|
|
34
|
+
|
|
35
|
+
if (token) request.headers.Authorization = `Bearer ${token}`;
|
|
35
36
|
// Handle FormData explicitly if needed
|
|
36
37
|
if (request.data instanceof FormData) {
|
|
37
38
|
const formData = request.data;
|
|
@@ -50,22 +51,22 @@ customAxios.interceptors.response.use(
|
|
|
50
51
|
console.log("Error.....", error);
|
|
51
52
|
if (error.response?.status === 401) ;
|
|
52
53
|
return Promise.reject(error); // Reject the error for further handling
|
|
53
|
-
}
|
|
54
|
+
},
|
|
54
55
|
);
|
|
55
56
|
|
|
56
57
|
// Attach Request Interceptor
|
|
57
58
|
customAxios.interceptors.request.use(requestHandler, (error) =>
|
|
58
|
-
Promise.reject(error)
|
|
59
|
+
Promise.reject(error),
|
|
59
60
|
);
|
|
60
61
|
|
|
61
62
|
let axiosSetUps = customAxios;
|
|
62
63
|
|
|
63
|
-
function setUpAxiosToUse(setUp) {
|
|
64
|
+
async function setUpAxiosToUse(setUp) {
|
|
64
65
|
axiosSetUps = setUp??customAxios;
|
|
65
|
-
}
|
|
66
|
-
const useFetch = async ({ url, method, data = {}, config }) => {
|
|
67
|
-
console.log(method,'------');
|
|
68
66
|
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const useFetch = async ({ url, method, data = {}, config,axiosInstance }) => {
|
|
69
70
|
const uniformMethod = `${method}`.toLowerCase();
|
|
70
71
|
const headerC = {
|
|
71
72
|
...config,
|
|
@@ -73,20 +74,25 @@ const useFetch = async ({ url, method, data = {}, config }) => {
|
|
|
73
74
|
...(config?.headers || {}),
|
|
74
75
|
},
|
|
75
76
|
};
|
|
77
|
+
const axiosClient = axiosInstance ?? axiosSetUps;
|
|
78
|
+
// console.log({headerC,data});
|
|
79
|
+
|
|
76
80
|
|
|
81
|
+
|
|
77
82
|
try {
|
|
78
83
|
const axiosMethods = {
|
|
79
|
-
get: () =>
|
|
80
|
-
post: () =>
|
|
81
|
-
put: () =>
|
|
82
|
-
delete: () =>
|
|
84
|
+
get: () => axiosClient.get(`${url}${generateParams(data)}`, headerC),
|
|
85
|
+
post: () => axiosClient.post(url, data, headerC),
|
|
86
|
+
put: () => axiosClient.put(url, data, headerC),
|
|
87
|
+
delete: () => axiosClient.delete(url, { data, ...headerC }),
|
|
83
88
|
};
|
|
84
89
|
|
|
85
90
|
if (!axiosMethods[uniformMethod]) {
|
|
86
91
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
87
92
|
}
|
|
88
93
|
const response = await axiosMethods[uniformMethod]();
|
|
89
|
-
if(response?.
|
|
94
|
+
if(response?.data){
|
|
95
|
+
// if(response?.status){
|
|
90
96
|
return response?.data ?? response ??{ Empty: "Empty" };
|
|
91
97
|
}
|
|
92
98
|
return false
|
|
@@ -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,20 +212,36 @@ 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=;
|
|
221
|
+
if (res?.error) {
|
|
222
|
+
const msg = { msg: ""};
|
|
223
|
+
if (res.error.response?.data?.error) {
|
|
224
|
+
msg.msg = res.error.response.data.error;
|
|
225
|
+
} else if (res.error.message) {
|
|
226
|
+
msg.msg = res.error.message;
|
|
227
|
+
} else if (res.error.response?.data?.errors) {
|
|
228
|
+
const errors = res.error.response.data.errors;
|
|
229
|
+
msg.msg = Object.values(errors)[0][0] || msg.msg;
|
|
230
|
+
}
|
|
231
|
+
if (res?.error?.response?.data?.payload?.message) {
|
|
232
|
+
msg.msg = res.error.response.data.payload.message;
|
|
233
|
+
}
|
|
234
|
+
return res
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
215
239
|
if (res) {
|
|
216
240
|
this[StateStore] = res;
|
|
217
241
|
if (mStore?.mUse) {
|
|
218
|
-
const checkType =
|
|
219
|
-
typeof res === "object" ? JSON.stringify(res) : res;
|
|
242
|
+
const checkType =typeof res === "object" ? JSON.stringify(res) : res;
|
|
220
243
|
sessionStorage.setItem(StateStore, JSON.stringify(checkType));
|
|
221
244
|
}
|
|
222
|
-
|
|
223
245
|
delete this.CheckQueriesInQue[callApi];
|
|
224
246
|
} else {
|
|
225
247
|
delete this.CheckQueriesInQue[callApi];
|
|
@@ -269,11 +291,12 @@ function createPomStore(
|
|
|
269
291
|
time: 0,
|
|
270
292
|
pagnated: false,
|
|
271
293
|
mStore: { mUse: 0, reset: 0 },
|
|
294
|
+
axiosInstance : null,
|
|
272
295
|
},
|
|
273
296
|
fasterDataCollection = null,
|
|
274
297
|
) {
|
|
275
298
|
this.Loading = true;
|
|
276
|
-
const { reload, StateStore, reqs, time, pagnated, mStore, config } = dd;
|
|
299
|
+
const { reload, StateStore, reqs, time, pagnated, mStore, config,axiosInstance } = dd;
|
|
277
300
|
const callApi = JSON.stringify(reqs);
|
|
278
301
|
const StateVariable = await this.parseData(StateStore, mStore);
|
|
279
302
|
this[StateStore] = StateVariable ?? [];
|
|
@@ -310,9 +333,10 @@ function createPomStore(
|
|
|
310
333
|
|
|
311
334
|
if (typeof fasterDataCollection == "function")
|
|
312
335
|
fasterDataCollection?.(StateVariable);
|
|
313
|
-
console.log(counters);
|
|
314
336
|
|
|
337
|
+
console.log({counters,reload,StateStore});
|
|
315
338
|
if (counters > 0) {
|
|
339
|
+
|
|
316
340
|
if (reload) {
|
|
317
341
|
await this.sleep(1000 * time);
|
|
318
342
|
return await this.CallApiData(
|
|
@@ -322,7 +346,8 @@ function createPomStore(
|
|
|
322
346
|
pagnated,
|
|
323
347
|
mStore,
|
|
324
348
|
config,
|
|
325
|
-
|
|
349
|
+
axiosInstance,
|
|
350
|
+
);
|
|
326
351
|
}
|
|
327
352
|
|
|
328
353
|
this.Loading = false;
|
|
@@ -338,6 +363,7 @@ function createPomStore(
|
|
|
338
363
|
pagnated,
|
|
339
364
|
mStore,
|
|
340
365
|
config,
|
|
366
|
+
axiosInstance
|
|
341
367
|
);
|
|
342
368
|
} catch (error) {
|
|
343
369
|
console.error(error);
|
package/dist/index.js
CHANGED
|
@@ -36,8 +36,7 @@ var requestHandler = (request) => {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
request.headers = { ...(request == null ? void 0 : request.headers) ?? {} };
|
|
39
|
-
if (token)
|
|
40
|
-
request.headers.Authorization = `Bearer ${token}`;
|
|
39
|
+
if (token) request.headers.Authorization = `Bearer ${token}`;
|
|
41
40
|
if (request.data instanceof FormData) {
|
|
42
41
|
const formData = request.data;
|
|
43
42
|
request.data = formData;
|
|
@@ -65,11 +64,10 @@ var custom_axios_default = customAxios;
|
|
|
65
64
|
|
|
66
65
|
// src/utils/useFetch.js
|
|
67
66
|
var axiosSetUps = custom_axios_default;
|
|
68
|
-
function setUpAxiosToUse(setUp) {
|
|
67
|
+
async function setUpAxiosToUse(setUp) {
|
|
69
68
|
axiosSetUps = setUp ?? custom_axios_default;
|
|
70
69
|
}
|
|
71
|
-
var useFetch = async ({ url, method, data = {}, config }) => {
|
|
72
|
-
console.log(method, "------");
|
|
70
|
+
var useFetch = async ({ url, method, data = {}, config, axiosInstance }) => {
|
|
73
71
|
const uniformMethod = `${method}`.toLowerCase();
|
|
74
72
|
const headerC = {
|
|
75
73
|
...config,
|
|
@@ -77,18 +75,19 @@ var useFetch = async ({ url, method, data = {}, config }) => {
|
|
|
77
75
|
...(config == null ? void 0 : config.headers) || {}
|
|
78
76
|
}
|
|
79
77
|
};
|
|
78
|
+
const axiosClient = axiosInstance ?? axiosSetUps;
|
|
80
79
|
try {
|
|
81
80
|
const axiosMethods = {
|
|
82
|
-
get: () =>
|
|
83
|
-
post: () =>
|
|
84
|
-
put: () =>
|
|
85
|
-
delete: () =>
|
|
81
|
+
get: () => axiosClient.get(`${url}${generateParams(data)}`, headerC),
|
|
82
|
+
post: () => axiosClient.post(url, data, headerC),
|
|
83
|
+
put: () => axiosClient.put(url, data, headerC),
|
|
84
|
+
delete: () => axiosClient.delete(url, { data, ...headerC })
|
|
86
85
|
};
|
|
87
86
|
if (!axiosMethods[uniformMethod]) {
|
|
88
87
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
89
88
|
}
|
|
90
89
|
const response = await axiosMethods[uniformMethod]();
|
|
91
|
-
if (response == null ? void 0 : response.
|
|
90
|
+
if (response == null ? void 0 : response.data) {
|
|
92
91
|
return (response == null ? void 0 : response.data) ?? response ?? { Empty: "Empty" };
|
|
93
92
|
}
|
|
94
93
|
return false;
|
|
@@ -180,10 +179,26 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
180
179
|
sleep(timer) {
|
|
181
180
|
return new Promise((r) => setTimeout(r, timer));
|
|
182
181
|
},
|
|
183
|
-
async CallApiData(StateStore, callApi, dataParams, pagnated, mStore = {}, config) {
|
|
182
|
+
async CallApiData(StateStore, callApi, dataParams, pagnated, mStore = {}, config, axiosInstance = null) {
|
|
183
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
184
184
|
if (!this.CheckQueriesInQue[callApi]) {
|
|
185
185
|
this.CheckQueriesInQue[callApi] = callApi;
|
|
186
|
-
let [res] = await Promise.all([useFetch({ ...dataParams, config })]);
|
|
186
|
+
let [res] = await Promise.all([useFetch({ ...dataParams, config, axiosInstance })]);
|
|
187
|
+
if (res == null ? void 0 : res.error) {
|
|
188
|
+
const msg = { msg: "", error: true };
|
|
189
|
+
if ((_b = (_a = res.error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.error) {
|
|
190
|
+
msg.msg = res.error.response.data.error;
|
|
191
|
+
} else if (res.error.message) {
|
|
192
|
+
msg.msg = res.error.message;
|
|
193
|
+
} else if ((_d = (_c = res.error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.errors) {
|
|
194
|
+
const errors = res.error.response.data.errors;
|
|
195
|
+
msg.msg = Object.values(errors)[0][0] || msg.msg;
|
|
196
|
+
}
|
|
197
|
+
if ((_h = (_g = (_f = (_e = res == null ? void 0 : res.error) == null ? void 0 : _e.response) == null ? void 0 : _f.data) == null ? void 0 : _g.payload) == null ? void 0 : _h.message) {
|
|
198
|
+
msg.msg = res.error.response.data.payload.message;
|
|
199
|
+
}
|
|
200
|
+
return res;
|
|
201
|
+
}
|
|
187
202
|
if (res) {
|
|
188
203
|
this[StateStore] = res;
|
|
189
204
|
if (mStore == null ? void 0 : mStore.mUse) {
|
|
@@ -231,10 +246,11 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
231
246
|
config: {},
|
|
232
247
|
time: 0,
|
|
233
248
|
pagnated: false,
|
|
234
|
-
mStore: { mUse: 0, reset: 0 }
|
|
249
|
+
mStore: { mUse: 0, reset: 0 },
|
|
250
|
+
axiosInstance: null
|
|
235
251
|
}, fasterDataCollection = null) {
|
|
236
252
|
this.Loading = true;
|
|
237
|
-
const { reload, StateStore, reqs, time, pagnated, mStore, config } = dd;
|
|
253
|
+
const { reload, StateStore, reqs, time, pagnated, mStore, config, axiosInstance } = dd;
|
|
238
254
|
const callApi = JSON.stringify(reqs);
|
|
239
255
|
const StateVariable = await this.parseData(StateStore, mStore);
|
|
240
256
|
this[StateStore] = StateVariable ?? [];
|
|
@@ -263,7 +279,7 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
263
279
|
const counters = this.validateObjectLength(StateVariable);
|
|
264
280
|
if (typeof fasterDataCollection == "function")
|
|
265
281
|
fasterDataCollection == null ? void 0 : fasterDataCollection(StateVariable);
|
|
266
|
-
console.log(counters);
|
|
282
|
+
console.log({ counters, reload, StateStore });
|
|
267
283
|
if (counters > 0) {
|
|
268
284
|
if (reload) {
|
|
269
285
|
await this.sleep(1e3 * time);
|
|
@@ -273,7 +289,8 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
273
289
|
reqs,
|
|
274
290
|
pagnated,
|
|
275
291
|
mStore,
|
|
276
|
-
config
|
|
292
|
+
config,
|
|
293
|
+
axiosInstance
|
|
277
294
|
);
|
|
278
295
|
}
|
|
279
296
|
this.Loading = false;
|
|
@@ -287,7 +304,8 @@ function createPomStore(piniaStore = "7286204094", callBack = null, ds = { State
|
|
|
287
304
|
reqs,
|
|
288
305
|
pagnated,
|
|
289
306
|
mStore,
|
|
290
|
-
config
|
|
307
|
+
config,
|
|
308
|
+
axiosInstance
|
|
291
309
|
);
|
|
292
310
|
} catch (error) {
|
|
293
311
|
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.5",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.cjs",
|
|
9
9
|
"module": "dist/index.js",
|