Skip to content

Commit

Permalink
Merge pull request #1180 from HubSpot/fix-project-dev-account-validation
Browse files Browse the repository at this point in the history
Fix account validation in hs project dev
  • Loading branch information
camden11 authored Sep 20, 2024
2 parents f60d56f + 5edeef4 commit 294736d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
11 changes: 6 additions & 5 deletions packages/cli/commands/project/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ const {
const {
confirmDefaultAccountIsTarget,
suggestRecommendedNestedAccount,
checkIfAppDeveloperAccount,
checkIfDefaultAccountIsSupported,
createSandboxForLocalDev,
createDeveloperTestAccountForLocalDev,
createNewProjectForLocalDev,
createInitialBuildForNewProject,
useExistingDevTestAccount,
validateAccountOption,
checkIfAccountFlagIsSupported,
checkIfParentAccountIsAuthed,
} = require('../../lib/localDev');

Expand Down Expand Up @@ -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
Expand All @@ -131,8 +134,6 @@ exports.handler = async options => {
} else {
targetProjectAccountId = accountId;
}
} else if (!targetProjectAccountId && hasPublicApps) {
checkIfAppDeveloperAccount(accountConfig);
}

let createNewSandbox = false;
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}."
Expand Down
22 changes: 15 additions & 7 deletions packages/cli/lib/localDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
})
Expand All @@ -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(
Expand Down Expand Up @@ -465,8 +473,8 @@ const getAccountHomeUrl = accountId => {

module.exports = {
confirmDefaultAccountIsTarget,
checkIfAppDeveloperAccount,
validateAccountOption,
checkIfDefaultAccountIsSupported,
checkIfAccountFlagIsSupported,
suggestRecommendedNestedAccount,
createSandboxForLocalDev,
createDeveloperTestAccountForLocalDev,
Expand Down

0 comments on commit 294736d

Please sign in to comment.