From e3bbfcfc79c5aa493c54a8b49c0d823eb1d9b8b0 Mon Sep 17 00:00:00 2001 From: Adam Wang Date: Fri, 23 Aug 2024 11:08:58 -0400 Subject: [PATCH] Remove deprecated sandbox sync command --- packages/cli/commands/sandbox.js | 2 - packages/cli/commands/sandbox/create.js | 1 + packages/cli/commands/sandbox/sync.js | 225 ------------------------ packages/cli/lang/en.lyaml | 30 ---- packages/cli/lib/localDev.js | 1 + 5 files changed, 2 insertions(+), 257 deletions(-) delete mode 100644 packages/cli/commands/sandbox/sync.js diff --git a/packages/cli/commands/sandbox.js b/packages/cli/commands/sandbox.js index 65c12427d..4d9b5c640 100644 --- a/packages/cli/commands/sandbox.js +++ b/packages/cli/commands/sandbox.js @@ -3,7 +3,6 @@ const { i18n } = require('../lib/lang'); const { uiBetaTag } = require('../lib/ui'); const create = require('./sandbox/create'); const del = require('./sandbox/delete'); -const sync = require('./sandbox/sync'); const i18nKey = 'commands.sandbox'; @@ -17,7 +16,6 @@ exports.builder = yargs => { yargs .command(create) .command(del) - .command(sync) .demandCommand(1, ''); return yargs; diff --git a/packages/cli/commands/sandbox/create.js b/packages/cli/commands/sandbox/create.js index fe75683d2..85e05c13b 100644 --- a/packages/cli/commands/sandbox/create.js +++ b/packages/cli/commands/sandbox/create.js @@ -145,6 +145,7 @@ exports.handler = async options => { }); const sandboxAccountConfig = getAccountConfig(result.sandbox.sandboxHubId); + // For v1 sandboxes, keep sync here. Once we migrate to v2, this will be handled by BE automatically const handleSyncSandbox = async syncTasks => { await syncSandbox({ accountConfig: sandboxAccountConfig, diff --git a/packages/cli/commands/sandbox/sync.js b/packages/cli/commands/sandbox/sync.js deleted file mode 100644 index 97f76c7ff..000000000 --- a/packages/cli/commands/sandbox/sync.js +++ /dev/null @@ -1,225 +0,0 @@ -const { - addAccountOptions, - addConfigOptions, - getAccountId, - addUseEnvironmentOptions, - addTestingOptions, -} = require('../../lib/commonOpts'); -const { trackCommandUsage } = require('../../lib/usageTracking'); -const { logger } = require('@hubspot/local-dev-lib/logger'); -const { loadAndValidateOptions } = require('../../lib/validation'); -const { i18n } = require('../../lib/lang'); -const { EXIT_CODES } = require('../../lib/enums/exitCodes'); -const { getAccountConfig, getEnv } = require('@hubspot/local-dev-lib/config'); -const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls'); -const { promptUser } = require('../../lib/prompts/promptUtils'); -const { - uiLine, - uiAccountDescription, - uiDeprecatedMessage, - uiDeprecatedDescription, -} = require('../../lib/ui'); -const { - isSandbox, - isStandardSandbox, - isDevelopmentSandbox, -} = require('../../lib/accountTypes'); -const { - getAvailableSyncTypes, - getSyncTypesWithContactRecordsPrompt, -} = require('../../lib/sandboxes'); -const { syncSandbox } = require('../../lib/sandboxSync'); -const { getValidEnv } = require('@hubspot/local-dev-lib/environment'); -const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/apiErrors'); -const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors'); -const { - HUBSPOT_ACCOUNT_TYPE_STRINGS, - HUBSPOT_ACCOUNT_TYPES, -} = require('@hubspot/local-dev-lib/constants/config'); - -const i18nKey = 'commands.sandbox.subcommands.sync'; - -exports.command = 'sync'; -exports.describe = uiDeprecatedDescription( - i18n(`${i18nKey}.describe`), - 'hs sandbox sync' -); - -exports.handler = async options => { - await loadAndValidateOptions(options); - - uiDeprecatedMessage('hs sandbox sync'); - - const { force } = options; // For scripting purposes - const accountId = getAccountId(options); - const accountConfig = getAccountConfig(accountId); - const env = getValidEnv(getEnv(accountId)); - - trackCommandUsage( - 'sandbox-sync', - { type: accountConfig.accountType }, - accountId - ); - - if ( - // Check if default account is a sandbox, otherwise exit - !isSandbox(accountConfig) - ) { - logger.error( - i18n(`${i18nKey}.failure.invalidAccountType`, { - accountType: - HUBSPOT_ACCOUNT_TYPE_STRINGS[ - HUBSPOT_ACCOUNT_TYPES[accountConfig.accountType] - ], - }) - ); - process.exit(EXIT_CODES.ERROR); - } - - // Verify parent account exists in the config - let parentAccountId = accountConfig.parentAccountId || undefined; - if (!parentAccountId || !getAccountId({ account: parentAccountId })) { - logger.log(''); - logger.error( - i18n(`${i18nKey}.failure.missingParentPortal`, { - sandboxName: uiAccountDescription(accountId), - }) - ); - process.exit(EXIT_CODES.ERROR); - } - - const parentAccountConfig = getAccountConfig(parentAccountId); - - let availableSyncTasks; - try { - availableSyncTasks = await getAvailableSyncTypes( - parentAccountConfig, - accountConfig - ); - } catch (error) { - if ( - isSpecifiedError(error, { - statusCode: 404, - category: 'OBJECT_NOT_FOUND', - subCategory: 'SandboxErrors.SANDBOX_NOT_FOUND', - }) - ) { - logger.error( - i18n('lib.sandbox.sync.failure.objectNotFound', { - account: uiAccountDescription(accountId), - }) - ); - } else { - logErrorInstance(error); - } - process.exit(EXIT_CODES.ERROR); - } - - if (isDevelopmentSandbox(accountConfig)) { - logger.log(i18n(`${i18nKey}.info.developmentSandbox`)); - logger.log( - i18n(`${i18nKey}.info.sync`, { - parentAccountName: uiAccountDescription(parentAccountId), - sandboxName: uiAccountDescription(accountId), - }) - ); - uiLine(); - logger.warn(i18n(`${i18nKey}.warning.developmentSandbox`)); - uiLine(); - logger.log(''); - - if (!force) { - // Skip confirmation if force flag is present. - const { confirmSandboxSyncPrompt: confirmed } = await promptUser([ - { - name: 'confirmSandboxSyncPrompt', - type: 'confirm', - message: i18n(`${i18nKey}.confirm.developmentSandbox`, { - parentAccountName: uiAccountDescription(parentAccountId), - sandboxName: uiAccountDescription(accountId), - }), - }, - ]); - if (!confirmed) { - process.exit(EXIT_CODES.SUCCESS); - } - } - } else if (isStandardSandbox(accountConfig)) { - const standardSyncUrl = `${getHubSpotWebsiteOrigin( - env - )}/sandboxes-developer/${parentAccountId}/sync?step=select_sync_path&id=${parentAccountId}_${accountId}`; - - logger.log( - i18n(`${i18nKey}.info.standardSandbox`, { - url: standardSyncUrl, - }) - ); - logger.log( - i18n(`${i18nKey}.info.sync`, { - parentAccountName: uiAccountDescription(parentAccountId), - sandboxName: uiAccountDescription(accountId), - }) - ); - uiLine(); - logger.warn(i18n(`${i18nKey}.warning.standardSandbox`)); - uiLine(); - logger.log(''); - - if (!force) { - // Skip confirmation if force flag is present. - const { confirmSandboxSyncPrompt: confirmed } = await promptUser([ - { - name: 'confirmSandboxSyncPrompt', - type: 'confirm', - message: i18n(`${i18nKey}.confirm.standardSandbox`, { - parentAccountName: uiAccountDescription(parentAccountId), - sandboxName: uiAccountDescription(accountId), - }), - }, - ]); - if (!confirmed) { - process.exit(EXIT_CODES.SUCCESS); - } - } - } else { - logger.error('Sync must be run in a sandbox account.'); - process.exit(EXIT_CODES.ERROR); - } - - try { - const syncTasks = await getSyncTypesWithContactRecordsPrompt( - accountConfig, - availableSyncTasks, - force - ); - - await syncSandbox({ - accountConfig, - parentAccountConfig, - env, - syncTasks, - allowEarlyTermination: true, - }); - - process.exit(EXIT_CODES.SUCCESS); - } catch (error) { - process.exit(EXIT_CODES.ERROR); - } -}; - -exports.builder = yargs => { - yargs.option('f', { - type: 'boolean', - alias: 'force', - describe: i18n(`${i18nKey}.examples.force`), - }); - - yargs.example([['$0 sandbox sync', i18n(`${i18nKey}.examples.default`)]]); - - addConfigOptions(yargs); - addAccountOptions(yargs); - addUseEnvironmentOptions(yargs); - addTestingOptions(yargs); - - return yargs; -}; diff --git a/packages/cli/lang/en.lyaml b/packages/cli/lang/en.lyaml index 911cf673e..024db1252 100644 --- a/packages/cli/lang/en.lyaml +++ b/packages/cli/lang/en.lyaml @@ -764,30 +764,6 @@ en: options: account: describe: "Account name or id to delete" - sync: - describe: "Sync to a sandbox account" - examples: - default: "Initiates a sync to a sandbox account." - force: "Skips all confirmation prompts when initiating a sync." - info: - developmentSandbox: "This will sync CRM object definitions." - standardSandbox: "This will sync all supported assets. - \nTo sync only specific assets, follow this link: {{#bold}}{{ url }}{{/bold}}" - sync: "\nSync direction: - \n- Target sandbox: {{#cyan}}{{#bold}}{{ sandboxName }}{{/bold}}{{/cyan}} - \n- Source account: {{#bold}}{{ parentAccountName }}{{/bold}} - \n\nRun {{#bold}}hs accounts use{{/bold}} to change your default account and sync to a different target sandbox." - warning: - developmentSandbox: "Syncing will update previously synced object definitions and add new ones from production to your development sandbox. Object definitions that were created in your sandbox will stay the same." - standardSandbox: "Syncing can have a big impact. Updates from your production account may overwrite changes in your standard sandbox. Standard sandboxes are usually shared with other Super Admins." - confirm: - developmentSandbox: "Sync CRM object definitions to {{#cyan}}{{#bold}}{{ sandboxName }}{{/bold}}{{/cyan}} from {{#bold}}{{ parentAccountName }}{{/bold}}?" - standardSandbox: "Sync all supported assets to {{#cyan}}{{#bold}}{{ sandboxName }}{{/bold}}{{/cyan}} from {{#bold}}{{ parentAccountName }}{{/bold}}?" - failure: - invalidAccountType: "Sync must be run in a sandbox account. Your default account is a {{ accountType }}. Run {{#bold}}hs auth{{/bold}} to connect your sandbox account to the CLI or {{#bold}}hs accounts use{{/bold}} to change your default account, then try again." - missingParentPortal: "The production account associated to {{#bold}}{{ sandboxName }}{{/bold}} is not connected to your HubSpot CLI. - \n- Run {{#bold}}hs auth{{/bold}} to connect that account to your terminal, then try again. - \n- Run {{#bold}}hs accounts use{{/bold}} to change your default account, if you want to sync to a different sandbox. Then try again.\n" secrets: describe: "Manage HubSpot secrets." subcommands: @@ -1117,12 +1093,6 @@ en: projectDevCommand: command: "hs project dev" message: "Run {{ command }} to set up your test environment and start local development" - sandboxSyncDevelopmentCommand: - command: "hs sandbox sync" - message: "Run {{ command }} to to update CRM object definitions in your sandbox" - sandboxSyncStandardCommand: - command: "hs sandbox sync" - message: "Run {{ command }} to to update all supported assets to your sandbox from production" sampleProjects: linkText: "HubSpot's sample projects" url: "https://developers.hubspot.com/docs/platform/sample-projects?utm_source=cli&utm_content=project_create_whats_next" diff --git a/packages/cli/lib/localDev.js b/packages/cli/lib/localDev.js index 826207499..7665531ac 100644 --- a/packages/cli/lib/localDev.js +++ b/packages/cli/lib/localDev.js @@ -195,6 +195,7 @@ const createSandboxForLocalDev = async (accountId, accountConfig, env) => { accountConfig, sandboxAccountConfig ); + // For v1 sandboxes, keep sync here. Once we migrate to v2, this will be handled by BE automatically await syncSandbox({ accountConfig: sandboxAccountConfig, parentAccountConfig: accountConfig,