@contentstack/cli-utilities 1.4.0 → 1.4.2
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/lib/auth-handler.js +2 -2
- package/lib/cli-ux.js +1 -1
- package/lib/index.js +3 -1
- package/lib/inquirer-table-prompt.js +176 -0
- package/package.json +1 -2
- package/types/auth-handler.d.ts +36 -37
- package/types/helpers.d.ts +1 -1
- package/types/index.d.ts +2 -65
package/lib/auth-handler.js
CHANGED
|
@@ -30,7 +30,7 @@ class AuthHandler {
|
|
|
30
30
|
this.authEmailKeyName = 'email';
|
|
31
31
|
this.oauthAccessTokenKeyName = 'oauthAccessToken';
|
|
32
32
|
this.oauthDateTimeKeyName = 'oauthDateTime';
|
|
33
|
-
this.oauthUserUidKeyName = '
|
|
33
|
+
this.oauthUserUidKeyName = 'userUid';
|
|
34
34
|
this.oauthOrgUidKeyName = 'oauthOrgUid';
|
|
35
35
|
this.oauthRefreshTokenKeyName = 'oauthRefreshToken';
|
|
36
36
|
this.authorisationTypeKeyName = 'authorisationType';
|
|
@@ -338,7 +338,7 @@ class AuthHandler {
|
|
|
338
338
|
}
|
|
339
339
|
});
|
|
340
340
|
}
|
|
341
|
-
|
|
341
|
+
isAuthenticated() {
|
|
342
342
|
const authorizationType = config_handler_1.default.get(this.authorisationTypeKeyName);
|
|
343
343
|
return (authorizationType === this.authorisationTypeOAUTHValue || authorizationType === this.authorisationTypeAUTHValue);
|
|
344
344
|
}
|
package/lib/cli-ux.js
CHANGED
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "Flags", { enumerable: true, get: function () { r
|
|
|
10
10
|
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return core_1.Command; } });
|
|
11
11
|
const ora_1 = tslib_1.__importDefault(require("ora"));
|
|
12
12
|
const message_handler_1 = tslib_1.__importDefault(require("./message-handler"));
|
|
13
|
-
inquirer_1.default.registerPrompt('table', require('inquirer-table-prompt'));
|
|
13
|
+
inquirer_1.default.registerPrompt('table', require('./inquirer-table-prompt'));
|
|
14
14
|
/**
|
|
15
15
|
* CLI Interface
|
|
16
16
|
*/
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stdout = exports.stderr = exports.execute = exports.ux = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.tsPath = exports.toCached = exports.run = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Args = exports.Command = exports.flags = exports.args = exports.NodeCrypto = exports.printFlagDeprecation = exports.managementSDKInitiator = exports.managementSDKClient = exports.configHandler = exports.authHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.logger = void 0;
|
|
3
|
+
exports.TablePrompt = exports.stdout = exports.stderr = exports.execute = exports.ux = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.tsPath = exports.toCached = exports.run = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Args = exports.Command = exports.flags = exports.args = exports.NodeCrypto = exports.printFlagDeprecation = exports.managementSDKInitiator = exports.managementSDKClient = exports.configHandler = exports.authHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.logger = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
var logger_1 = require("./logger");
|
|
6
6
|
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return tslib_1.__importDefault(logger_1).default; } });
|
|
@@ -51,3 +51,5 @@ Object.defineProperty(exports, "ux", { enumerable: true, get: function () { retu
|
|
|
51
51
|
Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return core_1.execute; } });
|
|
52
52
|
Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return core_1.stderr; } });
|
|
53
53
|
Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return core_1.stdout; } });
|
|
54
|
+
var inquirer_table_prompt_1 = require("./inquirer-table-prompt");
|
|
55
|
+
Object.defineProperty(exports, "TablePrompt", { enumerable: true, get: function () { return tslib_1.__importDefault(inquirer_table_prompt_1).default; } });
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const figures = require('figures');
|
|
4
|
+
const Table = require('cli-table');
|
|
5
|
+
const cliCursor = require('cli-cursor');
|
|
6
|
+
const Base = require('inquirer/lib/prompts/base');
|
|
7
|
+
const observe = require('inquirer/lib/utils/events');
|
|
8
|
+
const { map, takeUntil } = require('rxjs/operators');
|
|
9
|
+
const Choices = require('inquirer/lib/objects/choices');
|
|
10
|
+
class TablePrompt extends Base {
|
|
11
|
+
/**
|
|
12
|
+
* Initialise the prompt
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} questions
|
|
15
|
+
* @param {Object} rl
|
|
16
|
+
* @param {Object} answers
|
|
17
|
+
*/
|
|
18
|
+
constructor(questions, rl, answers) {
|
|
19
|
+
super(questions, rl, answers);
|
|
20
|
+
this.selectAll = this.opt.selectAll || false;
|
|
21
|
+
const formattedRows = this.selectAll
|
|
22
|
+
? [
|
|
23
|
+
{
|
|
24
|
+
name: 'Select All',
|
|
25
|
+
value: 'selectAll',
|
|
26
|
+
},
|
|
27
|
+
...(this.opt.rows || []),
|
|
28
|
+
]
|
|
29
|
+
: [];
|
|
30
|
+
this.columns = new Choices(this.opt.columns, []);
|
|
31
|
+
this.pointer = 0;
|
|
32
|
+
this.horizontalPointer = 0;
|
|
33
|
+
this.rows = new Choices(formattedRows, []);
|
|
34
|
+
this.values = this.columns.filter(() => true).map(() => undefined);
|
|
35
|
+
this.pageSize = this.opt.pageSize || 5;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Start the inquirer session
|
|
39
|
+
*
|
|
40
|
+
* @param {Function} callback
|
|
41
|
+
* @return {TablePrompt}
|
|
42
|
+
*/
|
|
43
|
+
_run(callback) {
|
|
44
|
+
this.done = callback;
|
|
45
|
+
const events = observe(this.rl);
|
|
46
|
+
const validation = this.handleSubmitEvents(events.line.pipe(map(this.getCurrentValue.bind(this))));
|
|
47
|
+
validation.success.forEach(this.onEnd.bind(this));
|
|
48
|
+
validation.error.forEach(this.onError.bind(this));
|
|
49
|
+
events.keypress.forEach(({ key }) => {
|
|
50
|
+
switch (key.name) {
|
|
51
|
+
case 'left':
|
|
52
|
+
return this.onLeftKey();
|
|
53
|
+
case 'right':
|
|
54
|
+
return this.onRightKey();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
events.normalizedUpKey.pipe(takeUntil(validation.success)).forEach(this.onUpKey.bind(this));
|
|
58
|
+
events.normalizedDownKey.pipe(takeUntil(validation.success)).forEach(this.onDownKey.bind(this));
|
|
59
|
+
events.spaceKey.pipe(takeUntil(validation.success)).forEach(this.onSpaceKey.bind(this));
|
|
60
|
+
if (this.rl.line) {
|
|
61
|
+
this.onKeypress();
|
|
62
|
+
}
|
|
63
|
+
cliCursor.hide();
|
|
64
|
+
this.render();
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
getCurrentValue() {
|
|
68
|
+
const currentValue = [];
|
|
69
|
+
this.rows.forEach((row, rowIndex) => {
|
|
70
|
+
currentValue.push(this.values[rowIndex]);
|
|
71
|
+
});
|
|
72
|
+
return currentValue;
|
|
73
|
+
}
|
|
74
|
+
onDownKey() {
|
|
75
|
+
const length = this.rows.realLength;
|
|
76
|
+
this.pointer = this.pointer < length - 1 ? this.pointer + 1 : this.pointer;
|
|
77
|
+
this.render();
|
|
78
|
+
}
|
|
79
|
+
onEnd(state) {
|
|
80
|
+
this.status = 'answered';
|
|
81
|
+
this.spaceKeyPressed = true;
|
|
82
|
+
this.render();
|
|
83
|
+
this.screen.done();
|
|
84
|
+
cliCursor.show();
|
|
85
|
+
if (this.selectAll) {
|
|
86
|
+
// remove select all row
|
|
87
|
+
const [, ...truncatedValue] = state.value;
|
|
88
|
+
this.done(truncatedValue);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
this.done(state.value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
onError(state) {
|
|
95
|
+
this.render(state.isValid);
|
|
96
|
+
}
|
|
97
|
+
onLeftKey() {
|
|
98
|
+
const length = this.columns.realLength;
|
|
99
|
+
this.horizontalPointer = this.horizontalPointer > 0 ? this.horizontalPointer - 1 : length - 1;
|
|
100
|
+
this.render();
|
|
101
|
+
}
|
|
102
|
+
onRightKey() {
|
|
103
|
+
const length = this.columns.realLength;
|
|
104
|
+
this.horizontalPointer = this.horizontalPointer < length - 1 ? this.horizontalPointer + 1 : 0;
|
|
105
|
+
this.render();
|
|
106
|
+
}
|
|
107
|
+
selectAllValues(value) {
|
|
108
|
+
let values = [];
|
|
109
|
+
for (let i = 0; i < this.rows.length; i++) {
|
|
110
|
+
values.push(value);
|
|
111
|
+
}
|
|
112
|
+
this.values = values;
|
|
113
|
+
}
|
|
114
|
+
onSpaceKey() {
|
|
115
|
+
var _a;
|
|
116
|
+
const value = this.columns.get(this.horizontalPointer).value;
|
|
117
|
+
const rowValue = ((_a = this.rows.get(this.pointer)) === null || _a === void 0 ? void 0 : _a.value) || '';
|
|
118
|
+
if (rowValue === 'selectAll') {
|
|
119
|
+
this.selectAllValues(value);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.values[this.pointer] = value;
|
|
123
|
+
}
|
|
124
|
+
this.spaceKeyPressed = true;
|
|
125
|
+
this.render();
|
|
126
|
+
}
|
|
127
|
+
onUpKey() {
|
|
128
|
+
this.pointer = this.pointer > 0 ? this.pointer - 1 : this.pointer;
|
|
129
|
+
this.render();
|
|
130
|
+
}
|
|
131
|
+
paginate() {
|
|
132
|
+
const middleOfPage = Math.floor(this.pageSize / 2);
|
|
133
|
+
const firstIndex = Math.max(0, this.pointer - middleOfPage);
|
|
134
|
+
const lastIndex = Math.min(firstIndex + this.pageSize - 1, this.rows.realLength - 1);
|
|
135
|
+
const lastPageOffset = this.pageSize - 1 - lastIndex + firstIndex;
|
|
136
|
+
return [Math.max(0, firstIndex - lastPageOffset), lastIndex];
|
|
137
|
+
}
|
|
138
|
+
render(error) {
|
|
139
|
+
let message = this.getQuestion();
|
|
140
|
+
let bottomContent = '';
|
|
141
|
+
if (!this.spaceKeyPressed) {
|
|
142
|
+
message +=
|
|
143
|
+
'(Press ' +
|
|
144
|
+
chalk.cyan.bold('<space>') +
|
|
145
|
+
' to select, ' +
|
|
146
|
+
chalk.cyan.bold('<Up and Down>') +
|
|
147
|
+
' to move rows, ' +
|
|
148
|
+
chalk.cyan.bold('<Left and Right>') +
|
|
149
|
+
' to move columns)';
|
|
150
|
+
}
|
|
151
|
+
const [firstIndex, lastIndex] = this.paginate();
|
|
152
|
+
const table = new Table({
|
|
153
|
+
head: [chalk.reset.dim(`${firstIndex + 1}-${lastIndex} of ${this.rows.realLength - 1}`)].concat(this.columns.pluck('name').map((name) => chalk.reset.bold(name))),
|
|
154
|
+
});
|
|
155
|
+
this.rows.forEach((row, rowIndex) => {
|
|
156
|
+
if (rowIndex < firstIndex || rowIndex > lastIndex)
|
|
157
|
+
return;
|
|
158
|
+
const columnValues = [];
|
|
159
|
+
this.columns.forEach((column, columnIndex) => {
|
|
160
|
+
const isSelected = this.status !== 'answered' && this.pointer === rowIndex && this.horizontalPointer === columnIndex;
|
|
161
|
+
const value = column.value === this.values[rowIndex] ? figures.radioOn : figures.radioOff;
|
|
162
|
+
columnValues.push(`${isSelected ? '[' : ' '} ${value} ${isSelected ? ']' : ' '}`);
|
|
163
|
+
});
|
|
164
|
+
const chalkModifier = this.status !== 'answered' && this.pointer === rowIndex ? chalk.reset.bold.cyan : chalk.reset;
|
|
165
|
+
table.push({
|
|
166
|
+
[chalkModifier(row.name)]: columnValues,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
message += '\n\n' + table.toString();
|
|
170
|
+
if (error) {
|
|
171
|
+
bottomContent = chalk.red('>> ') + error;
|
|
172
|
+
}
|
|
173
|
+
this.screen.render(message, bottomContent);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
module.exports = TablePrompt;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-utilities",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Utilities for contentstack projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"inquirer": "8.2.4",
|
|
41
41
|
"inquirer-search-checkbox": "^1.0.0",
|
|
42
42
|
"inquirer-search-list": "^1.2.6",
|
|
43
|
-
"inquirer-table-prompt": "git@github.com:kego1992/inquirer-table-prompt.git",
|
|
44
43
|
"lodash": "^4.17.15",
|
|
45
44
|
"open": "^8.4.2",
|
|
46
45
|
"ora": "^5.4.0",
|
package/types/auth-handler.d.ts
CHANGED
|
@@ -3,43 +3,42 @@
|
|
|
3
3
|
* Auth handler
|
|
4
4
|
*/
|
|
5
5
|
declare class AuthHandler {
|
|
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
|
-
isAuthorisationTypeOAuth(): Promise<boolean>;
|
|
6
|
+
private _host;
|
|
7
|
+
private codeVerifier;
|
|
8
|
+
private OAuthBaseURL;
|
|
9
|
+
private OAuthAppId;
|
|
10
|
+
private OAuthClientId;
|
|
11
|
+
private OAuthRedirectURL;
|
|
12
|
+
private OAuthScope;
|
|
13
|
+
private OAuthResponseType;
|
|
14
|
+
private authTokenKeyName;
|
|
15
|
+
private authEmailKeyName;
|
|
16
|
+
private oauthAccessTokenKeyName;
|
|
17
|
+
private oauthDateTimeKeyName;
|
|
18
|
+
private oauthUserUidKeyName;
|
|
19
|
+
private oauthOrgUidKeyName;
|
|
20
|
+
private oauthRefreshTokenKeyName;
|
|
21
|
+
private authorisationTypeKeyName;
|
|
22
|
+
private authorisationTypeOAUTHValue;
|
|
23
|
+
private authorisationTypeAUTHValue;
|
|
24
|
+
private allAuthConfigItems;
|
|
25
|
+
set host(contentStackHost: any);
|
|
26
|
+
constructor();
|
|
27
|
+
setOAuthBaseURL(): Promise<void>;
|
|
28
|
+
oauth(): Promise<object>;
|
|
29
|
+
createHTTPServer(): Promise<object>;
|
|
30
|
+
openOAuthURL(): Promise<object>;
|
|
31
|
+
getAccessToken(code: string): Promise<object>;
|
|
32
|
+
setConfigData(type: string, userData?: any): Promise<object>;
|
|
33
|
+
unsetConfigData(type?: string): Promise<void>;
|
|
34
|
+
refreshToken(): Promise<object>;
|
|
35
|
+
getUserDetails(data: any): Promise<object>;
|
|
36
|
+
isAuthenticated(): boolean;
|
|
37
|
+
getAuthorisationType(): Promise<any>;
|
|
38
|
+
isAuthorisationTypeBasic(): Promise<boolean>;
|
|
39
|
+
isAuthorisationTypeOAuth(): Promise<boolean>;
|
|
40
|
+
checkExpiryAndRefresh: (force?: boolean) => Promise<void | object>;
|
|
41
|
+
compareOAuthExpiry(force?: boolean): Promise<void | object>;
|
|
43
42
|
}
|
|
44
43
|
declare const _default: AuthHandler;
|
|
45
44
|
export default _default;
|
package/types/helpers.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isAuthenticated: () =>
|
|
1
|
+
export declare const isAuthenticated: () => boolean;
|
package/types/index.d.ts
CHANGED
|
@@ -4,74 +4,11 @@ export { default as CLIError } from './cli-error';
|
|
|
4
4
|
export { default as messageHandler } from './message-handler';
|
|
5
5
|
export { default as authHandler } from './auth-handler';
|
|
6
6
|
export { default as configHandler } from './config-handler';
|
|
7
|
-
export {
|
|
8
|
-
default as managementSDKClient,
|
|
9
|
-
managementSDKInitiator,
|
|
10
|
-
ContentstackClient,
|
|
11
|
-
ContentstackConfig,
|
|
12
|
-
} from './contentstack-management-sdk';
|
|
7
|
+
export { default as managementSDKClient, managementSDKInitiator, ContentstackClient, ContentstackConfig, } from './contentstack-management-sdk';
|
|
13
8
|
export { default as printFlagDeprecation } from './flag-deprecation-check';
|
|
14
9
|
export * from './http-client';
|
|
15
10
|
export { default as NodeCrypto } from './encrypter';
|
|
16
11
|
export { Args as args, Flags as flags, Command } from './cli-ux';
|
|
17
|
-
export {
|
|
18
|
-
Args,
|
|
19
|
-
CommandHelp,
|
|
20
|
-
Config,
|
|
21
|
-
Errors,
|
|
22
|
-
Flags,
|
|
23
|
-
loadHelpClass,
|
|
24
|
-
Help,
|
|
25
|
-
HelpBase,
|
|
26
|
-
HelpSection,
|
|
27
|
-
HelpSectionRenderer,
|
|
28
|
-
HelpSectionKeyValueTable,
|
|
29
|
-
Hook,
|
|
30
|
-
Interfaces,
|
|
31
|
-
Parser,
|
|
32
|
-
Plugin,
|
|
33
|
-
run,
|
|
34
|
-
toCached,
|
|
35
|
-
tsPath,
|
|
36
|
-
toStandardizedId,
|
|
37
|
-
toConfiguredId,
|
|
38
|
-
settings,
|
|
39
|
-
Settings,
|
|
40
|
-
flush,
|
|
41
|
-
ux,
|
|
42
|
-
execute,
|
|
43
|
-
stderr,
|
|
44
|
-
stdout,
|
|
45
|
-
} from '@oclif/core';
|
|
46
|
-
export { FlagInput } from '@oclif/core/lib/interfaces/parser';
|
|
47
12
|
export * from './helpers';
|
|
48
|
-
export {
|
|
49
|
-
Args,
|
|
50
|
-
CommandHelp,
|
|
51
|
-
Config,
|
|
52
|
-
Errors,
|
|
53
|
-
Flags,
|
|
54
|
-
loadHelpClass,
|
|
55
|
-
Help,
|
|
56
|
-
HelpBase,
|
|
57
|
-
HelpSection,
|
|
58
|
-
HelpSectionRenderer,
|
|
59
|
-
HelpSectionKeyValueTable,
|
|
60
|
-
Hook,
|
|
61
|
-
Interfaces,
|
|
62
|
-
Parser,
|
|
63
|
-
Plugin,
|
|
64
|
-
run,
|
|
65
|
-
toCached,
|
|
66
|
-
tsPath,
|
|
67
|
-
toStandardizedId,
|
|
68
|
-
toConfiguredId,
|
|
69
|
-
settings,
|
|
70
|
-
Settings,
|
|
71
|
-
flush,
|
|
72
|
-
ux,
|
|
73
|
-
execute,
|
|
74
|
-
stderr,
|
|
75
|
-
stdout,
|
|
76
|
-
} from '@oclif/core';
|
|
13
|
+
export { Args, CommandHelp, Config, Errors, Flags, loadHelpClass, Help, HelpBase, HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable, Hook, Interfaces, Parser, Plugin, run, toCached, tsPath, toStandardizedId, toConfiguredId, settings, Settings, flush, ux, execute, stderr, stdout, } from '@oclif/core';
|
|
77
14
|
export { FlagInput } from '@oclif/core/lib/interfaces/parser';
|