b2b-platform-utils 1.1.21 → 1.1.23
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/errorsMap.js +17 -6
- package/package.json +1 -1
package/errorsMap.js
CHANGED
|
@@ -61,6 +61,7 @@ const STATIC_ERRORS = [
|
|
|
61
61
|
{ errorCode: 1048, errorKey: 'footerMainTextNotFound', httpCode: 404, description: 'Footer Main Text block were not found.' },
|
|
62
62
|
{ errorCode: 1049, errorKey: 'footerApplicationsNotFound',httpCode: 404, description: 'Footer Applications block were not found.' },
|
|
63
63
|
{ errorCode: 1050, errorKey: 'footerBlockAlreadyExists', httpCode: 422, description: 'Footer block item already exists.' },
|
|
64
|
+
{ errorCode: 1051, errorKey: 'invalidTwoFaCode', httpCode: 422, description: 'Two Factor Auth code is invalid or expired.' },
|
|
64
65
|
];
|
|
65
66
|
|
|
66
67
|
const STATIC_BY_KEY = Object.fromEntries(STATIC_ERRORS.map(e => [e.errorKey, e]));
|
|
@@ -99,15 +100,23 @@ const api = {
|
|
|
99
100
|
list: () => [...STATIC_ERRORS]
|
|
100
101
|
};
|
|
101
102
|
|
|
102
|
-
// --- Dynamic shortcuts: errorsMap.<errorKey>() returns
|
|
103
|
+
// --- Dynamic shortcuts: errorsMap.<errorKey>() returns STRING (JSON) ---
|
|
103
104
|
module.exports = new Proxy(api, {
|
|
104
105
|
get(target, prop, receiver) {
|
|
105
106
|
// If method exists (get, getString, etc.) → return it
|
|
106
|
-
if (prop in target)
|
|
107
|
+
if (prop in target) {
|
|
108
|
+
return Reflect.get(target, prop, receiver);
|
|
109
|
+
}
|
|
107
110
|
|
|
108
|
-
// If property is a known errorKey → return a function () =>
|
|
111
|
+
// If property is a known errorKey → return a function () => getString(errorKey)
|
|
109
112
|
if (typeof prop === 'string' && STATIC_BY_KEY[prop]) {
|
|
110
|
-
|
|
113
|
+
// Legacy behavior: errorsMap.userNotFound() -> JSON string
|
|
114
|
+
return function () {
|
|
115
|
+
const obj = target.get(prop);
|
|
116
|
+
return obj ? JSON.stringify(obj) : undefined;
|
|
117
|
+
};
|
|
118
|
+
// Или короче:
|
|
119
|
+
// return () => target.getString(prop);
|
|
111
120
|
}
|
|
112
121
|
|
|
113
122
|
// Otherwise undefined
|
|
@@ -115,7 +124,9 @@ module.exports = new Proxy(api, {
|
|
|
115
124
|
},
|
|
116
125
|
|
|
117
126
|
has(target, prop) {
|
|
118
|
-
return
|
|
127
|
+
return (
|
|
128
|
+
prop in target ||
|
|
129
|
+
(typeof prop === 'string' && !!STATIC_BY_KEY[prop])
|
|
130
|
+
);
|
|
119
131
|
}
|
|
120
132
|
});
|
|
121
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "b2b-platform-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.23",
|
|
4
4
|
"description": "Shared utilities for Node.js microservices: errors map, local cache, logger, numbers, dates, filesystem, media optimization, paginator, slugger, crypto wrapper, sanitize HTML, sorting.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "KingSizer",
|