From 5b109c7dd3124438e8534ab5cdb7d7c28a6f3ddc Mon Sep 17 00:00:00 2001 From: raj pandey Date: Sat, 23 Mar 2024 14:51:38 +0530 Subject: [PATCH 1/2] replaced the messages key with their value and version bump --- package-lock.json | 59 ++++++++++--------- packages/contentstack-auth/package.json | 4 +- .../src/commands/auth/login.ts | 9 ++- .../src/commands/auth/logout.ts | 17 +++--- .../src/commands/auth/tokens/add.ts | 36 +++++++---- .../src/commands/auth/tokens/index.ts | 6 +- .../src/commands/auth/tokens/remove.ts | 22 +++---- .../src/commands/auth/whoami.ts | 7 +-- .../contentstack-auth/src/messages/index.ts | 55 +++++++++++++++++ packages/contentstack-branches/package.json | 2 +- packages/contentstack-export/package.json | 4 +- packages/contentstack/package.json | 2 +- pnpm-lock.yaml | 6 +- 13 files changed, 149 insertions(+), 80 deletions(-) create mode 100644 packages/contentstack-auth/src/messages/index.ts diff --git a/package-lock.json b/package-lock.json index 481ae29974..7cd4046dad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,9 +41,9 @@ } }, "node_modules/@apollo/client": { - "version": "3.9.8", - "resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.9.8.tgz", - "integrity": "sha512-ausPftEb2xAUkZqz+VkSSIhNxKraShJXdV2/NJ7JbHAAciGsFlapGtZ++b7lF0/+3Jp/p34g/i6dvO8b4WjQig==", + "version": "3.9.9", + "resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.9.9.tgz", + "integrity": "sha512-/sMecU/M0WK9knrguts1lSLV8xFKzIgOMVb4mi6MOxgJXjliDB8PvOtmXhTqh2cVMMR4TzXgOnb+af/690zlQw==", "dependencies": { "@graphql-typed-document-node/core": "^3.1.1", "@wry/caches": "^1.0.0", @@ -8352,9 +8352,9 @@ } }, "node_modules/aws-sdk": { - "version": "2.1582.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1582.0.tgz", - "integrity": "sha512-oPSk5e1D0oegX3lC+pUIKmI5e4depLi0+9fU7C73KDq65nq8NmdehpbytPHGPqfftqfa3FTEXb2yUPA4A9wM9w==", + "version": "2.1584.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1584.0.tgz", + "integrity": "sha512-57Qizb+bLOhrBLWQSWw6WXTtbO/lFKzLouHxTfm/QeXm38gs0Q0knFxhdH+sWc/DPPJYSRGy7MNiuQcmsq5zxA==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -9098,9 +9098,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001599", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001599.tgz", - "integrity": "sha512-LRAQHZ4yT1+f9LemSMeqdMpMxZcc4RMWdj4tiFe3G8tNkWK+E58g+/tzotb5cU6TbcVJLr4fySiAW7XmxQvZQA==", + "version": "1.0.30001600", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001600.tgz", + "integrity": "sha512-+2S9/2JFhYmYaDpZvo0lKkfvuKIglrx68MwOBqMGHhQsNkLjB5xtc/TGoEPs+MxjSyN/72qer2g97nzR641mOQ==", "dev": true, "funding": [ { @@ -10621,9 +10621,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.713", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.713.tgz", - "integrity": "sha512-vDarADhwntXiULEdmWd77g2dV6FrNGa8ecAC29MZ4TwPut2fvosD0/5sJd1qWNNe8HcJFAC+F5Lf9jW1NPtWmw==", + "version": "1.4.715", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.715.tgz", + "integrity": "sha512-XzWNH4ZSa9BwVUQSDorPWAUQ5WGuYz7zJUNpNif40zFCiCl20t8zgylmreNmn26h5kiyw2lg7RfTmeMBsDklqg==", "dev": true }, "node_modules/elegant-spinner": { @@ -22610,13 +22610,16 @@ } }, "node_modules/string.prototype.trimstart": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.7.tgz", - "integrity": "sha512-NGhtDFu3jCEm7B4Fy0DpLewdJQOZcQ0rGbwQ/+stjnrp2i+rlKeCvos9hOIeCmqwratM47OBxY7uFZzjxHXmrg==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.8.tgz", + "integrity": "sha512-UXSH262CSZY1tfu3G3Secr6uGLCFVPMhIqHjlgCUtCCcgihYc/xKs9djMTMUOb2j1mVSeU8EU6NWc/iQKU6Gfg==", "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.2.0", - "es-abstract": "^1.22.1" + "call-bind": "^1.0.7", + "define-properties": "^1.2.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -22827,9 +22830,9 @@ } }, "node_modules/tar": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.0.tgz", - "integrity": "sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz", + "integrity": "sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==", "dependencies": { "chownr": "^2.0.0", "fs-minipass": "^2.0.0", @@ -23641,9 +23644,9 @@ } }, "node_modules/typed-array-length": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/typed-array-length/-/typed-array-length-1.0.5.tgz", - "integrity": "sha512-yMi0PlwuznKHxKmcpoOdeLwxBoVPkqZxd7q2FgMkmD3bNwvF5VW0+UlUQ1k1vmktTu4Yu13Q0RIxEP8+B+wloA==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/typed-array-length/-/typed-array-length-1.0.6.tgz", + "integrity": "sha512-/OxDN6OtAk5KBpGb28T+HZc2M+ADtvRxXrKKbUwtsLgdoxgX13hyy7ek6bFRl5+aBs2yZzB0c4CnQfAtVypW/g==", "dependencies": { "call-bind": "^1.0.7", "for-each": "^0.3.3", @@ -25679,7 +25682,7 @@ "license": "MIT", "dependencies": { "@contentstack/cli-audit": "~1.5.1", - "@contentstack/cli-auth": "~1.3.17", + "@contentstack/cli-auth": "~1.3.18", "@contentstack/cli-cm-bootstrap": "~1.9.0", "@contentstack/cli-cm-branches": "~1.0.24", "@contentstack/cli-cm-bulk-publish": "~1.4.3", @@ -26008,7 +26011,7 @@ }, "packages/contentstack-auth": { "name": "@contentstack/cli-auth", - "version": "1.3.17", + "version": "1.3.18", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.16", @@ -26151,7 +26154,7 @@ "winston": "^3.7.2" }, "devDependencies": { - "@contentstack/cli-auth": "~1.3.17", + "@contentstack/cli-auth": "~1.3.18", "@contentstack/cli-config": "~1.6.1", "@contentstack/cli-dev-dependencies": "~1.2.4", "@oclif/plugin-help": "^5.1.19", @@ -26736,7 +26739,7 @@ "winston": "^3.7.2" }, "devDependencies": { - "@contentstack/cli-auth": "~1.3.17", + "@contentstack/cli-auth": "~1.3.18", "@contentstack/cli-config": "~1.6.1", "@contentstack/cli-dev-dependencies": "~1.2.4", "@oclif/plugin-help": "^5.1.19", diff --git a/packages/contentstack-auth/package.json b/packages/contentstack-auth/package.json index 6789197161..9473b51137 100644 --- a/packages/contentstack-auth/package.json +++ b/packages/contentstack-auth/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-auth", "description": "Contentstack CLI plugin for authentication activities", - "version": "1.3.17", + "version": "1.3.18", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "scripts": { @@ -96,4 +96,4 @@ } }, "repository": "contentstack/cli" -} +} \ No newline at end of file diff --git a/packages/contentstack-auth/src/commands/auth/login.ts b/packages/contentstack-auth/src/commands/auth/login.ts index f75de6439d..bd497308f8 100644 --- a/packages/contentstack-auth/src/commands/auth/login.ts +++ b/packages/contentstack-auth/src/commands/auth/login.ts @@ -1,16 +1,15 @@ -import { Command } from '@contentstack/cli-command'; import { cliux, CLIError, authHandler as oauthHandler, flags, managementSDKClient, - FlagInput + FlagInput, } from '@contentstack/cli-utilities'; import { User } from '../../interfaces'; import { authHandler, interactive } from '../../utils'; import { BaseCommand } from '../../base-command'; - +import { messages } from './../../messages/index'; export default class LoginCommand extends BaseCommand { static run; // to fix the test issue static description = 'User sessions login'; @@ -77,7 +76,7 @@ export default class LoginCommand extends BaseCommand { } } this.logger.error('login failed', errorMessage); - cliux.error('CLI_AUTH_LOGIN_FAILED'); + cliux.error(messages.CLI_AUTH_LOGIN_FAILED); cliux.error(errorMessage); process.exit(); } @@ -91,7 +90,7 @@ export default class LoginCommand extends BaseCommand { } await oauthHandler.setConfigData('basicAuth', user); this.logger.info('successfully logged in'); - cliux.success('CLI_AUTH_LOGIN_SUCCESS'); + cliux.success(messages.CLI_AUTH_LOGIN_SUCCESS); } catch (error) { throw error; } diff --git a/packages/contentstack-auth/src/commands/auth/logout.ts b/packages/contentstack-auth/src/commands/auth/logout.ts index e03bc45ce0..78c07e0bdd 100644 --- a/packages/contentstack-auth/src/commands/auth/logout.ts +++ b/packages/contentstack-auth/src/commands/auth/logout.ts @@ -1,4 +1,3 @@ -import { Command } from '@contentstack/cli-command'; import { cliux, configHandler, @@ -11,6 +10,8 @@ import { import { authHandler } from '../../utils'; import { BaseCommand } from '../../base-command'; +import { messages } from '../../messages/index'; + export default class LogoutCommand extends BaseCommand { static run; static description = 'User session logout'; @@ -41,7 +42,7 @@ export default class LogoutCommand extends BaseCommand { if (!confirm) { confirm = await cliux.inquire({ type: 'confirm', - message: 'CLI_AUTH_LOGOUT_CONFIRM', + message: messages.CLI_AUTH_LOGOUT_CONFIRM, name: 'confirmation', }); } @@ -50,17 +51,17 @@ export default class LogoutCommand extends BaseCommand { const managementAPIClient = await managementSDKClient({ host: this.cmaHost, skipTokenValidity: true }); authHandler.client = managementAPIClient; if (confirm === true && (await oauthHandler.isAuthenticated())) { - cliux.loader('CLI_AUTH_LOGOUT_LOADER_START'); + cliux.loader(messages.CLI_AUTH_LOGOUT_LOADER_START); if (await oauthHandler.isAuthorisationTypeBasic()) { await authHandler.logout(configHandler.get('authtoken')); } else if (await oauthHandler.isAuthorisationTypeOAuth()) { - await oauthHandler.oauthLogout() + await oauthHandler.oauthLogout(); } cliux.loader(''); - this.logger.info('successfully logged out'); - cliux.success('CLI_AUTH_LOGOUT_SUCCESS'); + this.logger.info('Successfully logged out'); + cliux.success(messages.CLI_AUTH_LOGOUT_SUCCESS); } else { - cliux.success('CLI_AUTH_LOGOUT_ALREADY'); + cliux.success(messages.CLI_AUTH_LOGOUT_ALREADY); } } catch (error) { let errorMessage = ''; @@ -77,7 +78,7 @@ export default class LogoutCommand extends BaseCommand { } this.logger.error('Logout failed', errorMessage); - cliux.print('CLI_AUTH_LOGOUT_FAILED', { color: 'yellow' }); + cliux.print(messages.CLI_AUTH_LOGOUT_FAILED, { color: 'yellow' }); cliux.print(errorMessage, { color: 'red' }); } finally { if (confirm === true) { diff --git a/packages/contentstack-auth/src/commands/auth/tokens/add.ts b/packages/contentstack-auth/src/commands/auth/tokens/add.ts index e1a1e5db52..331177e5fc 100644 --- a/packages/contentstack-auth/src/commands/auth/tokens/add.ts +++ b/packages/contentstack-auth/src/commands/auth/tokens/add.ts @@ -1,4 +1,3 @@ -import { Command } from '@contentstack/cli-command'; import { cliux, configHandler, @@ -11,6 +10,7 @@ import { } from '@contentstack/cli-utilities'; import { askTokenType } from '../../../utils/interactive'; import { BaseCommand } from '../../../base-command'; +import { messages } from '../../../messages'; export default class TokensAddCommand extends BaseCommand { static description = 'Adds management/delivery tokens to your session to use it with other CLI commands'; @@ -103,34 +103,46 @@ export default class TokensAddCommand extends BaseCommand { static aliases = ['tokens']; static examples = ['$ csdx auth:tokens']; @@ -49,11 +49,11 @@ export default class TokensListCommand extends BaseCommand { static description = 'Removes selected tokens'; @@ -21,7 +21,7 @@ export default class TokensRemoveCommand extends BaseCommand = []; if (token || ignore) { configHandler.delete(`tokens.${alias}`); - return cliux.success(`CLI_AUTH_TOKENS_REMOVE_SUCCESS`); + return cliux.success(messages.CLI_AUTH_TOKENS_REMOVE_SUCCESS); } if (tokens && Object.keys(tokens).length > 0) { @@ -33,12 +33,12 @@ export default class TokensRemoveCommand extends BaseCommand = await cliux.inquire({ name: 'selectedTokens', - message: 'CLI_AUTH_TOKENS_REMOVE_SELECT_TOKEN', + message: messages.CLI_AUTH_TOKENS_REMOVE_SELECT_TOKEN, type: 'checkbox', choices: tokenOptions, }); @@ -46,20 +46,20 @@ export default class TokensRemoveCommand extends BaseCommand{ - this.logger.info('selected tokens',ele); - }) - + + selectedTokens.forEach((ele) => { + this.logger.info('selected tokens', ele); + }); + selectedTokens.forEach((element) => { const selectedToken = element.split(':')[0]; configHandler.delete(`tokens.${selectedToken}`); - cliux.success('CLI_AUTH_TOKENS_REMOVE_SUCCESS'); + cliux.success(messages.CLI_AUTH_TOKENS_REMOVE_SUCCESS); this.logger.info('Token removed successfully !!', element); }); } catch (error) { this.logger.error('Token remove error', error.message); - cliux.print('CLI_AUTH_TOKENS_REMOVE_FAILED', { color: 'yellow' }); + cliux.print(messages.CLI_AUTH_TOKENS_REMOVE_FAILED, { color: 'yellow' }); cliux.print(error.message, { color: 'red' }); } } diff --git a/packages/contentstack-auth/src/commands/auth/whoami.ts b/packages/contentstack-auth/src/commands/auth/whoami.ts index 0b82a510d3..24f3139c92 100644 --- a/packages/contentstack-auth/src/commands/auth/whoami.ts +++ b/packages/contentstack-auth/src/commands/auth/whoami.ts @@ -1,7 +1,6 @@ -import { Command } from '@contentstack/cli-command'; import { cliux } from '@contentstack/cli-utilities'; import { BaseCommand } from '../../base-command'; - +import { messages } from '../../messages/index'; export default class WhoamiCommand extends BaseCommand { static description = 'Display current users email address'; @@ -12,7 +11,7 @@ export default class WhoamiCommand extends BaseCommand { async run(): Promise { try { if (this.email) { - cliux.print('CLI_AUTH_WHOAMI_LOGGED_IN_AS', { color: 'white' }); + cliux.print(messages.CLI_AUTH_WHOAMI_LOGGED_IN_AS, { color: 'white' }); cliux.print(this.email, { color: 'green' }); this.logger.info('Currently logged in user', this.email); } else { @@ -20,7 +19,7 @@ export default class WhoamiCommand extends BaseCommand { } } catch (error) { this.logger.error('whoami error', error.message); - cliux.print('CLI_AUTH_WHOAMI_FAILED', { color: 'yellow' }); + cliux.print(messages.CLI_AUTH_WHOAMI_FAILED, { color: 'yellow' }); cliux.print(error.message, { color: 'red' }); } } diff --git a/packages/contentstack-auth/src/messages/index.ts b/packages/contentstack-auth/src/messages/index.ts new file mode 100644 index 0000000000..93c6cd5a75 --- /dev/null +++ b/packages/contentstack-auth/src/messages/index.ts @@ -0,0 +1,55 @@ +const messages = { + 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', +}; + +export { messages }; diff --git a/packages/contentstack-branches/package.json b/packages/contentstack-branches/package.json index d21b85f260..7a19537956 100644 --- a/packages/contentstack-branches/package.json +++ b/packages/contentstack-branches/package.json @@ -25,7 +25,7 @@ "winston": "^3.7.2" }, "devDependencies": { - "@contentstack/cli-auth": "~1.3.17", + "@contentstack/cli-auth": "~1.3.18", "@contentstack/cli-config": "~1.6.1", "@contentstack/cli-dev-dependencies": "~1.2.4", "@oclif/plugin-help": "^5.1.19", diff --git a/packages/contentstack-export/package.json b/packages/contentstack-export/package.json index 9377e499df..8b17f5d1dd 100644 --- a/packages/contentstack-export/package.json +++ b/packages/contentstack-export/package.json @@ -24,7 +24,7 @@ "winston": "^3.7.2" }, "devDependencies": { - "@contentstack/cli-auth": "~1.3.17", + "@contentstack/cli-auth": "~1.3.18", "@contentstack/cli-config": "~1.6.1", "@contentstack/cli-dev-dependencies": "~1.2.4", "@oclif/plugin-help": "^5.1.19", @@ -98,4 +98,4 @@ } }, "repository": "https://github.com/contentstack/cli" -} +} \ No newline at end of file diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index dc91fc8e98..da64daefdf 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -23,7 +23,7 @@ }, "dependencies": { "@contentstack/cli-audit": "~1.5.1", - "@contentstack/cli-auth": "~1.3.17", + "@contentstack/cli-auth": "~1.3.18", "@contentstack/cli-cm-bootstrap": "~1.9.0", "@contentstack/cli-cm-branches": "~1.0.24", "@contentstack/cli-cm-bulk-publish": "~1.4.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 61d66c7bc6..028abaa1d4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,7 +11,7 @@ importers: packages/contentstack: specifiers: '@contentstack/cli-audit': ~1.5.1 - '@contentstack/cli-auth': ~1.3.17 + '@contentstack/cli-auth': ~1.3.18 '@contentstack/cli-cm-bootstrap': ~1.9.0 '@contentstack/cli-cm-branches': ~1.0.24 '@contentstack/cli-cm-bulk-publish': ~1.4.3 @@ -300,7 +300,7 @@ importers: packages/contentstack-branches: specifiers: - '@contentstack/cli-auth': ~1.3.17 + '@contentstack/cli-auth': ~1.3.18 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-config': ~1.6.1 '@contentstack/cli-dev-dependencies': ~1.2.4 @@ -606,7 +606,7 @@ importers: packages/contentstack-export: specifiers: - '@contentstack/cli-auth': ~1.3.17 + '@contentstack/cli-auth': ~1.3.18 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-config': ~1.6.1 '@contentstack/cli-dev-dependencies': ~1.2.4 From b36f64cd2961f1b7a171baf0a33a8cb4ed535e36 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Sat, 23 Mar 2024 15:07:53 +0530 Subject: [PATCH 2/2] 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;