@contentstack/cli-utilities 1.19.0 → 1.19.1

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.
@@ -229,8 +229,8 @@ export declare class HttpClient implements IHttpClient {
229
229
  * Get the axios instance for interceptor access
230
230
  */
231
231
  get interceptors(): {
232
- request: import("axios").AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig<any>>;
233
- response: import("axios").AxiosInterceptorManager<AxiosResponse<any, any, {}>>;
232
+ request: import("axios").AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig<any, any>>;
233
+ response: import("axios").AxiosInterceptorManager<AxiosResponse<any, any, {}, any>>;
234
234
  };
235
235
  /**
236
236
  * Returns the request payload depending on the selected request payload format.
@@ -12,6 +12,12 @@ export default class Logger {
12
12
  private isSensitiveKey;
13
13
  private redactObject;
14
14
  private redact;
15
+ /**
16
+ * Stringifies a log entry without throwing on circular references.
17
+ * `redact()` can fall back to the original (still-circular) object when
18
+ * cloning fails, so this must never assume the input is cycle-free.
19
+ */
20
+ private safeStringify;
15
21
  private shouldLog;
16
22
  error(message: string, meta?: any): void;
17
23
  warn(message: string, meta?: any): void;
@@ -53,7 +53,7 @@ class Logger {
53
53
  new winston.transports.File(Object.assign(Object.assign({}, this.loggerOptions), { filename: `${filePath}/${level}.log`, format: winston.format.combine(winston.format.timestamp(), winston.format.printf((info) => {
54
54
  // Apply minimal redaction for files (debugging info preserved)
55
55
  const redactedInfo = this.redact(info, false);
56
- return JSON.stringify(redactedInfo);
56
+ return this.safeStringify(redactedInfo);
57
57
  })) })),
58
58
  new winston.transports.Console({
59
59
  format: winston.format.combine(winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.printf((info) => {
@@ -97,6 +97,28 @@ class Logger {
97
97
  return info;
98
98
  }
99
99
  }
100
+ /**
101
+ * Stringifies a log entry without throwing on circular references.
102
+ * `redact()` can fall back to the original (still-circular) object when
103
+ * cloning fails, so this must never assume the input is cycle-free.
104
+ */
105
+ safeStringify(value) {
106
+ var _a;
107
+ const seen = new WeakSet();
108
+ try {
109
+ return JSON.stringify(value, (_key, val) => {
110
+ if (typeof val === 'object' && val !== null) {
111
+ if (seen.has(val))
112
+ return '[Circular]';
113
+ seen.add(val);
114
+ }
115
+ return val;
116
+ });
117
+ }
118
+ catch (_b) {
119
+ return JSON.stringify({ level: value === null || value === void 0 ? void 0 : value.level, message: (_a = value === null || value === void 0 ? void 0 : value.message) !== null && _a !== void 0 ? _a : '[Unserializable log entry]' });
120
+ }
121
+ }
100
122
  shouldLog(level, target) {
101
123
  // If console logging is disabled, don't log to console
102
124
  if (target === 'console' && this.config.consoleLoggingEnabled === false) {
@@ -143,9 +165,12 @@ class Logger {
143
165
  if (this.shouldLog('error', 'file')) {
144
166
  this.loggers.error.error(logPayload);
145
167
  }
146
- // For console, use debug level if hidden, otherwise error level
168
+ // For console, use debug level if hidden, otherwise error level. Each level's
169
+ // winston logger instance bundles both the file and console transports, so only
170
+ // write again here when the target differs from the one already written above —
171
+ // otherwise this would duplicate both the console line and the file entry.
147
172
  const consoleLevel = params.hidden ? 'debug' : 'error';
148
- if (this.shouldLog(consoleLevel, 'console')) {
173
+ if (consoleLevel !== 'error' && this.shouldLog(consoleLevel, 'console')) {
149
174
  this.loggers[consoleLevel].error(logPayload);
150
175
  }
151
176
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.19.0",
3
+ "version": "1.19.1",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",