b2b-platform-utils 1.1.21 → 1.1.22
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 +16 -6
- package/package.json +1 -1
package/errorsMap.js
CHANGED
|
@@ -99,15 +99,23 @@ const api = {
|
|
|
99
99
|
list: () => [...STATIC_ERRORS]
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
// --- Dynamic shortcuts: errorsMap.<errorKey>() returns
|
|
102
|
+
// --- Dynamic shortcuts: errorsMap.<errorKey>() returns STRING (JSON) ---
|
|
103
103
|
module.exports = new Proxy(api, {
|
|
104
104
|
get(target, prop, receiver) {
|
|
105
105
|
// If method exists (get, getString, etc.) → return it
|
|
106
|
-
if (prop in target)
|
|
106
|
+
if (prop in target) {
|
|
107
|
+
return Reflect.get(target, prop, receiver);
|
|
108
|
+
}
|
|
107
109
|
|
|
108
|
-
// If property is a known errorKey → return a function () =>
|
|
110
|
+
// If property is a known errorKey → return a function () => getString(errorKey)
|
|
109
111
|
if (typeof prop === 'string' && STATIC_BY_KEY[prop]) {
|
|
110
|
-
|
|
112
|
+
// Legacy behavior: errorsMap.userNotFound() -> JSON string
|
|
113
|
+
return function () {
|
|
114
|
+
const obj = target.get(prop);
|
|
115
|
+
return obj ? JSON.stringify(obj) : undefined;
|
|
116
|
+
};
|
|
117
|
+
// Или короче:
|
|
118
|
+
// return () => target.getString(prop);
|
|
111
119
|
}
|
|
112
120
|
|
|
113
121
|
// Otherwise undefined
|
|
@@ -115,7 +123,9 @@ module.exports = new Proxy(api, {
|
|
|
115
123
|
},
|
|
116
124
|
|
|
117
125
|
has(target, prop) {
|
|
118
|
-
return
|
|
126
|
+
return (
|
|
127
|
+
prop in target ||
|
|
128
|
+
(typeof prop === 'string' && !!STATIC_BY_KEY[prop])
|
|
129
|
+
);
|
|
119
130
|
}
|
|
120
131
|
});
|
|
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.22",
|
|
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",
|