From b36f64cd2961f1b7a171baf0a33a8cb4ed535e36 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Sat, 23 Mar 2024 15:07:53 +0530 Subject: [PATCH] fixed other messages --- .../contentstack-auth/messages/index.json | 51 ------------------- .../src/commands/auth/whoami.ts | 2 +- .../src/utils/auth-handler.ts | 3 +- .../src/utils/interactive.ts | 19 +++---- .../src/utils/tokens-validation.ts | 16 +++--- 5 files changed, 23 insertions(+), 68 deletions(-) delete mode 100644 packages/contentstack-auth/messages/index.json diff --git a/packages/contentstack-auth/messages/index.json b/packages/contentstack-auth/messages/index.json deleted file mode 100644 index d9c93793de..0000000000 --- a/packages/contentstack-auth/messages/index.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "CLI_AUTH_LOGIN_ASK_CHANNEL_FOR_OTP": "Please select OTP channel", - "CLI_AUTH_LOGIN_ENTER_EMAIL_ADDRESS": "Enter your email address", - "CLI_AUTH_LOGIN_ENTER_PASSWORD": "Enter your password", - "CLI_AUTH_LOGIN_SUCCESS": "Successfully logged in!!", - "CLI_AUTH_LOGIN_FAILED": "Login Error", - "CLI_AUTH_AUTHENTICATION_FAILED": "You need to login first. See: auth:login --help", - "CLI_AUTH_LOGIN_DESCRIPTION": "User session login", - "CLI_AUTH_LOGIN_FLAG_USERNAME": "User name", - "CLI_AUTH_LOGIN_FLAG_PASSWORD": "Password", - "CLI_AUTH_LOGIN_SECURITY_CODE_SEND_SUCCESS": "Security code sent to your mobile", - "CLI_AUTH_LOGIN_ASK_CHANNEL_FOR_SECURITY_CODE": "Two factor authentication enabled, please select a way to get the security code", - "CLI_AUTH_LOGIN_ENTER_SECURITY_CODE": "Please provide the security code", - "CLI_AUTH_LOGOUT_CONFIRM": "Are you sure you want to log out?", - "CLI_AUTH_LOGOUT_LOADER_START": "Logging out....", - "CLI_AUTH_LOGOUT_SUCCESS": "Successfully logged out", - "CLI_AUTH_LOGOUT_FAILED": "Error in logout, please login again", - "CLI_AUTH_LOGOUT_DESCRIPTION": "User session logout", - "CLI_AUTH_LOGOUT_FLAG_FORCE": "Force logging out for skipping the confirmation", - "CLI_AUTH_LOGOUT_ALREADY": "You're already logged out", - "CLI_AUTH_WHOAMI_LOGGED_IN_AS": "You are currently logged in with email", - "CLI_AUTH_WHOAMI_FAILED": "Failed to get the current user details", - "CLI_AUTH_WHOAMI_DESCRIPTION": "Display current users email address", - "CLI_AUTH_TOKENS_ADD_ASK_TOKEN_ALIAS": "Provide alias to store token", - "CLI_AUTH_TOKENS_ADD_CONFIRM_ALIAS_REPLACE": "Alias is already exists, do you want to replace?", - "CLI_AUTH_TOKENS_ADD_ENTER_API_KEY": "Enter the api key", - "CLI_AUTH_TOKENS_ADD_ENTER_TOKEN": "Enter the token", - "CLI_AUTH_TOKENS_ADD_ENTER_ENVIRONMENT": "Enter the environment name", - "CLI_AUTH_TOKENS_ADD_REPLACE_SUCCESS": "Successfully replaced the token", - "CLI_AUTH_TOKENS_ADD_SUCCESS": "Successfully added the token", - "CLI_AUTH_TOKENS_ADD_FAILED": "Failed to add the token", - "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", - "CLI_AUTH_TOKENS_ADD_FLAG_DELIVERY_TOKEN": "Set this while saving delivery token", - "CLI_AUTH_TOKENS_ADD_FLAG_MANAGEMENT_TOKEN": "Set this while saving management token", - "CLI_AUTH_TOKENS_ADD_FLAG_ENVIRONMENT_NAME": "Environment name for delivery token", - "CLI_AUTH_TOKENS_REMOVE_SUCCESS": "Token removed successfully !!", - "CLI_AUTH_TOKENS_REMOVE_FAILED": "Failed to remove the selected token", - "CLI_AUTH_TOKENS_NOT_FOUND": "No tokens are added yet!", - "CLI_AUTH_TOKENS_REMOVE_SELECT_TOKEN": "Select tokens to remove", - "CLI_AUTH_TOKENS_REMOVE_DESCRIPTION": "Removes selected tokens", - "CLI_AUTH_TOKENS_LIST_NO_TOKENS": "No tokens are added. Use auth:tokens:add command to add tokens.", - "CLI_AUTH_TOKENS_LIST_FAILED": "Failed to list the tokens", - "CLI_AUTH_TOKENS_LIST_DESCRIPTION": "Lists all existing tokens added to the session", - "CLI_AUTH_TOKENS_VALIDATION_INVALID_DELIVERY_TOKEN": "Invalid delivery token", - "CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME": "Invalid environment name", - "CLI_AUTH_TOKENS_VALIDATION_INVALID_MANAGEMENT_TOKEN": "Invalid management token", - "CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY": "Invalid api key", - "CLI_AUTH_EXIT_PROCESS": "Exiting the process...", - "CLI_SELECT_TOKEN_TYPE": "Select the type of token to add", - "CLI_AUTH_ENTER_BRANCH": "Enter branch name" -} diff --git a/packages/contentstack-auth/src/commands/auth/whoami.ts b/packages/contentstack-auth/src/commands/auth/whoami.ts index 24f3139c92..218266969c 100644 --- a/packages/contentstack-auth/src/commands/auth/whoami.ts +++ b/packages/contentstack-auth/src/commands/auth/whoami.ts @@ -15,7 +15,7 @@ export default class WhoamiCommand extends BaseCommand { cliux.print(this.email, { color: 'green' }); this.logger.info('Currently logged in user', this.email); } else { - cliux.error('CLI_AUTH_WHOAMI_FAILED'); + cliux.error(messages.CLI_AUTH_WHOAMI_FAILED); } } catch (error) { this.logger.error('whoami error', error.message); diff --git a/packages/contentstack-auth/src/utils/auth-handler.ts b/packages/contentstack-auth/src/utils/auth-handler.ts index 0a8a48215f..6fb37d370c 100644 --- a/packages/contentstack-auth/src/utils/auth-handler.ts +++ b/packages/contentstack-auth/src/utils/auth-handler.ts @@ -2,6 +2,7 @@ import { cliux, CLIError } from '@contentstack/cli-utilities'; import { User } from '../interfaces'; import { askOTPChannel, askOTP } from './interactive'; import { LoggerService } from '@contentstack/cli-utilities'; +import { messages } from '../messages'; /** * @class @@ -54,7 +55,7 @@ class AuthHandler { if (otpChannel === 'sms') { try { await this._client.axiosInstance.post('/user/request_token_sms', { user: loginPayload }); - cliux.print('CLI_AUTH_LOGIN_SECURITY_CODE_SEND_SUCCESS'); + cliux.print(messages.CLI_AUTH_LOGIN_SECURITY_CODE_SEND_SUCCESS); } catch (error) { this.logger.error('Failed to send the security code', error); reject(new CLIError({ message: 'Failed to login - failed to send the security code' })); diff --git a/packages/contentstack-auth/src/utils/interactive.ts b/packages/contentstack-auth/src/utils/interactive.ts index 979ebb70f7..d1877781d8 100644 --- a/packages/contentstack-auth/src/utils/interactive.ts +++ b/packages/contentstack-auth/src/utils/interactive.ts @@ -1,9 +1,10 @@ import { cliux } from '@contentstack/cli-utilities'; +import { messages } from '../messages'; export const askPassword = async () => { return cliux.inquire({ type: 'input', - message: 'CLI_AUTH_LOGIN_ENTER_PASSWORD', + message: messages.CLI_AUTH_LOGIN_ENTER_PASSWORD, name: 'password', transformer: (pswd: string) => { return '*'.repeat(pswd.length); @@ -15,7 +16,7 @@ export const askOTPChannel = async (): Promise => { return cliux.inquire({ type: 'list', name: 'otpChannel', - message: 'CLI_AUTH_LOGIN_ASK_CHANNEL_FOR_OTP', + message: messages.CLI_AUTH_LOGIN_ASK_CHANNEL_FOR_OTP, choices: [ { name: 'Authy App', value: 'authy' }, { name: 'SMS', value: 'sms' }, @@ -26,7 +27,7 @@ export const askOTPChannel = async (): Promise => { export const askOTP = async (): Promise => { return cliux.inquire({ type: 'input', - message: 'CLI_AUTH_LOGIN_ENTER_SECURITY_CODE', + message: messages.CLI_AUTH_LOGIN_ENTER_SECURITY_CODE, name: 'tfaToken', }); }; @@ -34,7 +35,7 @@ export const askOTP = async (): Promise => { export const askUsername = async (): Promise => { return cliux.inquire({ type: 'input', - message: 'CLI_AUTH_LOGIN_ENTER_EMAIL_ADDRESS', + message: messages.CLI_AUTH_LOGIN_ENTER_EMAIL_ADDRESS, name: 'username', }); }; @@ -43,10 +44,10 @@ export const askTokenType = async (): Promise => { return cliux.inquire({ type: 'list', name: 'tokenType', - message: 'CLI_SELECT_TOKEN_TYPE', + message: messages.CLI_SELECT_TOKEN_TYPE, choices: [ - { name: 'Management Token', value: 'management'}, - { name: 'Delivery Token', value: 'delivery'}, - ] + { name: 'Management Token', value: 'management' }, + { name: 'Delivery Token', value: 'delivery' }, + ], }); -} +}; diff --git a/packages/contentstack-auth/src/utils/tokens-validation.ts b/packages/contentstack-auth/src/utils/tokens-validation.ts index 0fe2bf0c4d..ea6c026013 100644 --- a/packages/contentstack-auth/src/utils/tokens-validation.ts +++ b/packages/contentstack-auth/src/utils/tokens-validation.ts @@ -1,5 +1,6 @@ import { messageHandler } from '@contentstack/cli-utilities'; import { LoggerService } from '@contentstack/cli-utilities'; +import { messages } from '../messages'; /** * Validate environment * @param contentStackClient @@ -12,7 +13,7 @@ export const validateEnvironment = async ( apiKey: string, environment: string, ): Promise => { - const newLogger = new LoggerService(process.cwd(),'cli-log'); + const newLogger = new LoggerService(process.cwd(), 'cli-log'); let result: { valid: boolean; message: string }; try { const validationResult = await contentStackClient.Stack({ api_key: apiKey }).environment(environment).fetch(); @@ -20,11 +21,14 @@ export const validateEnvironment = async ( if (validationResult.name === environment) { result = { valid: true, message: validationResult }; } else { - result = { valid: false, message: messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME') }; + result = { + valid: false, + message: messageHandler.parse(messages.CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME), + }; } } catch (error) { newLogger.error('validate environment error', error); - result = { valid: false, message: 'CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME' }; + result = { valid: false, message: messages.CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME }; } return result; }; @@ -36,7 +40,7 @@ export const validateEnvironment = async ( * @returns */ export const validateAPIKey = async (contentStackClient: any, apiKey: string): Promise => { - const newLogger = new LoggerService(process.cwd(),'cli-log'); + const newLogger = new LoggerService(process.cwd(), 'cli-log'); let result: { valid: boolean; message: string }; try { const validateAPIKeyResult = await contentStackClient.stack({ api_key: apiKey }).fetch(); @@ -44,11 +48,11 @@ export const validateAPIKey = async (contentStackClient: any, apiKey: string): P if (validateAPIKeyResult.api_key === apiKey) { result = { valid: true, message: validateAPIKeyResult }; } else { - result = { valid: false, message: messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY') }; + result = { valid: false, message: messageHandler.parse(messages.CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY) }; } } catch (error) { newLogger.error('validate api key error', error); - result = { valid: false, message: messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY') }; + result = { valid: false, message: messageHandler.parse(messages.CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY) }; } return result;