From 5edeef463ed1b005b00fe686721f5eb8cf2764cb Mon Sep 17 00:00:00 2001 From: Camden Phalen Date: Fri, 20 Sep 2024 13:57:41 -0400 Subject: [PATCH] Fix account validation in hs project dev --- packages/cli/commands/project/dev.js | 11 ++++++----- packages/cli/lang/en.lyaml | 4 +++- packages/cli/lib/localDev.js | 22 +++++++++++++++------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/cli/commands/project/dev.js b/packages/cli/commands/project/dev.js index dea06d930..071948ee0 100644 --- a/packages/cli/commands/project/dev.js +++ b/packages/cli/commands/project/dev.js @@ -40,13 +40,13 @@ const { const { confirmDefaultAccountIsTarget, suggestRecommendedNestedAccount, - checkIfAppDeveloperAccount, + checkIfDefaultAccountIsSupported, createSandboxForLocalDev, createDeveloperTestAccountForLocalDev, createNewProjectForLocalDev, createInitialBuildForNewProject, useExistingDevTestAccount, - validateAccountOption, + checkIfAccountFlagIsSupported, checkIfParentAccountIsAuthed, } = require('../../lib/localDev'); @@ -111,12 +111,15 @@ exports.handler = async options => { // The account that we are locally testing against let targetTestingAccountId = options.account ? accountId : null; + // Check that the default account or flag option is valid for the type of app in this project if (options.account) { - validateAccountOption(accountConfig, hasPublicApps); + checkIfAccountFlagIsSupported(accountConfig, hasPublicApps); if (hasPublicApps) { targetProjectAccountId = accountConfig.parentAccountId; } + } else { + checkIfDefaultAccountIsSupported(accountConfig, hasPublicApps); } // The user is targeting an account type that we recommend developing on @@ -131,8 +134,6 @@ exports.handler = async options => { } else { targetProjectAccountId = accountId; } - } else if (!targetProjectAccountId && hasPublicApps) { - checkIfAppDeveloperAccount(accountConfig); } let createNewSandbox = false; diff --git a/packages/cli/lang/en.lyaml b/packages/cli/lang/en.lyaml index 1b36f7dd4..e7ec1ce73 100644 --- a/packages/cli/lang/en.lyaml +++ b/packages/cli/lang/en.lyaml @@ -1008,7 +1008,9 @@ en: localDev: confirmDefaultAccountIsTarget: declineDefaultAccountExplanation: "To develop on a different account, run {{ useCommand }} to change your default account, then re-run {{ devCommand }}." - checkIfAppDevloperAccount: "This project contains a public app. Local development of public apps is only supported on developer accounts and developer test accounts. Change your default account using {{ useCommand }}, or link a new account with {{ authCommand }}." + checkIfDefaultAccountIsSupported: + publicApp: "This project contains a public app. Local development of public apps is only supported on developer accounts and developer test accounts. Change your default account using {{ useCommand }}, or link a new account with {{ authCommand }}." + privateApp: "This project contains a private app. Local development of private apps is not supported in developer accounts. Change your default account using {{ useCommand }}, or link a new account with {{ authCommand }}." validateAccountOption: invalidPublicAppAccount: "This project contains a public app. The \"--account\" flag must point to a developer test account to develop this project locally. Alternatively, change your default account to an App Developer Account using {{ useCommand }} and run {{ devCommand }} to set up a new Developer Test Account." invalidPrivateAppAccount: "This project contains a private app. The account specified with the \"--account\" flag points to a developer account, which do not support the local development of private apps. Update the \"--account\" flag to point to a standard, sandbox, or developer test account, or change your default account by running {{ useCommand }}." diff --git a/packages/cli/lib/localDev.js b/packages/cli/lib/localDev.js index fc447605e..b421095ad 100644 --- a/packages/cli/lib/localDev.js +++ b/packages/cli/lib/localDev.js @@ -82,11 +82,19 @@ const confirmDefaultAccountIsTarget = async accountConfig => { } }; -// Confirm the default account is a developer account if developing public apps -const checkIfAppDeveloperAccount = accountConfig => { - if (!isAppDeveloperAccount(accountConfig)) { +// Confirm the default account is supported for the type of apps being developed +const checkIfDefaultAccountIsSupported = (accountConfig, hasPublicApps) => { + if (hasPublicApps && !isAppDeveloperAccount(accountConfig)) { + logger.error( + i18n(`${i18nKey}.checkIfDefaultAccountIsSupported.publicApp`, { + useCommand: uiCommandReference('hs accounts use'), + authCommand: uiCommandReference('hs auth'), + }) + ); + process.exit(EXIT_CODES.SUCCESS); + } else if (!hasPublicApps && isAppDeveloperAccount(accountConfig)) { logger.error( - i18n(`${i18nKey}.checkIfAppDevloperAccount`, { + i18n(`${i18nKey}.checkIfDefaultAccountIsSupported.privateApp`, { useCommand: uiCommandReference('hs accounts use'), authCommand: uiCommandReference('hs auth'), }) @@ -111,7 +119,7 @@ const checkIfParentAccountIsAuthed = accountConfig => { }; // Confirm the default account is a developer account if developing public apps -const validateAccountOption = (accountConfig, hasPublicApps) => { +const checkIfAccountFlagIsSupported = (accountConfig, hasPublicApps) => { if (hasPublicApps) { if (!isDeveloperTestAccount) { logger.error( @@ -465,8 +473,8 @@ const getAccountHomeUrl = accountId => { module.exports = { confirmDefaultAccountIsTarget, - checkIfAppDeveloperAccount, - validateAccountOption, + checkIfDefaultAccountIsSupported, + checkIfAccountFlagIsSupported, suggestRecommendedNestedAccount, createSandboxForLocalDev, createDeveloperTestAccountForLocalDev,