@contentstack/cli-utilities 0.1.1-beta.1
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/.eslintignore +2 -0
- package/.eslintrc +40 -0
- package/.mocharc.json +12 -0
- package/.nycrc.json +5 -0
- package/LICENSE +21 -0
- package/lib/cli-error.js +16 -0
- package/lib/cli-ux.js +59 -0
- package/lib/config-handler.js +128 -0
- package/lib/flag-deprecation-check.js +40 -0
- package/lib/http-client/client.js +313 -0
- package/lib/http-client/http-response.js +46 -0
- package/lib/http-client/index.js +7 -0
- package/lib/index.js +17 -0
- package/lib/interfaces/index.js +2 -0
- package/lib/logger.js +92 -0
- package/lib/message-handler.js +43 -0
- package/lib/selectors/index.js +376 -0
- package/lib/selectors/interfaces.js +2 -0
- package/lib/selectors/validations.js +9 -0
- package/messages/auth.json +46 -0
- package/messages/config.json +9 -0
- package/messages/core.json +6 -0
- package/package.json +68 -0
- package/src/cli-error.ts +15 -0
- package/src/cli-ux.ts +78 -0
- package/src/config-handler.ts +142 -0
- package/src/flag-deprecation-check.ts +41 -0
- package/src/http-client/client.ts +369 -0
- package/src/http-client/http-response.ts +55 -0
- package/src/http-client/index.ts +7 -0
- package/src/index.ts +7 -0
- package/src/interfaces/index.ts +61 -0
- package/src/logger.ts +101 -0
- package/src/message-handler.ts +45 -0
- package/src/selectors/index.ts +381 -0
- package/src/selectors/interfaces.ts +39 -0
- package/src/selectors/validations.ts +5 -0
- package/test/helpers/init.js +4 -0
- package/test/tsconfig.json +6 -0
- package/tsconfig.json +20 -0
- package/types/cli-error.d.ts +4 -0
- package/types/cli-ux.d.ts +22 -0
- package/types/config-handler.d.ts +17 -0
- package/types/flag-deprecation-check.d.ts +7 -0
- package/types/http-client.d.ts +54 -0
- package/types/index.d.ts +7 -0
- package/types/interfaces/index.d.ts +50 -0
- package/types/logger.d.ts +17 -0
- package/types/message-handler.d.ts +12 -0
- package/types/selectors/index.d.ts +12 -0
- package/types/selectors/interfaces.d.ts +32 -0
- package/types/selectors/validations.d.ts +1 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printFlagDeprecation = exports.configHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.logger = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var logger_1 = require("./logger");
|
|
6
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return tslib_1.__importDefault(logger_1).default; } });
|
|
7
|
+
var cli_ux_1 = require("./cli-ux");
|
|
8
|
+
Object.defineProperty(exports, "cliux", { enumerable: true, get: function () { return tslib_1.__importDefault(cli_ux_1).default; } });
|
|
9
|
+
var cli_error_1 = require("./cli-error");
|
|
10
|
+
Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return tslib_1.__importDefault(cli_error_1).default; } });
|
|
11
|
+
var message_handler_1 = require("./message-handler");
|
|
12
|
+
Object.defineProperty(exports, "messageHandler", { enumerable: true, get: function () { return tslib_1.__importDefault(message_handler_1).default; } });
|
|
13
|
+
var config_handler_1 = require("./config-handler");
|
|
14
|
+
Object.defineProperty(exports, "configHandler", { enumerable: true, get: function () { return tslib_1.__importDefault(config_handler_1).default; } });
|
|
15
|
+
var flag_deprecation_check_1 = require("./flag-deprecation-check");
|
|
16
|
+
Object.defineProperty(exports, "printFlagDeprecation", { enumerable: true, get: function () { return tslib_1.__importDefault(flag_deprecation_check_1).default; } });
|
|
17
|
+
tslib_1.__exportStar(require("./http-client"), exports);
|
package/lib/logger.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const winston_1 = tslib_1.__importDefault(require("winston"));
|
|
5
|
+
const message_handler_1 = tslib_1.__importDefault(require("./message-handler"));
|
|
6
|
+
class LoggerService {
|
|
7
|
+
constructor(name) {
|
|
8
|
+
this.data = null;
|
|
9
|
+
this.name = null;
|
|
10
|
+
const logger = winston_1.default.createLogger({
|
|
11
|
+
transports: [
|
|
12
|
+
// new winston.transports.Console(),
|
|
13
|
+
new winston_1.default.transports.File({
|
|
14
|
+
filename: `./logs/${name}.log`,
|
|
15
|
+
}),
|
|
16
|
+
],
|
|
17
|
+
format: winston_1.default.format.combine(winston_1.default.format.colorize(), winston_1.default.format.printf((info) => {
|
|
18
|
+
let stringifiedParam;
|
|
19
|
+
try {
|
|
20
|
+
stringifiedParam = JSON.stringify(info.obj);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.log('warning: failed to log the result');
|
|
24
|
+
}
|
|
25
|
+
// parse message
|
|
26
|
+
info.message = message_handler_1.default.parse(info.message);
|
|
27
|
+
let message = `${LoggerService.dateFormat()}:${name}:${info.level}:${info.message}`;
|
|
28
|
+
message = info.obj ? message + `:${stringifiedParam}` : message;
|
|
29
|
+
message = this.data ? message + `:${JSON.stringify(this.data)}` : message;
|
|
30
|
+
return message;
|
|
31
|
+
})),
|
|
32
|
+
// level: (config.get('logger.level') as string) || 'error',
|
|
33
|
+
level: 'error',
|
|
34
|
+
silent: true
|
|
35
|
+
// silent: config.get('logger.enabled') && process.env.CLI_ENV !== 'TEST' ? false : false,
|
|
36
|
+
});
|
|
37
|
+
this.logger = logger;
|
|
38
|
+
}
|
|
39
|
+
static dateFormat() {
|
|
40
|
+
return new Date(Date.now()).toUTCString();
|
|
41
|
+
}
|
|
42
|
+
init(context) {
|
|
43
|
+
this.name = (context && context.plugin && context.plugin.name) || 'cli';
|
|
44
|
+
}
|
|
45
|
+
set loggerName(name) {
|
|
46
|
+
this.name = name;
|
|
47
|
+
}
|
|
48
|
+
setLogData(data) {
|
|
49
|
+
this.data = data;
|
|
50
|
+
}
|
|
51
|
+
async info(message, param) {
|
|
52
|
+
if (param) {
|
|
53
|
+
this.logger.log('info', message, {
|
|
54
|
+
obj: param,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.logger.log('info', message);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async debug(message, param) {
|
|
62
|
+
if (param) {
|
|
63
|
+
this.logger.log('debug', message, {
|
|
64
|
+
obj: param,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.logger.log('debug', message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async error(message, param) {
|
|
72
|
+
if (param) {
|
|
73
|
+
this.logger.log('error', message, {
|
|
74
|
+
obj: param,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.logger.log('error', message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async warn(message, param) {
|
|
82
|
+
if (param) {
|
|
83
|
+
this.logger.log('warn', message, {
|
|
84
|
+
obj: param,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.logger.log('warn', message);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.default = new LoggerService('cli');
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
5
|
+
const cli_error_1 = tslib_1.__importDefault(require("./cli-error"));
|
|
6
|
+
/**
|
|
7
|
+
* Message handler
|
|
8
|
+
*/
|
|
9
|
+
class Messages {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.messages = {};
|
|
12
|
+
}
|
|
13
|
+
init(context) {
|
|
14
|
+
if (!context.messageFilePath) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
this.messages = JSON.parse(fs_1.default.readFileSync(context.messageFilePath, 'utf-8'));
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
// create empty messages object if message file is not exist
|
|
22
|
+
if (error.code === 'ENOENT') {
|
|
23
|
+
this.messages = {};
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new cli_error_1.default(error.message);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
parse(messageKey, ...substitutions) {
|
|
31
|
+
const msg = this.messages[messageKey];
|
|
32
|
+
if (!msg) {
|
|
33
|
+
return messageKey;
|
|
34
|
+
}
|
|
35
|
+
if (substitutions.length > 0) {
|
|
36
|
+
const callSite = msg.split('%s');
|
|
37
|
+
callSite.push('');
|
|
38
|
+
return String.raw({ raw: callSite }, ...substitutions);
|
|
39
|
+
}
|
|
40
|
+
return msg;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.default = new Messages();
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chooseDeliveryTokenAlias = exports.chooseTokenAlias = exports.chooseLocale = exports.chooseLocales = exports.chooseEnvironment = exports.chooseEnvironments = exports.chooseContentTypes = exports.chooseEntry = exports.chooseContentType = exports.chooseStack = exports.chooseOrganization = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ora_1 = tslib_1.__importDefault(require("ora"));
|
|
6
|
+
const config_handler_1 = tslib_1.__importDefault(require("../config-handler"));
|
|
7
|
+
const validations_1 = require("./validations");
|
|
8
|
+
const inquirer = require('inquirer');
|
|
9
|
+
inquirer.registerPrompt('search-list', require('inquirer-search-list'));
|
|
10
|
+
inquirer.registerPrompt('search-checkbox', require('inquirer-search-checkbox'));
|
|
11
|
+
const { Command } = require('@contentstack/cli-command');
|
|
12
|
+
function chooseOrganization(client, displayMessage, region, orgUid) {
|
|
13
|
+
return new Promise(async (resolve, reject) => {
|
|
14
|
+
try {
|
|
15
|
+
const spinner = (0, ora_1.default)('Loading Organizations').start();
|
|
16
|
+
let { items: organizations } = await client.organization().fetchAll();
|
|
17
|
+
spinner.stop();
|
|
18
|
+
let orgMap = {};
|
|
19
|
+
if (orgUid) {
|
|
20
|
+
organizations.forEach((org) => {
|
|
21
|
+
orgMap[org.uid] = org.name;
|
|
22
|
+
});
|
|
23
|
+
if (orgMap[orgUid]) {
|
|
24
|
+
resolve({ orgUid: orgUid, orgName: orgMap[orgUid] });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return reject(new Error('The given orgUid doesn\'t exist or you might not have access to it.'));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
organizations.forEach((org) => {
|
|
32
|
+
orgMap[org.name] = org.uid;
|
|
33
|
+
});
|
|
34
|
+
const orgList = Object.keys(orgMap);
|
|
35
|
+
let inquirerConfig = {
|
|
36
|
+
type: 'search-list',
|
|
37
|
+
name: 'chosenOrganization',
|
|
38
|
+
message: displayMessage || 'Choose an organization',
|
|
39
|
+
choices: orgList,
|
|
40
|
+
loop: false,
|
|
41
|
+
validate: validations_1.shouldNotBeEmpty
|
|
42
|
+
};
|
|
43
|
+
inquirer.prompt(inquirerConfig).then(({ chosenOrganization }) => {
|
|
44
|
+
resolve({ orgUid: orgMap[chosenOrganization], orgName: chosenOrganization });
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
reject(error);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.chooseOrganization = chooseOrganization;
|
|
54
|
+
function chooseStack(client, organizationId, displayMessage, region) {
|
|
55
|
+
return new Promise(async (resolve, reject) => {
|
|
56
|
+
try {
|
|
57
|
+
const spinner = (0, ora_1.default)('Loading Stacks').start();
|
|
58
|
+
let { items: stacks } = await client.stack({ organization_uid: organizationId }).query({ query: {} }).find();
|
|
59
|
+
spinner.stop();
|
|
60
|
+
let stackMap = {};
|
|
61
|
+
stacks.forEach((stack) => {
|
|
62
|
+
stackMap[stack.name] = stack.api_key;
|
|
63
|
+
});
|
|
64
|
+
const stackList = Object.keys(stackMap);
|
|
65
|
+
let inquirerConfig = {
|
|
66
|
+
type: 'search-list',
|
|
67
|
+
name: 'chosenStack',
|
|
68
|
+
choices: stackList,
|
|
69
|
+
message: displayMessage || 'Choose a stack',
|
|
70
|
+
loop: false,
|
|
71
|
+
};
|
|
72
|
+
inquirer.prompt(inquirerConfig).then(({ chosenStack }) => {
|
|
73
|
+
resolve({ api_key: stackMap[chosenStack], name: chosenStack });
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error(error.message);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.chooseStack = chooseStack;
|
|
82
|
+
function chooseContentType(stackApiKey, displayMessage, region) {
|
|
83
|
+
return new Promise(async (resolve, reject) => {
|
|
84
|
+
const command = new Command();
|
|
85
|
+
command.managementAPIClient = { host: command.cmaHost, authtoken: command.authToken };
|
|
86
|
+
const client = command.managementAPIClient;
|
|
87
|
+
try {
|
|
88
|
+
const spinner = (0, ora_1.default)('Loading Content Types').start();
|
|
89
|
+
// let {items: contentTypes} = await client.stack({api_key: stackApiKey}).contentType().query({include_count: true}).find()
|
|
90
|
+
let contentTypes = await getAll(client.stack({ api_key: stackApiKey }).contentType());
|
|
91
|
+
spinner.stop();
|
|
92
|
+
let contentTypeMap = {};
|
|
93
|
+
contentTypes.forEach((contentType) => {
|
|
94
|
+
contentTypeMap[contentType.title] = contentType.uid;
|
|
95
|
+
});
|
|
96
|
+
const contentTypeList = Object.keys(contentTypeMap);
|
|
97
|
+
let inquirerConfig = {
|
|
98
|
+
type: 'search-list',
|
|
99
|
+
name: 'chosenContentType',
|
|
100
|
+
choices: contentTypeList,
|
|
101
|
+
message: displayMessage || 'Choose a content type',
|
|
102
|
+
loop: false,
|
|
103
|
+
};
|
|
104
|
+
inquirer.prompt(inquirerConfig).then(({ chosenContentType }) => {
|
|
105
|
+
resolve({ uid: contentTypeMap[chosenContentType], title: chosenContentType });
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error(error.message);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
exports.chooseContentType = chooseContentType;
|
|
114
|
+
function chooseEntry(contentTypeUid, stackApiKey, displayMessage, region) {
|
|
115
|
+
return new Promise(async (resolve, reject) => {
|
|
116
|
+
const command = new Command();
|
|
117
|
+
command.managementAPIClient = { host: command.cmaHost, authtoken: command.authToken };
|
|
118
|
+
const client = command.managementAPIClient;
|
|
119
|
+
try {
|
|
120
|
+
const spinner = (0, ora_1.default)('Loading Entries').start();
|
|
121
|
+
let entries = await getAll(client.stack({ api_key: stackApiKey }).contentType(contentTypeUid).entry());
|
|
122
|
+
spinner.stop();
|
|
123
|
+
let entryMap = {};
|
|
124
|
+
entries.forEach((entry) => {
|
|
125
|
+
entryMap[entry.title] = entry.uid;
|
|
126
|
+
});
|
|
127
|
+
const entryList = Object.keys(entryMap);
|
|
128
|
+
let inquirerConfig = {
|
|
129
|
+
type: 'search-list',
|
|
130
|
+
name: 'chosenEntry',
|
|
131
|
+
choices: entryList,
|
|
132
|
+
message: displayMessage || 'Choose an entry',
|
|
133
|
+
loop: false
|
|
134
|
+
};
|
|
135
|
+
inquirer.prompt(inquirerConfig).then(({ chosenEntry }) => {
|
|
136
|
+
resolve({ uid: entryMap[chosenEntry], title: chosenEntry });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error(error.message);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
exports.chooseEntry = chooseEntry;
|
|
145
|
+
function chooseContentTypes(stack, displayMessage) {
|
|
146
|
+
return new Promise(async (resolve, reject) => {
|
|
147
|
+
try {
|
|
148
|
+
const spinner = (0, ora_1.default)('Loading Content Types').start();
|
|
149
|
+
// let {items: contentTypes} = await client.stack({api_key: stackApiKey}).contentType().query({include_count: true}).find()
|
|
150
|
+
let contentTypes = await getAll(stack.contentType());
|
|
151
|
+
spinner.stop();
|
|
152
|
+
let contentTypeMap = {};
|
|
153
|
+
contentTypes.forEach((contentType) => {
|
|
154
|
+
contentTypeMap[contentType.title] = contentType.uid;
|
|
155
|
+
});
|
|
156
|
+
const contentTypeList = Object.keys(contentTypeMap);
|
|
157
|
+
let inquirerConfig = {
|
|
158
|
+
type: 'search-checkbox',
|
|
159
|
+
name: 'chosenContentTypes',
|
|
160
|
+
choices: contentTypeList,
|
|
161
|
+
message: displayMessage || 'Choose a content type',
|
|
162
|
+
loop: false,
|
|
163
|
+
};
|
|
164
|
+
inquirer.prompt(inquirerConfig).then(({ chosenContentTypes }) => {
|
|
165
|
+
let result = chosenContentTypes.map(ct => {
|
|
166
|
+
let foo = { uid: contentTypeMap[ct], title: ct };
|
|
167
|
+
return foo;
|
|
168
|
+
});
|
|
169
|
+
resolve(result);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error(error.message);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
exports.chooseContentTypes = chooseContentTypes;
|
|
178
|
+
function chooseEnvironments(stack, displayMessage) {
|
|
179
|
+
return new Promise(async (resolve, reject) => {
|
|
180
|
+
try {
|
|
181
|
+
const spinner = (0, ora_1.default)('Loading Environments').start();
|
|
182
|
+
// let {items: contentTypes} = await client.stack({api_key: stackApiKey}).contentType().query({include_count: true}).find()
|
|
183
|
+
let environments = await getAll(stack.environment());
|
|
184
|
+
spinner.stop();
|
|
185
|
+
let environmentMap = {};
|
|
186
|
+
environments.forEach((environment) => {
|
|
187
|
+
environmentMap[environment.name] = environment.uid;
|
|
188
|
+
});
|
|
189
|
+
const environmentList = Object.keys(environmentMap);
|
|
190
|
+
let inquirerConfig = {
|
|
191
|
+
type: 'search-checkbox',
|
|
192
|
+
name: 'chosenEnvironments',
|
|
193
|
+
choices: environmentList,
|
|
194
|
+
message: displayMessage || 'Choose an environment',
|
|
195
|
+
loop: false,
|
|
196
|
+
validate: validations_1.shouldNotBeEmpty
|
|
197
|
+
};
|
|
198
|
+
inquirer.prompt(inquirerConfig).then(({ chosenEnvironments }) => {
|
|
199
|
+
let result = chosenEnvironments.map(env => {
|
|
200
|
+
let foo = { uid: environmentMap[env], name: env };
|
|
201
|
+
return foo;
|
|
202
|
+
});
|
|
203
|
+
resolve(result);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
console.error(error.message);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
exports.chooseEnvironments = chooseEnvironments;
|
|
212
|
+
function chooseEnvironment(stack, displayMessage) {
|
|
213
|
+
return new Promise(async (resolve, reject) => {
|
|
214
|
+
try {
|
|
215
|
+
const spinner = (0, ora_1.default)('Loading Environments').start();
|
|
216
|
+
// let {items: contentTypes} = await client.stack({api_key: stackApiKey}).contentType().query({include_count: true}).find()
|
|
217
|
+
let environments = await getAll(stack.environment());
|
|
218
|
+
spinner.stop();
|
|
219
|
+
let environmentMap = {};
|
|
220
|
+
environments.forEach((environment) => {
|
|
221
|
+
environmentMap[environment.name] = environment.uid;
|
|
222
|
+
});
|
|
223
|
+
const environmentList = Object.keys(environmentMap);
|
|
224
|
+
let inquirerConfig = {
|
|
225
|
+
type: 'search-list',
|
|
226
|
+
name: 'chosenEnvironment',
|
|
227
|
+
choices: environmentList,
|
|
228
|
+
message: displayMessage || 'Choose an environment',
|
|
229
|
+
loop: false,
|
|
230
|
+
validate: validations_1.shouldNotBeEmpty
|
|
231
|
+
};
|
|
232
|
+
inquirer.prompt(inquirerConfig).then(({ chosenEnvironment }) => {
|
|
233
|
+
let result = { uid: environmentMap[chosenEnvironment], name: chosenEnvironment };
|
|
234
|
+
resolve(result);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
console.error(error.message);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
exports.chooseEnvironment = chooseEnvironment;
|
|
243
|
+
function chooseLocales(stack, displayMessage) {
|
|
244
|
+
return new Promise(async (resolve, reject) => {
|
|
245
|
+
try {
|
|
246
|
+
const spinner = (0, ora_1.default)('Loading Locales').start();
|
|
247
|
+
// let {items: contentTypes} = await client.stack({api_key: stackApiKey}).contentType().query({include_count: true}).find()
|
|
248
|
+
let locales = await getAll(stack.locale());
|
|
249
|
+
spinner.stop();
|
|
250
|
+
let localeMap = {};
|
|
251
|
+
locales.forEach((locale) => {
|
|
252
|
+
localeMap[locale.name] = locale.code;
|
|
253
|
+
});
|
|
254
|
+
const localeList = Object.keys(localeMap);
|
|
255
|
+
let inquirerConfig = {
|
|
256
|
+
type: 'search-checkbox',
|
|
257
|
+
name: 'chosenLocales',
|
|
258
|
+
choices: localeList,
|
|
259
|
+
message: displayMessage || 'Choose locales',
|
|
260
|
+
loop: false,
|
|
261
|
+
validate: validations_1.shouldNotBeEmpty,
|
|
262
|
+
};
|
|
263
|
+
inquirer.prompt(inquirerConfig).then(({ chosenLocales }) => {
|
|
264
|
+
let result = chosenLocales.map(locale => {
|
|
265
|
+
let foo = { code: localeMap[locale], name: locale };
|
|
266
|
+
return foo;
|
|
267
|
+
});
|
|
268
|
+
resolve(result);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
console.error(error.message);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
exports.chooseLocales = chooseLocales;
|
|
277
|
+
function chooseLocale(stack, displayMessage) {
|
|
278
|
+
return new Promise(async (resolve, reject) => {
|
|
279
|
+
try {
|
|
280
|
+
const spinner = (0, ora_1.default)('Loading Locales').start();
|
|
281
|
+
// let {items: contentTypes} = await client.stack({api_key: stackApiKey}).contentType().query({include_count: true}).find()
|
|
282
|
+
let locales = await getAll(stack.locale());
|
|
283
|
+
spinner.stop();
|
|
284
|
+
let localeMap = {};
|
|
285
|
+
locales.forEach((locale) => {
|
|
286
|
+
localeMap[locale.name] = locale.code;
|
|
287
|
+
});
|
|
288
|
+
const localeList = Object.keys(localeMap);
|
|
289
|
+
let inquirerConfig = {
|
|
290
|
+
type: 'search-list',
|
|
291
|
+
name: 'chosenLocale',
|
|
292
|
+
choices: localeList,
|
|
293
|
+
message: displayMessage || 'Choose locale',
|
|
294
|
+
loop: false,
|
|
295
|
+
validate: validations_1.shouldNotBeEmpty
|
|
296
|
+
};
|
|
297
|
+
inquirer.prompt(inquirerConfig).then(({ chosenLocale }) => {
|
|
298
|
+
let result = { code: localeMap[chosenLocale], name: chosenLocale };
|
|
299
|
+
resolve(result);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
console.error(error.message);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
exports.chooseLocale = chooseLocale;
|
|
308
|
+
function chooseTokenAlias() {
|
|
309
|
+
return new Promise(async (resolve, reject) => {
|
|
310
|
+
const tokens = config_handler_1.default.get('tokens');
|
|
311
|
+
const tokenList = Object.keys(tokens).filter((token) => tokens[token].type === 'management');
|
|
312
|
+
let inquirerConfig = {
|
|
313
|
+
type: 'search-list',
|
|
314
|
+
name: 'chosenToken',
|
|
315
|
+
choices: tokenList,
|
|
316
|
+
message: 'Choose an alias to use',
|
|
317
|
+
loop: false,
|
|
318
|
+
validate: validations_1.shouldNotBeEmpty,
|
|
319
|
+
};
|
|
320
|
+
inquirer.prompt(inquirerConfig).then(({ chosenToken }) => {
|
|
321
|
+
resolve({ apiKey: tokens[chosenToken].apiKey, token: tokens[chosenToken].token });
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
exports.chooseTokenAlias = chooseTokenAlias;
|
|
326
|
+
function chooseDeliveryTokenAlias() {
|
|
327
|
+
return new Promise(async (resolve, reject) => {
|
|
328
|
+
const tokens = config_handler_1.default.get('tokens');
|
|
329
|
+
const tokenList = Object.keys(tokens).filter((token) => tokens[token].type === 'delivery');
|
|
330
|
+
let inquirerConfig = {
|
|
331
|
+
type: 'search-list',
|
|
332
|
+
name: 'chosenToken',
|
|
333
|
+
choices: tokenList,
|
|
334
|
+
message: 'Choose an alias to use',
|
|
335
|
+
loop: false,
|
|
336
|
+
validate: validations_1.shouldNotBeEmpty,
|
|
337
|
+
};
|
|
338
|
+
inquirer.prompt(inquirerConfig).then(({ chosenToken }) => {
|
|
339
|
+
resolve({ apiKey: tokens[chosenToken].apiKey, token: tokens[chosenToken].token });
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
exports.chooseDeliveryTokenAlias = chooseDeliveryTokenAlias;
|
|
344
|
+
async function getAll(element, skip = 0) {
|
|
345
|
+
return new Promise(async (resolve) => {
|
|
346
|
+
let result = [];
|
|
347
|
+
result = await fetch(element, skip, result);
|
|
348
|
+
resolve(result);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
async function fetch(element, skip, accumulator) {
|
|
352
|
+
return new Promise(async (resolve) => {
|
|
353
|
+
let queryParams = { include_count: true, skip: skip };
|
|
354
|
+
let { items: result, count: count } = await element.query(queryParams).find();
|
|
355
|
+
accumulator = accumulator.concat(result);
|
|
356
|
+
skip += result.length;
|
|
357
|
+
if (skip < count)
|
|
358
|
+
return resolve(await fetch(element, skip, accumulator));
|
|
359
|
+
return resolve(accumulator);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
// async function callMe() {
|
|
363
|
+
// // let organization = await chooseOrganization()
|
|
364
|
+
// // console.log(organization)
|
|
365
|
+
// // let stack = await chooseStack(organization.orgUid)
|
|
366
|
+
// // console.log(stack)
|
|
367
|
+
// // let contentType = await chooseContentType(stack.api_key)
|
|
368
|
+
// // console.log(contentType)
|
|
369
|
+
// // let entry = await chooseEntry(contentType.uid, stack.api_key)
|
|
370
|
+
// // console.log(entry)
|
|
371
|
+
// // let entry = await chooseEntry(contentType.uid, stack.api_key)
|
|
372
|
+
// // console.log(entry)
|
|
373
|
+
// let token = await chooseTokenAlias()
|
|
374
|
+
// console.log(token)
|
|
375
|
+
// }
|
|
376
|
+
// callMe()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldNotBeEmpty = void 0;
|
|
4
|
+
function shouldNotBeEmpty(input) {
|
|
5
|
+
if (input.length === 0)
|
|
6
|
+
throw new Error('Please enter a valid value');
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
exports.shouldNotBeEmpty = shouldNotBeEmpty;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"CLI_AUTH_LOGIN_ENTER_EMAIL_ADDRESS": "Enter your email address",
|
|
3
|
+
"CLI_AUTH_LOGIN_ENTER_PASSWORD": "Enter your password",
|
|
4
|
+
"CLI_AUTH_LOGIN_SUCCESS": "Successfully logged in!!",
|
|
5
|
+
"CLI_AUTH_LOGIN_FAILED": "Login Error",
|
|
6
|
+
"CLI_AUTH_LOGIN_DESCRIPTION": "User session login",
|
|
7
|
+
"CLI_AUTH_LOGIN_FLAG_USERNAME": "User name",
|
|
8
|
+
"CLI_AUTH_LOGIN_FLAG_PASSWORD": "Password",
|
|
9
|
+
"CLI_AUTH_LOGIN_SECURITY_CODE_SEND_SUCCESS": "Security code sent to your mobile",
|
|
10
|
+
"CLI_AUTH_LOGIN_ASK_CHANNEL_FOR_SECURITY_CODE": "Two factor authentication enabled, please select a way to get the security code",
|
|
11
|
+
"CLI_AUTH_LOGIN_ENTER_SECURITY_CODE": "Please provide the security code",
|
|
12
|
+
"CLI_AUTH_LOGOUT_CONFIRM": "Are you sure you want to log out?",
|
|
13
|
+
"CLI_AUTH_LOGOUT_LOADER_START": "Logging out....",
|
|
14
|
+
"CLI_AUTH_LOGOUT_SUCCESS": "Successfully logged out",
|
|
15
|
+
"CLI_AUTH_LOGOUT_FAILED": "Error in logout, please login again",
|
|
16
|
+
"CLI_AUTH_LOGOUT_DESCRIPTION": "User session logout",
|
|
17
|
+
"CLI_AUTH_LOGOUT_FLAG_FORCE": "Force logging out for skipping the confirmation",
|
|
18
|
+
"CLI_AUTH_WHOAMI_LOGGED_IN_AS": "You are currently logged in with email",
|
|
19
|
+
"CLI_AUTH_WHOAMI_FAILED": "Failed to get the current user details",
|
|
20
|
+
"CLI_AUTH_WHOAMI_DESCRIPTION": "Display current users email address",
|
|
21
|
+
"CLI_AUTH_TOKENS_ADD_ASK_TOKEN_ALIAS": "Provide alias to store token",
|
|
22
|
+
"CLI_AUTH_TOKENS_ADD_CONFIRM_ALIAS_REPLACE": "Alias is already exists, do you want to replace?",
|
|
23
|
+
"CLI_AUTH_TOKENS_ADD_ENTER_API_KEY": "Enter the api key",
|
|
24
|
+
"CLI_AUTH_TOKENS_ADD_ENTER_TOKEN": "Enter the token",
|
|
25
|
+
"CLI_AUTH_TOKENS_ADD_ENTER_ENVIRONMENT": "Enter the environment name",
|
|
26
|
+
"CLI_AUTH_TOKENS_ADD_REPLACE_SUCCESS": "Successfully replaced the token",
|
|
27
|
+
"CLI_AUTH_TOKENS_ADD_SUCCESS": "Successfully added the token",
|
|
28
|
+
"CLI_AUTH_TOKENS_ADD_FAILED": "Failed to add the token",
|
|
29
|
+
"CLI_AUTH_TOKENS_ADD_DESCRIPTION": "Adds management/delivery tokens to your session to use it with further CLI command by default it adds management token if either of management or delivery flags are not set",
|
|
30
|
+
"CLI_AUTH_TOKENS_ADD_FLAG_DELIVERY_TOKEN": "Set this while saving delivery token",
|
|
31
|
+
"CLI_AUTH_TOKENS_ADD_FLAG_MANAGEMENT_TOKEN": "Set this while saving management token",
|
|
32
|
+
"CLI_AUTH_TOKENS_ADD_FLAG_ENVIRONMENT_NAME": "Environment name for delivery token",
|
|
33
|
+
"CLI_AUTH_TOKENS_REMOVE_SUCCESS": "Token removed successfully !!",
|
|
34
|
+
"CLI_AUTH_TOKENS_REMOVE_FAILED": "Failed to remove the selected token",
|
|
35
|
+
"CLI_AUTH_TOKENS_NOT_FOUND": "No tokens are added yet!",
|
|
36
|
+
"CLI_AUTH_TOKENS_REMOVE_SELECT_TOKEN": "Select tokens to remove",
|
|
37
|
+
"CLI_AUTH_TOKENS_REMOVE_DESCRIPTION": "Removes selected tokens",
|
|
38
|
+
"CLI_AUTH_TOKENS_LIST_NO_TOKENS": "No tokens are added. Use auth:tokens:add command to add tokens.",
|
|
39
|
+
"CLI_AUTH_TOKENS_LIST_FAILED": "Failed to list the tokens",
|
|
40
|
+
"CLI_AUTH_TOKENS_LIST_DESCRIPTION": "Lists all existing tokens added to the session",
|
|
41
|
+
"CLI_AUTH_TOKENS_VALIDATION_INVALID_DELIVERY_TOKEN": "Invalid delivery token",
|
|
42
|
+
"CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME": "Invalid environment name",
|
|
43
|
+
"CLI_AUTH_TOKENS_VALIDATION_INVALID_MANAGEMENT_TOKEN": "Invalid management token",
|
|
44
|
+
"CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY": "Invalid api key",
|
|
45
|
+
"CLI_AUTH_EXIT_PROCESS": "Exiting the process..."
|
|
46
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"CLI_CONFIG_SET_REGION_DESCRIPTION": "Set region for CLI",
|
|
3
|
+
"CLI_CONFIG_SET_REGION_FLAG_D_DESCRIPTION": "Custom host to set for content delivery API, if this flag is added then cma and name flags are required",
|
|
4
|
+
"CLI_CONFIG_SET_REGION_FLAG_M_DESCRIPTION": "Custom host to set for content management API, , if this flag is added then cda and name flags are required",
|
|
5
|
+
"CLI_CONFIG_SET_REGION_FLAG_N_DESCRIPTION": "Name for the region, if this flag is added then cda and cma flags are required",
|
|
6
|
+
"CLI_CONFIG_SET_REGION_DEFAULT": "No argument or custom flag provided. Setting region to default NA",
|
|
7
|
+
"CLI_CONFIG_GET_REGION_DESCRIPTION": "Get current region set for CLI",
|
|
8
|
+
"CLI_CONFIG_GET_REGION_NOT_FOUND": "No region found, please set by running command $ csdx config:set:region"
|
|
9
|
+
}
|