@contentstack/cli-utilities 2.0.0-beta.2 → 2.0.0-beta.4

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.
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
3
+ const chalk_1 = require("../chalk");
5
4
  class SummaryManager {
6
5
  constructor({ operationName, context }) {
7
6
  this.modules = new Map();
@@ -83,16 +82,16 @@ class SummaryManager {
83
82
  const totalItems = Array.from(this.modules.values()).reduce((sum, m) => sum + m.successCount + m.failureCount, 0);
84
83
  const totalSuccess = Array.from(this.modules.values()).reduce((sum, m) => sum + m.successCount, 0);
85
84
  const totalFailures = Array.from(this.modules.values()).reduce((sum, m) => sum + m.failureCount, 0);
86
- console.log('\n' + chalk_1.default.bold('='.repeat(80)));
87
- console.log(chalk_1.default.bold(`${this.operationName} SUMMARY`));
88
- console.log('\n' + chalk_1.default.bold('Overall Statistics:'));
89
- console.log(` Total ${this.operationName} Time: ${chalk_1.default.cyan(this.formatDuration(totalDuration))}`);
90
- console.log(` Modules Processed: ${chalk_1.default.cyan(completedModules)}/${chalk_1.default.cyan(totalModules)}`);
91
- console.log(` Items Processed: ${chalk_1.default.green(totalSuccess)} success, ${chalk_1.default.red(totalFailures)} failed of ${chalk_1.default.cyan(totalItems)} total`);
92
- console.log(` Success Rate: ${chalk_1.default.cyan(this.calculateSuccessRate(totalSuccess, totalItems))}%`);
85
+ console.log('\n' + (0, chalk_1.getChalk)().bold('='.repeat(80)));
86
+ console.log((0, chalk_1.getChalk)().bold(`${this.operationName} SUMMARY`));
87
+ console.log('\n' + (0, chalk_1.getChalk)().bold('Overall Statistics:'));
88
+ console.log(` Total ${this.operationName} Time: ${(0, chalk_1.getChalk)().cyan(this.formatDuration(totalDuration))}`);
89
+ console.log(` Modules Processed: ${(0, chalk_1.getChalk)().cyan(completedModules)}/${(0, chalk_1.getChalk)().cyan(totalModules)}`);
90
+ console.log(` Items Processed: ${(0, chalk_1.getChalk)().green(totalSuccess)} success, ${(0, chalk_1.getChalk)().red(totalFailures)} failed of ${(0, chalk_1.getChalk)().cyan(totalItems)} total`);
91
+ console.log(` Success Rate: ${(0, chalk_1.getChalk)().cyan(this.calculateSuccessRate(totalSuccess, totalItems))}%`);
93
92
  // Module Details
94
- console.log('\n' + chalk_1.default.bold('Module Details:'));
95
- console.log(chalk_1.default.gray('-'.repeat(80)));
93
+ console.log('\n' + (0, chalk_1.getChalk)().bold('Module Details:'));
94
+ console.log((0, chalk_1.getChalk)().gray('-'.repeat(80)));
96
95
  Array.from(this.modules.values()).forEach((module) => {
97
96
  const status = this.getStatusIcon(module.status);
98
97
  const totalCount = module.successCount + module.failureCount;
@@ -104,18 +103,18 @@ class SummaryManager {
104
103
  `${duration.padStart(8)}`);
105
104
  });
106
105
  // Final Status
107
- console.log('\n' + chalk_1.default.bold('Final Status:'));
106
+ console.log('\n' + (0, chalk_1.getChalk)().bold('Final Status:'));
108
107
  if (!this.hasFailures() && failedModules === 0) {
109
- console.log(chalk_1.default.bold.green(`✅ ${this.operationName} completed successfully!`));
108
+ console.log((0, chalk_1.getChalk)().bold.green(`✅ ${this.operationName} completed successfully!`));
110
109
  }
111
110
  else if (this.hasFailures() || failedModules > 0) {
112
- console.log(chalk_1.default.bold.yellow(`⚠️ ${this.operationName} completed with failures, see the logs for more details.`));
111
+ console.log((0, chalk_1.getChalk)().bold.yellow(`⚠️ ${this.operationName} completed with failures, see the logs for more details.`));
113
112
  }
114
113
  else {
115
- console.log(chalk_1.default.bold.red(`❌ ${this.operationName} failed`));
114
+ console.log((0, chalk_1.getChalk)().bold.red(`❌ ${this.operationName} failed`));
116
115
  }
117
- console.log(chalk_1.default.bold('='.repeat(80)));
118
- console.log(chalk_1.default.bold('='.repeat(80)));
116
+ console.log((0, chalk_1.getChalk)().bold('='.repeat(80)));
117
+ console.log((0, chalk_1.getChalk)().bold('='.repeat(80)));
119
118
  // Simple failure summary with log reference
120
119
  this.printFailureSummaryWithLogReference();
121
120
  }
@@ -130,35 +129,35 @@ class SummaryManager {
130
129
  if (modulesWithFailures.length === 0)
131
130
  return;
132
131
  const totalFailures = modulesWithFailures.reduce((sum, m) => sum + m.failures.length, 0);
133
- console.log('\n' + chalk_1.default.bold.red('Failure Summary:'));
134
- console.log(chalk_1.default.red('-'.repeat(50)));
132
+ console.log('\n' + (0, chalk_1.getChalk)().bold.red('Failure Summary:'));
133
+ console.log((0, chalk_1.getChalk)().red('-'.repeat(50)));
135
134
  modulesWithFailures.forEach((module) => {
136
- console.log(`${chalk_1.default.bold.red('✗')} ${chalk_1.default.bold(module.name)}: ${chalk_1.default.red(module.failures.length)} failures`);
135
+ console.log(`${(0, chalk_1.getChalk)().bold.red('✗')} ${(0, chalk_1.getChalk)().bold(module.name)}: ${(0, chalk_1.getChalk)().red(module.failures.length)} failures`);
137
136
  // Show just first 2-3 failures briefly
138
137
  const preview = module.failures.slice(0, 2);
139
138
  preview.forEach((failure) => {
140
- console.log(` • ${chalk_1.default.gray(failure.item)}`);
139
+ console.log(` • ${(0, chalk_1.getChalk)().gray(failure.item)}`);
141
140
  });
142
141
  if (module.failures.length > 2) {
143
- console.log(` ${chalk_1.default.gray(`... and ${module.failures.length - 2} more`)}`);
142
+ console.log(` ${(0, chalk_1.getChalk)().gray(`... and ${module.failures.length - 2} more`)}`);
144
143
  }
145
144
  });
146
- console.log(chalk_1.default.blue('\n📋 For detailed error information, check the log files:'));
147
- //console.log(chalk.blue(` ${getSessionLogPath()}`));
148
- console.log(chalk_1.default.gray(' Recent errors are logged with full context and stack traces.'));
145
+ console.log((0, chalk_1.getChalk)().blue('\n📋 For detailed error information, check the log files:'));
146
+ //console.log(getChalk().blue(` ${getSessionLogPath()}`));
147
+ console.log((0, chalk_1.getChalk)().gray(' Recent errors are logged with full context and stack traces.'));
149
148
  }
150
149
  getStatusIcon(status) {
151
150
  switch (status) {
152
151
  case 'completed':
153
- return chalk_1.default.green('✓');
152
+ return (0, chalk_1.getChalk)().green('✓');
154
153
  case 'failed':
155
- return chalk_1.default.red('✗');
154
+ return (0, chalk_1.getChalk)().red('✗');
156
155
  case 'running':
157
- return chalk_1.default.yellow('●');
156
+ return (0, chalk_1.getChalk)().yellow('●');
158
157
  case 'pending':
159
- return chalk_1.default.gray('○');
158
+ return (0, chalk_1.getChalk)().gray('○');
160
159
  default:
161
- return chalk_1.default.gray('?');
160
+ return (0, chalk_1.getChalk)().gray('?');
162
161
  }
163
162
  }
164
163
  formatDuration(ms) {
@@ -8,10 +8,51 @@ export interface ProxyConfig {
8
8
  };
9
9
  }
10
10
  /**
11
- * Get proxy configuration with priority: Environment variables > Global config
11
+ * Parse NO_PROXY / no_proxy env (both uppercase and lowercase).
12
+ * NO_PROXY has priority over HTTP_PROXY/HTTPS_PROXY: hosts in this list never use the proxy.
13
+ * Values are hostnames only, comma-separated; leading dot matches subdomains (e.g. .contentstack.io).
14
+ * The bypass list is fully dynamic: only env values are used (no hardcoded default).
15
+ * @returns List of trimmed entries, or empty array when NO_PROXY/no_proxy is unset
16
+ */
17
+ export declare function getNoProxyList(): string[];
18
+ /**
19
+ * Check if the given host should bypass the proxy based on NO_PROXY / no_proxy.
20
+ * Supports: exact host, leading-dot subdomain match (e.g. .contentstack.io), and wildcard *.
21
+ * @param host - Request hostname (with or without port; will be normalized)
22
+ * @returns true if proxy should not be used for this host
23
+ */
24
+ export declare function shouldBypassProxy(host: string): boolean;
25
+ /**
26
+ * Get proxy configuration. Sources (in order): env (HTTP_PROXY/HTTPS_PROXY), then global config
27
+ * from `csdx config:set:proxy --host --port --protocol `.
28
+ * For per-request use, prefer getProxyConfigForHost(host) so NO_PROXY overrides both sources.
12
29
  * @returns ProxyConfig object or undefined if no proxy is configured
13
30
  */
14
31
  export declare function getProxyConfig(): ProxyConfig | undefined;
32
+ /**
33
+ * Get proxy config only when the request host is not in NO_PROXY.
34
+ * NO_PROXY has priority over both HTTP_PROXY/HTTPS_PROXY and over proxy set via
35
+ * `csdx config:set:proxy` — if the host matches NO_PROXY, no proxy is used.
36
+ * Use this for all outbound requests so Contentstack and localhost bypass the proxy when set.
37
+ * @param host - Request hostname (e.g. api.contentstack.io or full URL like https://api.contentstack.io)
38
+ * @returns ProxyConfig or undefined if proxy is disabled or host should bypass (NO_PROXY)
39
+ */
40
+ export declare function getProxyConfigForHost(host: string): ProxyConfig | undefined;
41
+ /**
42
+ * Resolve request host for proxy/NO_PROXY checks: config.host or default CMA from region.
43
+ * Use when the caller may omit host so NO_PROXY still applies (e.g. from region.cma).
44
+ * @param config - Object with optional host (e.g. API client config)
45
+ * @returns Host string (hostname or empty)
46
+ */
47
+ export declare function resolveRequestHost(config: {
48
+ host?: string;
49
+ }): string;
50
+ /**
51
+ * Temporarily clear proxy-related env vars so SDK/axios cannot use them.
52
+ * Call the returned function to restore. Use when creating a client for a host in NO_PROXY.
53
+ * @returns Restore function (call to put env back)
54
+ */
55
+ export declare function clearProxyEnv(): () => void;
15
56
  /**
16
57
  * Check if proxy is configured (from any source)
17
58
  * @returns true if proxy is configured, false otherwise
@@ -1,14 +1,99 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProxyUrl = exports.hasProxy = exports.getProxyConfig = void 0;
3
+ exports.getNoProxyList = getNoProxyList;
4
+ exports.shouldBypassProxy = shouldBypassProxy;
5
+ exports.getProxyConfig = getProxyConfig;
6
+ exports.getProxyConfigForHost = getProxyConfigForHost;
7
+ exports.resolveRequestHost = resolveRequestHost;
8
+ exports.clearProxyEnv = clearProxyEnv;
9
+ exports.hasProxy = hasProxy;
10
+ exports.getProxyUrl = getProxyUrl;
4
11
  const tslib_1 = require("tslib");
5
12
  const config_handler_1 = tslib_1.__importDefault(require("./config-handler"));
6
13
  /**
7
- * Get proxy configuration with priority: Environment variables > Global config
14
+ * Parse NO_PROXY / no_proxy env (both uppercase and lowercase).
15
+ * NO_PROXY has priority over HTTP_PROXY/HTTPS_PROXY: hosts in this list never use the proxy.
16
+ * Values are hostnames only, comma-separated; leading dot matches subdomains (e.g. .contentstack.io).
17
+ * The bypass list is fully dynamic: only env values are used (no hardcoded default).
18
+ * @returns List of trimmed entries, or empty array when NO_PROXY/no_proxy is unset
19
+ */
20
+ function getNoProxyList() {
21
+ const raw = process.env.NO_PROXY || process.env.no_proxy || '';
22
+ return raw
23
+ .split(',')
24
+ .map((s) => s.trim())
25
+ .filter(Boolean);
26
+ }
27
+ /**
28
+ * Normalize host for NO_PROXY matching: strip protocol/URL, port, lowercase, handle IPv6 brackets.
29
+ * Accepts hostname, host:port, or full URL (e.g. https://api.contentstack.io).
30
+ */
31
+ function normalizeHost(host) {
32
+ if (!host || typeof host !== 'string')
33
+ return '';
34
+ let h = host.trim().toLowerCase();
35
+ // If it looks like a URL, extract hostname so NO_PROXY matching works (e.g. region.cma is full URL)
36
+ if (h.includes('://')) {
37
+ try {
38
+ const u = new URL(h);
39
+ h = u.hostname;
40
+ }
41
+ catch (_a) {
42
+ // fall through to port stripping below
43
+ }
44
+ }
45
+ const portIdx = h.lastIndexOf(':');
46
+ if (h.startsWith('[')) {
47
+ const close = h.indexOf(']');
48
+ if (close !== -1 && h.length > close + 1 && h[close + 1] === ':') {
49
+ h = h.slice(1, close);
50
+ }
51
+ }
52
+ else if (portIdx !== -1) {
53
+ const after = h.slice(portIdx + 1);
54
+ if (/^\d+$/.test(after)) {
55
+ h = h.slice(0, portIdx);
56
+ }
57
+ }
58
+ return h;
59
+ }
60
+ /**
61
+ * Check if the given host should bypass the proxy based on NO_PROXY / no_proxy.
62
+ * Supports: exact host, leading-dot subdomain match (e.g. .contentstack.io), and wildcard *.
63
+ * @param host - Request hostname (with or without port; will be normalized)
64
+ * @returns true if proxy should not be used for this host
65
+ */
66
+ function shouldBypassProxy(host) {
67
+ const normalized = normalizeHost(host);
68
+ if (!normalized)
69
+ return false;
70
+ const list = getNoProxyList();
71
+ for (const entry of list) {
72
+ const e = entry.trim().toLowerCase();
73
+ if (!e)
74
+ continue;
75
+ if (e === '*')
76
+ return true;
77
+ if (e.startsWith('.')) {
78
+ const domain = e.slice(1);
79
+ if (normalized === domain || normalized.endsWith(e))
80
+ return true;
81
+ }
82
+ else {
83
+ if (normalized === e)
84
+ return true;
85
+ }
86
+ }
87
+ return false;
88
+ }
89
+ /**
90
+ * Get proxy configuration. Sources (in order): env (HTTP_PROXY/HTTPS_PROXY), then global config
91
+ * from `csdx config:set:proxy --host --port --protocol `.
92
+ * For per-request use, prefer getProxyConfigForHost(host) so NO_PROXY overrides both sources.
8
93
  * @returns ProxyConfig object or undefined if no proxy is configured
9
94
  */
10
95
  function getProxyConfig() {
11
- // Priority 1: Check environment variables (HTTPS_PROXY or HTTP_PROXY)
96
+ // Priority 1: Environment variables (HTTPS_PROXY or HTTP_PROXY)
12
97
  const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
13
98
  if (proxyUrl) {
14
99
  try {
@@ -35,7 +120,7 @@ function getProxyConfig() {
35
120
  // Invalid URL, continue to check global config
36
121
  }
37
122
  }
38
- // Priority 2: Check global config store
123
+ // Priority 2: Global config (csdx config:set:proxy)
39
124
  const globalProxyConfig = config_handler_1.default.get('proxy');
40
125
  if (globalProxyConfig) {
41
126
  if (typeof globalProxyConfig === 'object') {
@@ -72,7 +157,65 @@ function getProxyConfig() {
72
157
  }
73
158
  return undefined;
74
159
  }
75
- exports.getProxyConfig = getProxyConfig;
160
+ /**
161
+ * Get proxy config only when the request host is not in NO_PROXY.
162
+ * NO_PROXY has priority over both HTTP_PROXY/HTTPS_PROXY and over proxy set via
163
+ * `csdx config:set:proxy` — if the host matches NO_PROXY, no proxy is used.
164
+ * Use this for all outbound requests so Contentstack and localhost bypass the proxy when set.
165
+ * @param host - Request hostname (e.g. api.contentstack.io or full URL like https://api.contentstack.io)
166
+ * @returns ProxyConfig or undefined if proxy is disabled or host should bypass (NO_PROXY)
167
+ */
168
+ function getProxyConfigForHost(host) {
169
+ if (shouldBypassProxy(host))
170
+ return undefined;
171
+ return getProxyConfig();
172
+ }
173
+ /**
174
+ * Resolve request host for proxy/NO_PROXY checks: config.host or default CMA from region.
175
+ * Use when the caller may omit host so NO_PROXY still applies (e.g. from region.cma).
176
+ * @param config - Object with optional host (e.g. API client config)
177
+ * @returns Host string (hostname or empty)
178
+ */
179
+ function resolveRequestHost(config) {
180
+ var _a;
181
+ if (config.host)
182
+ return config.host;
183
+ const cma = (_a = config_handler_1.default.get('region')) === null || _a === void 0 ? void 0 : _a.cma;
184
+ if (cma && typeof cma === 'string') {
185
+ if (cma.startsWith('http')) {
186
+ try {
187
+ const u = new URL(cma);
188
+ return u.hostname || cma;
189
+ }
190
+ catch (_b) {
191
+ return cma;
192
+ }
193
+ }
194
+ return cma;
195
+ }
196
+ return '';
197
+ }
198
+ /**
199
+ * Temporarily clear proxy-related env vars so SDK/axios cannot use them.
200
+ * Call the returned function to restore. Use when creating a client for a host in NO_PROXY.
201
+ * @returns Restore function (call to put env back)
202
+ */
203
+ function clearProxyEnv() {
204
+ const saved = {};
205
+ const keys = ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy', 'ALL_PROXY', 'all_proxy'];
206
+ for (const k of keys) {
207
+ if (k in process.env) {
208
+ saved[k] = process.env[k];
209
+ delete process.env[k];
210
+ }
211
+ }
212
+ return () => {
213
+ for (const k of keys) {
214
+ if (saved[k] !== undefined)
215
+ process.env[k] = saved[k];
216
+ }
217
+ };
218
+ }
76
219
  /**
77
220
  * Check if proxy is configured (from any source)
78
221
  * @returns true if proxy is configured, false otherwise
@@ -80,7 +223,6 @@ exports.getProxyConfig = getProxyConfig;
80
223
  function hasProxy() {
81
224
  return !!getProxyConfig() || !!process.env.HTTPS_PROXY || !!process.env.HTTP_PROXY || !!config_handler_1.default.get('proxy');
82
225
  }
83
- exports.hasProxy = hasProxy;
84
226
  /**
85
227
  * Get proxy URL string for display purposes
86
228
  * @returns Proxy URL string or 'proxy server' if not available
@@ -100,4 +242,3 @@ function getProxyUrl() {
100
242
  }
101
243
  return 'proxy server';
102
244
  }
103
- exports.getProxyUrl = getProxyUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.4",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -37,14 +37,14 @@
37
37
  "@contentstack/marketplace-sdk": "^1.5.0",
38
38
  "@oclif/core": "^4.3.0",
39
39
  "axios": "^1.13.5",
40
- "chalk": "^4.1.2",
40
+ "chalk": "^5.6.2",
41
41
  "cli-cursor": "^3.1.0",
42
42
  "cli-progress": "^3.12.0",
43
43
  "cli-table": "^0.3.11",
44
44
  "conf": "^10.2.0",
45
45
  "dotenv": "^16.6.1",
46
46
  "figures": "^3.2.0",
47
- "inquirer": "8.2.7",
47
+ "inquirer": "12.11.1",
48
48
  "inquirer-search-checkbox": "^1.0.0",
49
49
  "inquirer-search-list": "^1.2.6",
50
50
  "js-yaml": "^4.1.1",
@@ -68,7 +68,7 @@
68
68
  "@types/inquirer": "^9.0.8",
69
69
  "@types/mkdirp": "^1.0.2",
70
70
  "@types/mocha": "^10.0.10",
71
- "@types/node": "^14.18.63",
71
+ "@types/node": "^18.11.9",
72
72
  "@types/sinon": "^21.0.0",
73
73
  "@types/traverse": "^0.6.37",
74
74
  "chai": "^4.5.0",
@@ -80,6 +80,6 @@
80
80
  "nyc": "^15.1.0",
81
81
  "sinon": "^21.0.1",
82
82
  "ts-node": "^10.9.2",
83
- "typescript": "^4.9.5"
83
+ "typescript": "^5.0.0"
84
84
  }
85
- }
85
+ }