septor-store 0.0.5 → 1.0.0
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 +43 -2
- package/package.json +36 -34
- package/dist/index.cjs +0 -308
- package/dist/index.d.cts +0 -309
- package/dist/index.d.ts +0 -309
- package/dist/index.js +0 -267
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Vue 3 + TypeScript + Vite
|
|
2
|
+
|
|
2
3
|
<p align="center">
|
|
3
4
|
<img src="https://github.com/ssengedonazil/septor-store-testing/blob/POM/assets/septor-store.png?raw=true" alt="Septor Logo" width="180" />
|
|
4
5
|
</p>
|
|
@@ -7,7 +8,6 @@
|
|
|
7
8
|
|
|
8
9
|
# septor-store
|
|
9
10
|
|
|
10
|
-
Description (Full)
|
|
11
11
|
septor-store is a structured and scalable state management solution built on top of Pinia for Vue 3. It embraces the Plain Old Module (POM) pattern to simplify how developers—junior or senior—write, organize, and scale their application state. Whether you're just starting out or architecting large Vue applications, this tool helps you keep your stores clean, predictable, and easy to maintain.
|
|
12
12
|
|
|
13
13
|
### Features
|
|
@@ -23,6 +23,7 @@ septor-store is a structured and scalable state management solution built on top
|
|
|
23
23
|
| Post + Submit Support | Easily manage POST data and track responses |
|
|
24
24
|
| Flexible Callbacks | Use custom callbacks on state update |
|
|
25
25
|
| Loading & Error States | Built-in support for loading/errors |
|
|
26
|
+
| clean all the state against the store id
|
|
26
27
|
|
|
27
28
|
- Automatic API Call Queue Management Prevents multiple simultaneous calls to the same endpoint by tracking ongoing requests.
|
|
28
29
|
- Session Storage Caching Support Optionally caches API responses in sessionStorage for faster retrieval and offline resilience.
|
|
@@ -262,9 +263,49 @@ const handleSubmit = async () => {
|
|
|
262
263
|
const res = await store.stateGenaratorApi(config, (oldData) => {
|
|
263
264
|
console.log('Previous post result if any:', oldData)
|
|
264
265
|
})
|
|
265
|
-
|
|
266
266
|
result.value = res
|
|
267
267
|
}
|
|
268
268
|
</script>
|
|
269
269
|
|
|
270
270
|
```
|
|
271
|
+
|
|
272
|
+
### Usage **EXAMPLE 3** Remove all the data stored(cleare)🤭
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
Note: StateClean this activates the opearation
|
|
276
|
+
|
|
277
|
+
const usePomStore = pomPinia('myCustomStoreId',null,{StateClean:true});
|
|
278
|
+
const pomStore = usePomStore();
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
const handleSubmit = async () => {
|
|
282
|
+
const config = {
|
|
283
|
+
StateStore: 'packageList',
|
|
284
|
+
reqs: {
|
|
285
|
+
url: '/api/packagelist', //call your endpoint
|
|
286
|
+
method: 'post',
|
|
287
|
+
data: user.value,
|
|
288
|
+
},
|
|
289
|
+
reload: true,
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const res = await pomStore.stateGenaratorApi(config, (oldData) => {
|
|
293
|
+
console.log('Previous post result if any:', oldData)
|
|
294
|
+
})
|
|
295
|
+
result.value = res
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
pomStore.WipeStates(stateId) // remove just a paticular id (eg packageList)
|
|
299
|
+
pomStore.WipeStates() // remove all the states
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
🤝 Contributing and Feedback
|
|
304
|
+
We welcome all contributions and feedback to improve septor-store!
|
|
305
|
+
If you encounter any bugs, have suggestions, or want to contribute,
|
|
306
|
+
please open an issue or submit a pull request:
|
|
307
|
+
👉 Report Issues or Suggestions : <https://github.com/ssengedonazil/septor-store-testing>
|
|
308
|
+
|
|
309
|
+
If you find this package useful, consider supporting me:
|
|
310
|
+
|
|
311
|
+
[](https://ko-fi.com/ssengendonazil)
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "septor-store",
|
|
3
|
-
"description": "
|
|
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": "0.0
|
|
6
|
+
"version": "1.0.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.cjs",
|
|
9
9
|
"module": "dist/index.js",
|
|
@@ -25,46 +25,48 @@
|
|
|
25
25
|
"vue": "^3.5.13"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/axios": "^0.14.4",
|
|
28
|
+
"@types/axios": "^0.14.4",
|
|
29
29
|
"tsup": "^8.4.0",
|
|
30
30
|
"typescript": "~5.8.3"
|
|
31
31
|
},
|
|
32
32
|
"keywords": [
|
|
33
|
-
"pinia",
|
|
34
33
|
"vue",
|
|
34
|
+
"vue3",
|
|
35
|
+
"pinia",
|
|
36
|
+
"pinia store",
|
|
37
|
+
"vue pinia plugin",
|
|
35
38
|
"state management",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"pom-pattern",
|
|
45
|
-
"vue-pinia",
|
|
46
|
-
"vue-store",
|
|
47
|
-
"pinia-store",
|
|
48
|
-
"modular-state",
|
|
49
|
-
"api-cache",
|
|
50
|
-
"api-state-manager",
|
|
51
|
-
"typescript",
|
|
52
|
-
"vue-typescript",
|
|
53
|
-
"pinia-plugin",
|
|
54
|
-
"state-library",
|
|
39
|
+
"vue state management",
|
|
40
|
+
"api caching",
|
|
41
|
+
"vue ssr",
|
|
42
|
+
"vue spa",
|
|
43
|
+
"store plugin",
|
|
44
|
+
"modular state",
|
|
45
|
+
"dynamic store",
|
|
46
|
+
"state persistence",
|
|
55
47
|
"frontend tools",
|
|
56
|
-
"
|
|
57
|
-
"session
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"vue
|
|
61
|
-
"
|
|
48
|
+
"api queue",
|
|
49
|
+
"session storage",
|
|
50
|
+
"pom pattern",
|
|
51
|
+
"plain old module",
|
|
52
|
+
"vue typescript",
|
|
53
|
+
"typescript",
|
|
54
|
+
"reactive state",
|
|
55
|
+
"data fetching",
|
|
62
56
|
"vuex alternative",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
57
|
+
"state library",
|
|
58
|
+
"state sync",
|
|
59
|
+
"loading state",
|
|
60
|
+
"vue plugin",
|
|
61
|
+
"pinia plugin",
|
|
62
|
+
"septor store",
|
|
63
|
+
"septor-store-vue"
|
|
64
|
+
],
|
|
65
|
+
"funding": [
|
|
66
|
+
{
|
|
67
|
+
"type": "ko-fi",
|
|
68
|
+
"url": "https://ko-fi.com/ssengedonazil"
|
|
69
|
+
}
|
|
68
70
|
],
|
|
69
71
|
"author": "Ssengendo Nazil",
|
|
70
72
|
"repository": {
|
package/dist/index.cjs
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/index.js
|
|
30
|
-
var index_exports = {};
|
|
31
|
-
__export(index_exports, {
|
|
32
|
-
generateParams: () => generateParams,
|
|
33
|
-
getBearerToken: () => getBearerToken,
|
|
34
|
-
pomPinia: () => createPomStore,
|
|
35
|
-
setBearerToken: () => setBearerToken,
|
|
36
|
-
useFetch: () => useFetch
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(index_exports);
|
|
39
|
-
|
|
40
|
-
// src/StoreManager/pomStateManagement.js
|
|
41
|
-
var import_pinia = require("pinia");
|
|
42
|
-
|
|
43
|
-
// src/utils/custom-axios.js
|
|
44
|
-
var import_axios = __toESM(require("axios"), 1);
|
|
45
|
-
|
|
46
|
-
// src/utils/abortHandler.js
|
|
47
|
-
var AbortHandler = {
|
|
48
|
-
abortController: new AbortController(),
|
|
49
|
-
abortHttpRequests() {
|
|
50
|
-
this.abortController.abort();
|
|
51
|
-
this.abortController = new AbortController();
|
|
52
|
-
custom_axios_default.defaults.signal = this.abortController.signal;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
var abortHandler_default = AbortHandler;
|
|
56
|
-
|
|
57
|
-
// src/utils/custom-axios.js
|
|
58
|
-
var import_meta = {};
|
|
59
|
-
var baseURL = typeof import_meta !== "undefined" ? import_meta.env.VITE_BACKEND_URL ?? "" : void 0;
|
|
60
|
-
var customAxios = import_axios.default.create({
|
|
61
|
-
baseURL,
|
|
62
|
-
signal: abortHandler_default.abortController.signal
|
|
63
|
-
// Signal that is assiciated with any request to be made with this axios instance
|
|
64
|
-
});
|
|
65
|
-
var requestHandler = (request) => {
|
|
66
|
-
const tokenData = getBearerToken();
|
|
67
|
-
const token = (tokenData == null ? void 0 : tokenData.token) ?? null;
|
|
68
|
-
const expiresIn = (tokenData == null ? void 0 : tokenData.expiresIn) ?? null;
|
|
69
|
-
if (expiresIn) {
|
|
70
|
-
const timestamp = (tokenData == null ? void 0 : tokenData.timestamp) ?? null;
|
|
71
|
-
const now = Date.now();
|
|
72
|
-
if (expiresIn && now - timestamp > expiresIn * 1e3) {
|
|
73
|
-
console.warn("Token has expired.");
|
|
74
|
-
localStorage.removeItem("logginToken");
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (token) {
|
|
79
|
-
request.headers.Authorization = `Bearer ${token}`;
|
|
80
|
-
}
|
|
81
|
-
if (request.data instanceof FormData) {
|
|
82
|
-
const formData = request.data;
|
|
83
|
-
request.data = formData;
|
|
84
|
-
} else if (request.data) {
|
|
85
|
-
request.data = { ...request.data ?? {} };
|
|
86
|
-
}
|
|
87
|
-
return request;
|
|
88
|
-
};
|
|
89
|
-
customAxios.interceptors.response.use(
|
|
90
|
-
(response) => response,
|
|
91
|
-
// Resolve response as is
|
|
92
|
-
(error) => {
|
|
93
|
-
var _a;
|
|
94
|
-
console.log("Error.....", error);
|
|
95
|
-
if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
|
|
96
|
-
}
|
|
97
|
-
return Promise.reject(error);
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
customAxios.interceptors.request.use(
|
|
101
|
-
requestHandler,
|
|
102
|
-
(error) => Promise.reject(error)
|
|
103
|
-
);
|
|
104
|
-
var custom_axios_default = customAxios;
|
|
105
|
-
|
|
106
|
-
// src/utils/useFetch.js
|
|
107
|
-
var useFetch = async ({ url, method, data }) => {
|
|
108
|
-
let _data = data ?? {};
|
|
109
|
-
try {
|
|
110
|
-
let response = null;
|
|
111
|
-
const uniformMethod = method.toLowerCase();
|
|
112
|
-
if (uniformMethod === "get") {
|
|
113
|
-
const params = generateParams(_data ?? {});
|
|
114
|
-
response = await custom_axios_default.get(`${url}${params}`);
|
|
115
|
-
} else {
|
|
116
|
-
response = await custom_axios_default.post(url, _data);
|
|
117
|
-
}
|
|
118
|
-
return (response == null ? void 0 : response.data) ?? { Empty: "Empty" };
|
|
119
|
-
} catch (err) {
|
|
120
|
-
console.error(err);
|
|
121
|
-
return { success: false, error: err };
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var generateParams = (params = {}) => {
|
|
125
|
-
let data = "?";
|
|
126
|
-
for (let key in params) {
|
|
127
|
-
if (Object.hasOwnProperty.call(params, key)) {
|
|
128
|
-
if (params[key]) {
|
|
129
|
-
if (Array.isArray(params[key])) {
|
|
130
|
-
const elements = params[key];
|
|
131
|
-
for (const ele of elements) {
|
|
132
|
-
data += `${key}[]=${ele}&`;
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
data += `${key}=${params[key]}&`;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return data.slice(0, -1);
|
|
141
|
-
};
|
|
142
|
-
function setBearerToken(name = { token: null }) {
|
|
143
|
-
if (typeof name !== "object" || name === null || Array.isArray(name))
|
|
144
|
-
throw new TypeError("setBearerToken expects an object {token} with a 'token' property.");
|
|
145
|
-
const tokenObj = { token: null, ...name, timestamp: Date.now() };
|
|
146
|
-
localStorage.setItem("logginToken", JSON.stringify(tokenObj));
|
|
147
|
-
}
|
|
148
|
-
function getBearerToken() {
|
|
149
|
-
const token = localStorage.getItem("logginToken");
|
|
150
|
-
try {
|
|
151
|
-
return token ? JSON.parse(token) : null;
|
|
152
|
-
} catch (e) {
|
|
153
|
-
console.error("Invalid token format in localStorage:", e);
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// src/StoreManager/pomStateManagement.js
|
|
159
|
-
function createPomStore(piniaStore = "7286204094", callBack = null) {
|
|
160
|
-
const storeId = "POM" + piniaStore;
|
|
161
|
-
const piniaData = (0, import_pinia.defineStore)(storeId, {
|
|
162
|
-
state: () => {
|
|
163
|
-
const StateObjectsContainer = {
|
|
164
|
-
CheckQueriesInQue: {},
|
|
165
|
-
StateValue: {},
|
|
166
|
-
Loading: true,
|
|
167
|
-
isThereAnyDataChangeInAform: false
|
|
168
|
-
};
|
|
169
|
-
return StateObjectsContainer;
|
|
170
|
-
},
|
|
171
|
-
getters: {
|
|
172
|
-
stateItems: (state) => (TagetState) => {
|
|
173
|
-
return state[TagetState] = state[TagetState];
|
|
174
|
-
}
|
|
175
|
-
// store.getStateItem(key1) usage to ge the ge
|
|
176
|
-
// getStateItem: (state) => (stateKey=nu) => state[stateKey],
|
|
177
|
-
},
|
|
178
|
-
actions: {
|
|
179
|
-
validateObjectLength(object) {
|
|
180
|
-
if (Array.isArray(object)) {
|
|
181
|
-
return object.length;
|
|
182
|
-
} else if (typeof object == "object") {
|
|
183
|
-
const lng = Object.keys(object);
|
|
184
|
-
return lng.length;
|
|
185
|
-
}
|
|
186
|
-
return 0;
|
|
187
|
-
},
|
|
188
|
-
pageNumber(pageUrl) {
|
|
189
|
-
const inputString = pageUrl;
|
|
190
|
-
const regex = /\?(page)+=\d+/;
|
|
191
|
-
const match = regex.exec(inputString);
|
|
192
|
-
if (match) {
|
|
193
|
-
const matchedPattern = match[0];
|
|
194
|
-
const dataBack = matchedPattern.split("?page=").join().replace(/[^\d]/, "");
|
|
195
|
-
return dataBack;
|
|
196
|
-
} else return "1";
|
|
197
|
-
},
|
|
198
|
-
sleep(timer) {
|
|
199
|
-
return new Promise((r) => setTimeout(r, timer));
|
|
200
|
-
},
|
|
201
|
-
async CallApiData(StateStore, callApi, dataParams, pagnated, mStore = {}) {
|
|
202
|
-
if (!this.CheckQueriesInQue[callApi]) {
|
|
203
|
-
this.CheckQueriesInQue[callApi] = callApi;
|
|
204
|
-
let [res] = await Promise.all([
|
|
205
|
-
useFetch(dataParams)
|
|
206
|
-
]);
|
|
207
|
-
if (res) {
|
|
208
|
-
this[StateStore] = res;
|
|
209
|
-
if (mStore == null ? void 0 : mStore.mUse) {
|
|
210
|
-
const checkType = typeof res === "object" ? JSON.stringify(res) : res;
|
|
211
|
-
sessionStorage.setItem(StateStore, JSON.stringify(checkType));
|
|
212
|
-
}
|
|
213
|
-
delete this.CheckQueriesInQue[callApi];
|
|
214
|
-
} else {
|
|
215
|
-
delete this.CheckQueriesInQue[callApi];
|
|
216
|
-
console.error(res);
|
|
217
|
-
}
|
|
218
|
-
this.Loading = false;
|
|
219
|
-
return res;
|
|
220
|
-
}
|
|
221
|
-
this.Loading = false;
|
|
222
|
-
return this[StateStore] ?? [];
|
|
223
|
-
},
|
|
224
|
-
async parseData(dataResponseName = "xxx", mStore = { mUse: false, reset: false }) {
|
|
225
|
-
try {
|
|
226
|
-
if (mStore == null ? void 0 : mStore.reset) {
|
|
227
|
-
sessionStorage.removeItem(dataResponseName);
|
|
228
|
-
}
|
|
229
|
-
if (mStore == null ? void 0 : mStore.mUse) {
|
|
230
|
-
const thisData = JSON.parse(
|
|
231
|
-
JSON.parse(sessionStorage.getItem(dataResponseName) || {})
|
|
232
|
-
);
|
|
233
|
-
return thisData;
|
|
234
|
-
}
|
|
235
|
-
} catch (error) {
|
|
236
|
-
}
|
|
237
|
-
return this[dataResponseName];
|
|
238
|
-
},
|
|
239
|
-
async stateGenaratorApi(dd = { reload: true, StateStore: "", reqs: {}, time: 0, pagnated: false, mStore: { mUse: 0 } }, fasterDataCollection = null) {
|
|
240
|
-
this.Loading = true;
|
|
241
|
-
const { reload, StateStore, reqs, time, pagnated, mStore } = dd;
|
|
242
|
-
const callApi = JSON.stringify(reqs);
|
|
243
|
-
const StateVariable = await this.parseData(StateStore, mStore);
|
|
244
|
-
this[StateStore] = StateVariable ?? [];
|
|
245
|
-
if (this.StateValue[StateStore]) {
|
|
246
|
-
this.StateValue[StateStore] = false;
|
|
247
|
-
this[StateStore] = false;
|
|
248
|
-
}
|
|
249
|
-
if (this.CheckQueriesInQue[callApi]) {
|
|
250
|
-
console.warn(`************************************* dont call this api again ${reqs["url"]} \u{1F6E9}\uFE0F *************************************`, reqs);
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
try {
|
|
254
|
-
const counters = this.validateObjectLength(StateVariable);
|
|
255
|
-
if (typeof fasterDataCollection == "function")
|
|
256
|
-
fasterDataCollection(StateVariable);
|
|
257
|
-
if (counters > 0) {
|
|
258
|
-
if (reload) {
|
|
259
|
-
const delay = await this.sleep(1e3 * time);
|
|
260
|
-
return await this.CallApiData(
|
|
261
|
-
StateStore,
|
|
262
|
-
callApi,
|
|
263
|
-
reqs,
|
|
264
|
-
pagnated,
|
|
265
|
-
mStore
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
this.Loading = false;
|
|
269
|
-
return this[StateStore];
|
|
270
|
-
} else {
|
|
271
|
-
this.Loading = true;
|
|
272
|
-
}
|
|
273
|
-
return await this.CallApiData(
|
|
274
|
-
StateStore,
|
|
275
|
-
callApi,
|
|
276
|
-
reqs,
|
|
277
|
-
pagnated,
|
|
278
|
-
mStore
|
|
279
|
-
);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
if (this.CheckQueriesInQue[callApi])
|
|
282
|
-
delete this.CheckQueriesInQue[callApi];
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
Creator() {
|
|
286
|
-
if (typeof callBack === "function") {
|
|
287
|
-
return callBack(this);
|
|
288
|
-
}
|
|
289
|
-
},
|
|
290
|
-
DriveManual() {
|
|
291
|
-
return function() {
|
|
292
|
-
return this;
|
|
293
|
-
};
|
|
294
|
-
},
|
|
295
|
-
pagenatedData() {
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
return piniaData();
|
|
300
|
-
}
|
|
301
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
302
|
-
0 && (module.exports = {
|
|
303
|
-
generateParams,
|
|
304
|
-
getBearerToken,
|
|
305
|
-
pomPinia,
|
|
306
|
-
setBearerToken,
|
|
307
|
-
useFetch
|
|
308
|
-
});
|
package/dist/index.d.cts
DELETED
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import { defineStore } from 'pinia';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
|
|
4
|
-
const AbortHandler = {
|
|
5
|
-
abortController: new AbortController()};
|
|
6
|
-
|
|
7
|
-
const baseURL = typeof import.meta !== 'undefined' ? (import.meta.env.VITE_BACKEND_URL ??""): undefined;
|
|
8
|
-
|
|
9
|
-
const customAxios = axios.create({
|
|
10
|
-
baseURL: baseURL,
|
|
11
|
-
signal: AbortHandler.abortController.signal, // Signal that is assiciated with any request to be made with this axios instance
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// Request Interceptor
|
|
15
|
-
const requestHandler = (request) => {
|
|
16
|
-
const tokenData = getBearerToken();
|
|
17
|
-
const token = tokenData?.token ?? null; // Always retrieve the latest token
|
|
18
|
-
const expiresIn = tokenData?.expiresIn ?? null;
|
|
19
|
-
|
|
20
|
-
if (expiresIn) {
|
|
21
|
-
const timestamp = tokenData?.timestamp ?? null;
|
|
22
|
-
const now = Date.now();
|
|
23
|
-
if (expiresIn && (now - timestamp) > (expiresIn * 1000)) {
|
|
24
|
-
console.warn("Token has expired.");
|
|
25
|
-
localStorage.removeItem("logginToken");
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (token) {
|
|
31
|
-
request.headers.Authorization = `Bearer ${token}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Handle FormData explicitly if needed
|
|
35
|
-
if (request.data instanceof FormData) {
|
|
36
|
-
// Keep FormData unchanged
|
|
37
|
-
const formData = request.data;
|
|
38
|
-
request.data = formData;
|
|
39
|
-
} else if (request.data) {
|
|
40
|
-
request.data = { ...(request.data ?? {}) };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return request;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// Response Interceptor
|
|
47
|
-
customAxios.interceptors.response.use(
|
|
48
|
-
(response) => response, // Resolve response as is
|
|
49
|
-
(error) => {
|
|
50
|
-
console.log("Error.....", error);
|
|
51
|
-
if (error.response?.status === 401) ;
|
|
52
|
-
return Promise.reject(error); // Reject the error for further handling
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
// Attach Request Interceptor
|
|
57
|
-
customAxios.interceptors.request.use(requestHandler, (error) =>
|
|
58
|
-
Promise.reject(error)
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const useFetch = async ({ url, method, data }) => {
|
|
62
|
-
let _data = data ?? {};
|
|
63
|
-
try {
|
|
64
|
-
let response=null;
|
|
65
|
-
const uniformMethod = method.toLowerCase();
|
|
66
|
-
if (uniformMethod === 'get') {
|
|
67
|
-
const params = generateParams(_data ?? {});
|
|
68
|
-
response = await customAxios.get(`${url}${params}`);
|
|
69
|
-
} else {
|
|
70
|
-
response = await customAxios.post(url, _data);
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
// console.log(response, "responseresponseresponseresponse");
|
|
74
|
-
return response?.data ?? { Empty: 'Empty' };
|
|
75
|
-
} catch (err) {
|
|
76
|
-
console.error(err);
|
|
77
|
-
return { success: false, error: err };
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const generateParams = (params={}) => {
|
|
82
|
-
let data = "?";
|
|
83
|
-
for (let key in params) {
|
|
84
|
-
if (Object.hasOwnProperty.call(params, key)) {
|
|
85
|
-
if (params[key]) {
|
|
86
|
-
if (Array.isArray(params[key])) {
|
|
87
|
-
const elements = params[key] ;
|
|
88
|
-
for (const ele of elements) {
|
|
89
|
-
data += `${key}[]=${ele}&`;
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
data += `${key}=${params[key]}&`;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return data.slice(0, -1);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
function setBearerToken(name = { token: null }) {
|
|
101
|
-
if (typeof name !== "object" || name === null || Array.isArray(name))
|
|
102
|
-
throw new TypeError("setBearerToken expects an object {token} with a 'token' property.");
|
|
103
|
-
|
|
104
|
-
const tokenObj = { token: null, ...name,timestamp: Date.now() };
|
|
105
|
-
localStorage.setItem("logginToken", JSON.stringify(tokenObj));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function getBearerToken() {
|
|
109
|
-
const token = localStorage.getItem('logginToken');
|
|
110
|
-
try {
|
|
111
|
-
return token ? JSON.parse(token) : null;
|
|
112
|
-
} catch (e) {
|
|
113
|
-
console.error('Invalid token format in localStorage:', e);
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function createPomStore(
|
|
119
|
-
piniaStore = "7286204094",
|
|
120
|
-
callBack=null
|
|
121
|
-
) {
|
|
122
|
-
const storeId = "POM" + piniaStore;
|
|
123
|
-
const piniaData = defineStore(storeId, {
|
|
124
|
-
state: () => {
|
|
125
|
-
const StateObjectsContainer = {
|
|
126
|
-
CheckQueriesInQue: {},
|
|
127
|
-
StateValue: {},
|
|
128
|
-
Loading: true,
|
|
129
|
-
isThereAnyDataChangeInAform: false,
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
return StateObjectsContainer;
|
|
133
|
-
// return {...this.state,...StateObjectsContainer}
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
getters: {
|
|
137
|
-
stateItems: (state) => (TagetState) => {
|
|
138
|
-
/**
|
|
139
|
-
make data basing on state TagetState this acts as a clusure in ()() read about it
|
|
140
|
-
store.stateItems(key1) usage to ge the ge
|
|
141
|
-
*
|
|
142
|
-
*/
|
|
143
|
-
return (state[TagetState] = state[TagetState]);
|
|
144
|
-
},
|
|
145
|
-
// store.getStateItem(key1) usage to ge the ge
|
|
146
|
-
|
|
147
|
-
// getStateItem: (state) => (stateKey=nu) => state[stateKey],
|
|
148
|
-
},
|
|
149
|
-
actions: {
|
|
150
|
-
validateObjectLength(object) {
|
|
151
|
-
if (Array.isArray(object)) {
|
|
152
|
-
return object.length;
|
|
153
|
-
} else if (typeof object == "object") {
|
|
154
|
-
const lng = Object.keys(object);
|
|
155
|
-
return lng.length;
|
|
156
|
-
}
|
|
157
|
-
return 0;
|
|
158
|
-
},
|
|
159
|
-
pageNumber(pageUrl) {
|
|
160
|
-
const inputString = pageUrl; //'?page=124234232&&';
|
|
161
|
-
const regex = /\?(page)+=\d+/;
|
|
162
|
-
const match = regex.exec(inputString);
|
|
163
|
-
|
|
164
|
-
if (match) {
|
|
165
|
-
// /according to the patern ' i expect 1 value /
|
|
166
|
-
const matchedPattern = match[0];
|
|
167
|
-
const dataBack = matchedPattern
|
|
168
|
-
.split("?page=")
|
|
169
|
-
.join()
|
|
170
|
-
.replace(/[^\d]/, "");
|
|
171
|
-
|
|
172
|
-
return dataBack;
|
|
173
|
-
} else return "1";
|
|
174
|
-
},
|
|
175
|
-
sleep(timer) {
|
|
176
|
-
return new Promise((r) => setTimeout(r, timer));
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
async CallApiData(
|
|
180
|
-
StateStore,
|
|
181
|
-
callApi,
|
|
182
|
-
dataParams,
|
|
183
|
-
pagnated ,
|
|
184
|
-
mStore={}
|
|
185
|
-
) {
|
|
186
|
-
if (!this.CheckQueriesInQue[callApi]) {
|
|
187
|
-
this.CheckQueriesInQue[callApi] = callApi;
|
|
188
|
-
let [res] = await Promise.all([
|
|
189
|
-
useFetch (dataParams),
|
|
190
|
-
]);
|
|
191
|
-
|
|
192
|
-
if (res) {
|
|
193
|
-
this[StateStore] = res;
|
|
194
|
-
if (mStore?.mUse) {
|
|
195
|
-
const checkType =typeof res === "object" ? JSON.stringify(res) : res;
|
|
196
|
-
sessionStorage.setItem(StateStore, JSON.stringify(checkType));
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
delete this.CheckQueriesInQue[callApi];
|
|
200
|
-
} else {
|
|
201
|
-
delete this.CheckQueriesInQue[callApi];
|
|
202
|
-
console.error(res);
|
|
203
|
-
}
|
|
204
|
-
this.Loading = false;
|
|
205
|
-
return res;
|
|
206
|
-
}
|
|
207
|
-
this.Loading = false;
|
|
208
|
-
return this[StateStore] ?? [];
|
|
209
|
-
},
|
|
210
|
-
async parseData(
|
|
211
|
-
dataResponseName = "xxx",
|
|
212
|
-
mStore = { mUse: false, reset: false }
|
|
213
|
-
) {
|
|
214
|
-
try {
|
|
215
|
-
if (mStore?.reset) {
|
|
216
|
-
sessionStorage.removeItem(dataResponseName);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (mStore?.mUse) {
|
|
220
|
-
const thisData = JSON.parse(
|
|
221
|
-
JSON.parse(sessionStorage.getItem(dataResponseName) || {})
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
return thisData;
|
|
225
|
-
}
|
|
226
|
-
} catch (error) {}
|
|
227
|
-
|
|
228
|
-
return this[dataResponseName];
|
|
229
|
-
},
|
|
230
|
-
async stateGenaratorApi(dd = { reload: true, StateStore: "", reqs: {}, time: 0, pagnated: false, mStore: { mUse: 0 },},fasterDataCollection=null) {
|
|
231
|
-
this.Loading = true;
|
|
232
|
-
const { reload, StateStore, reqs, time, pagnated, mStore } = dd;
|
|
233
|
-
const callApi = JSON.stringify(reqs);
|
|
234
|
-
const StateVariable = await this.parseData(StateStore, mStore);
|
|
235
|
-
this[StateStore] = StateVariable ?? [];
|
|
236
|
-
|
|
237
|
-
if (this.StateValue[StateStore]) {
|
|
238
|
-
/**
|
|
239
|
-
* dynamically lets create the state store
|
|
240
|
-
**/
|
|
241
|
-
this.StateValue[StateStore] = false;
|
|
242
|
-
this[StateStore] = false;
|
|
243
|
-
// this[StateStore] =null ;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (this.CheckQueriesInQue[callApi]) {
|
|
247
|
-
console.warn(`************************************* dont call this api again ${reqs["url"]} 🛩️ *************************************`,reqs);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
try {
|
|
251
|
-
const counters = this.validateObjectLength(StateVariable);
|
|
252
|
-
if (typeof fasterDataCollection == "function")
|
|
253
|
-
fasterDataCollection(StateVariable);
|
|
254
|
-
|
|
255
|
-
if (counters > 0) {
|
|
256
|
-
if (reload) {
|
|
257
|
-
const delay = await this.sleep(1000 * time);
|
|
258
|
-
return await this.CallApiData(
|
|
259
|
-
StateStore,
|
|
260
|
-
callApi,
|
|
261
|
-
reqs,
|
|
262
|
-
pagnated,
|
|
263
|
-
mStore
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
this.Loading = false;
|
|
268
|
-
return this[StateStore];
|
|
269
|
-
} else {
|
|
270
|
-
this.Loading = true;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return await this.CallApiData(
|
|
274
|
-
StateStore,
|
|
275
|
-
callApi,
|
|
276
|
-
reqs,
|
|
277
|
-
pagnated,
|
|
278
|
-
mStore
|
|
279
|
-
);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
// console.error(error);
|
|
282
|
-
if (this.CheckQueriesInQue[callApi])
|
|
283
|
-
delete this.CheckQueriesInQue[callApi];
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
Creator() {
|
|
287
|
-
/**
|
|
288
|
-
*
|
|
289
|
-
* this will retun a call back wth the full object
|
|
290
|
-
* **/
|
|
291
|
-
if (typeof callBack === "function") {
|
|
292
|
-
return callBack(this);
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
DriveManual() {
|
|
296
|
-
return function () {
|
|
297
|
-
return this;
|
|
298
|
-
};
|
|
299
|
-
},
|
|
300
|
-
pagenatedData() {},
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
return piniaData();
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// module.e = createPomStore
|
|
308
|
-
|
|
309
|
-
export { generateParams, getBearerToken, createPomStore as pomPinia, setBearerToken, useFetch };
|
package/dist/index.d.ts
DELETED
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import { defineStore } from 'pinia';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
|
|
4
|
-
const AbortHandler = {
|
|
5
|
-
abortController: new AbortController()};
|
|
6
|
-
|
|
7
|
-
const baseURL = typeof import.meta !== 'undefined' ? (import.meta.env.VITE_BACKEND_URL ??""): undefined;
|
|
8
|
-
|
|
9
|
-
const customAxios = axios.create({
|
|
10
|
-
baseURL: baseURL,
|
|
11
|
-
signal: AbortHandler.abortController.signal, // Signal that is assiciated with any request to be made with this axios instance
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// Request Interceptor
|
|
15
|
-
const requestHandler = (request) => {
|
|
16
|
-
const tokenData = getBearerToken();
|
|
17
|
-
const token = tokenData?.token ?? null; // Always retrieve the latest token
|
|
18
|
-
const expiresIn = tokenData?.expiresIn ?? null;
|
|
19
|
-
|
|
20
|
-
if (expiresIn) {
|
|
21
|
-
const timestamp = tokenData?.timestamp ?? null;
|
|
22
|
-
const now = Date.now();
|
|
23
|
-
if (expiresIn && (now - timestamp) > (expiresIn * 1000)) {
|
|
24
|
-
console.warn("Token has expired.");
|
|
25
|
-
localStorage.removeItem("logginToken");
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (token) {
|
|
31
|
-
request.headers.Authorization = `Bearer ${token}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Handle FormData explicitly if needed
|
|
35
|
-
if (request.data instanceof FormData) {
|
|
36
|
-
// Keep FormData unchanged
|
|
37
|
-
const formData = request.data;
|
|
38
|
-
request.data = formData;
|
|
39
|
-
} else if (request.data) {
|
|
40
|
-
request.data = { ...(request.data ?? {}) };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return request;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// Response Interceptor
|
|
47
|
-
customAxios.interceptors.response.use(
|
|
48
|
-
(response) => response, // Resolve response as is
|
|
49
|
-
(error) => {
|
|
50
|
-
console.log("Error.....", error);
|
|
51
|
-
if (error.response?.status === 401) ;
|
|
52
|
-
return Promise.reject(error); // Reject the error for further handling
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
// Attach Request Interceptor
|
|
57
|
-
customAxios.interceptors.request.use(requestHandler, (error) =>
|
|
58
|
-
Promise.reject(error)
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const useFetch = async ({ url, method, data }) => {
|
|
62
|
-
let _data = data ?? {};
|
|
63
|
-
try {
|
|
64
|
-
let response=null;
|
|
65
|
-
const uniformMethod = method.toLowerCase();
|
|
66
|
-
if (uniformMethod === 'get') {
|
|
67
|
-
const params = generateParams(_data ?? {});
|
|
68
|
-
response = await customAxios.get(`${url}${params}`);
|
|
69
|
-
} else {
|
|
70
|
-
response = await customAxios.post(url, _data);
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
// console.log(response, "responseresponseresponseresponse");
|
|
74
|
-
return response?.data ?? { Empty: 'Empty' };
|
|
75
|
-
} catch (err) {
|
|
76
|
-
console.error(err);
|
|
77
|
-
return { success: false, error: err };
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const generateParams = (params={}) => {
|
|
82
|
-
let data = "?";
|
|
83
|
-
for (let key in params) {
|
|
84
|
-
if (Object.hasOwnProperty.call(params, key)) {
|
|
85
|
-
if (params[key]) {
|
|
86
|
-
if (Array.isArray(params[key])) {
|
|
87
|
-
const elements = params[key] ;
|
|
88
|
-
for (const ele of elements) {
|
|
89
|
-
data += `${key}[]=${ele}&`;
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
data += `${key}=${params[key]}&`;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return data.slice(0, -1);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
function setBearerToken(name = { token: null }) {
|
|
101
|
-
if (typeof name !== "object" || name === null || Array.isArray(name))
|
|
102
|
-
throw new TypeError("setBearerToken expects an object {token} with a 'token' property.");
|
|
103
|
-
|
|
104
|
-
const tokenObj = { token: null, ...name,timestamp: Date.now() };
|
|
105
|
-
localStorage.setItem("logginToken", JSON.stringify(tokenObj));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function getBearerToken() {
|
|
109
|
-
const token = localStorage.getItem('logginToken');
|
|
110
|
-
try {
|
|
111
|
-
return token ? JSON.parse(token) : null;
|
|
112
|
-
} catch (e) {
|
|
113
|
-
console.error('Invalid token format in localStorage:', e);
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function createPomStore(
|
|
119
|
-
piniaStore = "7286204094",
|
|
120
|
-
callBack=null
|
|
121
|
-
) {
|
|
122
|
-
const storeId = "POM" + piniaStore;
|
|
123
|
-
const piniaData = defineStore(storeId, {
|
|
124
|
-
state: () => {
|
|
125
|
-
const StateObjectsContainer = {
|
|
126
|
-
CheckQueriesInQue: {},
|
|
127
|
-
StateValue: {},
|
|
128
|
-
Loading: true,
|
|
129
|
-
isThereAnyDataChangeInAform: false,
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
return StateObjectsContainer;
|
|
133
|
-
// return {...this.state,...StateObjectsContainer}
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
getters: {
|
|
137
|
-
stateItems: (state) => (TagetState) => {
|
|
138
|
-
/**
|
|
139
|
-
make data basing on state TagetState this acts as a clusure in ()() read about it
|
|
140
|
-
store.stateItems(key1) usage to ge the ge
|
|
141
|
-
*
|
|
142
|
-
*/
|
|
143
|
-
return (state[TagetState] = state[TagetState]);
|
|
144
|
-
},
|
|
145
|
-
// store.getStateItem(key1) usage to ge the ge
|
|
146
|
-
|
|
147
|
-
// getStateItem: (state) => (stateKey=nu) => state[stateKey],
|
|
148
|
-
},
|
|
149
|
-
actions: {
|
|
150
|
-
validateObjectLength(object) {
|
|
151
|
-
if (Array.isArray(object)) {
|
|
152
|
-
return object.length;
|
|
153
|
-
} else if (typeof object == "object") {
|
|
154
|
-
const lng = Object.keys(object);
|
|
155
|
-
return lng.length;
|
|
156
|
-
}
|
|
157
|
-
return 0;
|
|
158
|
-
},
|
|
159
|
-
pageNumber(pageUrl) {
|
|
160
|
-
const inputString = pageUrl; //'?page=124234232&&';
|
|
161
|
-
const regex = /\?(page)+=\d+/;
|
|
162
|
-
const match = regex.exec(inputString);
|
|
163
|
-
|
|
164
|
-
if (match) {
|
|
165
|
-
// /according to the patern ' i expect 1 value /
|
|
166
|
-
const matchedPattern = match[0];
|
|
167
|
-
const dataBack = matchedPattern
|
|
168
|
-
.split("?page=")
|
|
169
|
-
.join()
|
|
170
|
-
.replace(/[^\d]/, "");
|
|
171
|
-
|
|
172
|
-
return dataBack;
|
|
173
|
-
} else return "1";
|
|
174
|
-
},
|
|
175
|
-
sleep(timer) {
|
|
176
|
-
return new Promise((r) => setTimeout(r, timer));
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
async CallApiData(
|
|
180
|
-
StateStore,
|
|
181
|
-
callApi,
|
|
182
|
-
dataParams,
|
|
183
|
-
pagnated ,
|
|
184
|
-
mStore={}
|
|
185
|
-
) {
|
|
186
|
-
if (!this.CheckQueriesInQue[callApi]) {
|
|
187
|
-
this.CheckQueriesInQue[callApi] = callApi;
|
|
188
|
-
let [res] = await Promise.all([
|
|
189
|
-
useFetch (dataParams),
|
|
190
|
-
]);
|
|
191
|
-
|
|
192
|
-
if (res) {
|
|
193
|
-
this[StateStore] = res;
|
|
194
|
-
if (mStore?.mUse) {
|
|
195
|
-
const checkType =typeof res === "object" ? JSON.stringify(res) : res;
|
|
196
|
-
sessionStorage.setItem(StateStore, JSON.stringify(checkType));
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
delete this.CheckQueriesInQue[callApi];
|
|
200
|
-
} else {
|
|
201
|
-
delete this.CheckQueriesInQue[callApi];
|
|
202
|
-
console.error(res);
|
|
203
|
-
}
|
|
204
|
-
this.Loading = false;
|
|
205
|
-
return res;
|
|
206
|
-
}
|
|
207
|
-
this.Loading = false;
|
|
208
|
-
return this[StateStore] ?? [];
|
|
209
|
-
},
|
|
210
|
-
async parseData(
|
|
211
|
-
dataResponseName = "xxx",
|
|
212
|
-
mStore = { mUse: false, reset: false }
|
|
213
|
-
) {
|
|
214
|
-
try {
|
|
215
|
-
if (mStore?.reset) {
|
|
216
|
-
sessionStorage.removeItem(dataResponseName);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (mStore?.mUse) {
|
|
220
|
-
const thisData = JSON.parse(
|
|
221
|
-
JSON.parse(sessionStorage.getItem(dataResponseName) || {})
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
return thisData;
|
|
225
|
-
}
|
|
226
|
-
} catch (error) {}
|
|
227
|
-
|
|
228
|
-
return this[dataResponseName];
|
|
229
|
-
},
|
|
230
|
-
async stateGenaratorApi(dd = { reload: true, StateStore: "", reqs: {}, time: 0, pagnated: false, mStore: { mUse: 0 },},fasterDataCollection=null) {
|
|
231
|
-
this.Loading = true;
|
|
232
|
-
const { reload, StateStore, reqs, time, pagnated, mStore } = dd;
|
|
233
|
-
const callApi = JSON.stringify(reqs);
|
|
234
|
-
const StateVariable = await this.parseData(StateStore, mStore);
|
|
235
|
-
this[StateStore] = StateVariable ?? [];
|
|
236
|
-
|
|
237
|
-
if (this.StateValue[StateStore]) {
|
|
238
|
-
/**
|
|
239
|
-
* dynamically lets create the state store
|
|
240
|
-
**/
|
|
241
|
-
this.StateValue[StateStore] = false;
|
|
242
|
-
this[StateStore] = false;
|
|
243
|
-
// this[StateStore] =null ;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (this.CheckQueriesInQue[callApi]) {
|
|
247
|
-
console.warn(`************************************* dont call this api again ${reqs["url"]} 🛩️ *************************************`,reqs);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
try {
|
|
251
|
-
const counters = this.validateObjectLength(StateVariable);
|
|
252
|
-
if (typeof fasterDataCollection == "function")
|
|
253
|
-
fasterDataCollection(StateVariable);
|
|
254
|
-
|
|
255
|
-
if (counters > 0) {
|
|
256
|
-
if (reload) {
|
|
257
|
-
const delay = await this.sleep(1000 * time);
|
|
258
|
-
return await this.CallApiData(
|
|
259
|
-
StateStore,
|
|
260
|
-
callApi,
|
|
261
|
-
reqs,
|
|
262
|
-
pagnated,
|
|
263
|
-
mStore
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
this.Loading = false;
|
|
268
|
-
return this[StateStore];
|
|
269
|
-
} else {
|
|
270
|
-
this.Loading = true;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return await this.CallApiData(
|
|
274
|
-
StateStore,
|
|
275
|
-
callApi,
|
|
276
|
-
reqs,
|
|
277
|
-
pagnated,
|
|
278
|
-
mStore
|
|
279
|
-
);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
// console.error(error);
|
|
282
|
-
if (this.CheckQueriesInQue[callApi])
|
|
283
|
-
delete this.CheckQueriesInQue[callApi];
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
Creator() {
|
|
287
|
-
/**
|
|
288
|
-
*
|
|
289
|
-
* this will retun a call back wth the full object
|
|
290
|
-
* **/
|
|
291
|
-
if (typeof callBack === "function") {
|
|
292
|
-
return callBack(this);
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
DriveManual() {
|
|
296
|
-
return function () {
|
|
297
|
-
return this;
|
|
298
|
-
};
|
|
299
|
-
},
|
|
300
|
-
pagenatedData() {},
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
return piniaData();
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// module.e = createPomStore
|
|
308
|
-
|
|
309
|
-
export { generateParams, getBearerToken, createPomStore as pomPinia, setBearerToken, useFetch };
|
package/dist/index.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
// src/StoreManager/pomStateManagement.js
|
|
2
|
-
import { defineStore } from "pinia";
|
|
3
|
-
|
|
4
|
-
// src/utils/custom-axios.js
|
|
5
|
-
import axios from "axios";
|
|
6
|
-
|
|
7
|
-
// src/utils/abortHandler.js
|
|
8
|
-
var AbortHandler = {
|
|
9
|
-
abortController: new AbortController(),
|
|
10
|
-
abortHttpRequests() {
|
|
11
|
-
this.abortController.abort();
|
|
12
|
-
this.abortController = new AbortController();
|
|
13
|
-
custom_axios_default.defaults.signal = this.abortController.signal;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
var abortHandler_default = AbortHandler;
|
|
17
|
-
|
|
18
|
-
// src/utils/custom-axios.js
|
|
19
|
-
var baseURL = typeof import.meta !== "undefined" ? import.meta.env.VITE_BACKEND_URL ?? "" : void 0;
|
|
20
|
-
var customAxios = axios.create({
|
|
21
|
-
baseURL,
|
|
22
|
-
signal: abortHandler_default.abortController.signal
|
|
23
|
-
// Signal that is assiciated with any request to be made with this axios instance
|
|
24
|
-
});
|
|
25
|
-
var requestHandler = (request) => {
|
|
26
|
-
const tokenData = getBearerToken();
|
|
27
|
-
const token = (tokenData == null ? void 0 : tokenData.token) ?? null;
|
|
28
|
-
const expiresIn = (tokenData == null ? void 0 : tokenData.expiresIn) ?? null;
|
|
29
|
-
if (expiresIn) {
|
|
30
|
-
const timestamp = (tokenData == null ? void 0 : tokenData.timestamp) ?? null;
|
|
31
|
-
const now = Date.now();
|
|
32
|
-
if (expiresIn && now - timestamp > expiresIn * 1e3) {
|
|
33
|
-
console.warn("Token has expired.");
|
|
34
|
-
localStorage.removeItem("logginToken");
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (token) {
|
|
39
|
-
request.headers.Authorization = `Bearer ${token}`;
|
|
40
|
-
}
|
|
41
|
-
if (request.data instanceof FormData) {
|
|
42
|
-
const formData = request.data;
|
|
43
|
-
request.data = formData;
|
|
44
|
-
} else if (request.data) {
|
|
45
|
-
request.data = { ...request.data ?? {} };
|
|
46
|
-
}
|
|
47
|
-
return request;
|
|
48
|
-
};
|
|
49
|
-
customAxios.interceptors.response.use(
|
|
50
|
-
(response) => response,
|
|
51
|
-
// Resolve response as is
|
|
52
|
-
(error) => {
|
|
53
|
-
var _a;
|
|
54
|
-
console.log("Error.....", error);
|
|
55
|
-
if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
|
|
56
|
-
}
|
|
57
|
-
return Promise.reject(error);
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
customAxios.interceptors.request.use(
|
|
61
|
-
requestHandler,
|
|
62
|
-
(error) => Promise.reject(error)
|
|
63
|
-
);
|
|
64
|
-
var custom_axios_default = customAxios;
|
|
65
|
-
|
|
66
|
-
// src/utils/useFetch.js
|
|
67
|
-
var useFetch = async ({ url, method, data }) => {
|
|
68
|
-
let _data = data ?? {};
|
|
69
|
-
try {
|
|
70
|
-
let response = null;
|
|
71
|
-
const uniformMethod = method.toLowerCase();
|
|
72
|
-
if (uniformMethod === "get") {
|
|
73
|
-
const params = generateParams(_data ?? {});
|
|
74
|
-
response = await custom_axios_default.get(`${url}${params}`);
|
|
75
|
-
} else {
|
|
76
|
-
response = await custom_axios_default.post(url, _data);
|
|
77
|
-
}
|
|
78
|
-
return (response == null ? void 0 : response.data) ?? { Empty: "Empty" };
|
|
79
|
-
} catch (err) {
|
|
80
|
-
console.error(err);
|
|
81
|
-
return { success: false, error: err };
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
var generateParams = (params = {}) => {
|
|
85
|
-
let data = "?";
|
|
86
|
-
for (let key in params) {
|
|
87
|
-
if (Object.hasOwnProperty.call(params, key)) {
|
|
88
|
-
if (params[key]) {
|
|
89
|
-
if (Array.isArray(params[key])) {
|
|
90
|
-
const elements = params[key];
|
|
91
|
-
for (const ele of elements) {
|
|
92
|
-
data += `${key}[]=${ele}&`;
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
data += `${key}=${params[key]}&`;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return data.slice(0, -1);
|
|
101
|
-
};
|
|
102
|
-
function setBearerToken(name = { token: null }) {
|
|
103
|
-
if (typeof name !== "object" || name === null || Array.isArray(name))
|
|
104
|
-
throw new TypeError("setBearerToken expects an object {token} with a 'token' property.");
|
|
105
|
-
const tokenObj = { token: null, ...name, timestamp: Date.now() };
|
|
106
|
-
localStorage.setItem("logginToken", JSON.stringify(tokenObj));
|
|
107
|
-
}
|
|
108
|
-
function getBearerToken() {
|
|
109
|
-
const token = localStorage.getItem("logginToken");
|
|
110
|
-
try {
|
|
111
|
-
return token ? JSON.parse(token) : null;
|
|
112
|
-
} catch (e) {
|
|
113
|
-
console.error("Invalid token format in localStorage:", e);
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// src/StoreManager/pomStateManagement.js
|
|
119
|
-
function createPomStore(piniaStore = "7286204094", callBack = null) {
|
|
120
|
-
const storeId = "POM" + piniaStore;
|
|
121
|
-
const piniaData = defineStore(storeId, {
|
|
122
|
-
state: () => {
|
|
123
|
-
const StateObjectsContainer = {
|
|
124
|
-
CheckQueriesInQue: {},
|
|
125
|
-
StateValue: {},
|
|
126
|
-
Loading: true,
|
|
127
|
-
isThereAnyDataChangeInAform: false
|
|
128
|
-
};
|
|
129
|
-
return StateObjectsContainer;
|
|
130
|
-
},
|
|
131
|
-
getters: {
|
|
132
|
-
stateItems: (state) => (TagetState) => {
|
|
133
|
-
return state[TagetState] = state[TagetState];
|
|
134
|
-
}
|
|
135
|
-
// store.getStateItem(key1) usage to ge the ge
|
|
136
|
-
// getStateItem: (state) => (stateKey=nu) => state[stateKey],
|
|
137
|
-
},
|
|
138
|
-
actions: {
|
|
139
|
-
validateObjectLength(object) {
|
|
140
|
-
if (Array.isArray(object)) {
|
|
141
|
-
return object.length;
|
|
142
|
-
} else if (typeof object == "object") {
|
|
143
|
-
const lng = Object.keys(object);
|
|
144
|
-
return lng.length;
|
|
145
|
-
}
|
|
146
|
-
return 0;
|
|
147
|
-
},
|
|
148
|
-
pageNumber(pageUrl) {
|
|
149
|
-
const inputString = pageUrl;
|
|
150
|
-
const regex = /\?(page)+=\d+/;
|
|
151
|
-
const match = regex.exec(inputString);
|
|
152
|
-
if (match) {
|
|
153
|
-
const matchedPattern = match[0];
|
|
154
|
-
const dataBack = matchedPattern.split("?page=").join().replace(/[^\d]/, "");
|
|
155
|
-
return dataBack;
|
|
156
|
-
} else return "1";
|
|
157
|
-
},
|
|
158
|
-
sleep(timer) {
|
|
159
|
-
return new Promise((r) => setTimeout(r, timer));
|
|
160
|
-
},
|
|
161
|
-
async CallApiData(StateStore, callApi, dataParams, pagnated, mStore = {}) {
|
|
162
|
-
if (!this.CheckQueriesInQue[callApi]) {
|
|
163
|
-
this.CheckQueriesInQue[callApi] = callApi;
|
|
164
|
-
let [res] = await Promise.all([
|
|
165
|
-
useFetch(dataParams)
|
|
166
|
-
]);
|
|
167
|
-
if (res) {
|
|
168
|
-
this[StateStore] = res;
|
|
169
|
-
if (mStore == null ? void 0 : mStore.mUse) {
|
|
170
|
-
const checkType = typeof res === "object" ? JSON.stringify(res) : res;
|
|
171
|
-
sessionStorage.setItem(StateStore, JSON.stringify(checkType));
|
|
172
|
-
}
|
|
173
|
-
delete this.CheckQueriesInQue[callApi];
|
|
174
|
-
} else {
|
|
175
|
-
delete this.CheckQueriesInQue[callApi];
|
|
176
|
-
console.error(res);
|
|
177
|
-
}
|
|
178
|
-
this.Loading = false;
|
|
179
|
-
return res;
|
|
180
|
-
}
|
|
181
|
-
this.Loading = false;
|
|
182
|
-
return this[StateStore] ?? [];
|
|
183
|
-
},
|
|
184
|
-
async parseData(dataResponseName = "xxx", mStore = { mUse: false, reset: false }) {
|
|
185
|
-
try {
|
|
186
|
-
if (mStore == null ? void 0 : mStore.reset) {
|
|
187
|
-
sessionStorage.removeItem(dataResponseName);
|
|
188
|
-
}
|
|
189
|
-
if (mStore == null ? void 0 : mStore.mUse) {
|
|
190
|
-
const thisData = JSON.parse(
|
|
191
|
-
JSON.parse(sessionStorage.getItem(dataResponseName) || {})
|
|
192
|
-
);
|
|
193
|
-
return thisData;
|
|
194
|
-
}
|
|
195
|
-
} catch (error) {
|
|
196
|
-
}
|
|
197
|
-
return this[dataResponseName];
|
|
198
|
-
},
|
|
199
|
-
async stateGenaratorApi(dd = { reload: true, StateStore: "", reqs: {}, time: 0, pagnated: false, mStore: { mUse: 0 } }, fasterDataCollection = null) {
|
|
200
|
-
this.Loading = true;
|
|
201
|
-
const { reload, StateStore, reqs, time, pagnated, mStore } = dd;
|
|
202
|
-
const callApi = JSON.stringify(reqs);
|
|
203
|
-
const StateVariable = await this.parseData(StateStore, mStore);
|
|
204
|
-
this[StateStore] = StateVariable ?? [];
|
|
205
|
-
if (this.StateValue[StateStore]) {
|
|
206
|
-
this.StateValue[StateStore] = false;
|
|
207
|
-
this[StateStore] = false;
|
|
208
|
-
}
|
|
209
|
-
if (this.CheckQueriesInQue[callApi]) {
|
|
210
|
-
console.warn(`************************************* dont call this api again ${reqs["url"]} \u{1F6E9}\uFE0F *************************************`, reqs);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
try {
|
|
214
|
-
const counters = this.validateObjectLength(StateVariable);
|
|
215
|
-
if (typeof fasterDataCollection == "function")
|
|
216
|
-
fasterDataCollection(StateVariable);
|
|
217
|
-
if (counters > 0) {
|
|
218
|
-
if (reload) {
|
|
219
|
-
const delay = await this.sleep(1e3 * time);
|
|
220
|
-
return await this.CallApiData(
|
|
221
|
-
StateStore,
|
|
222
|
-
callApi,
|
|
223
|
-
reqs,
|
|
224
|
-
pagnated,
|
|
225
|
-
mStore
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
this.Loading = false;
|
|
229
|
-
return this[StateStore];
|
|
230
|
-
} else {
|
|
231
|
-
this.Loading = true;
|
|
232
|
-
}
|
|
233
|
-
return await this.CallApiData(
|
|
234
|
-
StateStore,
|
|
235
|
-
callApi,
|
|
236
|
-
reqs,
|
|
237
|
-
pagnated,
|
|
238
|
-
mStore
|
|
239
|
-
);
|
|
240
|
-
} catch (error) {
|
|
241
|
-
if (this.CheckQueriesInQue[callApi])
|
|
242
|
-
delete this.CheckQueriesInQue[callApi];
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
Creator() {
|
|
246
|
-
if (typeof callBack === "function") {
|
|
247
|
-
return callBack(this);
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
DriveManual() {
|
|
251
|
-
return function() {
|
|
252
|
-
return this;
|
|
253
|
-
};
|
|
254
|
-
},
|
|
255
|
-
pagenatedData() {
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
return piniaData();
|
|
260
|
-
}
|
|
261
|
-
export {
|
|
262
|
-
generateParams,
|
|
263
|
-
getBearerToken,
|
|
264
|
-
createPomStore as pomPinia,
|
|
265
|
-
setBearerToken,
|
|
266
|
-
useFetch
|
|
267
|
-
};
|