Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
117 lines (96 loc) · 2.78 KB
/
Copy pathindex.ts
File metadata and controls
117 lines (96 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { URL } from 'url';
import * as ContentstackDeliverySDK from 'contentstack';
import { configHandler, CLIError, Command, cliux } from '@contentstack/cli-utilities';
import { Region } from './interfaces';
const defaultRateLimit = 5;
abstract class ContentstackCommand extends Command {
private _email: string;
private _region: Region;
private _rateLimit: string;
private _deliveryAPIClient: any;
get context() {
// @ts-ignore
return this.config.context || this.config.options?.context || {};
}
get email() {
if (this._email) return this._email;
this._email = configHandler.get('email');
if (this._email) return this._email;
throw new CLIError('You are not logged in. Run the command: $ csdx auth:login');
}
get deliveryAPIClient() {
if (this._deliveryAPIClient) return this._deliveryAPIClient;
this._deliveryAPIClient = ContentstackDeliverySDK;
return this._deliveryAPIClient;
}
get region() {
if (!this._region) this._region = configHandler.get('region');
if (!this._region) {
//NOTE: this.log suggestion not working
cliux.print('Error: Region not configured. Please set the region with command $ csdx config:set:region', {
color: 'red',
});
cliux.print(
`Suggestions: To set the region https://www.contentstack.com/docs/developers/cli/configure-regions-in-the-cli`,
{ color: 'yellow' },
);
process.exit(1);
}
return this._region;
}
get rateLimit() {
this._rateLimit = configHandler.get('rate-limit');
if (this._rateLimit) return this._rateLimit;
return defaultRateLimit;
}
get cmaHost() {
const cma = this.region.cma;
if (cma.startsWith('http')) {
const u = new URL(cma);
if (u.host) return u.host;
}
return cma;
}
get cdaHost() {
const cda = this.region.cda;
if (cda.startsWith('http')) {
const u = new URL(cda);
if (u.host) return u.host;
}
return cda;
}
get uiHost() {
return this.region.uiHost;
}
get cdaAPIUrl() {
const cda = this.region.cda;
return cda.startsWith('http') ? cda : `https://${cda}`;
}
get cmaAPIUrl() {
const cma = this.region.cma;
return cma.startsWith('http') ? cma : `https://${cma}`;
}
getToken(alias) {
if (alias) {
const token = configHandler.get(`tokens.${alias}`);
if (token) return token;
}
throw new CLIError('No token found');
}
get developerHubUrl() {
return this.region.developerHubUrl;
}
get launchHubUrl() {
return this.region.launchHubUrl;
}
get personalizeUrl() {
return this.region.personalizeUrl;
}
get composableStudioUrl() {
return this.region.composableStudioUrl;
}
}
module.exports = {
Command: ContentstackCommand,
};
export { ContentstackCommand as Command };