chore: update cloud cli (#23392)

* chore: update cloud cli

* chore: condition to include prompt property

* chore: fix verification

* fix: lint errors

* fix: prettier issue

---------

Co-authored-by: Dimitris Messinis <dimitris.messinis@strapi.io>
Co-authored-by: Simone Taeggi <startae14@gmail.com>
This commit is contained in:
Maxime Castres 2025-05-05 13:37:52 +02:00 committed by GitHub
parent 59bf9b3f30
commit 0cf1e6de90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 15 deletions

View File

@ -52,7 +52,7 @@ For more information, see
- https://v4.zod.dev/
- https://v4.zod.dev/json-schema
- https://v4.zod.dev/metadata
:::
:::
### [Debug](https://github.com/debug-js/debug)

View File

@ -25,7 +25,7 @@ export async function promptLogin(ctx: CLIContext) {
}
export default async function loginAction(ctx: CLIContext): Promise<boolean> {
const { logger } = ctx;
const { logger, promptExperiment } = ctx;
const tokenService = await tokenServiceFactory(ctx);
const existingToken = await tokenService.retrieveToken();
const cloudApiService = await cloudApiFactory(ctx, existingToken || undefined);
@ -62,7 +62,9 @@ export default async function loginAction(ctx: CLIContext): Promise<boolean> {
logger.debug(e);
return false;
}
await trackEvent(ctx, cloudApiService, 'willLoginAttempt', {});
await trackEvent(ctx, cloudApiService, 'willLoginAttempt', {
...(promptExperiment && { promptExperiment }),
});
logger.debug('🔐 Creating device authentication request...', {
client_id: cliConfig.clientId,
@ -155,7 +157,10 @@ export default async function loginAction(ctx: CLIContext): Promise<boolean> {
'There seems to be a problem with your login information. Please try logging in again.'
);
spinnerFail();
await trackEvent(ctx, cloudApiService, 'didNotLogin', { loginMethod: 'cli' });
await trackEvent(ctx, cloudApiService, 'didNotLogin', {
loginMethod: 'cli',
...(promptExperiment && { promptExperiment }),
});
return false;
}
if (
@ -164,7 +169,10 @@ export default async function loginAction(ctx: CLIContext): Promise<boolean> {
) {
logger.debug(e);
spinnerFail();
await trackEvent(ctx, cloudApiService, 'didNotLogin', { loginMethod: 'cli' });
await trackEvent(ctx, cloudApiService, 'didNotLogin', {
loginMethod: 'cli',
...(promptExperiment && { promptExperiment }),
});
return false;
}
// Await interval before retrying
@ -179,7 +187,10 @@ export default async function loginAction(ctx: CLIContext): Promise<boolean> {
'To access your dashboard, please copy and paste the following URL into your web browser:'
);
logger.log(chalk.underline(`${apiConfig.dashboardBaseUrl}/projects`));
await trackEvent(ctx, cloudApiService, 'didLogin', { loginMethod: 'cli' });
await trackEvent(ctx, cloudApiService, 'didLogin', {
loginMethod: 'cli',
...(promptExperiment && { promptExperiment }),
});
};
await authenticate();

View File

@ -21,6 +21,8 @@ export type CloudCliConfig = {
questions: ReadonlyArray<DistinctQuestion<ProjectAnswers>>;
defaults: Partial<ProjectAnswers>;
introText: string;
userChoice?: object;
reference?: string;
};
projectDeployment: {
confirmationText: string;
@ -34,6 +36,7 @@ export type CloudCliConfig = {
export interface CLIContext {
cwd: string;
logger: Logger;
promptExperiment?: string;
}
export type StrapiCloudCommand = (params: {

View File

@ -16,6 +16,7 @@ function assertCloudError(e: unknown): asserts e is CloudError {
}
export async function handleCloudLogin(): Promise<void> {
let cloudApiConfig;
const logger = cloudServices.createLogger({
silent: false,
debug: process.argv.includes('--debug'),
@ -27,25 +28,31 @@ export async function handleCloudLogin(): Promise<void> {
try {
const { data: config } = await cloudApiService.config();
cloudApiConfig = config;
logger.log(parseToChalk(config.projectCreation.introText));
} catch (e: unknown) {
logger.debug(e);
logger.error(defaultErrorMessage);
return;
}
const { userChoice } = await inquirer.prompt<{ userChoice: string }>([
{
type: 'list',
name: 'userChoice',
message: `Please log in or sign up.`,
choices: ['Login/Sign up', 'Skip'],
},
]);
const { userChoice } = await inquirer.prompt<{ userChoice: string }>(
cloudApiConfig.projectCreation?.userChoice || [
{
type: 'list',
name: 'userChoice',
message: `Please log in or sign up.`,
choices: ['Login/Sign up', 'Skip'],
},
]
);
if (userChoice !== 'Skip') {
if (!userChoice.toLowerCase().includes('skip')) {
const cliContext = {
logger,
cwd: process.cwd(),
...(cloudApiConfig.projectCreation?.reference && {
promptExperiment: cloudApiConfig.projectCreation?.reference,
}),
};
try {