b2b-platform-utils 1.1.18 → 1.1.20
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 +2 -1
- package/logger.js +28 -5
- package/package.json +1 -1
package/errorsMap.js
CHANGED
|
@@ -59,7 +59,8 @@ const STATIC_ERRORS = [
|
|
|
59
59
|
{ errorCode: 1046, errorKey: 'footerBrandCoreNotFound', httpCode: 404, description: 'Footer Brand Core block were not found.' },
|
|
60
60
|
{ errorCode: 1047, errorKey: 'footerPaymentsNotFound', httpCode: 404, description: 'Footer Payments block were not found.' },
|
|
61
61
|
{ errorCode: 1048, errorKey: 'footerMainTextNotFound', httpCode: 404, description: 'Footer Main Text block were not found.' },
|
|
62
|
-
{ errorCode: 1049, errorKey: '
|
|
62
|
+
{ errorCode: 1049, errorKey: 'footerApplicationsNotFound',httpCode: 404, description: 'Footer Applications block were not found.' },
|
|
63
|
+
{ errorCode: 1050, errorKey: 'footerBlockAlreadyExists', httpCode: 422, description: 'Footer block item already exists.' },
|
|
63
64
|
];
|
|
64
65
|
|
|
65
66
|
const STATIC_BY_KEY = Object.fromEntries(STATIC_ERRORS.map(e => [e.errorKey, e]));
|
package/logger.js
CHANGED
|
@@ -94,16 +94,39 @@ function safeStringify(value) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
97
|
+
* Flexible debug logger supporting (msg), (obj), (msg, obj), (obj, msg).
|
|
98
|
+
*
|
|
99
|
+
* @param {...any} args - Message and/or data.
|
|
99
100
|
*/
|
|
100
|
-
function debug(
|
|
101
|
+
function debug(...args) {
|
|
101
102
|
const { isProd } = resolveContext();
|
|
102
|
-
|
|
103
|
+
|
|
104
|
+
let message = null;
|
|
105
|
+
let data = null;
|
|
106
|
+
|
|
107
|
+
// Extract pieces from args
|
|
108
|
+
for (const arg of args) {
|
|
109
|
+
if (typeof arg === 'string' && !message) {
|
|
110
|
+
message = arg;
|
|
111
|
+
} else if (typeof arg === 'object' && arg !== null && !data) {
|
|
112
|
+
data = arg;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Normalize payload
|
|
117
|
+
const payload = {
|
|
118
|
+
level: 'debug',
|
|
119
|
+
message: message || 'debug log',
|
|
120
|
+
data: data || null,
|
|
121
|
+
timestamp: Date.now()
|
|
122
|
+
};
|
|
103
123
|
|
|
104
124
|
if (isProd) {
|
|
105
|
-
|
|
125
|
+
// Structured JSON for production
|
|
126
|
+
asyncWrite('stdout', serializeJSON('debug', payload.message, { data: payload.data }));
|
|
106
127
|
} else {
|
|
128
|
+
// Pretty colored dev-mode output
|
|
129
|
+
const text = safeStringify(payload);
|
|
107
130
|
asyncWrite('stdout', colorize('\x1b[35m', '🐛', text, 'DEBUG'));
|
|
108
131
|
}
|
|
109
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "b2b-platform-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.20",
|
|
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",
|