diff --git a/packages/cli/commands/auth.js b/packages/cli/commands/auth.js index edf302c76..50cd9f43d 100644 --- a/packages/cli/commands/auth.js +++ b/packages/cli/commands/auth.js @@ -9,7 +9,7 @@ const { const { i18n } = require('../lib/lang'); const { updateConfigWithPersonalAccessKey, -} = require('@hubspot/cli-lib/personalAccessKey'); +} = require('@hubspot/local-dev-lib/personalAccessKey'); const { updateAccountConfig, writeConfig, @@ -40,6 +40,7 @@ const { trackAuthAction, trackCommandUsage } = require('../lib/usageTracking'); const { authenticateWithOauth } = require('../lib/oauth'); const { EXIT_CODES } = require('../lib/enums/exitCodes'); const { uiFeatureHighlight } = require('../lib/ui'); +const { logErrorInstance } = require('../lib/errorHandlers/standardErrors'); const i18nKey = 'cli.commands.auth'; @@ -97,7 +98,15 @@ exports.handler = async options => { break; case PERSONAL_ACCESS_KEY_AUTH_METHOD.value: configData = await personalAccessKeyPrompt({ env, account }); - updatedConfig = await updateConfigWithPersonalAccessKey(configData); + + try { + updatedConfig = await updateConfigWithPersonalAccessKey( + configData.personalAccesskey, + env + ); + } catch (e) { + logErrorInstance(e); + } if (!updatedConfig) { break; diff --git a/packages/cli/commands/init.js b/packages/cli/commands/init.js index 4d20ff51f..589aa3c48 100644 --- a/packages/cli/commands/init.js +++ b/packages/cli/commands/init.js @@ -25,7 +25,7 @@ const { i18n } = require('../lib/lang'); const { logger } = require('@hubspot/cli-lib/logger'); const { updateConfigWithPersonalAccessKey, -} = require('@hubspot/cli-lib/personalAccessKey'); +} = require('@hubspot/local-dev-lib/personalAccessKey'); const { getCwd } = require('@hubspot/local-dev-lib/path'); const { trackCommandUsage, trackAuthAction } = require('../lib/usageTracking'); const { setLogLevel, addTestingOptions } = require('../lib/commonOpts'); @@ -51,14 +51,22 @@ const TRACKING_STATUS = { }; const personalAccessKeyConfigCreationFlow = async (env, account) => { - const configData = await personalAccessKeyPrompt({ env, account }); + const { personalAccessKey } = await personalAccessKeyPrompt({ env, account }); const { name } = await enterAccountNamePrompt(); - const accountConfig = { - ...configData, - name, - }; - return updateConfigWithPersonalAccessKey(accountConfig, true); + let updatedConfig; + + try { + updatedConfig = updateConfigWithPersonalAccessKey( + personalAccessKey, + env, + name, + true + ); + } catch (e) { + logErrorInstance(e); + } + return updatedConfig; }; const oauthConfigCreationFlow = async env => { diff --git a/packages/cli/lib/sandboxes.js b/packages/cli/lib/sandboxes.js index 23793a6fd..fb8900148 100644 --- a/packages/cli/lib/sandboxes.js +++ b/packages/cli/lib/sandboxes.js @@ -4,7 +4,7 @@ const { handleExit, handleKeypress } = require('./process'); const { logger } = require('@hubspot/cli-lib/logger'); const { updateConfigWithPersonalAccessKey, -} = require('@hubspot/cli-lib/personalAccessKey'); +} = require('@hubspot/local-dev-lib/personalAccessKey'); const { EXIT_CODES } = require('./enums/exitCodes'); const { enterAccountNamePrompt } = require('./prompts/enterAccountNamePrompt'); const { @@ -25,6 +25,7 @@ const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls'); const { personalAccessKeyPrompt, } = require('./prompts/personalAccessKeyPrompt'); +const { logErrorInstance } = require('./errorHandlers/standardErrors'); const STANDARD_SANDBOX = 'standard'; const DEVELOPER_SANDBOX = 'developer'; @@ -234,14 +235,26 @@ const validateSandboxUsageLimits = async (accountConfig, sandboxType, env) => { * @returns {String} validName saved into config */ const saveSandboxToConfig = async (env, result, force = false) => { - let configData = { env, personalAccessKey: result.personalAccessKey }; - if (!result.personalAccessKey) { - configData = await personalAccessKeyPrompt({ + let personalAccessKey = result.personalAccessKey; + if (personalAccessKey) { + const configData = await personalAccessKeyPrompt({ env, account: result.sandbox.sandboxHubId, }); + personalAccessKey = configData.personalAccessKey; } - const updatedConfig = await updateConfigWithPersonalAccessKey(configData); + + let updatedConfig; + + try { + updatedConfig = await updateConfigWithPersonalAccessKey( + personalAccessKey, + env + ); + } catch (e) { + logErrorInstance(e); + } + if (!updatedConfig) { throw new Error('Failed to update config with personal access key.'); }