@contentstack/cli-config 1.7.3 → 1.8.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 +68 -1
- package/lib/commands/config/get/rate-limit.d.ts +6 -0
- package/lib/commands/config/get/rate-limit.js +39 -0
- package/lib/commands/config/remove/rate-limit.d.ts +8 -0
- package/lib/commands/config/remove/rate-limit.js +34 -0
- package/lib/commands/config/set/rate-limit.d.ts +8 -0
- package/lib/commands/config/set/rate-limit.js +83 -0
- package/lib/interfaces/index.d.ts +16 -0
- package/lib/utils/common-utilities.d.ts +15 -0
- package/lib/utils/common-utilities.js +9 -0
- package/lib/utils/interactive.d.ts +1 -0
- package/lib/utils/interactive.js +9 -1
- package/lib/utils/rate-limit-handler.d.ts +4 -0
- package/lib/utils/rate-limit-handler.js +69 -0
- package/oclif.manifest.json +81 -1
- package/package.json +5 -2
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.
|
|
21
|
+
@contentstack/cli-config/1.8.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
|
|
@@ -186,6 +206,26 @@ EXAMPLES
|
|
|
186
206
|
|
|
187
207
|
_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
208
|
|
|
209
|
+
## `csdx config:remove:rate-limit`
|
|
210
|
+
|
|
211
|
+
Remove rate-limit of the organization
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
USAGE
|
|
215
|
+
$ csdx config:remove:rate-limit [--org <value>]
|
|
216
|
+
|
|
217
|
+
FLAGS
|
|
218
|
+
--org=<value> Provide the organization UID
|
|
219
|
+
|
|
220
|
+
DESCRIPTION
|
|
221
|
+
Remove rate-limit of the organization
|
|
222
|
+
|
|
223
|
+
EXAMPLES
|
|
224
|
+
$ csdx config:remove:rate-limit --org <<org_uid>>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
_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)_
|
|
228
|
+
|
|
189
229
|
## `csdx config:set:base-branch`
|
|
190
230
|
|
|
191
231
|
Set branch for CLI
|
|
@@ -259,6 +299,33 @@ EXAMPLES
|
|
|
259
299
|
|
|
260
300
|
_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
301
|
|
|
302
|
+
## `csdx config:set:rate-limit`
|
|
303
|
+
|
|
304
|
+
Set rate-limit for CLI
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
USAGE
|
|
308
|
+
$ csdx config:set:rate-limit [--org <value>] [--utilize <value>] [--limit-name <value>] [--default]
|
|
309
|
+
|
|
310
|
+
FLAGS
|
|
311
|
+
--default Reset to default rate limit
|
|
312
|
+
--limit-name=<value>... [Optional] Provide the limit names separated by commas ['limit', 'getLimit', 'bulkLimit']
|
|
313
|
+
--org=<value> Provide the organization UID
|
|
314
|
+
--utilize=<value> [default: 50] Provide the utilization percentages for rate limit, separated by commas
|
|
315
|
+
|
|
316
|
+
DESCRIPTION
|
|
317
|
+
Set rate-limit for CLI
|
|
318
|
+
|
|
319
|
+
EXAMPLES
|
|
320
|
+
$ csdx config:set:rate-limit --org <<org_uid>>
|
|
321
|
+
|
|
322
|
+
$ csdx config:set:rate-limit --org <<org_uid>> --utilize 70,80 --limit-name getLimit,limit
|
|
323
|
+
|
|
324
|
+
$ csdx config:set:rate-limit --org <<org_uid>> --default
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
_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)_
|
|
328
|
+
|
|
262
329
|
## `csdx config:set:region [REGION]`
|
|
263
330
|
|
|
264
331
|
Set region for CLI
|
|
@@ -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'];
|
|
@@ -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>>'];
|
|
@@ -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
|
+
];
|
|
@@ -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>;
|
package/lib/utils/interactive.js
CHANGED
|
@@ -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,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;
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.8.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",
|
|
@@ -111,6 +126,28 @@
|
|
|
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",
|
|
@@ -172,6 +209,49 @@
|
|
|
172
209
|
},
|
|
173
210
|
"args": {}
|
|
174
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",
|
|
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
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
"args": {}
|
|
254
|
+
},
|
|
175
255
|
"config:set:region": {
|
|
176
256
|
"id": "config:set:region",
|
|
177
257
|
"description": "Set region for CLI",
|
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.
|
|
4
|
+
"version": "1.8.0",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "npm run clean && npm run compile",
|
|
@@ -81,7 +81,10 @@
|
|
|
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"
|