b2b-platform-utils 1.1.20 → 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/logger.js +1 -2
- 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/logger.js
CHANGED
|
@@ -115,10 +115,9 @@ function debug(...args) {
|
|
|
115
115
|
|
|
116
116
|
// Normalize payload
|
|
117
117
|
const payload = {
|
|
118
|
-
level: 'debug',
|
|
119
118
|
message: message || 'debug log',
|
|
120
119
|
data: data || null,
|
|
121
|
-
timestamp: Date.
|
|
120
|
+
timestamp: new Date().toISOString()
|
|
122
121
|
};
|
|
123
122
|
|
|
124
123
|
if (isProd) {
|
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",
|