@contentstack/cli-command 0.1.1-beta.2 → 0.1.1-beta.3
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/package.json +5 -4
- package/src/custom-errors.js +0 -23
- package/src/index.js +0 -103
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-command",
|
|
3
|
-
"version": "0.1.1-beta.
|
|
3
|
+
"version": "0.1.1-beta.3",
|
|
4
4
|
"description": "Base class for Contentstack command",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"author": "Contentstack",
|
|
@@ -10,16 +10,17 @@
|
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "git+https://github.com/contentstack/cli.git"
|
|
13
|
-
},
|
|
13
|
+
},
|
|
14
14
|
"files": [
|
|
15
|
-
"src"
|
|
15
|
+
"./src"
|
|
16
16
|
],
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
19
19
|
"homepage": "https://github.com/contentstack/cli#readme",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@contentstack/management": "^1.
|
|
21
|
+
"@contentstack/management": "^1.3.0",
|
|
22
22
|
"@oclif/command": "^1.8.0",
|
|
23
|
+
"@oclif/config": "^1.17.0",
|
|
23
24
|
"configstore": "^5.0.1",
|
|
24
25
|
"contentstack": "^3.10.1"
|
|
25
26
|
},
|
package/src/custom-errors.js
DELETED
|
@@ -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,103 +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
|
-
} else {
|
|
25
|
-
params.host = this.cmaHost
|
|
26
|
-
}
|
|
27
|
-
this._managementAPIClient = ContentstackManagementSDK.client(params)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get email() {
|
|
31
|
-
if (this._email) return this._email
|
|
32
|
-
this._email = config.get('email')
|
|
33
|
-
if(this._email) return this._email
|
|
34
|
-
throw new NotLoggedIn()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get deliveryAPIClient() {
|
|
38
|
-
if (this._deliveryAPIClient) return this._deliveryAPIClient
|
|
39
|
-
this._deliveryAPIClient = ContentstackDeliverySDK
|
|
40
|
-
return this._deliveryAPIClient
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get region() {
|
|
44
|
-
if (this._region) return this._region
|
|
45
|
-
this._region = config.get('region')
|
|
46
|
-
if (this._region) return this._region
|
|
47
|
-
// return defaultRegion
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get rateLimit() {
|
|
51
|
-
this._rateLimit = config.get('rate-limit')
|
|
52
|
-
if (this._rateLimit) return this._rateLimit
|
|
53
|
-
return defaultRateLimit
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get cmaHost() {
|
|
57
|
-
let cma = this.region.cma
|
|
58
|
-
if (cma.startsWith('http')) {
|
|
59
|
-
const u = url.parse(cma)
|
|
60
|
-
if (u.host) return u.host
|
|
61
|
-
}
|
|
62
|
-
return cma
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get cdaHost() {
|
|
66
|
-
let cda = this.region.cda
|
|
67
|
-
if (cda.startsWith('http')) {
|
|
68
|
-
const u = url.parse(cda)
|
|
69
|
-
if (u.host) return u.host
|
|
70
|
-
}
|
|
71
|
-
return cda
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
get cdaAPIUrl() {
|
|
75
|
-
let cda = this.region.cda
|
|
76
|
-
return cda.startsWith('http') ? cda : `https://${cda}`
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
get cmaAPIUrl() {
|
|
80
|
-
let cma = this.region.cma
|
|
81
|
-
return cma.startsWith('http') ? cma : `https://${cma}`
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
get authToken() {
|
|
85
|
-
if (this._authToken) return this._authToken
|
|
86
|
-
this._authToken = config.get('authtoken')
|
|
87
|
-
if (this._authToken) return this._authToken
|
|
88
|
-
throw new NotLoggedIn()
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
getToken(alias) {
|
|
92
|
-
if (alias) {
|
|
93
|
-
const token = config.get(`tokens.${alias}`)
|
|
94
|
-
if (token) return token
|
|
95
|
-
}
|
|
96
|
-
throw new TokenNotFound(alias)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
module.exports = {
|
|
101
|
-
Command: ContentstackCommand,
|
|
102
|
-
flags
|
|
103
|
-
}
|