@modernman00/shared-js-lib 1.2.81 โ 1.2.82
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/AcctMgt/AdminAuthForm.js +26 -0
- package/AcctMgt/createFormHandler.js +25 -13
- package/AcctMgt/processAll.js +23 -1
- package/AcctMgt/recaptchaToken.js +25 -10
- package/AcctMgt/update.js +66 -33
- package/Alert.js +158 -0
- package/AuthInterceptor.js +56 -0
- package/ButtonLoader.js +133 -0
- package/Clipboard.js +45 -0
- package/Cookie.js +1 -19
- package/FormLock.js +58 -0
- package/Http.js +158 -51
- package/InlineValidation.js +78 -0
- package/NetworkGuard.js +54 -0
- package/README.md +74 -0
- package/ShowResponse.js +120 -0
- package/axiosWrapper.js +3 -0
- package/config/version.php +1 -1
- package/index.js +8 -0
- package/package.json +10 -2
- package/release-history.md +20 -0
package/ShowResponse.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { id, qSel } from './UtilityHtml.js';
|
|
2
|
+
import { swalToast, swalSuccess, swalError } from './Alert.js';
|
|
2
3
|
|
|
3
4
|
export const showError = (e) =>
|
|
4
5
|
console.error(
|
|
@@ -9,6 +10,23 @@ export const msgException = (errorMessage) => {
|
|
|
9
10
|
throw new Error(errorMessage);
|
|
10
11
|
};
|
|
11
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Drop-in SweetAlert-backed notification.
|
|
15
|
+
* If status is true or 'green', shows success toast; otherwise shows error toast/modal.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} message - Message to display
|
|
18
|
+
* @param {boolean|string} [status=true] - true/'green' for success, false/'red' for error
|
|
19
|
+
* @param {boolean} [asToast=true] - true to show as sleek toast, false for modal
|
|
20
|
+
* @returns {Promise<any>}
|
|
21
|
+
*/
|
|
22
|
+
export const swalNotification = async (message, status = true, asToast = true) => {
|
|
23
|
+
const isSuccess = status === true || status === 'green' || status === 'is-success' || status === 'w3-green';
|
|
24
|
+
if (isSuccess) {
|
|
25
|
+
return await swalSuccess(message, asToast);
|
|
26
|
+
}
|
|
27
|
+
return await swalError(message, !asToast);
|
|
28
|
+
};
|
|
29
|
+
|
|
12
30
|
/**
|
|
13
31
|
*
|
|
14
32
|
* @param {*} elementId - element id
|
|
@@ -55,3 +73,105 @@ export const showResponse = (theId, message, status) => {
|
|
|
55
73
|
responseEl.innerHTML = '';
|
|
56
74
|
}, 5000); // Disappear after 5 seconds
|
|
57
75
|
};
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Defensive Error Unwrapping Utility
|
|
80
|
+
*
|
|
81
|
+
* Extracts a human-readable string message from any error shape
|
|
82
|
+
* (string, Error object, Axios/Fetch HTTP response, validation map).
|
|
83
|
+
* Mathematically guarantees that [object Object] is NEVER returned.
|
|
84
|
+
*
|
|
85
|
+
* @param {any} err - The error object, string, or HTTP response error
|
|
86
|
+
* @param {string} defaultMessage - Fallback message if extraction yields empty
|
|
87
|
+
* @returns {string} Clean human-readable error text
|
|
88
|
+
*/
|
|
89
|
+
export const extractErrorMessage = (err, defaultMessage = "An unexpected error occurred.") => {
|
|
90
|
+
if (err === null || err === undefined) {
|
|
91
|
+
return defaultMessage;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (typeof err === "string") {
|
|
95
|
+
const trimmed = err.trim();
|
|
96
|
+
return trimmed && trimmed !== "[object Object]" ? trimmed : defaultMessage;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 1. Check Axios / HTTP response envelope (err.response.data)
|
|
100
|
+
if (err && typeof err === "object") {
|
|
101
|
+
const resData = err.response ? err.response.data : (err.data || null);
|
|
102
|
+
|
|
103
|
+
if (resData) {
|
|
104
|
+
if (typeof resData === "string") {
|
|
105
|
+
const trimmed = resData.trim();
|
|
106
|
+
if (trimmed && trimmed !== "[object Object]") return trimmed;
|
|
107
|
+
} else if (typeof resData === "object") {
|
|
108
|
+
// Check standard envelope fields: error, message, msg
|
|
109
|
+
if (typeof resData.error === "string" && resData.error.trim() && resData.error.trim() !== "[object Object]") {
|
|
110
|
+
return resData.error.trim();
|
|
111
|
+
}
|
|
112
|
+
if (typeof resData.message === "string" && resData.message.trim() && resData.message.trim() !== "[object Object]") {
|
|
113
|
+
return resData.message.trim();
|
|
114
|
+
}
|
|
115
|
+
if (typeof resData.msg === "string" && resData.msg.trim() && resData.msg.trim() !== "[object Object]") {
|
|
116
|
+
return resData.msg.trim();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Check validation errors map (e.g. { errors: { email: ["Invalid"], password: ["Too short"] } })
|
|
120
|
+
const errorsSource = resData.errors || resData.error;
|
|
121
|
+
if (errorsSource && typeof errorsSource === "object") {
|
|
122
|
+
if (Array.isArray(errorsSource)) {
|
|
123
|
+
const msgs = errorsSource.map(m => typeof m === "string" ? m : (m?.message || JSON.stringify(m))).filter(Boolean);
|
|
124
|
+
if (msgs.length > 0) return msgs.join(", ");
|
|
125
|
+
} else {
|
|
126
|
+
const values = Object.values(errorsSource).flat().map(v => typeof v === "string" ? v : (v?.message || JSON.stringify(v))).filter(Boolean);
|
|
127
|
+
if (values.length > 0) return values.join(", ");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 2. Check standard Error instance message
|
|
134
|
+
if (typeof err.message === "string" && err.message.trim() && err.message.trim() !== "[object Object]") {
|
|
135
|
+
return err.message.trim();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 3. Check direct error/msg properties on object
|
|
139
|
+
if (typeof err.error === "string" && err.error.trim() && err.error.trim() !== "[object Object]") {
|
|
140
|
+
return err.error.trim();
|
|
141
|
+
}
|
|
142
|
+
if (typeof err.msg === "string" && err.msg.trim() && err.msg.trim() !== "[object Object]") {
|
|
143
|
+
return err.msg.trim();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// 4. Check errors map directly on object
|
|
147
|
+
if (err.errors && typeof err.errors === "object") {
|
|
148
|
+
if (Array.isArray(err.errors)) {
|
|
149
|
+
const msgs = err.errors.map(m => typeof m === "string" ? m : (m?.message || JSON.stringify(m))).filter(Boolean);
|
|
150
|
+
if (msgs.length > 0) return msgs.join(", ");
|
|
151
|
+
} else {
|
|
152
|
+
const values = Object.values(err.errors).flat().map(v => typeof v === "string" ? v : (v?.message || JSON.stringify(v))).filter(Boolean);
|
|
153
|
+
if (values.length > 0) return values.join(", ");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 5. Check custom toString if not default Object toString
|
|
158
|
+
try {
|
|
159
|
+
if (typeof err.toString === "function") {
|
|
160
|
+
const str = err.toString();
|
|
161
|
+
if (str && str !== "[object Object]" && typeof str === "string") {
|
|
162
|
+
return str;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} catch (_) {}
|
|
166
|
+
|
|
167
|
+
// 6. Safe JSON stringify fallback
|
|
168
|
+
try {
|
|
169
|
+
const jsonStr = JSON.stringify(err);
|
|
170
|
+
if (jsonStr && jsonStr !== "{}" && jsonStr.length < 200) {
|
|
171
|
+
return jsonStr;
|
|
172
|
+
}
|
|
173
|
+
} catch (_) {}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return defaultMessage;
|
|
177
|
+
};
|
package/axiosWrapper.js
CHANGED
|
@@ -4,6 +4,9 @@ import axiosRetry from 'axios-retry';
|
|
|
4
4
|
|
|
5
5
|
axiosRetry(axios, { retries: 3 });
|
|
6
6
|
|
|
7
|
+
// Ensure Axios always sends cookies (like the HttpOnly auth token) with every request
|
|
8
|
+
axios.defaults.withCredentials = true;
|
|
9
|
+
|
|
7
10
|
axios.interceptors.request.use(config => {
|
|
8
11
|
config.headers['X-Requested-With'] = 'XMLHttpRequest';
|
|
9
12
|
|
package/config/version.php
CHANGED
package/index.js
CHANGED
|
@@ -2,6 +2,13 @@ export * from './Http.js';
|
|
|
2
2
|
export * from './UtilityHtml.js';
|
|
3
3
|
export * from './Utility.js';
|
|
4
4
|
export * from './Loader.js';
|
|
5
|
+
export * from './Alert.js';
|
|
6
|
+
export * from './ButtonLoader.js';
|
|
7
|
+
export * from './FormLock.js';
|
|
8
|
+
export * from './NetworkGuard.js';
|
|
9
|
+
export * from './InlineValidation.js';
|
|
10
|
+
export * from './Clipboard.js';
|
|
11
|
+
export * from './AuthInterceptor.js';
|
|
5
12
|
export * from './Cookie.js';
|
|
6
13
|
export * from './FormHelper.js'
|
|
7
14
|
export * from './ShowResponse.js';
|
|
@@ -15,4 +22,5 @@ export * from './AcctMgt/processAll.js';
|
|
|
15
22
|
export * from './AcctMgt/update.js';
|
|
16
23
|
export * from './AcctMgt/registerHandler.js';
|
|
17
24
|
export * from './AcctMgt/recaptchaToken.js';
|
|
25
|
+
export * from './AcctMgt/AdminAuthForm.js';
|
|
18
26
|
export * from './general.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modernman00/shared-js-lib",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.82",
|
|
4
4
|
"description": "Reusable JS utilities for numerous js problems",
|
|
5
5
|
"homepage": "https://github.com/modernman00/shared-js-lib#readme",
|
|
6
6
|
"keywords": [
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"axios": "^1.13.2",
|
|
27
27
|
"axios-retry": "^4.5.0",
|
|
28
|
-
"settings": "^0.1.1"
|
|
28
|
+
"settings": "^0.1.1",
|
|
29
|
+
"sweetalert2": "^11.26.25"
|
|
29
30
|
},
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public"
|
|
@@ -40,6 +41,13 @@
|
|
|
40
41
|
"FormHelper.js",
|
|
41
42
|
"Http.js",
|
|
42
43
|
"Loader.js",
|
|
44
|
+
"Alert.js",
|
|
45
|
+
"ButtonLoader.js",
|
|
46
|
+
"FormLock.js",
|
|
47
|
+
"NetworkGuard.js",
|
|
48
|
+
"InlineValidation.js",
|
|
49
|
+
"Clipboard.js",
|
|
50
|
+
"AuthInterceptor.js",
|
|
43
51
|
"ShowResponse.js",
|
|
44
52
|
"Utility.js",
|
|
45
53
|
"UtilityHtml.js",
|
package/release-history.md
CHANGED
|
@@ -101,3 +101,23 @@
|
|
|
101
101
|
|
|
102
102
|
- ๐ Bump version to v1.2.74 _(by modernman00)_
|
|
103
103
|
- ๐งน Auto-commit before release _(by modernman00)_
|
|
104
|
+
|
|
105
|
+
## v1.2.76 โ 2026-07-17 17:47
|
|
106
|
+
### Changelog for v1.2.76
|
|
107
|
+
|
|
108
|
+
- ๐ Bump version to v1.2.76 _(by modernman00)_
|
|
109
|
+
- ๐งน Auto-commit before release _(by modernman00)_
|
|
110
|
+
- ๐งน Auto-commit before release _(by modernman00)_
|
|
111
|
+
- ๐งน Auto-commit before release _(by modernman00)_
|
|
112
|
+
- ๐งน Auto-commit before release _(by modernman00)_
|
|
113
|
+
- ๐งน Auto-commit before release _(by modernman00)_
|
|
114
|
+
- refactor: improve robustness of UI utilities and add comprehensive unit test coverage _(by modernman00)_
|
|
115
|
+
- ๐งน Auto-commit before release _(by modernman00)_
|
|
116
|
+
|
|
117
|
+
## v1.2.77 โ 2026-07-17 22:53
|
|
118
|
+
### Changelog for v1.2.77
|
|
119
|
+
|
|
120
|
+
- ๐ Bump version to v1.2.77 _(by modernman00)_
|
|
121
|
+
- ๐งน Auto-commit before release _(by modernman00)_
|
|
122
|
+
- ๐ feat: Enterprise-wide WebAuthn Biometric Login Rollout (FaceID / TouchID) across all 6 applications.
|
|
123
|
+
- ๐ sec: Enforced strict FIDO2 challenge invalidation, origin verification, and defensive degradation per TAT governance.
|