Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ const setupConfig = async (exportCmdFlags: any): Promise<ExportConfig> => {

config.apiKey =
exportCmdFlags['stack-uid'] || exportCmdFlags['stack-api-key'] || config.apiKey || (await askAPIKey());
if (typeof config.apiKey !== 'string') {
log.debug('Invalid API key received!', { apiKey: config.apiKey });
throw new Error('Invalid API key received');
if (typeof config.apiKey !== 'string' || !config.apiKey || !config.apiKey.trim()) {
log.debug('Invalid or empty API key received!', { apiKey: config.apiKey });
throw new Error('Invalid or empty API key received. Please provide a valid stack API key.');
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/contentstack-export/src/utils/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ export const askAPIKey = async (): Promise<string> => {
type: 'input',
message: 'Enter the stack api key',
name: 'apiKey',
validate: (input: string) => {
if (!input || !input.trim()) {
return 'Stack API key cannot be empty. Please enter a valid stack API key.';
}
return true;
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ describe('Export Config Handler', () => {
await setupConfig(flags);
expect.fail('Should have thrown an error');
} catch (error: any) {
expect(error.message).to.include('Invalid API key received');
expect(error.message).to.include('Invalid or empty API key received. Please provide a valid stack API key.');
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
handleAndLogError,
configHandler,
createLogContext,
cliux,
loadChalk
} from '@contentstack/cli-utilities';

import { ImportConfig, Context } from '../../../types';
Expand Down Expand Up @@ -64,6 +66,7 @@ export default class ImportSetupCommand extends Command {
static usage = 'cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]';

async run(): Promise<void> {
await loadChalk();
try {
const { flags } = await this.parse(ImportSetupCommand);
let importSetupConfig = await setupImportConfig(flags);
Expand Down Expand Up @@ -95,17 +98,24 @@ export default class ImportSetupCommand extends Command {

CLIProgressManager.printGlobalSummary();

log.success(
`Backup folder and mapper files have been successfully created for the stack using the API key ${importSetupConfig.apiKey}.`,
importSetupConfig.context,
);
log.success(
`The backup folder has been created at '${pathValidator(path.join(importSetupConfig.backupDir))}'.`,
importSetupConfig.context,
);
const successMessage = `Backup folder and mapper files have been successfully created for the stack using the API key ${importSetupConfig.apiKey}.`;
const backupPathMessage = `The backup folder has been created at '${pathValidator(path.join(importSetupConfig.backupDir))}'.`;
Comment on lines +101 to +102

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move these to messages/index.json?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we resolve the variables or values used in these logs


log.success(successMessage, importSetupConfig.context);
log.success(backupPathMessage, importSetupConfig.context);

// log.success maps to the info level, which is suppressed on the console for
// progress-supported modules when showConsoleLogs is false. Print the backup
// folder path directly so it is always visible, regardless of that setting.
const showConsoleLogs = configHandler.get('log')?.showConsoleLogs ?? false;
if (!showConsoleLogs) {
cliux.print(successMessage);
cliux.print(backupPathMessage);
}
} catch (error) {
CLIProgressManager.printGlobalSummary();
handleAndLogError(error);
cliux.error(`ERROR: ${error instanceof Error ? error.message : String(error)}`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const setupConfig = async (importCmdFlags: any): Promise<ImportConfig> => {
} else {
config.apiKey =
importCmdFlags['stack-uid'] || importCmdFlags['stack-api-key'] || config.target_stack || (await askAPIKey());
if (typeof config.apiKey !== 'string') {
throw new Error('Invalid API key received');
if (typeof config.apiKey !== 'string' || !config.apiKey || !config.apiKey.trim()) {
throw new Error('Invalid or empty API key received. Please provide a valid stack API key.');
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/contentstack-import-setup/src/utils/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ export const askAPIKey = async (): Promise<string> => {
type: 'input',
message: 'Enter the stack api key',
name: 'apiKey',
validate: (input: string) => {
if (!input || !input.trim()) {
return 'Stack API key cannot be empty. Please enter a valid stack API key.';
}
return true;
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ const setupConfig = async (importCmdFlags: any): Promise<ImportConfig> => {
}
config.apiKey =
importCmdFlags['stack-uid'] || importCmdFlags['stack-api-key'] || config.apiKey || (await askAPIKey());
if (typeof config.apiKey !== 'string') {
throw new Error('Invalid API key received');
if (typeof config.apiKey !== 'string' || !config.apiKey || !config.apiKey.trim()) {
log.debug('Invalid or empty API key received!', { apiKey: config.apiKey });
throw new Error('Invalid or empty API key received. Please provide a valid stack API key.');
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/contentstack-import/src/utils/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export const askAPIKey = async (): Promise<string> => {
type: 'input',
message: 'Enter the stack api key',
name: 'apiKey',
validate: (input: string) => {
if (!input || !input.trim()) {
return 'Stack API key cannot be empty. Please enter a valid stack API key.';
}
return true;
},
});
};

Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading