@contentstack/cli-config 1.7.3 → 1.9.0

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.7.3 linux-x64 node-v18.20.4
21
+ @contentstack/cli-config/1.9.0 linux-x64 node-v18.20.4
22
22
  $ csdx --help [COMMAND]
23
23
  USAGE
24
24
  $ csdx COMMAND
@@ -32,13 +32,16 @@ USAGE
32
32
  * [`csdx config:get:base-branch`](#csdx-configgetbase-branch)
33
33
  * [`csdx config:get:ea-header`](#csdx-configgetea-header)
34
34
  * [`csdx config:get:early-access-header`](#csdx-configgetearly-access-header)
35
+ * [`csdx config:get:rate-limit`](#csdx-configgetrate-limit)
35
36
  * [`csdx config:get:region`](#csdx-configgetregion)
36
37
  * [`csdx config:remove:base-branch`](#csdx-configremovebase-branch)
37
38
  * [`csdx config:remove:ea-header`](#csdx-configremoveea-header)
38
39
  * [`csdx config:remove:early-access-header`](#csdx-configremoveearly-access-header)
40
+ * [`csdx config:remove:rate-limit`](#csdx-configremoverate-limit)
39
41
  * [`csdx config:set:base-branch`](#csdx-configsetbase-branch)
40
42
  * [`csdx config:set:ea-header`](#csdx-configsetea-header)
41
43
  * [`csdx config:set:early-access-header`](#csdx-configsetearly-access-header)
44
+ * [`csdx config:set:rate-limit`](#csdx-configsetrate-limit)
42
45
  * [`csdx config:set:region [REGION]`](#csdx-configsetregion-region)
43
46
 
44
47
  ## `csdx config:get:base-branch`
@@ -96,6 +99,23 @@ EXAMPLES
96
99
 
97
100
  _See code: [src/commands/config/get/early-access-header.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/get/early-access-header.ts)_
98
101
 
102
+ ## `csdx config:get:rate-limit`
103
+
104
+ Get rate-limit of organizations
105
+
106
+ ```
107
+ USAGE
108
+ $ csdx config:get:rate-limit
109
+
110
+ DESCRIPTION
111
+ Get rate-limit of organizations
112
+
113
+ EXAMPLES
114
+ $ csdx config:get:rate-limit
115
+ ```
116
+
117
+ _See code: [src/commands/config/get/rate-limit.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/get/rate-limit.ts)_
118
+
99
119
  ## `csdx config:get:region`
100
120
 
101
121
  Get current region set for CLI
@@ -122,8 +142,8 @@ USAGE
122
142
  $ csdx config:remove:base-branch [-k <value>] [-y]
123
143
 
124
144
  FLAGS
125
- -k, --stack-api-key=<value> Stack API Key
126
- -y, --yes Force Remove
145
+ -k, --stack-api-key=<value> Stack API key.
146
+ -y, --yes Force remove.
127
147
 
128
148
  DESCRIPTION
129
149
  Remove branch config for CLI
@@ -145,8 +165,9 @@ USAGE
145
165
  $ csdx config:remove:ea-header [--header-alias <value>] [-y]
146
166
 
147
167
  FLAGS
148
- -y, --yes Force Remove
149
- --header-alias=<value> Early access header alias
168
+ -y, --yes (optional) Force the removal of Early Access header configuration by skipping the
169
+ confirmation.
170
+ --header-alias=<value> (optional) Provide the Early Access header alias name.
150
171
 
151
172
  DESCRIPTION
152
173
  Remove Early Access header
@@ -169,8 +190,9 @@ USAGE
169
190
  $ csdx config:remove:early-access-header [--header-alias <value>] [-y]
170
191
 
171
192
  FLAGS
172
- -y, --yes Force Remove
173
- --header-alias=<value> Early access header alias
193
+ -y, --yes (optional) Force the removal of Early Access header configuration by skipping the
194
+ confirmation.
195
+ --header-alias=<value> (optional) Provide the Early Access header alias name.
174
196
 
175
197
  DESCRIPTION
176
198
  Remove Early Access header
@@ -186,6 +208,26 @@ EXAMPLES
186
208
 
187
209
  _See code: [src/commands/config/remove/early-access-header.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/remove/early-access-header.ts)_
188
210
 
211
+ ## `csdx config:remove:rate-limit`
212
+
213
+ Remove rate-limit of the organization
214
+
215
+ ```
216
+ USAGE
217
+ $ csdx config:remove:rate-limit [--org <value>]
218
+
219
+ FLAGS
220
+ --org=<value> Provide the organization UID
221
+
222
+ DESCRIPTION
223
+ Remove rate-limit of the organization
224
+
225
+ EXAMPLES
226
+ $ csdx config:remove:rate-limit --org <<org_uid>>
227
+ ```
228
+
229
+ _See code: [src/commands/config/remove/rate-limit.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/remove/rate-limit.ts)_
230
+
189
231
  ## `csdx config:set:base-branch`
190
232
 
191
233
  Set branch for CLI
@@ -195,8 +237,8 @@ USAGE
195
237
  $ csdx config:set:base-branch [-k <value>] [--base-branch <value>]
196
238
 
197
239
  FLAGS
198
- -k, --stack-api-key=<value> Stack API Key
199
- --base-branch=<value> Base Branch
240
+ -k, --stack-api-key=<value> Stack API key
241
+ --base-branch=<value> Base branch (Target branch).
200
242
 
201
243
  DESCRIPTION
202
244
  Set branch for CLI
@@ -218,8 +260,8 @@ USAGE
218
260
  $ csdx config:set:ea-header [--header-alias <value>] [--header <value>]
219
261
 
220
262
  FLAGS
221
- --header=<value> Early access header value
222
- --header-alias=<value> Early access header alias
263
+ --header=<value> (optional) Provide the Early Access header alias name.
264
+ --header-alias=<value> (optional) Provide the Early Access header value.
223
265
 
224
266
  DESCRIPTION
225
267
  Set Early Access header
@@ -242,8 +284,8 @@ USAGE
242
284
  $ csdx config:set:early-access-header [--header-alias <value>] [--header <value>]
243
285
 
244
286
  FLAGS
245
- --header=<value> Early access header value
246
- --header-alias=<value> Early access header alias
287
+ --header=<value> (optional) Provide the Early Access header alias name.
288
+ --header-alias=<value> (optional) Provide the Early Access header value.
247
289
 
248
290
  DESCRIPTION
249
291
  Set Early Access header
@@ -259,6 +301,33 @@ EXAMPLES
259
301
 
260
302
  _See code: [src/commands/config/set/early-access-header.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/set/early-access-header.ts)_
261
303
 
304
+ ## `csdx config:set:rate-limit`
305
+
306
+ Set rate-limit for CLI
307
+
308
+ ```
309
+ USAGE
310
+ $ csdx config:set:rate-limit [--org <value>] [--utilize <value>] [--limit-name <value>] [--default]
311
+
312
+ FLAGS
313
+ --default Reset to default rate limit
314
+ --limit-name=<value>... [Optional] Provide the limit names separated by commas ['limit', 'getLimit', 'bulkLimit']
315
+ --org=<value> Provide the organization UID
316
+ --utilize=<value> [default: 50] Provide the utilization percentages for rate limit, separated by commas
317
+
318
+ DESCRIPTION
319
+ Set rate-limit for CLI
320
+
321
+ EXAMPLES
322
+ $ csdx config:set:rate-limit --org <<org_uid>>
323
+
324
+ $ csdx config:set:rate-limit --org <<org_uid>> --utilize 70,80 --limit-name getLimit,limit
325
+
326
+ $ csdx config:set:rate-limit --org <<org_uid>> --default
327
+ ```
328
+
329
+ _See code: [src/commands/config/set/rate-limit.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/set/rate-limit.ts)_
330
+
262
331
  ## `csdx config:set:region [REGION]`
263
332
 
264
333
  Set region for CLI
@@ -299,15 +368,15 @@ EXAMPLES
299
368
 
300
369
  $ csdx config:set:region GCP-NA
301
370
 
302
- $ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India"
371
+ $ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India"
303
372
 
304
- $ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --developer-hub <developer_hub_url>
373
+ $ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --developer-hub <custom_developer_hub_url>
305
374
 
306
- $ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --personalize <personalize_url>
375
+ $ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --personalize <custom_personalize_url>
307
376
 
308
- $ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --launch <launch_url>
377
+ $ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --launch <custom_launch_url>
309
378
 
310
- $ csdx config:set:region --cda <contentstack_cda_endpoint> --cma <contentstack_cma_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --developer-hub <developer_hub_url> --personalize <personalize_url> --launch <launch_url>
379
+ $ csdx config:set:region --cda <custom_cda_host_url> --cma <custom_cma_host_url> --ui-host <custom_ui_host_url> --name "India" --developer-hub <custom_developer_hub_url> --launch <custom_launch_url> --personalize <custom_personalize_url>
311
380
  ```
312
381
 
313
382
  _See code: [src/commands/config/set/region.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/set/region.ts)_
@@ -0,0 +1,6 @@
1
+ import { Command } from '@contentstack/cli-command';
2
+ export default class RateLimitGetCommand extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ run(): Promise<void>;
6
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
4
+ const cli_command_1 = require("@contentstack/cli-command");
5
+ class RateLimitGetCommand extends cli_command_1.Command {
6
+ async run() {
7
+ try {
8
+ const rateLimit = cli_utilities_1.configHandler.get('rateLimit') || {};
9
+ const formatLimit = (limit) => (limit ? `${limit.value}(${limit.utilize}%)` : '0');
10
+ const tableData = Object.entries(rateLimit).map(([org, limits]) => ({
11
+ Org: org === 'default' ? 'default' : org,
12
+ 'Get Limit': formatLimit(limits.getLimit),
13
+ Limit: formatLimit(limits.limit),
14
+ 'Bulk Limit': formatLimit(limits.bulkLimit),
15
+ }));
16
+ const columns = {
17
+ Org: {
18
+ minWidth: 10,
19
+ },
20
+ 'Get Limit': {
21
+ minWidth: 20,
22
+ },
23
+ Limit: {
24
+ minWidth: 20,
25
+ },
26
+ 'Bulk Limit': {
27
+ minWidth: 20,
28
+ },
29
+ };
30
+ cli_utilities_1.cliux.table(tableData, columns, { printLine: cli_utilities_1.cliux.print });
31
+ }
32
+ catch (error) {
33
+ this.log('Unable to retrieve the rate limits configuration', error instanceof Error ? error.message : error);
34
+ }
35
+ }
36
+ }
37
+ exports.default = RateLimitGetCommand;
38
+ RateLimitGetCommand.description = 'Get rate-limit of organizations';
39
+ RateLimitGetCommand.examples = ['$ csdx config:get:rate-limit'];
@@ -43,7 +43,7 @@ class RemoveBranchConfigCommand extends cli_command_1.Command {
43
43
  exports.default = RemoveBranchConfigCommand;
44
44
  RemoveBranchConfigCommand.description = 'Remove branch config for CLI';
45
45
  RemoveBranchConfigCommand.flags = {
46
- 'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Stack API Key' }),
47
- yes: cli_utilities_1.flags.boolean({ char: 'y', description: 'Force Remove' }),
46
+ 'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Stack API key.' }),
47
+ yes: cli_utilities_1.flags.boolean({ char: 'y', description: 'Force remove.' }),
48
48
  };
49
49
  RemoveBranchConfigCommand.examples = ['$ csdx config:remove:base-branch', '$ csdx config:remove:base-branch --stack-api-key <value>'];
@@ -32,8 +32,8 @@ exports.default = RemoveEarlyAccessHeader;
32
32
  RemoveEarlyAccessHeader.description = 'Remove Early Access header';
33
33
  RemoveEarlyAccessHeader.aliases = ['config:remove:ea-header'];
34
34
  RemoveEarlyAccessHeader.flags = {
35
- 'header-alias': cli_utilities_1.flags.string({ description: 'Early access header alias' }),
36
- yes: cli_utilities_1.flags.boolean({ char: 'y', description: 'Force Remove' }),
35
+ 'header-alias': cli_utilities_1.flags.string({ description: '(optional) Provide the Early Access header alias name.' }),
36
+ yes: cli_utilities_1.flags.boolean({ char: 'y', description: '(optional) Force the removal of Early Access header configuration by skipping the confirmation.' }),
37
37
  };
38
38
  RemoveEarlyAccessHeader.examples = [
39
39
  '$ <%= config.bin %> <%= command.id %>',
@@ -0,0 +1,8 @@
1
+ import { FlagInput } from '@contentstack/cli-utilities';
2
+ import { Command } from '@contentstack/cli-command';
3
+ export default class RateLimitRemoveCommand extends Command {
4
+ static description: string;
5
+ static flags: FlagInput;
6
+ static examples: string[];
7
+ run(): Promise<void>;
8
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
4
+ const cli_command_1 = require("@contentstack/cli-command");
5
+ const interactive_1 = require("../../../utils/interactive");
6
+ class RateLimitRemoveCommand extends cli_command_1.Command {
7
+ async run() {
8
+ try {
9
+ const { flags } = await this.parse(RateLimitRemoveCommand);
10
+ let { org } = flags;
11
+ if (!org) {
12
+ org = await (0, interactive_1.askOrgID)();
13
+ }
14
+ const rateLimit = cli_utilities_1.configHandler.get('rateLimit') || {};
15
+ if (!rateLimit[org]) {
16
+ cli_utilities_1.cliux.print(`No rate limit found for the organization UID: ${org}`, { color: 'red' });
17
+ return;
18
+ }
19
+ cli_utilities_1.configHandler.delete(`rateLimit.${org}`);
20
+ cli_utilities_1.cliux.print(`Rate limit entry for organization UID ${org} has been removed.`, { color: 'green' });
21
+ }
22
+ catch (error) {
23
+ this.log('Unable to remove the rate limit entry', error instanceof Error ? error.message : error);
24
+ }
25
+ }
26
+ }
27
+ exports.default = RateLimitRemoveCommand;
28
+ RateLimitRemoveCommand.description = 'Remove rate-limit of the organization';
29
+ RateLimitRemoveCommand.flags = {
30
+ org: cli_utilities_1.flags.string({
31
+ description: 'Provide the organization UID',
32
+ }),
33
+ };
34
+ RateLimitRemoveCommand.examples = ['$ csdx config:remove:rate-limit --org <<org_uid>>'];
@@ -28,8 +28,8 @@ class BranchSetCommand extends cli_command_1.Command {
28
28
  exports.default = BranchSetCommand;
29
29
  BranchSetCommand.description = 'Set branch for CLI';
30
30
  BranchSetCommand.flags = {
31
- 'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Stack API Key' }),
32
- 'base-branch': cli_utilities_1.flags.string({ description: 'Base Branch' }),
31
+ 'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Stack API key' }),
32
+ 'base-branch': cli_utilities_1.flags.string({ description: 'Base branch (Target branch).' }),
33
33
  };
34
34
  BranchSetCommand.examples = [
35
35
  '$ csdx config:set:base-branch',
@@ -26,8 +26,8 @@ exports.default = SetEarlyAccessHeaderCommand;
26
26
  SetEarlyAccessHeaderCommand.description = 'Set Early Access header';
27
27
  SetEarlyAccessHeaderCommand.aliases = ['config:set:ea-header'];
28
28
  SetEarlyAccessHeaderCommand.flags = {
29
- 'header-alias': cli_utilities_1.flags.string({ description: 'Early access header alias' }),
30
- header: cli_utilities_1.flags.string({ description: 'Early access header value' }),
29
+ 'header-alias': cli_utilities_1.flags.string({ description: '(optional) Provide the Early Access header value.' }),
30
+ header: cli_utilities_1.flags.string({ description: '(optional) Provide the Early Access header alias name.' }),
31
31
  };
32
32
  SetEarlyAccessHeaderCommand.examples = [
33
33
  '$ <%= config.bin %> <%= command.id %>',
@@ -0,0 +1,8 @@
1
+ import { FlagInput } from '@contentstack/cli-utilities';
2
+ import { BaseCommand } from '../../../base-command';
3
+ export default class SetRateLimitCommand extends BaseCommand<typeof SetRateLimitCommand> {
4
+ static description: string;
5
+ static flags: FlagInput;
6
+ static examples: string[];
7
+ run(): Promise<void>;
8
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
4
+ const rate_limit_handler_1 = require("../../../utils/rate-limit-handler");
5
+ const base_command_1 = require("../../../base-command");
6
+ const interactive_1 = require("../../../utils/interactive");
7
+ const common_utilities_1 = require("../../../utils/common-utilities");
8
+ class SetRateLimitCommand extends base_command_1.BaseCommand {
9
+ async run() {
10
+ var _a, _b, _c;
11
+ if (!(0, cli_utilities_1.isAuthenticated)()) {
12
+ const err = { errorMessage: 'You are not logged in. Please login with command $ csdx auth:login' };
13
+ cli_utilities_1.cliux.print(err.errorMessage, { color: 'red' });
14
+ this.exit(1);
15
+ }
16
+ const { flags } = await this.parse(SetRateLimitCommand);
17
+ let { org, utilize, 'limit-name': limitName } = flags;
18
+ const config = { org: '', limitName: common_utilities_1.limitNamesConfig, host: this.cmaHost };
19
+ if (!org) {
20
+ org = await (0, interactive_1.askOrgID)();
21
+ }
22
+ config.org = org;
23
+ config.default = flags.default;
24
+ if (utilize) {
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
+ if (utilizeValues.some((u) => isNaN(u) || u < 0 || u > 100)) {
27
+ cli_utilities_1.cliux.error('Utilize percentages must be numbers between 0 and 100.');
28
+ return;
29
+ }
30
+ 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
+ cli_utilities_1.cliux.error('The number of utilization percentages must match the number of limit names provided.');
32
+ return;
33
+ }
34
+ else {
35
+ config.utilize = utilize.split(',').map((v) => v.trim());
36
+ }
37
+ }
38
+ if (limitName) {
39
+ const invalidLimitNames = limitName[0].split(',').map((name) => name.trim());
40
+ if (invalidLimitNames.some((name) => !common_utilities_1.limitNamesConfig.includes(name))) {
41
+ cli_utilities_1.cliux.error(`Invalid limit names provided: ${invalidLimitNames.join(', ')}`);
42
+ return;
43
+ }
44
+ else {
45
+ config['limit-name'] = limitName[0].split(',').map((n) => n.trim());
46
+ }
47
+ }
48
+ const limitHandler = new rate_limit_handler_1.RateLimitHandler();
49
+ const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(config);
50
+ limitHandler.setClient(managementAPIClient);
51
+ try {
52
+ await limitHandler.setRateLimit(config);
53
+ }
54
+ catch (error) {
55
+ cli_utilities_1.cliux.error(`Error: Something went wrong while setting rate limit for org: ${org}`);
56
+ cli_utilities_1.cliux.error(error);
57
+ }
58
+ }
59
+ }
60
+ exports.default = SetRateLimitCommand;
61
+ SetRateLimitCommand.description = 'Set rate-limit for CLI';
62
+ SetRateLimitCommand.flags = {
63
+ org: cli_utilities_1.flags.string({
64
+ description: 'Provide the organization UID',
65
+ }),
66
+ utilize: cli_utilities_1.flags.string({
67
+ description: 'Provide the utilization percentages for rate limit, separated by commas',
68
+ default: '50',
69
+ }),
70
+ 'limit-name': cli_utilities_1.flags.string({
71
+ description: "[Optional] Provide the limit names separated by commas ['limit', 'getLimit', 'bulkLimit']",
72
+ multiple: true,
73
+ }),
74
+ default: cli_utilities_1.flags.boolean({
75
+ default: false,
76
+ description: 'Reset to default rate limit',
77
+ }),
78
+ };
79
+ SetRateLimitCommand.examples = [
80
+ '$ csdx config:set:rate-limit --org <<org_uid>>',
81
+ '$ csdx config:set:rate-limit --org <<org_uid>> --utilize 70,80 --limit-name getLimit,limit',
82
+ '$ csdx config:set:rate-limit --org <<org_uid>> --default',
83
+ ];
@@ -121,11 +121,11 @@ RegionSetCommand.examples = [
121
121
  '$ csdx config:set:region AZURE-NA',
122
122
  '$ csdx config:set:region AZURE-EU',
123
123
  '$ csdx config:set:region GCP-NA',
124
- '$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India"',
125
- '$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --developer-hub <developer_hub_url>',
126
- '$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --personalize <personalize_url>',
127
- '$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --launch <launch_url>',
128
- '$ csdx config:set:region --cda <contentstack_cda_endpoint> --cma <contentstack_cma_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --developer-hub <developer_hub_url> --personalize <personalize_url> --launch <launch_url>',
124
+ '$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India"',
125
+ '$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --developer-hub <custom_developer_hub_url>',
126
+ '$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --personalize <custom_personalize_url>',
127
+ '$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --launch <custom_launch_url>',
128
+ '$ csdx config:set:region --cda <custom_cda_host_url> --cma <custom_cma_host_url> --ui-host <custom_ui_host_url> --name "India" --developer-hub <custom_developer_hub_url> --launch <custom_launch_url> --personalize <custom_personalize_url>',
129
129
  ];
130
130
  RegionSetCommand.args = {
131
131
  region: cli_utilities_1.args.string({ description: 'Name for the region' }),
@@ -17,3 +17,19 @@ export interface Region {
17
17
  personalizeUrl: string;
18
18
  launchHubUrl: string;
19
19
  }
20
+ export interface Limit {
21
+ value: number;
22
+ utilize: number;
23
+ }
24
+ export interface RateLimitConfig {
25
+ getLimit?: Limit;
26
+ limit?: Limit;
27
+ bulkLimit?: Limit;
28
+ }
29
+ export interface SetRateLimitConfig {
30
+ org: string;
31
+ utilize?: number;
32
+ limitName?: string[];
33
+ default?: boolean;
34
+ host?: string;
35
+ }
@@ -0,0 +1,15 @@
1
+ export declare const limitNamesConfig: string[];
2
+ export declare const defaultRalteLimitConfig: {
3
+ getLimit: {
4
+ value: number;
5
+ utilize: number;
6
+ };
7
+ limit: {
8
+ value: number;
9
+ utilize: number;
10
+ };
11
+ bulkLimit: {
12
+ value: number;
13
+ utilize: number;
14
+ };
15
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultRalteLimitConfig = exports.limitNamesConfig = void 0;
4
+ exports.limitNamesConfig = ['getLimit', 'limit', 'bulkLimit'];
5
+ exports.defaultRalteLimitConfig = {
6
+ getLimit: { value: 10, utilize: 50 },
7
+ limit: { value: 10, utilize: 50 },
8
+ bulkLimit: { value: 1, utilize: 50 },
9
+ };
@@ -6,3 +6,4 @@ export declare function askConfirmation(): Promise<boolean>;
6
6
  export declare function inquireRequireFieldValidation(input: string): string | boolean;
7
7
  export declare function askEarlyAccessHeaderValue(): Promise<string>;
8
8
  export declare function askEarlyAccessHeaderAlias(): Promise<string>;
9
+ export declare const askOrgID: () => Promise<string>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.askEarlyAccessHeaderAlias = exports.askEarlyAccessHeaderValue = exports.inquireRequireFieldValidation = exports.askConfirmation = exports.askBaseBranch = exports.askStackAPIKey = exports.askCustomRegion = exports.askRegions = void 0;
3
+ exports.askOrgID = exports.askEarlyAccessHeaderAlias = exports.askEarlyAccessHeaderValue = exports.inquireRequireFieldValidation = exports.askConfirmation = exports.askBaseBranch = exports.askStackAPIKey = exports.askCustomRegion = exports.askRegions = void 0;
4
4
  const cli_utilities_1 = require("@contentstack/cli-utilities");
5
5
  const askRegions = async () => {
6
6
  return cli_utilities_1.cliux.inquire({
@@ -94,3 +94,11 @@ async function askEarlyAccessHeaderAlias() {
94
94
  });
95
95
  }
96
96
  exports.askEarlyAccessHeaderAlias = askEarlyAccessHeaderAlias;
97
+ const askOrgID = async () => {
98
+ return cli_utilities_1.cliux.inquire({
99
+ type: 'input',
100
+ message: 'Provide the organization UID',
101
+ name: 'org',
102
+ });
103
+ };
104
+ exports.askOrgID = askOrgID;
@@ -0,0 +1,4 @@
1
+ export declare class RateLimitHandler {
2
+ setClient(managementSDKClient: any): void;
3
+ setRateLimit(config: any): Promise<void>;
4
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RateLimitHandler = void 0;
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
5
+ const common_utilities_1 = require("../utils/common-utilities");
6
+ let client;
7
+ class RateLimitHandler {
8
+ setClient(managementSDKClient) {
9
+ client = managementSDKClient;
10
+ }
11
+ async setRateLimit(config) {
12
+ var _a;
13
+ const rateLimit = cli_utilities_1.configHandler.get('rateLimit');
14
+ rateLimit.default = Object.assign({}, common_utilities_1.defaultRalteLimitConfig);
15
+ if (config.default) {
16
+ rateLimit[config.org] = Object.assign({}, rateLimit.default);
17
+ cli_utilities_1.configHandler.set('rateLimit', rateLimit);
18
+ cli_utilities_1.cliux.success(`Rate limit reset to default for org: ${config.org}`);
19
+ return;
20
+ }
21
+ if (!rateLimit[config.org]) {
22
+ rateLimit[config.org] = Object.assign({}, rateLimit.default);
23
+ }
24
+ const limitNames = Array.isArray(config['limit-name']) ? config['limit-name'] : [];
25
+ const utilizeValues = Array.isArray(config.utilize) ? config.utilize.map((v) => Number(v)) : [];
26
+ const unavailableLimits = [];
27
+ try {
28
+ const organizations = await client.organization(config.org).fetch({ include_plan: true });
29
+ const features = ((_a = organizations.plan) === null || _a === void 0 ? void 0 : _a.features) || [];
30
+ const limitsToUpdate = Object.assign({}, rateLimit[config.org]);
31
+ let utilizationMap = {};
32
+ limitNames.forEach((name, index) => {
33
+ if (utilizeValues[index] !== undefined) {
34
+ utilizationMap[name] = utilizeValues[index];
35
+ }
36
+ });
37
+ common_utilities_1.limitNamesConfig.forEach((limitName) => {
38
+ var _a, _b, _c;
39
+ const feature = features.find((f) => f.uid === limitName);
40
+ if (feature) {
41
+ limitsToUpdate[limitName] = {
42
+ value: feature.limit || ((_a = rateLimit[config.org][limitName]) === null || _a === void 0 ? void 0 : _a.value) || ((_b = rateLimit.default[limitName]) === null || _b === void 0 ? void 0 : _b.value),
43
+ utilize: utilizationMap[limitName] || ((_c = common_utilities_1.defaultRalteLimitConfig[limitName]) === null || _c === void 0 ? void 0 : _c.utilize),
44
+ };
45
+ }
46
+ else {
47
+ unavailableLimits.push(limitName);
48
+ }
49
+ });
50
+ if (unavailableLimits.length > 0) {
51
+ cli_utilities_1.cliux.print(`You have not subscribed to these limits: ${unavailableLimits.join(', ')}`, {
52
+ color: 'yellow',
53
+ });
54
+ }
55
+ rateLimit[config.org] = limitsToUpdate;
56
+ cli_utilities_1.configHandler.set('rateLimit', rateLimit);
57
+ cli_utilities_1.cliux.success(`Rate limit has been set successfully for org: ${config.org}`);
58
+ Object.entries(limitsToUpdate).forEach(([limit, { value, utilize }]) => {
59
+ if (!unavailableLimits.includes(limit)) {
60
+ cli_utilities_1.cliux.success(`${limit}: ${value}(${utilize}%)`);
61
+ }
62
+ });
63
+ }
64
+ catch (error) {
65
+ throw new Error(error);
66
+ }
67
+ }
68
+ }
69
+ exports.RateLimitHandler = RateLimitHandler;
@@ -56,7 +56,7 @@ const regions = {
56
56
  uiHost: 'https://gcp-na-app.contentstack.com',
57
57
  name: 'GCP-NA',
58
58
  'developerHubUrl': 'https://gcp-na-developerhub-api.contentstack.com',
59
- 'launchHubUrl': 'Not available',
59
+ 'launchHubUrl': 'https://gcp-na-launch-api.contentstack.com',
60
60
  'personalizeUrl': 'https://gcp-na-personalize-api.contentstack.com',
61
61
  },
62
62
  };
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.3",
2
+ "version": "1.9.0",
3
3
  "commands": {
4
4
  "config:get:base-branch": {
5
5
  "id": "config:get:base-branch",
@@ -33,6 +33,21 @@
33
33
  "flags": {},
34
34
  "args": {}
35
35
  },
36
+ "config:get:rate-limit": {
37
+ "id": "config:get:rate-limit",
38
+ "description": "Get rate-limit of organizations",
39
+ "strict": true,
40
+ "pluginName": "@contentstack/cli-config",
41
+ "pluginAlias": "@contentstack/cli-config",
42
+ "pluginType": "core",
43
+ "aliases": [],
44
+ "hiddenAliases": [],
45
+ "examples": [
46
+ "$ csdx config:get:rate-limit"
47
+ ],
48
+ "flags": {},
49
+ "args": {}
50
+ },
36
51
  "config:get:region": {
37
52
  "id": "config:get:region",
38
53
  "description": "Get current region set for CLI",
@@ -66,14 +81,14 @@
66
81
  "name": "stack-api-key",
67
82
  "type": "option",
68
83
  "char": "k",
69
- "description": "Stack API Key",
84
+ "description": "Stack API key.",
70
85
  "multiple": false
71
86
  },
72
87
  "yes": {
73
88
  "name": "yes",
74
89
  "type": "boolean",
75
90
  "char": "y",
76
- "description": "Force Remove",
91
+ "description": "Force remove.",
77
92
  "allowNo": false
78
93
  }
79
94
  },
@@ -98,19 +113,41 @@
98
113
  "header-alias": {
99
114
  "name": "header-alias",
100
115
  "type": "option",
101
- "description": "Early access header alias",
116
+ "description": "(optional) Provide the Early Access header alias name.",
102
117
  "multiple": false
103
118
  },
104
119
  "yes": {
105
120
  "name": "yes",
106
121
  "type": "boolean",
107
122
  "char": "y",
108
- "description": "Force Remove",
123
+ "description": "(optional) Force the removal of Early Access header configuration by skipping the confirmation.",
109
124
  "allowNo": false
110
125
  }
111
126
  },
112
127
  "args": {}
113
128
  },
129
+ "config:remove:rate-limit": {
130
+ "id": "config:remove:rate-limit",
131
+ "description": "Remove rate-limit of the organization",
132
+ "strict": true,
133
+ "pluginName": "@contentstack/cli-config",
134
+ "pluginAlias": "@contentstack/cli-config",
135
+ "pluginType": "core",
136
+ "aliases": [],
137
+ "hiddenAliases": [],
138
+ "examples": [
139
+ "$ csdx config:remove:rate-limit --org <<org_uid>>"
140
+ ],
141
+ "flags": {
142
+ "org": {
143
+ "name": "org",
144
+ "type": "option",
145
+ "description": "Provide the organization UID",
146
+ "multiple": false
147
+ }
148
+ },
149
+ "args": {}
150
+ },
114
151
  "config:set:base-branch": {
115
152
  "id": "config:set:base-branch",
116
153
  "description": "Set branch for CLI",
@@ -129,13 +166,13 @@
129
166
  "name": "stack-api-key",
130
167
  "type": "option",
131
168
  "char": "k",
132
- "description": "Stack API Key",
169
+ "description": "Stack API key",
133
170
  "multiple": false
134
171
  },
135
172
  "base-branch": {
136
173
  "name": "base-branch",
137
174
  "type": "option",
138
- "description": "Base Branch",
175
+ "description": "Base branch (Target branch).",
139
176
  "multiple": false
140
177
  }
141
178
  },
@@ -160,14 +197,57 @@
160
197
  "header-alias": {
161
198
  "name": "header-alias",
162
199
  "type": "option",
163
- "description": "Early access header alias",
200
+ "description": "(optional) Provide the Early Access header value.",
164
201
  "multiple": false
165
202
  },
166
203
  "header": {
167
204
  "name": "header",
168
205
  "type": "option",
169
- "description": "Early access header value",
206
+ "description": "(optional) Provide the Early Access header alias name.",
207
+ "multiple": false
208
+ }
209
+ },
210
+ "args": {}
211
+ },
212
+ "config:set:rate-limit": {
213
+ "id": "config:set:rate-limit",
214
+ "description": "Set rate-limit for CLI",
215
+ "strict": true,
216
+ "pluginName": "@contentstack/cli-config",
217
+ "pluginAlias": "@contentstack/cli-config",
218
+ "pluginType": "core",
219
+ "aliases": [],
220
+ "hiddenAliases": [],
221
+ "examples": [
222
+ "$ csdx config:set:rate-limit --org <<org_uid>>",
223
+ "$ csdx config:set:rate-limit --org <<org_uid>> --utilize 70,80 --limit-name getLimit,limit",
224
+ "$ csdx config:set:rate-limit --org <<org_uid>> --default"
225
+ ],
226
+ "flags": {
227
+ "org": {
228
+ "name": "org",
229
+ "type": "option",
230
+ "description": "Provide the organization UID",
170
231
  "multiple": false
232
+ },
233
+ "utilize": {
234
+ "name": "utilize",
235
+ "type": "option",
236
+ "description": "Provide the utilization percentages for rate limit, separated by commas",
237
+ "multiple": false,
238
+ "default": "50"
239
+ },
240
+ "limit-name": {
241
+ "name": "limit-name",
242
+ "type": "option",
243
+ "description": "[Optional] Provide the limit names separated by commas ['limit', 'getLimit', 'bulkLimit']",
244
+ "multiple": true
245
+ },
246
+ "default": {
247
+ "name": "default",
248
+ "type": "boolean",
249
+ "description": "Reset to default rate limit",
250
+ "allowNo": false
171
251
  }
172
252
  },
173
253
  "args": {}
@@ -188,11 +268,11 @@
188
268
  "$ csdx config:set:region AZURE-NA",
189
269
  "$ csdx config:set:region AZURE-EU",
190
270
  "$ csdx config:set:region GCP-NA",
191
- "$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name \"India\"",
192
- "$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name \"India\" --developer-hub <developer_hub_url>",
193
- "$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name \"India\" --personalize <personalize_url>",
194
- "$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name \"India\" --launch <launch_url>",
195
- "$ csdx config:set:region --cda <contentstack_cda_endpoint> --cma <contentstack_cma_endpoint> --ui-host <contentstack_ui_host_endpoint> --name \"India\" --developer-hub <developer_hub_url> --personalize <personalize_url> --launch <launch_url>"
271
+ "$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name \"India\"",
272
+ "$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name \"India\" --developer-hub <custom_developer_hub_url>",
273
+ "$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name \"India\" --personalize <custom_personalize_url>",
274
+ "$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name \"India\" --launch <custom_launch_url>",
275
+ "$ csdx config:set:region --cda <custom_cda_host_url> --cma <custom_cma_host_url> --ui-host <custom_ui_host_url> --name \"India\" --developer-hub <custom_developer_hub_url> --launch <custom_launch_url> --personalize <custom_personalize_url>"
196
276
  ],
197
277
  "flags": {
198
278
  "cda": {
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.7.3",
4
+ "version": "1.9.0",
5
5
  "author": "Contentstack",
6
6
  "scripts": {
7
7
  "build": "npm run clean && npm run compile",
@@ -23,34 +23,34 @@
23
23
  "dependencies": {
24
24
  "@contentstack/cli-command": "~1.3.2",
25
25
  "@contentstack/cli-utilities": "~1.8.0",
26
- "chalk": "^4.0.0",
27
- "debug": "^4.1.1",
28
- "inquirer": "8.2.4",
29
- "lodash": "^4.17.20",
26
+ "chalk": "^4.1.2",
27
+ "debug": "^4.3.7",
28
+ "inquirer": "8.2.6",
29
+ "lodash": "^4.17.21",
30
30
  "mkdirp": "^1.0.4",
31
- "winston": "^3.7.2"
31
+ "winston": "^3.17.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@oclif/test": "^2.5.6",
35
- "@types/chai": "^4.2.18",
36
- "@types/inquirer": "^9.0.3",
37
- "@types/mkdirp": "^1.0.1",
38
- "@types/mocha": "^8.2.2",
39
- "@types/node": "^14.14.32",
40
- "@types/sinon": "^10.0.2",
41
- "chai": "^4.3.4",
42
- "eslint": "^8.18.0",
34
+ "@oclif/test": "^4.1.0",
35
+ "@types/chai": "^4.3.20",
36
+ "@types/inquirer": "^9.0.7",
37
+ "@types/mkdirp": "^1.0.2",
38
+ "@types/mocha": "^8.2.3",
39
+ "@types/node": "^14.18.63",
40
+ "@types/sinon": "^10.0.20",
41
+ "chai": "^4.5.0",
42
+ "eslint": "^8.57.1",
43
43
  "eslint-config-oclif": "^4.0.0",
44
- "eslint-config-oclif-typescript": "^3.0.8",
44
+ "eslint-config-oclif-typescript": "^3.1.12",
45
45
  "globby": "^10.0.2",
46
- "mocha": "10.1.0",
46
+ "mocha": "10.8.2",
47
47
  "nyc": "^15.1.0",
48
- "oclif": "^3.8.1",
48
+ "oclif": "^3.17.2",
49
49
  "rimraf": "^2.7.1",
50
- "sinon": "^19.0.0",
51
- "tmp": "^0.2.2",
52
- "ts-node": "^10.9.1",
53
- "typescript": "^4.9.3"
50
+ "sinon": "^19.0.2",
51
+ "tmp": "^0.2.3",
52
+ "ts-node": "^10.9.2",
53
+ "typescript": "^4.9.5"
54
54
  },
55
55
  "engines": {
56
56
  "node": ">=14.0.0"
@@ -81,8 +81,11 @@
81
81
  "config:get:region": "RGT",
82
82
  "config:set:region": "RST",
83
83
  "config:get:base-branch": "BRGT",
84
- "config:set:base-branch": "BRST"
84
+ "config:set:base-branch": "BRST",
85
+ "config:set:rate-limit": "RLST",
86
+ "config:get:rate-limit": "RLGT",
87
+ "config:remove:rate-limit": "RLRM"
85
88
  }
86
89
  },
87
90
  "repository": "contentstack/cli"
88
- }
91
+ }