@contentstack/cli-command 0.1.1-beta.6 → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Contentstack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,70 @@
1
- @contentstack/cli-command
2
- ===================
1
+ @contentstack/cli-auth
2
+ ===
3
+
4
+ It is Contentstack’s CLI plugin to perform authentication-related activities. To get started with authenticating yourself with the CLI, refer to the [CLI’s Authentication documentation](https://www.contentstack.com/docs/developers/cli/authentication)
3
5
 
4
6
  [![License](https://img.shields.io/npm/l/@contentstack/cli)](https://github.com/contentstack/cli/blob/main/LICENSE)
5
7
 
6
- Base class for Contentstack CLI commands. Built off of [oclif](https://oclif.io). To get started with Contentstack CLI, refer to the [CLI documentation](https://www.contentstack.com/docs/developers/cli/).
8
+ <!-- toc -->
9
+ * [Usage](#usage)
10
+ * [Commands](#commands)
11
+ <!-- tocstop -->
12
+ # Usage
13
+ <!-- usage -->
14
+ ```sh-session
15
+ $ npm install -g @contentstack/cli-command-test
16
+ $ csdx COMMAND
17
+ running command...
18
+ $ csdx (-v|--version|version)
19
+ @contentstack/cli-command-test/0.1.1-beta.1 linux-x64 node-v12.22.1
20
+ $ csdx --help [COMMAND]
21
+ USAGE
22
+ $ csdx COMMAND
23
+ ...
24
+ ```
25
+ <!-- usagestop -->
26
+ # Commands
27
+ <!-- commands -->
28
+ * [`csdx config:get:region`](#csdx-configgetregion)
29
+ * [`csdx config:set:region`](#csdx-configsetregion)
30
+
31
+ ## `csdx config:get:region`
32
+
33
+ Set region for CLI
34
+
35
+ ```
36
+ USAGE
37
+ $ csdx config:get:region
38
+
39
+ EXAMPLE
40
+ $ csdx config:get:region
41
+ ```
42
+
43
+ _See code: [src/commands/config/get/region.ts](https://github.com/contentstack/cli/blob/v0.1.1-beta.1/src/commands/config/get/region.ts)_
44
+
45
+ ## `csdx config:set:region`
46
+
47
+ Set region for CLI
48
+
49
+ ```
50
+ USAGE
51
+ $ csdx config:set:region
52
+
53
+ OPTIONS
54
+ -d, --cda=cda Custom host to set for content delivery API, if this flag is added then cma and name flags are
55
+ required
56
+
57
+ -m, --cma=cma Custom host to set for content management API, , if this flag is added then cda and name flags are
58
+ required
59
+
60
+ -n, --name=name Name for the region, if this flag is added then cda and cma flags are required
61
+
62
+ EXAMPLES
63
+ $ csdx config:set:region EU
64
+ $ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --name "India"
65
+ $ csdx config:set:region --cma="https://in-api.contentstack.com" --cda="https://in-cda.contentstack.com"
66
+ --name="India"
67
+ ```
68
+
69
+ _See code: [src/commands/config/set/region.ts](https://github.com/contentstack/cli/blob/v0.1.1-beta.1/src/commands/config/set/region.ts)_
70
+ <!-- commandsstop -->
package/lib/index.js ADDED
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flags = exports.Command = void 0;
4
+ const command_1 = require("@oclif/command");
5
+ Object.defineProperty(exports, "flags", { enumerable: true, get: function () { return command_1.flags; } });
6
+ const ContentstackManagementSDK = require("@contentstack/management");
7
+ const ContentstackDeliverySDK = require("contentstack");
8
+ const url = require("url");
9
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
10
+ const defaultRateLimit = 5;
11
+ class ContentstackCommand extends command_1.Command {
12
+ get context() {
13
+ // @ts-ignore
14
+ return this.config.context;
15
+ }
16
+ get managementAPIClient() {
17
+ if (this._managementAPIClient)
18
+ return this._managementAPIClient;
19
+ this._managementAPIClient = ContentstackManagementSDK.client({ host: this.cmaHost });
20
+ return this._managementAPIClient;
21
+ }
22
+ set managementAPIClient(params) {
23
+ this._managementAPIClient = ContentstackManagementSDK.client(params);
24
+ }
25
+ get email() {
26
+ if (this._email)
27
+ return this._email;
28
+ this._email = cli_utilities_1.configHandler.get('email');
29
+ if (this._email)
30
+ return this._email;
31
+ throw new cli_utilities_1.CLIError('You are not logged in. Please login with command $ csdx auth:login');
32
+ }
33
+ get deliveryAPIClient() {
34
+ if (this._deliveryAPIClient)
35
+ return this._deliveryAPIClient;
36
+ this._deliveryAPIClient = ContentstackDeliverySDK;
37
+ return this._deliveryAPIClient;
38
+ }
39
+ get region() {
40
+ if (this._region)
41
+ return this._region;
42
+ this._region = cli_utilities_1.configHandler.get('region');
43
+ if (this._region)
44
+ return this._region;
45
+ }
46
+ get rateLimit() {
47
+ this._rateLimit = cli_utilities_1.configHandler.get('rate-limit');
48
+ if (this._rateLimit)
49
+ return this._rateLimit;
50
+ return defaultRateLimit;
51
+ }
52
+ get cmaHost() {
53
+ let cma = this.region.cma;
54
+ if (cma.startsWith('http')) {
55
+ const u = url.parse(cma);
56
+ if (u.host)
57
+ return u.host;
58
+ }
59
+ return cma;
60
+ }
61
+ get cdaHost() {
62
+ let cda = this.region.cda;
63
+ if (cda.startsWith('http')) {
64
+ const u = url.parse(cda);
65
+ if (u.host)
66
+ return u.host;
67
+ }
68
+ return cda;
69
+ }
70
+ get cdaAPIUrl() {
71
+ let cda = this.region.cda;
72
+ return cda.startsWith('http') ? cda : `https://${cda}`;
73
+ }
74
+ get cmaAPIUrl() {
75
+ let cma = this.region.cma;
76
+ return cma.startsWith('http') ? cma : `https://${cma}`;
77
+ }
78
+ get authToken() {
79
+ if (this._authToken)
80
+ return this._authToken;
81
+ this._authToken = cli_utilities_1.configHandler.get('authtoken');
82
+ if (this._authToken)
83
+ return this._authToken;
84
+ throw new cli_utilities_1.CLIError('You are not logged in. Please login with command $ csdx auth:login');
85
+ }
86
+ getToken(alias) {
87
+ if (alias) {
88
+ const token = cli_utilities_1.configHandler.get(`tokens.${alias}`);
89
+ if (token)
90
+ return token;
91
+ }
92
+ throw new cli_utilities_1.CLIError('No token found');
93
+ }
94
+ }
95
+ exports.Command = ContentstackCommand;
96
+ module.exports = {
97
+ Command: ContentstackCommand,
98
+ flags: command_1.flags,
99
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,30 +1,66 @@
1
1
  {
2
2
  "name": "@contentstack/cli-command",
3
- "version": "0.1.1-beta.6",
4
- "description": "Base class for Contentstack command",
5
- "main": "./src/index.js",
3
+ "description": "Contentstack CLI plugin for configuration",
4
+ "version": "1.0.0",
6
5
  "author": "Contentstack",
6
+ "main": "lib/index.js",
7
+ "types": "./types/index.d.ts",
7
8
  "scripts": {
8
- "test": "nyc mocha --forbid-only \\\"test/**/*.test.js\\\""
9
+ "prepack": "npm run clean && npm run compile",
10
+ "clean": "rm -rf ./lib && rm -rf tsconfig.build.tsbuildinfo",
11
+ "compile": "tsc -b tsconfig.json",
12
+ "test:report": "tsc -p test && nyc --reporter=lcov --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
13
+ "pretest": "tsc -p test",
14
+ "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
15
+ "posttest": "npm run lint",
16
+ "lint": "eslint src/**/*.ts",
17
+ "format": "eslint src/**/*.ts --fix"
9
18
  },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/contentstack/cli.git"
13
- },
14
- "files": [
15
- "/src"
16
- ],
17
- "license": "MIT",
18
- "bugs": "https://github.com/contentstack/cli/issues",
19
- "homepage": "https://github.com/contentstack/cli#readme",
20
19
  "dependencies": {
20
+ "@contentstack/cli-utilities": "^1.0.0",
21
21
  "@contentstack/management": "^1.3.0",
22
- "@oclif/command": "^1.8.0",
23
- "@oclif/config": "^1.17.0",
24
- "configstore": "^5.0.1",
22
+ "@oclif/command": "^1.8.16",
25
23
  "contentstack": "^3.10.1"
26
24
  },
25
+ "devDependencies": {
26
+ "@oclif/plugin-help": "^5.1.12",
27
+ "@oclif/test": "^1.2.8",
28
+ "@types/chai": "^4.2.18",
29
+ "@types/mkdirp": "^1.0.1",
30
+ "@types/mocha": "^8.2.2",
31
+ "@types/node": "^14.14.32",
32
+ "@types/sinon": "^10.0.2",
33
+ "@types/tar": "^4.0.3",
34
+ "chai": "^4.3.4",
35
+ "eslint": "^8.18.0",
36
+ "eslint-config-oclif": "^3.1.0",
37
+ "eslint-config-oclif-typescript": "^0.1.0",
38
+ "mocha": "^9.2.2",
39
+ "nyc": "^15.1.0",
40
+ "rimraf": "^2.7.1",
41
+ "sinon": "^11.1.1",
42
+ "ts-node": "^8.10.2",
43
+ "typescript": "^4.7.4"
44
+ },
27
45
  "engines": {
28
46
  "node": ">=8.0.0"
29
- }
30
- }
47
+ },
48
+ "files": [
49
+ "/lib",
50
+ "/npm-shrinkwrap.json",
51
+ "/oclif.manifest.json"
52
+ ],
53
+ "homepage": "https://github.com/contentstack/cli",
54
+ "keywords": [
55
+ "contentstack",
56
+ "cli",
57
+ "plugin"
58
+ ],
59
+ "license": "MIT",
60
+ "husky": {
61
+ "hooks": {
62
+ "pre-commit": "npm run lint"
63
+ }
64
+ },
65
+ "repository": "contentstack/cli"
66
+ }
@@ -1,23 +0,0 @@
1
- class TokenNotFound extends Error {
2
- constructor(value) {
3
- super()
4
- this.value = value
5
- this.message = 'Token not found'
6
- this.toString = function () {
7
- return this.value + this.message
8
- }
9
- }
10
- }
11
-
12
- class NotLoggedIn extends Error {
13
- constructor() {
14
- super()
15
- this.message = 'You are not logged in. Please login with command $ csdx auth:login'
16
- this.toString = function () {
17
- return this.message
18
- }
19
- }
20
- }
21
-
22
- module.exports.TokenNotFound = TokenNotFound
23
- module.exports.NotLoggedIn = NotLoggedIn
package/src/index.js DELETED
@@ -1,101 +0,0 @@
1
- const {Command, flags} = require('@oclif/command')
2
- const ContentstackManagementSDK = require('@contentstack/management')
3
- const ContentstackDeliverySDK = require('contentstack')
4
- const {TokenNotFound, NotLoggedIn} = require('./custom-errors')
5
- const Configstore = require('configstore')
6
- const config = new Configstore('contentstack_cli')
7
- const url = require('url')
8
- const defaultRegion = {cma: 'https://api.contentstack.io', cda: 'https://cdn.contentstack.io', name: 'NA'}
9
- const defaultRateLimit = 5
10
-
11
-
12
- class ContentstackCommand extends Command {
13
-
14
- get managementAPIClient() {
15
- if (this._managementAPIClient) return this._managementAPIClient
16
- this._managementAPIClient = ContentstackManagementSDK.client({host:this.cmaHost})
17
- return this._managementAPIClient
18
- }
19
-
20
- set managementAPIClient(params) {
21
- if(params && params.host) {
22
- //can not set host explicitly as CLI runs under constant host coming from config
23
- params.host = this.cmaHost
24
- }
25
- this._managementAPIClient = ContentstackManagementSDK.client(params)
26
- }
27
-
28
- get email() {
29
- if (this._email) return this._email
30
- this._email = config.get('email')
31
- if(this._email) return this._email
32
- throw new NotLoggedIn()
33
- }
34
-
35
- get deliveryAPIClient() {
36
- if (this._deliveryAPIClient) return this._deliveryAPIClient
37
- this._deliveryAPIClient = ContentstackDeliverySDK
38
- return this._deliveryAPIClient
39
- }
40
-
41
- get region() {
42
- if (this._region) return this._region
43
- this._region = config.get('region')
44
- if (this._region) return this._region
45
- // return defaultRegion
46
- }
47
-
48
- get rateLimit() {
49
- this._rateLimit = config.get('rate-limit')
50
- if (this._rateLimit) return this._rateLimit
51
- return defaultRateLimit
52
- }
53
-
54
- get cmaHost() {
55
- let cma = this.region.cma
56
- if (cma.startsWith('http')) {
57
- const u = url.parse(cma)
58
- if (u.host) return u.host
59
- }
60
- return cma
61
- }
62
-
63
- get cdaHost() {
64
- let cda = this.region.cda
65
- if (cda.startsWith('http')) {
66
- const u = url.parse(cda)
67
- if (u.host) return u.host
68
- }
69
- return cda
70
- }
71
-
72
- get cdaAPIUrl() {
73
- let cda = this.region.cda
74
- return cda.startsWith('http') ? cda : `https://${cda}`
75
- }
76
-
77
- get cmaAPIUrl() {
78
- let cma = this.region.cma
79
- return cma.startsWith('http') ? cma : `https://${cma}`
80
- }
81
-
82
- get authToken() {
83
- if (this._authToken) return this._authToken
84
- this._authToken = config.get('authtoken')
85
- if (this._authToken) return this._authToken
86
- throw new NotLoggedIn()
87
- }
88
-
89
- getToken(alias) {
90
- if (alias) {
91
- const token = config.get(`tokens.${alias}`)
92
- if (token) return token
93
- }
94
- throw new TokenNotFound(alias)
95
- }
96
- }
97
-
98
- module.exports = {
99
- Command: ContentstackCommand,
100
- flags
101
- }