import chalk from 'chalk'; import { ask } from './readline-helper'; import { HttpMethod, RootAPIHelper } from './root-api'; export const handleProductModuleNameChange = async (params: { newName: string; oldName: string; host: string; productModuleKey: string; apiKey: string; }) => { const { newName, oldName } = params; console.log( chalk.yellow( `\nIt looks like you are attempting to update the product module name from '${oldName}' to '${newName}'.`, ), ); const answerRenameProductModule = await ask.yesNo( `\nWould you like to update the product module name to '${newName}' (y/n)? `, ); if (!answerRenameProductModule) { console.log(chalk.yellow(`\nProduct module name was not updated. It will be reverted on your next pull.\n`)); } if (answerRenameProductModule) { const { apiKey, host, productModuleKey } = params; const rootApi = new RootAPIHelper({ host, apiKey, throwResponseErrors: true }); const response = await rootApi.send({ path: `/cli/product-modules/${productModuleKey}`, method: HttpMethod.Patch, body: { product_module_name: newName }, }); console.log(chalk.green(`\nProduct module name updated to '${response.name as string}'.\n`)); } };