b2b-platform-utils 1.1.10 → 1.1.11

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 CHANGED
@@ -50,7 +50,8 @@ const STATIC_ERRORS = [
50
50
  { errorCode: 1037, errorKey: 'bonusConfirmationRequired', httpCode: 404, description: 'For bonus activation confirmation of personal user data requited.' },
51
51
  { errorCode: 1038, errorKey: 'promoNotFound', httpCode: 404, description: 'Promo was not found.' },
52
52
  { errorCode: 1039, errorKey: 'badSignature', httpCode: 401, description: 'Untrusted request, bad signature.' },
53
- { errorCode: 1040, errorKey: 'mailTemplateNotFound', httpCode: 404, description: 'Email template was not found.' }
53
+ { errorCode: 1040, errorKey: 'mailTemplateNotFound', httpCode: 404, description: 'Email template was not found.' },
54
+ { errorCode: 1040, errorKey: 'domainNotFound', httpCode: 404, description: 'Domain was not found.' }
54
55
  ];
55
56
 
56
57
  const STATIC_BY_KEY = Object.fromEntries(STATIC_ERRORS.map(e => [e.errorKey, e]));
package/logger.js CHANGED
@@ -74,6 +74,24 @@ function serializeJSON(level, message, extra = {}) {
74
74
  function colorize(colorCode, icon, message, label) {
75
75
  return `${colorCode}${icon} ${message} [${label}] \x1b[0m`;
76
76
  }
77
+ /**
78
+ * Safe stringify with support for Set, Map, Error, Buffer, etc.
79
+ * @param {any} value
80
+ * @returns {string}
81
+ */
82
+ function safeStringify(value) {
83
+ return JSON.stringify(
84
+ value,
85
+ (key, val) => {
86
+ if (val instanceof Set) return Array.from(val); // convert Set → array
87
+ if (val instanceof Map) return Object.fromEntries(val); // Map → object
88
+ if (val instanceof Error) return { name: val.name, message: val.message, stack: val.stack };
89
+ if (Buffer.isBuffer(val)) return `Buffer[${val.length}]`;
90
+ return val;
91
+ },
92
+ 2 // pretty print with 2 spaces (optional)
93
+ );
94
+ }
77
95
 
78
96
  /**
79
97
  * Print a debug payload (object) as magenta JSON or structured JSON in prod.
@@ -81,16 +99,14 @@ function colorize(colorCode, icon, message, label) {
81
99
  */
82
100
  function debug(data) {
83
101
  const { isProd } = resolveContext();
102
+ const text = safeStringify(data);
103
+
84
104
  if (isProd) {
85
105
  asyncWrite('stdout', serializeJSON('debug', 'debug payload', { data }));
86
106
  } else {
87
- const payload = (() => {
88
- try { return JSON.stringify(data); } catch { return String(data); }
89
- })();
90
- asyncWrite('stdout', colorize('\x1b[35m', '🐛', payload, 'DEBUG'));
107
+ asyncWrite('stdout', colorize('\x1b[35m', '🐛', text, 'DEBUG'));
91
108
  }
92
109
  }
93
-
94
110
  /**
95
111
  * Print a green success note.
96
112
  * @param {string|number|boolean} message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "b2b-platform-utils",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
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",