Skip to content

Commit b7f5206

Browse files
committed
Enhance API key validation in import/export configurations
- Added checks to ensure the API key is not empty or only whitespace in both import and export configuration handlers. - Updated interactive prompts to validate API key input, providing user feedback if the input is invalid.
1 parent 7455a69 commit b7f5206

File tree

7 files changed

+1136
-1049
lines changed

7 files changed

+1136
-1049
lines changed

package-lock.json

Lines changed: 1107 additions & 1049 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-export/src/utils/export-config-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ const setupConfig = async (exportCmdFlags: any): Promise<ExportConfig> => {
8585
log.debug('Invalid API key received!', { apiKey: config.apiKey });
8686
throw new Error('Invalid API key received');
8787
}
88+
if (!config.apiKey || !config.apiKey.trim()) {
89+
log.debug('Empty API key received!', { apiKey: config.apiKey });
90+
throw new Error('Stack API key cannot be empty. Please provide a valid stack API key.');
91+
}
8892
}
8993
}
9094

packages/contentstack-export/src/utils/interactive.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,11 @@ export const askAPIKey = async (): Promise<string> => {
6464
type: 'input',
6565
message: 'Enter the stack api key',
6666
name: 'apiKey',
67+
validate: (input: string) => {
68+
if (!input || !input.trim()) {
69+
return 'Stack API key cannot be empty. Please enter a valid stack API key.';
70+
}
71+
return true;
72+
},
6773
});
6874
};

packages/contentstack-import-setup/src/utils/import-config-handler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ const setupConfig = async (importCmdFlags: any): Promise<ImportConfig> => {
6363
if (typeof config.apiKey !== 'string') {
6464
throw new Error('Invalid API key received');
6565
}
66+
if (!config.apiKey || !config.apiKey.trim()) {
67+
throw new Error('Stack API key cannot be empty. Please provide a valid stack API key.');
68+
}
6669
}
6770
}
6871

packages/contentstack-import-setup/src/utils/interactive.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,11 @@ export const askAPIKey = async (): Promise<string> => {
3232
type: 'input',
3333
message: 'Enter the stack api key',
3434
name: 'apiKey',
35+
validate: (input: string) => {
36+
if (!input || !input.trim()) {
37+
return 'Stack API key cannot be empty. Please enter a valid stack API key.';
38+
}
39+
return true;
40+
},
3541
});
3642
};

packages/contentstack-import/src/utils/import-config-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ const setupConfig = async (importCmdFlags: any): Promise<ImportConfig> => {
8484
if (typeof config.apiKey !== 'string') {
8585
throw new Error('Invalid API key received');
8686
}
87+
if (!config.apiKey || !config.apiKey.trim()) {
88+
log.debug('Empty API key received!', { apiKey: config.apiKey });
89+
throw new Error('Stack API key cannot be empty. Please provide a valid stack API key.');
90+
}
8791
}
8892
}
8993

packages/contentstack-import/src/utils/interactive.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export const askAPIKey = async (): Promise<string> => {
1919
type: 'input',
2020
message: 'Enter the stack api key',
2121
name: 'apiKey',
22+
validate: (input: string) => {
23+
if (!input || !input.trim()) {
24+
return 'Stack API key cannot be empty. Please enter a valid stack API key.';
25+
}
26+
return true;
27+
},
2228
});
2329
};
2430

0 commit comments

Comments
 (0)