@contentstack/cli-utilities 1.13.0 → 1.13.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.
@@ -48,6 +48,12 @@ class AuthenticationHandler {
48
48
  return this.token;
49
49
  }
50
50
  async refreshAccessToken(error, maxRetryCount = 1) {
51
+ // Add configurable delay only for CI/CD pipelines
52
+ const delayMs = process.env.DELAY_MS;
53
+ if (delayMs) {
54
+ const delay = parseInt(delayMs, 10);
55
+ await new Promise((resolve) => setTimeout(resolve, delay));
56
+ }
51
57
  if (error.response && error.response.status) {
52
58
  switch (error.response.status) {
53
59
  case 401:
@@ -20,5 +20,13 @@ declare const cliErrorHandler: CLIErrorHandler;
20
20
  * debug type and additional details.
21
21
  */
22
22
  declare function handleAndLogError(error: unknown, context?: ErrorContext, errorMessage?: string): void;
23
+ /**
24
+ * Get the log path for centralized logging
25
+ * Priority:
26
+ * 1. CS_CLI_LOG_PATH environment variable (user override)
27
+ * 2. User config (log.path from CLI config)
28
+ * 3. Current working directory + logs (where user ran the command)
29
+ * 4. Home directory (~/contentstack/logs) (fallback)
30
+ */
23
31
  declare function getLogPath(): string;
24
32
  export { v2Logger, cliErrorHandler, handleAndLogError, getLogPath };
package/lib/logger/log.js CHANGED
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLogPath = exports.handleAndLogError = exports.cliErrorHandler = exports.v2Logger = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const os = tslib_1.__importStar(require("os"));
5
7
  const path = tslib_1.__importStar(require("path"));
6
8
  const logger_1 = tslib_1.__importDefault(require("./logger"));
7
9
  const cli_error_handler_1 = require("./cli-error-handler");
@@ -49,10 +51,11 @@ exports.cliErrorHandler = cliErrorHandler;
49
51
  function handleAndLogError(error, context, errorMessage) {
50
52
  var _a;
51
53
  const classified = cliErrorHandler.classifyError(error, context, errorMessage);
54
+ const apiError = ((_a = classified.error) === null || _a === void 0 ? void 0 : _a.message) || (classified === null || classified === void 0 ? void 0 : classified.message) || 'Unknown error';
52
55
  // Always log the error
53
56
  v2Logger.logError({
54
57
  type: classified.type,
55
- message: errorMessage || ((_a = classified.error) === null || _a === void 0 ? void 0 : _a.message) || classified.message,
58
+ message: errorMessage ? `${errorMessage}\nAPI Error: ${apiError}` : `${apiError}`,
56
59
  error: classified.error,
57
60
  context: typeof classified.context === 'string' ? { message: classified.context } : classified.context,
58
61
  hidden: classified.hidden,
@@ -60,7 +63,37 @@ function handleAndLogError(error, context, errorMessage) {
60
63
  });
61
64
  }
62
65
  exports.handleAndLogError = handleAndLogError;
66
+ /**
67
+ * Get the log path for centralized logging
68
+ * Priority:
69
+ * 1. CS_CLI_LOG_PATH environment variable (user override)
70
+ * 2. User config (log.path from CLI config)
71
+ * 3. Current working directory + logs (where user ran the command)
72
+ * 4. Home directory (~/contentstack/logs) (fallback)
73
+ */
63
74
  function getLogPath() {
64
- return process.env.CS_CLI_LOG_PATH || __1.configHandler.get('log.path') || path.join(__dirname, 'logs');
75
+ // 1. Environment variable override
76
+ if (process.env.CS_CLI_LOG_PATH) {
77
+ return process.env.CS_CLI_LOG_PATH;
78
+ }
79
+ // 2. User configured path
80
+ const configuredPath = __1.configHandler.get('log.path');
81
+ if (configuredPath) {
82
+ return configuredPath;
83
+ }
84
+ // 3. Use current working directory (where user ran the command)
85
+ try {
86
+ const cwdPath = path.join(process.cwd(), 'logs');
87
+ if (!fs.existsSync(cwdPath)) {
88
+ fs.mkdirSync(cwdPath, { recursive: true });
89
+ }
90
+ fs.accessSync(cwdPath, fs.constants.W_OK);
91
+ return cwdPath;
92
+ }
93
+ catch (error) {
94
+ // If current directory is not writable, fall back to home directory
95
+ }
96
+ // 4. Fallback to home directory
97
+ return path.join(os.homedir(), 'contentstack', 'logs');
65
98
  }
66
99
  exports.getLogPath = getLogPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",