@contentstack/cli-config 1.18.0 → 2.0.0-beta

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/README.md CHANGED
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
18
18
  $ csdx COMMAND
19
19
  running command...
20
20
  $ csdx (--version)
21
- @contentstack/cli-config/1.18.0 linux-x64 node-v22.22.0
21
+ @contentstack/cli-config/2.0.0-beta linux-x64 node-v22.22.0
22
22
  $ csdx --help [COMMAND]
23
23
  USAGE
24
24
  $ csdx COMMAND
@@ -456,18 +456,18 @@ Set region for CLI
456
456
 
457
457
  ```
458
458
  USAGE
459
- $ csdx config:set:region [REGION] [-d <value> -m <value> --ui-host <value> -n <value>] [--developer-hub <value>]
460
- [--personalize <value>] [--launch <value>] [--studio <value>]
459
+ $ csdx config:set:region [REGION] [--cda <value> --cma <value> --ui-host <value> -n <value>] [--developer-hub
460
+ <value>] [--personalize <value>] [--launch <value>] [--studio <value>]
461
461
 
462
462
  ARGUMENTS
463
463
  [REGION] Name for the region
464
464
 
465
465
  FLAGS
466
- -d, --cda=<value> Custom host to set for content delivery API, if this flag is added then cma, ui-host and
466
+ -n, --name=<value> Name for the region, if this flag is added then cda, cma and ui-host flags are required
467
+ --cda=<value> Custom host to set for content delivery API, if this flag is added then cma, ui-host and
467
468
  name flags are required
468
- -m, --cma=<value> Custom host to set for content management API, , if this flag is added then cda, ui-host
469
+ --cma=<value> Custom host to set for content management API, , if this flag is added then cda, ui-host
469
470
  and name flags are required
470
- -n, --name=<value> Name for the region, if this flag is added then cda, cma and ui-host flags are required
471
471
  --developer-hub=<value> Custom host to set for Developer hub API
472
472
  --launch=<value> Custom host to set for Launch API
473
473
  --personalize=<value> Custom host to set for Personalize API
@@ -5,9 +5,9 @@ const cli_command_1 = require("@contentstack/cli-command");
5
5
  class GetEarlyAccessHeaderCommand extends cli_command_1.Command {
6
6
  async run() {
7
7
  try {
8
- let config = cli_utilities_1.configHandler.get(`earlyAccessHeaders`);
8
+ const config = cli_utilities_1.configHandler.get(`earlyAccessHeaders`);
9
9
  if (config && Object.keys(config).length > 0) {
10
- let tableData = Object.keys(config).map((key) => ({
10
+ const tableData = Object.keys(config).map((key) => ({
11
11
  ['Alias']: key,
12
12
  ['Early access header']: config[key],
13
13
  }));
@@ -22,7 +22,7 @@ class LogSetCommand extends cli_command_1.Command {
22
22
  currentLoggingConfig.path = resolvedPath;
23
23
  }
24
24
  if (flags['show-console-logs'] !== undefined) {
25
- currentLoggingConfig['show-console-logs'] = flags['show-console-logs'];
25
+ currentLoggingConfig['showConsoleLogs'] = flags['show-console-logs'];
26
26
  }
27
27
  cli_utilities_1.configHandler.set('log', currentLoggingConfig);
28
28
  if (flags['level'] !== undefined) {
@@ -32,8 +32,9 @@ class LogSetCommand extends cli_command_1.Command {
32
32
  cli_utilities_1.cliux.success(cli_utilities_1.messageHandler.parse('CLI_CONFIG_LOG_PATH_SET', currentLoggingConfig.path));
33
33
  }
34
34
  if (flags['show-console-logs'] !== undefined) {
35
- cli_utilities_1.cliux.success(cli_utilities_1.messageHandler.parse('CLI_CONFIG_LOG_CONSOLE_SET', String(currentLoggingConfig['show-console-logs'])));
35
+ cli_utilities_1.cliux.success(cli_utilities_1.messageHandler.parse('CLI_CONFIG_LOG_CONSOLE_SET', String(currentLoggingConfig['showConsoleLogs'])));
36
36
  }
37
+ cli_utilities_1.cliux.success(cli_utilities_1.messageHandler.parse('CLI_CONFIG_LOG_SET_SUCCESS'));
37
38
  }
38
39
  catch (error) {
39
40
  (0, cli_utilities_1.handleAndLogError)(error, { module: 'config-set-log' });
@@ -25,11 +25,13 @@ class SetRateLimitCommand extends base_command_1.BaseCommand {
25
25
  const utilizeValues = (_a = utilize === null || utilize === void 0 ? void 0 : utilize.split(',')) === null || _a === void 0 ? void 0 : _a.map((u) => Number(u.trim()));
26
26
  if (utilizeValues.some((u) => isNaN(u) || u < 0 || u > 100)) {
27
27
  cli_utilities_1.cliux.error('Utilization percentages must be numbers between 0 and 100.');
28
- return;
28
+ this.exit(1);
29
+ return; // Unreachable in production, but needed when exit is stubbed in tests
29
30
  }
30
31
  if ((limitName === null || limitName === void 0 ? void 0 : limitName.length) > 0 && ((_c = (_b = limitName[0]) === null || _b === void 0 ? void 0 : _b.split(',')) === null || _c === void 0 ? void 0 : _c.length) !== utilizeValues.length) {
31
32
  cli_utilities_1.cliux.error('The number of utilization percentages must match the number of limit names.');
32
- return;
33
+ this.exit(1);
34
+ return; // Unreachable in production, but needed when exit is stubbed in tests
33
35
  }
34
36
  else {
35
37
  config.utilize = utilize.split(',').map((v) => v.trim());
@@ -39,7 +41,8 @@ class SetRateLimitCommand extends base_command_1.BaseCommand {
39
41
  const invalidLimitNames = limitName[0].split(',').map((name) => name.trim());
40
42
  if (invalidLimitNames.some((name) => !common_utilities_1.limitNamesConfig.includes(name))) {
41
43
  cli_utilities_1.cliux.error(`Invalid limit names provided: ${invalidLimitNames.join(', ')}`);
42
- return;
44
+ this.exit(1);
45
+ return; // Unreachable in production, but needed when exit is stubbed in tests
43
46
  }
44
47
  else {
45
48
  config['limit-name'] = limitName[0].split(',').map((n) => n.trim());
@@ -98,16 +98,12 @@ exports.default = RegionSetCommand;
98
98
  RegionSetCommand.description = 'Set region for CLI';
99
99
  RegionSetCommand.flags = {
100
100
  cda: cli_utilities_1.flags.string({
101
- char: 'd',
102
101
  description: 'Custom host to set for content delivery API, if this flag is added then cma, ui-host and name flags are required',
103
102
  dependsOn: ['cma', 'ui-host', 'name'],
104
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-d'], ['--cda']),
105
103
  }),
106
104
  cma: cli_utilities_1.flags.string({
107
- char: 'm',
108
105
  description: 'Custom host to set for content management API, , if this flag is added then cda, ui-host and name flags are required',
109
106
  dependsOn: ['cda', 'ui-host', 'name'],
110
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-m'], ['--cma']),
111
107
  }),
112
108
  'ui-host': cli_utilities_1.flags.string({
113
109
  description: 'Custom UI host to set for CLI, if this flag is added then cda, cma and name flags are required',
@@ -34,3 +34,6 @@ export interface SetRateLimitConfig {
34
34
  default?: boolean;
35
35
  host?: string;
36
36
  }
37
+ export interface RegionsMap {
38
+ [key: string]: Region;
39
+ }
@@ -28,7 +28,7 @@ function getEffectiveLogConfig(currentConfig = {}) {
28
28
  var _a;
29
29
  const logLevel = (currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.level) || exports.LOG_CONFIG_DEFAULTS.LEVEL;
30
30
  const logPath = resolveLogPath((currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.path) || exports.LOG_CONFIG_DEFAULTS.PATH);
31
- const showConsoleLogs = (_a = currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig['show-console-logs']) !== null && _a !== void 0 ? _a : exports.LOG_CONFIG_DEFAULTS.SHOW_CONSOLE_LOGS;
31
+ const showConsoleLogs = (_a = currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig['showConsoleLogs']) !== null && _a !== void 0 ? _a : exports.LOG_CONFIG_DEFAULTS.SHOW_CONSOLE_LOGS;
32
32
  return {
33
33
  level: logLevel,
34
34
  path: logPath,
@@ -10,7 +10,7 @@ class RateLimitHandler {
10
10
  }
11
11
  async setRateLimit(config) {
12
12
  var _a;
13
- const rateLimit = cli_utilities_1.configHandler.get('rateLimit');
13
+ const rateLimit = cli_utilities_1.configHandler.get('rateLimit') || {};
14
14
  rateLimit.default = Object.assign({}, common_utilities_1.defaultRalteLimitConfig);
15
15
  if (config.default) {
16
16
  rateLimit[config.org] = Object.assign({}, rateLimit.default);
@@ -62,7 +62,10 @@ class RateLimitHandler {
62
62
  });
63
63
  }
64
64
  catch (error) {
65
- throw new Error(error);
65
+ if (error instanceof Error) {
66
+ throw new Error(`Error: ${error.message}`);
67
+ }
68
+ throw new Error(String(error));
66
69
  }
67
70
  }
68
71
  }
@@ -1,105 +1,5 @@
1
- declare const regions: {
2
- NA: {
3
- name: string;
4
- cma: string;
5
- cda: string;
6
- uiHost: string;
7
- developerHubUrl: string;
8
- launchHubUrl: string;
9
- personalizeUrl: string;
10
- composableStudioUrl: string;
11
- };
12
- 'AWS-NA': {
13
- name: string;
14
- cma: string;
15
- cda: string;
16
- uiHost: string;
17
- developerHubUrl: string;
18
- launchHubUrl: string;
19
- personalizeUrl: string;
20
- composableStudioUrl: string;
21
- };
22
- EU: {
23
- name: string;
24
- cma: string;
25
- cda: string;
26
- uiHost: string;
27
- developerHubUrl: string;
28
- launchHubUrl: string;
29
- personalizeUrl: string;
30
- composableStudioUrl: string;
31
- };
32
- 'AWS-EU': {
33
- name: string;
34
- cma: string;
35
- cda: string;
36
- uiHost: string;
37
- developerHubUrl: string;
38
- launchHubUrl: string;
39
- personalizeUrl: string;
40
- composableStudioUrl: string;
41
- };
42
- AU: {
43
- name: string;
44
- cma: string;
45
- cda: string;
46
- uiHost: string;
47
- developerHubUrl: string;
48
- launchHubUrl: string;
49
- personalizeUrl: string;
50
- composableStudioUrl: string;
51
- };
52
- 'AWS-AU': {
53
- name: string;
54
- cma: string;
55
- cda: string;
56
- uiHost: string;
57
- developerHubUrl: string;
58
- launchHubUrl: string;
59
- personalizeUrl: string;
60
- composableStudioUrl: string;
61
- };
62
- 'AZURE-NA': {
63
- name: string;
64
- cma: string;
65
- cda: string;
66
- uiHost: string;
67
- developerHubUrl: string;
68
- launchHubUrl: string;
69
- personalizeUrl: string;
70
- composableStudioUrl: string;
71
- };
72
- 'AZURE-EU': {
73
- name: string;
74
- cma: string;
75
- cda: string;
76
- uiHost: string;
77
- developerHubUrl: string;
78
- launchHubUrl: string;
79
- personalizeUrl: string;
80
- composableStudioUrl: string;
81
- };
82
- 'GCP-NA': {
83
- name: string;
84
- cma: string;
85
- cda: string;
86
- uiHost: string;
87
- developerHubUrl: string;
88
- launchHubUrl: string;
89
- personalizeUrl: string;
90
- composableStudioUrl: string;
91
- };
92
- 'GCP-EU': {
93
- name: string;
94
- cma: string;
95
- cda: string;
96
- uiHost: string;
97
- developerHubUrl: string;
98
- launchHubUrl: string;
99
- personalizeUrl: string;
100
- composableStudioUrl: string;
101
- };
102
- };
1
+ import { Region, RegionsMap } from '../interfaces';
2
+ declare const regions: RegionsMap;
103
3
  declare class UserConfig {
104
4
  /**
105
5
  *
@@ -107,7 +7,7 @@ declare class UserConfig {
107
7
  * @param {string} region It Can be AWS-NA, AWS-EU, AWS-AU, AZURE-NA, AZURE-EU, GCP-NA, GCP-EU
108
8
  * @returns {object} region object with cma, cda, region property
109
9
  */
110
- setRegion(region: any): any;
10
+ setRegion(region: any): Region;
111
11
  /**
112
12
  *
113
13
  * Get current host set for CLI
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.regions = void 0;
4
4
  const cli_utilities_1 = require("@contentstack/cli-utilities");
5
+ const utils_1 = require("@contentstack/utils");
5
6
  function validURL(str) {
6
7
  const pattern = new RegExp('^(https?:\\/\\/)?' + // protocol (http or https)
7
8
  '([a-zA-Z0-9.-]+|' + // domain name
@@ -13,109 +14,61 @@ function validURL(str) {
13
14
  'i');
14
15
  return pattern.test(str);
15
16
  }
16
- // Available region list
17
- const regions = {
18
- NA: {
19
- name: 'NA',
20
- cma: 'https://api.contentstack.io',
21
- cda: 'https://cdn.contentstack.io',
22
- uiHost: 'https://app.contentstack.com',
23
- developerHubUrl: 'https://developerhub-api.contentstack.com',
24
- launchHubUrl: 'https://launch-api.contentstack.com',
25
- personalizeUrl: 'https://personalize-api.contentstack.com',
26
- composableStudioUrl: 'https://composable-studio-api.contentstack.com',
27
- },
28
- 'AWS-NA': {
29
- name: 'AWS-NA',
30
- cma: 'https://api.contentstack.io',
31
- cda: 'https://cdn.contentstack.io',
32
- uiHost: 'https://app.contentstack.com',
33
- developerHubUrl: 'https://developerhub-api.contentstack.com',
34
- launchHubUrl: 'https://launch-api.contentstack.com',
35
- personalizeUrl: 'https://personalize-api.contentstack.com',
36
- composableStudioUrl: 'https://composable-studio-api.contentstack.com',
37
- },
38
- EU: {
39
- name: 'EU',
40
- cma: 'https://eu-api.contentstack.com',
41
- cda: 'https://eu-cdn.contentstack.com',
42
- uiHost: 'https://eu-app.contentstack.com',
43
- developerHubUrl: 'https://eu-developerhub-api.contentstack.com',
44
- launchHubUrl: 'https://eu-launch-api.contentstack.com',
45
- personalizeUrl: 'https://eu-personalize-api.contentstack.com',
46
- composableStudioUrl: 'https://eu-composable-studio-api.contentstack.com',
47
- },
48
- 'AWS-EU': {
49
- name: 'AWS-EU',
50
- cma: 'https://eu-api.contentstack.com',
51
- cda: 'https://eu-cdn.contentstack.com',
52
- uiHost: 'https://eu-app.contentstack.com',
53
- developerHubUrl: 'https://eu-developerhub-api.contentstack.com',
54
- launchHubUrl: 'https://eu-launch-api.contentstack.com',
55
- personalizeUrl: 'https://eu-personalize-api.contentstack.com',
56
- composableStudioUrl: 'https://eu-composable-studio-api.contentstack.com',
57
- },
58
- AU: {
59
- name: 'AU',
60
- cma: 'https://au-api.contentstack.com',
61
- cda: 'https://au-cdn.contentstack.com',
62
- uiHost: 'https://au-app.contentstack.com',
63
- developerHubUrl: 'https://au-developerhub-api.contentstack.com',
64
- launchHubUrl: 'https://au-launch-api.contentstack.com',
65
- personalizeUrl: 'https://au-personalize-api.contentstack.com',
66
- composableStudioUrl: 'https://au-composable-studio-api.contentstack.com',
67
- },
68
- 'AWS-AU': {
69
- name: 'AWS-AU',
70
- cma: 'https://au-api.contentstack.com',
71
- cda: 'https://au-cdn.contentstack.com',
72
- uiHost: 'https://au-app.contentstack.com',
73
- developerHubUrl: 'https://au-developerhub-api.contentstack.com',
74
- launchHubUrl: 'https://au-launch-api.contentstack.com',
75
- personalizeUrl: 'https://au-personalize-api.contentstack.com',
76
- composableStudioUrl: 'https://au-composable-studio-api.contentstack.com',
77
- },
78
- 'AZURE-NA': {
79
- name: 'AZURE-NA',
80
- cma: 'https://azure-na-api.contentstack.com',
81
- cda: 'https://azure-na-cdn.contentstack.com',
82
- uiHost: 'https://azure-na-app.contentstack.com',
83
- developerHubUrl: 'https://azure-na-developerhub-api.contentstack.com',
84
- launchHubUrl: 'https://azure-na-launch-api.contentstack.com',
85
- personalizeUrl: 'https://azure-na-personalize-api.contentstack.com',
86
- composableStudioUrl: 'https://azure-na-composable-studio-api.contentstack.com',
87
- },
88
- 'AZURE-EU': {
89
- name: 'AZURE-EU',
90
- cma: 'https://azure-eu-api.contentstack.com',
91
- cda: 'https://azure-eu-cdn.contentstack.com',
92
- uiHost: 'https://azure-eu-app.contentstack.com',
93
- developerHubUrl: 'https://azure-eu-developerhub-api.contentstack.com',
94
- launchHubUrl: 'https://azure-eu-launch-api.contentstack.com',
95
- personalizeUrl: 'https://azure-eu-personalize-api.contentstack.com',
96
- composableStudioUrl: 'https://azure-eu-composable-studio-api.contentstack.com',
97
- },
98
- 'GCP-NA': {
99
- name: 'GCP-NA',
100
- cma: 'https://gcp-na-api.contentstack.com',
101
- cda: 'https://gcp-na-cdn.contentstack.com',
102
- uiHost: 'https://gcp-na-app.contentstack.com',
103
- developerHubUrl: 'https://gcp-na-developerhub-api.contentstack.com',
104
- launchHubUrl: 'https://gcp-na-launch-api.contentstack.com',
105
- personalizeUrl: 'https://gcp-na-personalize-api.contentstack.com',
106
- composableStudioUrl: 'https://gcp-na-composable-studio-api.contentstack.com',
107
- },
108
- 'GCP-EU': {
109
- name: 'GCP-EU',
110
- cma: 'https://gcp-eu-api.contentstack.com',
111
- cda: 'https://gcp-eu-cdn.contentstack.com',
112
- uiHost: 'https://gcp-eu-app.contentstack.com',
113
- developerHubUrl: 'https://gcp-eu-developerhub-api.contentstack.com',
114
- launchHubUrl: 'https://gcp-eu-launch-api.contentstack.com',
115
- personalizeUrl: 'https://gcp-eu-personalize-api.contentstack.com',
116
- composableStudioUrl: 'https://gcp-eu-composable-studio-api.contentstack.com',
117
- },
118
- };
17
+ /**
18
+ * Helper function to build region object from @contentstack/utils
19
+ * @param {string} regionKey - Region identifier
20
+ * @returns {object} Region object with all necessary URLs
21
+ */
22
+ function getRegionObject(regionKey) {
23
+ try {
24
+ // getContentstackEndpoint handles all aliases defined in regions.json
25
+ const endpoints = (0, utils_1.getContentstackEndpoint)(regionKey);
26
+ if (typeof endpoints === 'string') {
27
+ throw new Error('Invalid endpoint response');
28
+ }
29
+ return {
30
+ name: regionKey,
31
+ cma: endpoints.contentManagement,
32
+ cda: endpoints.contentDelivery,
33
+ uiHost: endpoints.application,
34
+ developerHubUrl: endpoints.developerHub,
35
+ launchHubUrl: endpoints.launch,
36
+ personalizeUrl: endpoints.personalizeManagement,
37
+ composableStudioUrl: endpoints.composableStudio,
38
+ };
39
+ }
40
+ catch (error) {
41
+ return null;
42
+ }
43
+ }
44
+ /**
45
+ * Get all available regions dynamically
46
+ * This creates a regions object similar to the old hardcoded one but using @contentstack/utils
47
+ */
48
+ function getAvailableRegions() {
49
+ const regionKeys = [
50
+ 'NA',
51
+ 'AWS-NA',
52
+ 'EU',
53
+ 'AWS-EU',
54
+ 'AU',
55
+ 'AWS-AU',
56
+ 'AZURE-NA',
57
+ 'AZURE-EU',
58
+ 'GCP-NA',
59
+ 'GCP-EU',
60
+ ];
61
+ const regions = {};
62
+ for (const key of regionKeys) {
63
+ const regionObj = getRegionObject(key);
64
+ if (regionObj) {
65
+ regions[key] = regionObj;
66
+ }
67
+ }
68
+ return regions;
69
+ }
70
+ // Available region list - now dynamically generated
71
+ const regions = getAvailableRegions();
119
72
  exports.regions = regions;
120
73
  class UserConfig {
121
74
  /**
@@ -571,7 +571,6 @@
571
571
  ],
572
572
  "flags": {
573
573
  "cda": {
574
- "char": "d",
575
574
  "dependsOn": [
576
575
  "cma",
577
576
  "ui-host",
@@ -584,7 +583,6 @@
584
583
  "type": "option"
585
584
  },
586
585
  "cma": {
587
- "char": "m",
588
586
  "dependsOn": [
589
587
  "cda",
590
588
  "ui-host",
@@ -667,5 +665,5 @@
667
665
  ]
668
666
  }
669
667
  },
670
- "version": "1.18.0"
668
+ "version": "2.0.0-beta"
671
669
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli-config",
3
3
  "description": "Contentstack CLI plugin for configuration",
4
- "version": "1.18.0",
4
+ "version": "2.0.0-beta",
5
5
  "author": "Contentstack",
6
6
  "scripts": {
7
7
  "build": "npm run clean && npm run compile",
@@ -22,10 +22,11 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@contentstack/cli-command": "~1.7.2",
25
- "@contentstack/cli-utilities": "~1.17.0",
25
+ "@contentstack/cli-utilities": "~1.17.2",
26
+ "@contentstack/utils": "~1.7.0",
26
27
  "@oclif/core": "^4.3.0",
27
28
  "@oclif/plugin-help": "^6.2.28",
28
- "lodash": "^4.17.21"
29
+ "lodash": "^4.17.23"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@oclif/test": "^4.1.13",