@shoper/cli 0.1.0-9 → 0.2.1-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/build/cli/auth/cli_auth_errors_factory.js +1 -1
- package/build/cli/auth/tokens/cli_auth_tokens_errors_factory.js +1 -1
- package/build/cli/auth/tokens/cli_auth_tokens_initalizer.js +1 -1
- package/build/cli/class/base_command.js +14 -0
- package/build/cli/class/errors/file_system_errors_factory.js +1 -1
- package/build/cli/class/errors/http/http_errors_constants.js +1 -0
- package/build/cli/class/errors/{http_errors_factory.js → http/http_errors_factory.js} +3 -2
- package/build/cli/commands/auth/cli_auth_add_token_command.js +22 -19
- package/build/cli/commands/auth/cli_auth_commands_constants.js +3 -0
- package/build/cli/commands/auth/cli_auth_commands_utils.js +46 -0
- package/build/cli/commands/auth/cli_auth_list_tokens_command.js +19 -6
- package/build/cli/commands/auth/cli_auth_remove_token_command.js +37 -13
- package/build/cli/commands/auth/cli_auth_switch_token_command.js +20 -11
- package/build/cli/commands/auth/ui/invalid_token_index_error.js +11 -0
- package/build/cli/commands/auth/ui/missing_credentials_error.js +9 -0
- package/build/cli/commands/auth/ui/missing_token_index_error.js +19 -0
- package/build/cli/commands/cli_ui_dump_command.js +11 -0
- package/build/cli/commands/cli_update_command.js +13 -4
- package/build/cli/commands/commands_constants.js +6 -4
- package/build/cli/core/cli_setup.js +33 -14
- package/build/cli/features/controls/controls_constants.js +12 -0
- package/build/cli/features/controls/controls_dto_mappers.js +55 -0
- package/build/cli/features/controls/ui/controls_mappers.js +62 -0
- package/build/cli/features/controls/ui/form.js +4 -0
- package/build/cli/features/controls/ui/form_constants.js +7 -0
- package/build/cli/features/controls/validators/greater_eq_than_validator.js +5 -0
- package/build/cli/features/controls/validators/length_validator.js +6 -0
- package/build/cli/features/controls/validators/required_validator.js +5 -0
- package/build/cli/features/controls/validators/validator_constants.js +13 -0
- package/build/cli/features/execution_context/execution_context_service.js +5 -5
- package/build/cli/features/http_requester/http_requester_initializer.js +1 -1
- package/build/cli/hooks/authorization/ensure_authorization_hook.js +2 -2
- package/build/cli/hooks/authorization/ensure_authorization_hook_constants.js +7 -8
- package/build/index.js +37 -19
- package/build/theme/class/archive/theme_archive.js +44 -0
- package/build/theme/class/archive/theme_archive_errors_factory.js +11 -0
- package/build/theme/class/checksums/theme_checksums.js +170 -0
- package/build/theme/{features/theme/utils → class}/checksums/theme_checksums_error_factory.js +1 -1
- package/build/theme/class/checksums/theme_checksums_utils.js +17 -0
- package/build/theme/class/fetch_resources/fetch_resources.js +1 -0
- package/build/theme/class/fetch_resources/fetch_resources_errors_factory.js +1 -1
- package/build/theme/class/fetch_resources/fetch_resources_utils.js +4 -1
- package/build/theme/class/files_upload/theme_files_upload.js +61 -0
- package/build/theme/class/files_upload/theme_files_upload_http_api.js +23 -0
- package/build/theme/commands/delete/theme_delete_command.js +97 -0
- package/build/theme/commands/delete/ui/theme_deleted_successfully.js +15 -0
- package/build/theme/commands/delete/ui/theme_deletion_warning.js +10 -0
- package/build/theme/commands/info/theme_info_command.js +79 -0
- package/build/theme/commands/info/theme_info_command_utils.js +39 -0
- package/build/theme/commands/init/theme_init_command.js +84 -0
- package/build/theme/commands/init/ui/theme_created_success.js +15 -0
- package/build/theme/commands/list/theme_list_command.js +25 -0
- package/build/theme/commands/list/theme_list_command_utils.js +27 -0
- package/build/theme/commands/publish/theme_publish_command.js +76 -0
- package/build/theme/commands/pull/theme_pull_command.js +174 -0
- package/build/theme/commands/pull/ui/theme_pull_id_mismatch_error.js +7 -0
- package/build/theme/commands/pull/ui/theme_pull_unpublished_changes_warning.js +10 -0
- package/build/theme/commands/pull/ui/theme_pulled_success.js +5 -0
- package/build/theme/commands/push/theme_push_command.js +112 -0
- package/build/theme/commands/push/ui/theme_push_skip_into.js +7 -0
- package/build/theme/commands/push/ui/theme_pushed_success.js +5 -0
- package/build/theme/commands/push/ui/theme_unpermitted_actions_error.js +12 -0
- package/build/theme/commands/theme_commands_constants.js +9 -6
- package/build/theme/commands/theme_verify_command.js +64 -22
- package/build/theme/commands/ui/invalid_theme_id.js +11 -0
- package/build/theme/commands/ui/missing_theme_files.js +15 -0
- package/build/theme/commands/ui/missing_theme_id_error.js +13 -0
- package/build/theme/commands/ui/ouside_of_theme_directory_context_error.js +7 -0
- package/build/theme/commands/ui/theme_directory_context_error.js +7 -0
- package/build/theme/commands/ui/theme_error.js +29 -0
- package/build/theme/commands/ui/theme_work_url_mismatch.js +17 -0
- package/build/theme/commands/ui/unpermitted_command_error.js +18 -0
- package/build/theme/features/theme/actions/api/theme_actions_api.js +3 -0
- package/build/theme/features/theme/actions/service/theme_actions_service.js +15 -3
- package/build/theme/features/theme/actions/service/theme_actions_service_constants.js +1 -0
- package/build/theme/features/theme/actions/theme_actions_constants.js +5 -2
- package/build/theme/features/theme/actions/theme_actions_initializer.js +1 -1
- package/build/theme/features/theme/actions/theme_actions_utils.js +60 -7
- package/build/theme/features/theme/delete/api/theme_delete_api.js +13 -0
- package/build/theme/features/theme/delete/http/theme_delete_http_api.js +17 -0
- package/build/theme/features/theme/delete/service/theme_delete_service.js +31 -0
- package/build/theme/features/theme/delete/theme_delete_constants.js +2 -0
- package/build/theme/features/theme/delete/theme_delete_initalizer.js +20 -0
- package/build/theme/features/theme/fetch/service/theme_fetch_service.js +30 -10
- package/build/theme/features/theme/info/theme_info_utils.js +9 -0
- package/build/theme/features/theme/init/service/theme_init_service.js +9 -4
- package/build/theme/features/theme/init/theme_init_initializer.js +3 -3
- package/build/theme/features/theme/merge/api/theme_merge_api.js +0 -12
- package/build/theme/features/theme/merge/service/theme_merge_service.js +20 -28
- package/build/theme/features/theme/push/service/theme_push_service.js +67 -166
- package/build/theme/features/theme/push/theme_push_constants.js +2 -0
- package/build/theme/features/theme/push/theme_push_errors_factory.js +7 -4
- package/build/theme/features/theme/push/theme_push_initializer.js +1 -7
- package/build/theme/features/theme/push/theme_push_utils.js +25 -0
- package/build/theme/features/theme/skinstore/api/theme_skinstore_api.js +19 -0
- package/build/theme/features/theme/skinstore/http/theme_skinstore_http_api.js +17 -0
- package/build/theme/features/theme/skinstore/service/theme_skinstore_service.js +32 -0
- package/build/theme/features/theme/skinstore/theme_publish_constants.js +4 -0
- package/build/theme/features/theme/skinstore/theme_skinstore_initialzier.js +20 -0
- package/build/theme/features/theme/utils/files_structure/theme_file_structure_errors_factory.js +10 -0
- package/build/theme/features/theme/utils/files_structure/theme_files_structure_utils.js +76 -0
- package/build/theme/features/theme/utils/hidden_directory/hidden_directory_utils.js +32 -0
- package/build/theme/features/theme/utils/meta_data/theme_meta_data_constants.js +1 -0
- package/build/theme/features/theme/utils/meta_data/theme_meta_data_error_factory.js +15 -0
- package/build/theme/features/theme/utils/meta_data/theme_meta_data_utils.js +39 -0
- package/build/theme/features/theme/utils/{directories → resources}/theme_resources_with_id_directory_utils.js +3 -14
- package/build/theme/features/theme/utils/theme_images_utils.js +1 -19
- package/build/theme/features/theme/verify/api/theme_verify_api.js +13 -0
- package/build/theme/features/theme/verify/http/theme_verify_http_api.js +30 -0
- package/build/theme/features/theme/verify/theme_verify_constants.js +2 -0
- package/build/theme/features/theme/verify/theme_verify_initializer.js +19 -0
- package/build/theme/features/theme/verify/verify/theme_verify_service.js +55 -0
- package/build/theme/features/themes/list/api/themes_list_api.js +3 -0
- package/build/theme/features/themes/list/services/themes_list_service.js +13 -7
- package/build/theme/hooks/{ensure_theme_meta_data_untouched.js → ensure_theme_meta_data_untouched_hook.js} +2 -2
- package/build/theme/hooks/theme_checksums/ensure_theme_current_checksums_up_to_date_constants.js +1 -2
- package/build/theme/hooks/theme_checksums/{ensure_theme_current_checksums_up_to_date.js → ensure_theme_current_checksums_up_to_date_hook.js} +2 -5
- package/build/theme/hooks/themes_actions/ensure_themes_actions_hook.js +1 -0
- package/build/theme/hooks/themes_actions/ensure_themes_actions_hook_constants.js +1 -1
- package/build/theme/index.js +34 -8
- package/build/theme/utils/directory_validator/directory_validator_constants.js +2 -6
- package/build/theme/utils/directory_validator/directory_validator_utils.js +7 -25
- package/build/ui/box.js +2 -0
- package/build/ui/color_constants.js +30 -0
- package/build/ui/command.js +6 -0
- package/build/ui/file_name.js +6 -0
- package/build/ui/flag.js +6 -0
- package/build/ui/icons/error_icon.js +7 -0
- package/build/ui/icons/info_icon.js +7 -0
- package/build/ui/icons/success_icon.js +7 -0
- package/build/ui/icons/warning_icon.js +7 -0
- package/build/ui/link.js +8 -0
- package/build/ui/list/list.js +10 -0
- package/build/ui/list/list_constants.js +4 -0
- package/build/ui/list/list_item.js +11 -0
- package/build/ui/message_box/error.js +4 -0
- package/build/ui/message_box/info.js +4 -0
- package/build/ui/message_box/message_box.js +11 -0
- package/build/ui/message_box/message_box_constants.js +24 -0
- package/build/ui/message_box/success.js +4 -0
- package/build/ui/message_box/warning.js +4 -0
- package/build/ui/prompts/prompt_confirmation.js +11 -0
- package/build/ui/prompts/prompt_input.js +10 -0
- package/build/ui/table/t_cell.js +7 -0
- package/build/ui/table/t_header.js +9 -0
- package/build/ui/table/t_row.js +5 -0
- package/build/ui/table/table.js +18 -0
- package/build/ui/text.js +2 -0
- package/build/ui/tip.js +9 -0
- package/build/ui/ui_dump/ui_component_box.js +9 -0
- package/build/ui/ui_dump/ui_dump.js +53 -0
- package/build/ui/ui_dump/ui_dump_constants.js +21 -0
- package/build/ui/ui_utils.js +11 -0
- package/build/ui/validation_errors/validation_error_content.js +19 -0
- package/build/ui/validation_errors/validation_errors.js +21 -0
- package/build/ui/validation_errors/validation_errors_utils.js +17 -0
- package/build/utils/checksums/checksums_utils.js +9 -26
- package/build/utils/download_file/download_file_errors_factory.js +1 -1
- package/build/utils/download_file/download_file_utils.js +4 -2
- package/build/utils/fs/errors/stream_read_error.js +1 -1
- package/build/utils/fs/errors/stream_write_error.js +1 -1
- package/build/utils/fs/fs_utils.js +12 -1
- package/build/utils/path_utils.js +18 -2
- package/build/utils/platform_utils.js +3 -0
- package/build/utils/zip/create_zip_utils.js +1 -1
- package/build/utils/zip/errors/create_zip_error.js +1 -1
- package/build/utils/zip/errors/open_zip_error.js +1 -1
- package/oclif.config.js +3 -3
- package/package.json +14 -9
- package/build/cli/commands/files_diff_command.js +0 -174
- package/build/theme/commands/theme_init_command.js +0 -53
- package/build/theme/commands/theme_list_command.js +0 -16
- package/build/theme/commands/theme_pull_command.js +0 -126
- package/build/theme/commands/theme_push_command.js +0 -65
- package/build/theme/commands/theme_show_changes_command.js +0 -60
- package/build/theme/features/theme/directory/theme_directory_utils.js +0 -76
- package/build/theme/features/theme/publish/theme_publish_constants.js +0 -2
- package/build/theme/features/theme/utils/checksums/theme_checksums_utils.js +0 -94
- /package/build/cli/{features → class}/caches/cache_factory.js +0 -0
- /package/build/cli/{features → class}/caches/json_cache/json_cache.js +0 -0
- /package/build/cli/{features → class}/caches/memory_cache.js +0 -0
- /package/build/cli/class/errors/{app_error → app}/app_error.js +0 -0
- /package/build/cli/class/errors/{app_error → app}/app_error_constants.js +0 -0
- /package/build/theme/features/theme/{publish → skinstore}/theme_publish_utils.js +0 -0
|
@@ -3,7 +3,7 @@ import { CliAuthTokensApi } from './api/cli_auth_tokens_api.js';
|
|
|
3
3
|
import { CLiAuthTokensService } from './service/cli_auth_tokens_service.js';
|
|
4
4
|
import { CLI_AUTH_TOKENS_FEATURE_NAME, CLI_AUTH_TOKENS_FILE_NAME } from './cli_auth_tokens_constants.js';
|
|
5
5
|
import { CLI_DATA_DIRECTORY_API_NAME } from '../../features/data_directory/cli_data_directory_constants.js';
|
|
6
|
-
import { JsonCache } from '../../
|
|
6
|
+
import { JsonCache } from '../../class/caches/json_cache/json_cache.js';
|
|
7
7
|
// schema
|
|
8
8
|
// {
|
|
9
9
|
// default: string;
|
|
@@ -5,6 +5,8 @@ export class BaseCommand extends Command {
|
|
|
5
5
|
commandBus;
|
|
6
6
|
eventBus;
|
|
7
7
|
globalCoresContainersRegistry;
|
|
8
|
+
flags;
|
|
9
|
+
args;
|
|
8
10
|
constructor(argv, config) {
|
|
9
11
|
super(argv, config);
|
|
10
12
|
const { queryBus, commandBus, eventBus, globalCoresContainersRegistry } = getStarCoreEnvironment();
|
|
@@ -22,4 +24,16 @@ export class BaseCommand extends Command {
|
|
|
22
24
|
_createApiDuplicationError(apiName) {
|
|
23
25
|
return new AppError(`${apiName} hasn't been registered`);
|
|
24
26
|
}
|
|
27
|
+
async init() {
|
|
28
|
+
await super.init();
|
|
29
|
+
const { args, flags } = await this.parse({
|
|
30
|
+
flags: this.ctor.flags,
|
|
31
|
+
baseFlags: super.ctor.baseFlags,
|
|
32
|
+
enableJsonFlag: this.ctor.enableJsonFlag,
|
|
33
|
+
args: this.ctor.args,
|
|
34
|
+
strict: this.ctor.strict
|
|
35
|
+
});
|
|
36
|
+
this.flags = flags;
|
|
37
|
+
this.args = args;
|
|
38
|
+
}
|
|
25
39
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const HTTP_NOT_FOUND_ERROR_CODE = 'not_found';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AppError } from '
|
|
1
|
+
import { AppError } from '../app/app_error.js';
|
|
2
|
+
import { HTTP_NOT_FOUND_ERROR_CODE } from './http_errors_constants.js';
|
|
2
3
|
export class HttpErrorsFactory {
|
|
3
4
|
static createUnauthorizedError() {
|
|
4
5
|
return new AppError({
|
|
@@ -15,7 +16,7 @@ export class HttpErrorsFactory {
|
|
|
15
16
|
static createNotFoundError() {
|
|
16
17
|
return new AppError({
|
|
17
18
|
message: 'Not found',
|
|
18
|
-
code:
|
|
19
|
+
code: HTTP_NOT_FOUND_ERROR_CODE
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
import { BaseCliCommand } from '../../class/base_cli_command.js';
|
|
2
2
|
import { CLI_AUTH_TOKENS_API_NAME } from '../../auth/tokens/cli_auth_tokens_constants.js';
|
|
3
|
-
import
|
|
3
|
+
import { promptInput } from '../../../ui/prompts/prompt_input.js';
|
|
4
|
+
import { renderOnce } from '../../../ui/ui_utils.js';
|
|
5
|
+
import { Success } from '../../../ui/message_box/success.js';
|
|
6
|
+
import { Text } from '../../../ui/text.js';
|
|
7
|
+
import { Box } from '../../../ui/box.js';
|
|
8
|
+
import { Command } from '../../../ui/command.js';
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import { Error } from '../../../ui/message_box/error.js';
|
|
4
11
|
export class CliAuthAddTokenCommand extends BaseCliCommand {
|
|
5
|
-
static
|
|
6
|
-
|
|
7
|
-
static examples = [
|
|
8
|
-
{
|
|
9
|
-
description: 'Add token.',
|
|
10
|
-
command: '<%= config.bin %> <%= command.id %>'
|
|
11
|
-
}
|
|
12
|
-
];
|
|
12
|
+
static summary = 'Adds a new authentication token and saves it locally.';
|
|
13
|
+
static description = 'The added token will be set as your default authentication token.\n\nUse this when you’ve generated a token in your store panel and want to authenticate your CLI commands.';
|
|
14
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
13
15
|
async run() {
|
|
14
16
|
const cliAuthTokensApi = this.getApi(CLI_AUTH_TOKENS_API_NAME);
|
|
15
|
-
const { token } = await inquirer.prompt([
|
|
16
|
-
{
|
|
17
|
-
type: 'input',
|
|
18
|
-
name: 'token',
|
|
19
|
-
message: 'Enter token:'
|
|
20
|
-
}
|
|
21
|
-
]);
|
|
22
17
|
try {
|
|
18
|
+
const { input: token } = await promptInput('Please paste your CLI token:');
|
|
23
19
|
cliAuthTokensApi.addToken(token);
|
|
24
20
|
cliAuthTokensApi.setDefaultToken(cliAuthTokensApi.getTokensCount());
|
|
25
|
-
|
|
21
|
+
renderOnce(React.createElement(Success, null,
|
|
22
|
+
React.createElement(Text, null, "Token saved locally and set as your default. You can now authenticate using this token."),
|
|
23
|
+
React.createElement(Box, null,
|
|
24
|
+
React.createElement(Text, null,
|
|
25
|
+
"Run ",
|
|
26
|
+
React.createElement(Command, null, "shoper auth list-tokens"),
|
|
27
|
+
" to view your saved tokens."))));
|
|
26
28
|
}
|
|
27
29
|
catch (err) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
renderOnce(React.createElement(Error, { header: "Error: Failed to add token: " },
|
|
31
|
+
React.createElement(Box, null,
|
|
32
|
+
React.createElement(Text, null, err.toString()))));
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Text } from '../../../ui/text.js';
|
|
2
|
+
import { TOKEN_SCOPE_TO_DESCRIPTION } from './cli_auth_commands_constants.js';
|
|
3
|
+
import { CSS_BACKGROUND_COLORS, CSS_TEXT_COLORS } from '../../../ui/color_constants.js';
|
|
4
|
+
import { DateUtils } from '@dreamcommerce/utilities';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
export class CliAuthCommandsUtils {
|
|
7
|
+
static mapToTableData(data, defaultIndex, tokensApi) {
|
|
8
|
+
return {
|
|
9
|
+
headers: [
|
|
10
|
+
{
|
|
11
|
+
content: 'Index',
|
|
12
|
+
width: 10
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
content: 'Token Name',
|
|
16
|
+
width: 40
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
content: 'Store',
|
|
20
|
+
width: 40
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
content: 'Access Scope',
|
|
24
|
+
width: 20
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
content: 'Valid until',
|
|
28
|
+
width: 20
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
rows: data.map((tokenData, index) => {
|
|
32
|
+
const tokenIndex = index + 1;
|
|
33
|
+
const isDefault = defaultIndex !== null && tokenIndex === defaultIndex;
|
|
34
|
+
const tokenName = isDefault ? React.createElement(Text, { bold: true }, `${tokenData.name} (Default)`) : tokenData.name;
|
|
35
|
+
const hasExpired = tokensApi.hasTokenExpired(tokenIndex);
|
|
36
|
+
return [
|
|
37
|
+
React.createElement(Text, { bold: isDefault }, tokenIndex),
|
|
38
|
+
tokenName,
|
|
39
|
+
React.createElement(Text, { bold: isDefault }, tokenData.iss),
|
|
40
|
+
TOKEN_SCOPE_TO_DESCRIPTION[tokenData.scope],
|
|
41
|
+
React.createElement(Text, { color: hasExpired ? CSS_TEXT_COLORS.invert : undefined, backgroundColor: hasExpired ? CSS_BACKGROUND_COLORS.danger : undefined }, DateUtils.toLocaleDate(new Date(tokenData.exp * 1000), 'pl-PL'))
|
|
42
|
+
];
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
import { BaseCliCommand } from '../../class/base_cli_command.js';
|
|
2
2
|
import { CLI_AUTH_TOKENS_API_NAME } from '../../auth/tokens/cli_auth_tokens_constants.js';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { CliAuthCommandsUtils } from './cli_auth_commands_utils.js';
|
|
5
|
+
import { Table } from '../../../ui/table/table.js';
|
|
6
|
+
import { render } from '../../../ui/ui_utils.js';
|
|
7
|
+
import { Box } from '../../../ui/box.js';
|
|
8
|
+
import { Tip } from '../../../ui/tip.js';
|
|
9
|
+
import { Command } from '../../../ui/command.js';
|
|
10
|
+
import { Text } from '../../../ui/text.js';
|
|
11
|
+
import { Info } from '../../../ui/message_box/info.js';
|
|
3
12
|
export class CliAuthListTokensCommand extends BaseCliCommand {
|
|
4
|
-
static
|
|
5
|
-
static
|
|
13
|
+
static summary = 'Displays a list of all authentication tokens stored locally.';
|
|
14
|
+
static description = 'For each token, you’ll see its name, index, assigned store URL, access scope and expiration date.\n\nUse this to review your tokens and check which one is set as the default.';
|
|
15
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
6
16
|
async run() {
|
|
7
17
|
const tokensApi = this.getApi(CLI_AUTH_TOKENS_API_NAME);
|
|
8
18
|
const tokensPayloads = tokensApi.getAllTokensPayloads();
|
|
9
19
|
if (!tokensPayloads.length) {
|
|
10
|
-
|
|
20
|
+
await render(React.createElement(Info, null,
|
|
21
|
+
React.createElement(Box, null,
|
|
22
|
+
React.createElement(Text, null, "No tokens found")),
|
|
23
|
+
React.createElement(Tip, null,
|
|
24
|
+
"Generate one using ",
|
|
25
|
+
React.createElement(Command, null, "shoper auth add-token"))));
|
|
11
26
|
return;
|
|
12
27
|
}
|
|
13
|
-
tokensPayloads.
|
|
14
|
-
this.log(`Token name: ${tokenPayload.name}, storeUrl: ${tokenPayload.iss}`);
|
|
15
|
-
});
|
|
28
|
+
await render(React.createElement(Table, { data: CliAuthCommandsUtils.mapToTableData(tokensPayloads, tokensApi.getDefaultTokenIndex(), tokensApi) }));
|
|
16
29
|
}
|
|
17
30
|
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { BaseCliCommand } from '../../class/base_cli_command.js';
|
|
2
2
|
import { Args } from '@oclif/core';
|
|
3
3
|
import { CLI_AUTH_TOKENS_API_NAME } from '../../auth/tokens/cli_auth_tokens_constants.js';
|
|
4
|
+
import { renderOnce } from '../../../ui/ui_utils.js';
|
|
5
|
+
import { MissingTokenIndexError } from './ui/missing_token_index_error.js';
|
|
6
|
+
import { InvalidTokenIndexError } from './ui/invalid_token_index_error.js';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { Text } from '../../../ui/text.js';
|
|
9
|
+
import { Command } from '../../../ui/command.js';
|
|
10
|
+
import { Box } from '../../../ui/box.js';
|
|
11
|
+
import { promptConfirmation } from '../../../ui/prompts/prompt_confirmation.js';
|
|
12
|
+
import { Info } from '../../../ui/message_box/info.js';
|
|
13
|
+
import { Success } from '../../../ui/message_box/success.js';
|
|
14
|
+
import { Warning } from '../../../ui/message_box/warning.js';
|
|
15
|
+
import { Error } from '../../../ui/message_box/error.js';
|
|
4
16
|
export class CliAuthRemoveTokenCommand extends BaseCliCommand {
|
|
5
|
-
static summary = '
|
|
6
|
-
static description = '
|
|
17
|
+
static summary = 'Removes a locally saved authentication token.';
|
|
18
|
+
static description = 'Use this to clean up tokens you no longer need.';
|
|
7
19
|
static examples = [
|
|
8
20
|
{
|
|
9
21
|
description: 'Remove token with index 2',
|
|
@@ -13,25 +25,37 @@ export class CliAuthRemoveTokenCommand extends BaseCliCommand {
|
|
|
13
25
|
static args = {
|
|
14
26
|
index: Args.integer({
|
|
15
27
|
description: 'Index of the token to remove',
|
|
16
|
-
required:
|
|
28
|
+
required: false
|
|
17
29
|
})
|
|
18
30
|
};
|
|
19
31
|
async run() {
|
|
20
32
|
const cliAuthTokensApi = this.getApi(CLI_AUTH_TOKENS_API_NAME);
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
const { index } = this.args;
|
|
34
|
+
if (!index || !cliAuthTokensApi.hasToken(index)) {
|
|
35
|
+
renderOnce(React.createElement(MissingTokenIndexError, { command: React.createElement(Command, null, "shoper auth remove-token [TOKEN_INDEX]") }));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const token = cliAuthTokensApi.getTokenPayload(index);
|
|
39
|
+
if (!token) {
|
|
40
|
+
renderOnce(React.createElement(InvalidTokenIndexError, null));
|
|
26
41
|
return;
|
|
27
42
|
}
|
|
28
43
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
renderOnce(React.createElement(Warning, { header: `Warning: This will permanently delete the token "${token.name}" assigned to "${token.iss}". This action cannot be undone.` }));
|
|
45
|
+
const { proceed } = await promptConfirmation('Proceed?');
|
|
46
|
+
if (proceed) {
|
|
47
|
+
cliAuthTokensApi.removeToken(index);
|
|
48
|
+
cliAuthTokensApi.setDefaultToken(cliAuthTokensApi.getTokensCount());
|
|
49
|
+
renderOnce(React.createElement(Success, { header: `Success: Token "${token.name}" has been removed.` }));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
renderOnce(React.createElement(Info, null,
|
|
53
|
+
React.createElement(Text, null, "Token removal was cancelled.")));
|
|
32
54
|
}
|
|
33
|
-
catch {
|
|
34
|
-
|
|
55
|
+
catch (err) {
|
|
56
|
+
renderOnce(React.createElement(Error, { header: "Error: Failed to remove token: " },
|
|
57
|
+
React.createElement(Box, null,
|
|
58
|
+
React.createElement(Text, null, err.toString()))));
|
|
35
59
|
}
|
|
36
60
|
}
|
|
37
61
|
}
|
|
@@ -1,36 +1,45 @@
|
|
|
1
1
|
import { BaseCliCommand } from '../../class/base_cli_command.js';
|
|
2
2
|
import { CLI_AUTH_TOKENS_API_NAME } from '../../auth/tokens/cli_auth_tokens_constants.js';
|
|
3
|
+
import { renderOnce } from '../../../ui/ui_utils.js';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { Text } from '../../../ui/text.js';
|
|
6
|
+
import { Box } from '../../../ui/box.js';
|
|
3
7
|
import { Args } from '@oclif/core';
|
|
8
|
+
import { MissingTokenIndexError } from './ui/missing_token_index_error.js';
|
|
9
|
+
import { Command } from '../../../ui/command.js';
|
|
10
|
+
import { Error } from '../../../ui/message_box/error.js';
|
|
11
|
+
import { Success } from '../../../ui/message_box/success.js';
|
|
4
12
|
export class CliAuthSwitchTokenCommand extends BaseCliCommand {
|
|
5
|
-
static
|
|
6
|
-
|
|
13
|
+
static summary = 'Changes the active authentication token used by the CLI.';
|
|
14
|
+
static description = 'Use this to switch between multiple saved tokens when working with different stores.';
|
|
7
15
|
static examples = [
|
|
8
16
|
{
|
|
9
|
-
description: 'Set token 2 as default.',
|
|
17
|
+
description: 'Set token with index "2" as default.',
|
|
10
18
|
command: '<%= config.bin %> <%= command.id %> 2'
|
|
11
19
|
}
|
|
12
20
|
];
|
|
13
21
|
static args = {
|
|
14
22
|
index: Args.integer({
|
|
15
23
|
description: 'Index of the token to set as default',
|
|
16
|
-
required:
|
|
24
|
+
required: false
|
|
17
25
|
})
|
|
18
26
|
};
|
|
19
27
|
async run() {
|
|
20
28
|
const cliAuthTokensApi = this.getApi(CLI_AUTH_TOKENS_API_NAME);
|
|
21
|
-
const {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.log(`Token with index "${index}" does not exist.`);
|
|
29
|
+
const { index } = this.args;
|
|
30
|
+
if (!index || !cliAuthTokensApi.hasToken(index)) {
|
|
31
|
+
renderOnce(React.createElement(MissingTokenIndexError, { command: React.createElement(Command, null, "shoper auth switch-token [TOKEN_INDEX]") }));
|
|
25
32
|
return;
|
|
26
33
|
}
|
|
27
34
|
try {
|
|
28
35
|
cliAuthTokensApi.setDefaultToken(index);
|
|
36
|
+
const defaultToken = cliAuthTokensApi.getDefaultTokenPayload();
|
|
37
|
+
renderOnce(React.createElement(Success, { header: `Success: Token "${defaultToken?.name}" assigned to "${defaultToken?.iss}" is now active` }));
|
|
29
38
|
}
|
|
30
39
|
catch (err) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
renderOnce(React.createElement(Error, { header: "Error: Failed to switch token: " },
|
|
41
|
+
React.createElement(Box, null,
|
|
42
|
+
React.createElement(Text, null, err.toString()))));
|
|
34
43
|
}
|
|
35
44
|
}
|
|
36
45
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Tip } from '../../../../ui/tip.js';
|
|
2
|
+
import { Command } from '../../../../ui/command.js';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Error } from '../../../../ui/message_box/error.js';
|
|
5
|
+
export const InvalidTokenIndexError = () => {
|
|
6
|
+
return (React.createElement(Error, { header: "Error: Invalid token index." },
|
|
7
|
+
React.createElement(Tip, null,
|
|
8
|
+
"Run ",
|
|
9
|
+
React.createElement(Command, null, "shoper auth list-tokens"),
|
|
10
|
+
" to see available token index values.")));
|
|
11
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box } from '../../../../ui/box.js';
|
|
3
|
+
import { Text } from '../../../../ui/text.js';
|
|
4
|
+
import { Error } from '../../../../ui/message_box/error.js';
|
|
5
|
+
export const MissingCredentialsError = () => {
|
|
6
|
+
return (React.createElement(Error, { header: "Error: Credentials not found." },
|
|
7
|
+
React.createElement(Box, null,
|
|
8
|
+
React.createElement(Text, null, "Please authorize first."))));
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Box } from '../../../../ui/box.js';
|
|
2
|
+
import { Text } from '../../../../ui/text.js';
|
|
3
|
+
import { Newline } from 'ink';
|
|
4
|
+
import { Command } from '../../../../ui/command.js';
|
|
5
|
+
import { Tip } from '../../../../ui/tip.js';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Error } from '../../../../ui/message_box/error.js';
|
|
8
|
+
export const MissingTokenIndexError = ({ command }) => {
|
|
9
|
+
return (React.createElement(Error, { header: "Error: Missing token index." },
|
|
10
|
+
React.createElement(Box, null,
|
|
11
|
+
React.createElement(Text, null,
|
|
12
|
+
"Usage:",
|
|
13
|
+
React.createElement(Newline, null),
|
|
14
|
+
command)),
|
|
15
|
+
React.createElement(Tip, null,
|
|
16
|
+
"Run ",
|
|
17
|
+
React.createElement(Command, null, "shoper auth list-tokens"),
|
|
18
|
+
" to see available token index values.")));
|
|
19
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCliCommand } from '../class/base_cli_command.js';
|
|
2
|
+
import { render } from 'ink';
|
|
3
|
+
import { UiDump } from '../../ui/ui_dump/ui_dump.js';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
export class CliUIDumpCommand extends BaseCliCommand {
|
|
6
|
+
static summary = 'Prints all CLI UI elements';
|
|
7
|
+
static hidden = true;
|
|
8
|
+
async run() {
|
|
9
|
+
render(React.createElement(UiDump, null));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { CLI_VERSION_API_NAME } from '../features/version/cli_version_constants.js';
|
|
2
2
|
import { CLI_NAME } from '../cli_constants.js';
|
|
3
3
|
import { BaseCliCommand } from '../class/base_cli_command.js';
|
|
4
|
+
import { renderOnce } from '../../ui/ui_utils.js';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { Error } from '../../ui/message_box/error.js';
|
|
4
7
|
export class CliUpdateCommand extends BaseCliCommand {
|
|
5
8
|
static summary = 'Update the Shoper CLI';
|
|
6
9
|
static description = 'Update the Shoper CLI to the latest version.';
|
|
@@ -9,17 +12,23 @@ export class CliUpdateCommand extends BaseCliCommand {
|
|
|
9
12
|
const cliVersionApi = this.getApi(CLI_VERSION_API_NAME);
|
|
10
13
|
try {
|
|
11
14
|
const installedVersion = await cliVersionApi.getGloballyInstalledVersion();
|
|
12
|
-
if (!installedVersion)
|
|
13
|
-
|
|
15
|
+
if (!installedVersion) {
|
|
16
|
+
renderOnce(React.createElement(Error, null,
|
|
17
|
+
"The Shoper CLI is not installed globally. In order to work with CLI, please install it globally. Use \"npm install -g $",
|
|
18
|
+
CLI_NAME,
|
|
19
|
+
"\" to install it."));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
14
22
|
const stdout = await cliVersionApi.update();
|
|
15
23
|
this.log(stdout);
|
|
16
24
|
}
|
|
17
25
|
catch (error) {
|
|
18
26
|
//npm code for EACCES
|
|
19
27
|
if (error?.code === 243) {
|
|
20
|
-
|
|
28
|
+
renderOnce(React.createElement(Error, { header: error.message }));
|
|
29
|
+
return;
|
|
21
30
|
}
|
|
22
|
-
|
|
31
|
+
renderOnce(React.createElement(Error, { header: "Error: Failed to update the CLI. Please try again later." }));
|
|
23
32
|
}
|
|
24
33
|
}
|
|
25
34
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
export const CLI_AUTH_TOPIC_NAME = 'auth';
|
|
1
2
|
export const CLI_COMMANDS_NAMES = {
|
|
2
3
|
help: 'help',
|
|
3
4
|
version: 'version',
|
|
4
5
|
update: 'update',
|
|
5
|
-
authListTokens:
|
|
6
|
-
authAddToken:
|
|
7
|
-
authRemoveToken:
|
|
8
|
-
switchToken:
|
|
6
|
+
authListTokens: `${CLI_AUTH_TOPIC_NAME}:list-tokens`,
|
|
7
|
+
authAddToken: `${CLI_AUTH_TOPIC_NAME}:add-token`,
|
|
8
|
+
authRemoveToken: `${CLI_AUTH_TOPIC_NAME}:remove-token`,
|
|
9
|
+
switchToken: `${CLI_AUTH_TOPIC_NAME}:switch-token`,
|
|
10
|
+
uiDump: 'ui-dump'
|
|
9
11
|
};
|
|
@@ -8,12 +8,9 @@ import { ExecutionContextInitializer } from '../features/execution_context/execu
|
|
|
8
8
|
import { CliVersionInitializer } from '../features/version/cli_version_initializer.js';
|
|
9
9
|
import { CliAuthTokensInitializer } from '../auth/tokens/cli_auth_tokens_initalizer.js';
|
|
10
10
|
import { CliAuthInitializer } from '../auth/cli_auth_initializer.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { ThemeMergeInitializer } from '../../theme/features/theme/merge/theme_merge_initializer.js';
|
|
15
|
-
import { ThemeActionsInitializer } from '../../theme/features/theme/actions/theme_actions_initializer.js';
|
|
16
|
-
import { ThemePushInitializer } from '../../theme/features/theme/push/theme_push_initializer.js';
|
|
11
|
+
import { THEME_TOPIC_NAME } from '../../theme/commands/theme_commands_constants.js';
|
|
12
|
+
import { getThemeInitializersForCommand } from '../../theme/index.js';
|
|
13
|
+
import { CLI_AUTH_TOPIC_NAME, CLI_COMMANDS_NAMES } from '../commands/commands_constants.js';
|
|
17
14
|
tmp.setGracefulCleanup();
|
|
18
15
|
export const cliSetup = async () => {
|
|
19
16
|
//TODO jakis ładny komuniakt błedu
|
|
@@ -25,16 +22,9 @@ export const cliSetup = async () => {
|
|
|
25
22
|
HTTPRequesterInitializer,
|
|
26
23
|
CliDataDirectoryInitializer,
|
|
27
24
|
ExecutionContextInitializer,
|
|
28
|
-
CliVersionInitializer,
|
|
29
25
|
CliAuthTokensInitializer,
|
|
30
26
|
CliAuthInitializer,
|
|
31
|
-
|
|
32
|
-
ThemeActionsInitializer,
|
|
33
|
-
//TODO dnamicznie inicjalizowanie ficzurów wykorzystywanych w poszczególnych komendach
|
|
34
|
-
ThemeInitInitializer,
|
|
35
|
-
ThemeMergeInitializer,
|
|
36
|
-
ThemeFetchInitializer,
|
|
37
|
-
ThemePushInitializer
|
|
27
|
+
...getCommandBaseInitializers()
|
|
38
28
|
],
|
|
39
29
|
options: {
|
|
40
30
|
featuresTracking: false,
|
|
@@ -42,3 +32,32 @@ export const cliSetup = async () => {
|
|
|
42
32
|
}
|
|
43
33
|
});
|
|
44
34
|
};
|
|
35
|
+
const getCommandBaseInitializers = () => {
|
|
36
|
+
// console.log('process.argv', process.argv);
|
|
37
|
+
if (isCommandsTopic(process.argv[2]))
|
|
38
|
+
return getCommandWithTopicBaseInitializers();
|
|
39
|
+
return getCommandWithoutTopicBaseInitializers();
|
|
40
|
+
};
|
|
41
|
+
const isCommandsTopic = (arg) => {
|
|
42
|
+
return arg === THEME_TOPIC_NAME || arg === CLI_AUTH_TOPIC_NAME;
|
|
43
|
+
};
|
|
44
|
+
const getCommandWithTopicBaseInitializers = () => {
|
|
45
|
+
const topic = process.argv[2];
|
|
46
|
+
const command = process.argv[3];
|
|
47
|
+
switch (topic) {
|
|
48
|
+
case THEME_TOPIC_NAME: {
|
|
49
|
+
return getThemeInitializersForCommand(command);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return [];
|
|
53
|
+
};
|
|
54
|
+
const getCommandWithoutTopicBaseInitializers = () => {
|
|
55
|
+
const command = process.argv[3];
|
|
56
|
+
switch (command) {
|
|
57
|
+
case CLI_COMMANDS_NAMES.version:
|
|
58
|
+
case CLI_COMMANDS_NAMES.update: {
|
|
59
|
+
return [CliVersionInitializer];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return [];
|
|
63
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const CONTROLS_DTO_TYPES = {
|
|
2
|
+
text: 'text',
|
|
3
|
+
number: 'number',
|
|
4
|
+
select: 'select',
|
|
5
|
+
multiSelectDropDown: 'multiSelectDropDown'
|
|
6
|
+
};
|
|
7
|
+
export const CONTROLS_TYPES = {
|
|
8
|
+
text: 'text',
|
|
9
|
+
number: 'number',
|
|
10
|
+
select: 'select',
|
|
11
|
+
multiSelect: 'multiSelect'
|
|
12
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CONTROLS_DTO_TYPES, CONTROLS_TYPES } from './controls_constants.js';
|
|
2
|
+
export const toTextControl = ({ validators, label, isRequired, defaultValue, name }) => {
|
|
3
|
+
return {
|
|
4
|
+
type: CONTROLS_TYPES.text,
|
|
5
|
+
name,
|
|
6
|
+
label,
|
|
7
|
+
isRequired,
|
|
8
|
+
defaultValue,
|
|
9
|
+
validators
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export const toNumberControl = ({ validators, label, isRequired, name }) => {
|
|
13
|
+
return {
|
|
14
|
+
type: CONTROLS_TYPES.number,
|
|
15
|
+
name,
|
|
16
|
+
label,
|
|
17
|
+
isRequired,
|
|
18
|
+
validators
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const toSelectControl = ({ label, isRequired, name, options }) => {
|
|
22
|
+
return {
|
|
23
|
+
type: CONTROLS_TYPES.select,
|
|
24
|
+
name,
|
|
25
|
+
label,
|
|
26
|
+
isRequired,
|
|
27
|
+
options: options.selectOptions.map(({ label, key }) => ({ label, value: key }))
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export const toMultiSelectControl = ({ label, isRequired, name, options }) => {
|
|
31
|
+
return {
|
|
32
|
+
type: CONTROLS_TYPES.multiSelect,
|
|
33
|
+
name,
|
|
34
|
+
label,
|
|
35
|
+
isRequired,
|
|
36
|
+
options: options.selectOptions.map(({ label, key }) => ({ label, value: key }))
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export const toControls = (controls) => {
|
|
40
|
+
return controls.map(toControl);
|
|
41
|
+
};
|
|
42
|
+
export const toControl = (control) => {
|
|
43
|
+
switch (control.type) {
|
|
44
|
+
case CONTROLS_DTO_TYPES.text:
|
|
45
|
+
return toTextControl(control);
|
|
46
|
+
case CONTROLS_DTO_TYPES.number:
|
|
47
|
+
return toNumberControl(control);
|
|
48
|
+
case CONTROLS_DTO_TYPES.select:
|
|
49
|
+
return toSelectControl(control);
|
|
50
|
+
case CONTROLS_DTO_TYPES.multiSelectDropDown:
|
|
51
|
+
return toMultiSelectControl(control);
|
|
52
|
+
default:
|
|
53
|
+
throw new Error(`Unknown control type`);
|
|
54
|
+
}
|
|
55
|
+
};
|