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 @@ -106,6 +109,7 @@ export default class ImportSetupCommand extends Command {
} 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