@modernman00/shared-js-lib 1.2.41 → 1.2.42

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.
Files changed (32) hide show
  1. package/Http.js +66 -70
  2. package/config/version.php +1 -1
  3. package/package.json +1 -1
  4. package/coverage/clover.xml +0 -578
  5. package/coverage/coverage-final.json +0 -16
  6. package/coverage/lcov-report/base.css +0 -224
  7. package/coverage/lcov-report/block-navigation.js +0 -87
  8. package/coverage/lcov-report/favicon.png +0 -0
  9. package/coverage/lcov-report/index.html +0 -131
  10. package/coverage/lcov-report/prettify.css +0 -1
  11. package/coverage/lcov-report/prettify.js +0 -2
  12. package/coverage/lcov-report/shared-js-lib/AcctMgt/changePassword.js.html +0 -352
  13. package/coverage/lcov-report/shared-js-lib/AcctMgt/code.js.html +0 -235
  14. package/coverage/lcov-report/shared-js-lib/AcctMgt/forgot.js.html +0 -256
  15. package/coverage/lcov-report/shared-js-lib/AcctMgt/index.html +0 -176
  16. package/coverage/lcov-report/shared-js-lib/AcctMgt/login.js.html +0 -304
  17. package/coverage/lcov-report/shared-js-lib/AcctMgt/loginUtility.js.html +0 -115
  18. package/coverage/lcov-report/shared-js-lib/AcctMgt/processAll.js.html +0 -280
  19. package/coverage/lcov-report/shared-js-lib/Cookie.js.html +0 -250
  20. package/coverage/lcov-report/shared-js-lib/FormHelper.js.html +0 -1057
  21. package/coverage/lcov-report/shared-js-lib/Http.js.html +0 -721
  22. package/coverage/lcov-report/shared-js-lib/Loader.js.html +0 -196
  23. package/coverage/lcov-report/shared-js-lib/ShowResponse.js.html +0 -238
  24. package/coverage/lcov-report/shared-js-lib/Utility.js.html +0 -538
  25. package/coverage/lcov-report/shared-js-lib/UtilityHtml.js.html +0 -685
  26. package/coverage/lcov-report/shared-js-lib/axiosWrapper.js.html +0 -145
  27. package/coverage/lcov-report/shared-js-lib/general.js.html +0 -301
  28. package/coverage/lcov-report/shared-js-lib/index.html +0 -251
  29. package/coverage/lcov-report/shared-js-lib/theAutoComplete.js.html +0 -364
  30. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  31. package/coverage/lcov-report/sorter.js +0 -210
  32. package/coverage/lcov.info +0 -1207
package/Http.js CHANGED
@@ -34,7 +34,7 @@ export const postFormData = async (url, formId, redirect = null, css = null) =>
34
34
  // }
35
35
 
36
36
  // extract the form entries
37
- // extract the form entriesËËË
37
+ // extract the form entriesËËË
38
38
  const form = id(formId)
39
39
 
40
40
  if (!form) {
@@ -58,13 +58,13 @@ export const postFormData = async (url, formId, redirect = null, css = null) =>
58
58
 
59
59
  // check if response.data.message is an array
60
60
  const { message } = response.data || {};
61
- if( !message) {
61
+ if (!message) {
62
62
  throw new Error('Response data does not contain a message');
63
63
  }
64
64
  processFormDataAction(successClass, message, notificationId);
65
65
 
66
66
  if (redirect) {
67
- redirectAfterDelay(redirect, 2000);
67
+ redirectAfterDelay(redirect, 2000);
68
68
  }
69
69
 
70
70
  } catch (error) {
@@ -116,97 +116,93 @@ const getNotificationClassByCSS = (css, status) => {
116
116
 
117
117
 
118
118
  /**
119
- *
120
- * @param { the url you want to get} URL
121
- * @returns
122
- // now we can use that data from the outside!
123
- axiosTest()
124
- .then(data => {
125
- response.json({ message: 'Request received!', data })
126
- })
127
- .catch(err => console.log(err))
119
+ * Fetches data from a given URL using Axios, with optional Bearer token authentication.
120
+ * Resolves to the response data from the server.
121
+ * Rejects with an error object if something goes wrong.
122
+ *
123
+ * @param {string} URL - The URL to fetch data from.
124
+ * @param {string|null} token - Optional Bearer token for authentication.
125
+ * @returns {Promise<object>} - Resolves to the response data from the server or an error object if something goes wrong.
126
+ * // Example usage of getApiData function
127
+
128
+ // With auth token
129
+ // const data = await getApiData('https://api.example.com/users', myAuthToken);
130
+ // if (data.status && data.status !== 200) {
131
+ // console.error("API error:", data);
132
+ // } else {
133
+ // console.log("User data:", data);
134
+ // }
135
+
136
+ // Without auth token
137
+ // const publicData = await getApiData('https://api.example.com/public');
138
+ // console.log(publicData);
139
+
128
140
  */
129
141
 
130
142
  export const getApiData = async (URL, token = null) => {
131
143
  try {
132
-
133
144
  const config = {
134
145
  headers: {
135
- 'X-Requested-With': 'XMLHttpRequest',
136
- 'Content-Type': 'application/json',
137
- 'Accept': 'application/json',
138
- 'Authorization': 'Bearer ' + token
146
+ "X-Requested-With": "XMLHttpRequest",
147
+ "Content-Type": "application/json",
148
+ Accept: "application/json",
149
+ ...(token && { Authorization: `Bearer ${token}` }), // only add if token exists
139
150
  },
140
151
  };
141
152
 
142
- const fetch = await axios.get(URL, config);
143
- return fetch.data;
144
-
145
-
153
+ const response = await axios.get(URL, config);
154
+ return response.data;
146
155
  } catch (error) {
147
-
148
- return error;
149
-
156
+ // return something cleaner
157
+ if (error.response) {
158
+ // server responded with error
159
+ return { status: error.response.status, data: error.response.data };
160
+ } else {
161
+ // network or other issue
162
+ return { status: "network_error", message: error.message };
163
+ }
150
164
  }
165
+ };
151
166
 
152
167
 
153
- };
154
168
 
169
+
170
+ /**
171
+ * Fetches data from two API endpoints in parallel.
172
+ *
173
+ * @param {string} url1 - The first API endpoint.
174
+ * @param {string} url2 - The second API endpoint.
175
+ * @param {string|null} token - Optional Bearer token for authentication.
176
+ *
177
+ * @returns {Promise<object[]>} - Resolves to an array of response data [res1.data, res2.data]
178
+ * or an error object if something goes wrong.
179
+ *
180
+ * Usage:
181
+ * const [users, posts] = await getMultipleApiData('/api/users', '/api/posts', myToken);
182
+ */
155
183
  export const getMultipleApiData = async (url1, url2, token = null) => {
156
184
  try {
157
-
158
185
  const config = {
159
186
  headers: {
160
- 'X-Requested-With': 'XMLHttpRequest',
161
- 'Content-Type': 'application/json',
162
- 'Accept': 'application/json',
163
- 'Authorization': 'Bearer ' + token
187
+ "X-Requested-With": "XMLHttpRequest",
188
+ "Content-Type": "application/json",
189
+ Accept: "application/json",
190
+ ...(token && { Authorization: `Bearer ${token}` }), // add only if token exists
164
191
  },
165
192
  };
166
193
 
167
- const fetch = await axios.all([
194
+ // run requests in parallel
195
+ const [res1, res2] = await axios.all([
168
196
  axios.get(url1, config),
169
- axios.get(url2, config)
197
+ axios.get(url2, config),
170
198
  ]);
171
- return fetch;
172
199
 
200
+ return [res1.data, res2.data]; // return just the data
173
201
  } catch (error) {
174
-
175
- return error;
176
-
177
- }
178
-
179
-
180
- };
181
-
182
-
183
- // build a function to post multiple api form data
184
-
185
- export const postMultipleApiData = async (url1, url2, formData, token = null) => {
186
- try {
187
-
188
- const config = {
189
- headers: {
190
- 'X-Requested-With': 'XMLHttpRequest',
191
- 'Content-Type': 'application/json',
192
- 'Accept': 'application/json',
193
- 'Authorization': 'Bearer ' + token
194
- },
195
- };
196
- const fetch = await axios.all([
197
- axios.post(url1, formData, config),
198
- axios.post(url2, formData, config)
199
- ]);
200
-
201
- return fetch;
202
-
203
- } catch (error) {
204
- return error;
202
+ if (error.response) {
203
+ return { status: error.response.status, data: error.response.data };
204
+ } else {
205
+ return { status: "network_error", message: error.message };
206
+ }
205
207
  }
206
208
  };
207
- /**
208
- *
209
- * @param { name} cname
210
- * @param {* value} cvalue
211
- * @param {* no of days 365} exdays
212
- */
@@ -1,3 +1,3 @@
1
1
  <?php
2
- define('APP_VERSION', 'v1.2.42');
2
+ define('APP_VERSION', 'v1.2.43');
3
3
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernman00/shared-js-lib",
3
- "version": "1.2.41",
3
+ "version": "1.2.42",
4
4
  "description": "Reusable JS utilities for numerous js problems",
5
5
  "homepage": "https://github.com/modernman00/shared-js-lib#readme",
6
6
  "keywords": [