@hubspot/cli 7.7.16-experimental.1 → 7.7.16-experimental.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,9 +98,9 @@ async function handleConfigMigration() {
98
98
  const describe = en_1.commands.account.subcommands.auth.describe;
99
99
  const command = 'auth';
100
100
  async function handler(args) {
101
- const { providedAccountId, disableTracking, personalAccessKey: providedPersonalAccessKey, } = args;
101
+ const { disableTracking, personalAccessKey: providedPersonalAccessKey, derivedAccountId, } = args;
102
102
  if (!disableTracking) {
103
- (0, usageTracking_1.trackCommandUsage)('account-auth', {}, providedAccountId);
103
+ (0, usageTracking_1.trackCommandUsage)('account-auth', {}, derivedAccountId);
104
104
  await (0, usageTracking_1.trackAuthAction)('account-auth', authType, TRACKING_STATUS.STARTED);
105
105
  }
106
106
  const configMigrationSuccess = await handleConfigMigration();
@@ -114,7 +114,7 @@ async function handler(args) {
114
114
  }
115
115
  (0, config_1.loadConfig)('');
116
116
  (0, process_1.handleExit)(config_1.deleteEmptyConfigFile);
117
- const updatedConfig = await updateConfigWithNewAccount(args.qa ? environments_1.ENVIRONMENTS.QA : environments_1.ENVIRONMENTS.PROD, configAlreadyExists, providedPersonalAccessKey, providedAccountId);
117
+ const updatedConfig = await updateConfigWithNewAccount(args.qa ? environments_1.ENVIRONMENTS.QA : environments_1.ENVIRONMENTS.PROD, configAlreadyExists, providedPersonalAccessKey, derivedAccountId);
118
118
  if (!updatedConfig) {
119
119
  if (!disableTracking) {
120
120
  await (0, usageTracking_1.trackAuthAction)('account-auth', authType, TRACKING_STATUS.ERROR);
package/commands/auth.js CHANGED
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const git_1 = require("../lib/ui/git");
4
- const logger_1 = require("@hubspot/local-dev-lib/logger");
5
4
  const auth_1 = require("@hubspot/local-dev-lib/constants/auth");
6
5
  const environments_1 = require("@hubspot/local-dev-lib/constants/environments");
7
6
  const config_1 = require("@hubspot/local-dev-lib/constants/config");
8
- const lang_1 = require("../lib/lang");
9
7
  const personalAccessKey_1 = require("@hubspot/local-dev-lib/personalAccessKey");
10
8
  const config_2 = require("@hubspot/local-dev-lib/config");
11
9
  const text_1 = require("@hubspot/local-dev-lib/text");
@@ -21,6 +19,8 @@ const exitCodes_1 = require("../lib/enums/exitCodes");
21
19
  const ui_1 = require("../lib/ui");
22
20
  const index_1 = require("../lib/errorHandlers/index");
23
21
  const en_1 = require("../lang/en");
22
+ const logger_1 = require("../lib/ui/logger");
23
+ const parsing_1 = require("../lib/parsing");
24
24
  const TRACKING_STATUS = {
25
25
  STARTED: 'started',
26
26
  ERROR: 'error',
@@ -32,9 +32,19 @@ const ALLOWED_AUTH_METHODS = [
32
32
  ];
33
33
  const SUPPORTED_AUTHENTICATION_PROTOCOLS_TEXT = (0, text_1.commaSeparatedValues)(ALLOWED_AUTH_METHODS);
34
34
  const command = 'auth';
35
- const describe = (0, lang_1.i18n)('commands.auth.describe');
35
+ const describe = en_1.commands.auth.describe;
36
36
  async function handler(args) {
37
- const { authType: authTypeFlagValue, config: configFlagValue, qa, providedAccountId, personalAccessKey: providedPersonalAccessKey, } = args;
37
+ const { authType: authTypeFlagValue, config: configFlagValue, qa, personalAccessKey: providedPersonalAccessKey, userProvidedAccount, } = args;
38
+ let parsedUserProvidedAccountId;
39
+ try {
40
+ if (userProvidedAccount) {
41
+ parsedUserProvidedAccountId = (0, parsing_1.parseStringToNumber)(userProvidedAccount);
42
+ }
43
+ }
44
+ catch (err) {
45
+ (0, index_1.logError)(en_1.commands.auth.errors.invalidAccountIdProvided);
46
+ process.exit(exitCodes_1.EXIT_CODES.ERROR);
47
+ }
38
48
  const authType = (authTypeFlagValue && authTypeFlagValue.toLowerCase()) ||
39
49
  auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value;
40
50
  (0, commonOpts_1.setLogLevel)(args);
@@ -46,13 +56,11 @@ async function handler(args) {
46
56
  (0, git_1.checkAndWarnGitInclusion)(configPath);
47
57
  }
48
58
  if ((0, config_2.configFileExists)(true)) {
49
- logger_1.logger.error((0, lang_1.i18n)(`commands.auth.errors.globalConfigFileExists`, {
50
- accountAuthCommand: (0, ui_1.uiCommandReference)('hs account auth'),
51
- }));
59
+ logger_1.uiLogger.error(en_1.commands.auth.errors.globalConfigFileExists('hs account auth'));
52
60
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
53
61
  }
54
62
  (0, usageTracking_1.trackCommandUsage)('auth');
55
- (0, usageTracking_1.trackAuthAction)('auth', authType, TRACKING_STATUS.STARTED, providedAccountId);
63
+ (0, usageTracking_1.trackAuthAction)('auth', authType, TRACKING_STATUS.STARTED, parsedUserProvidedAccountId);
56
64
  let configData;
57
65
  let updatedConfig;
58
66
  let validName;
@@ -73,7 +81,7 @@ async function handler(args) {
73
81
  ? { personalAccessKey: providedPersonalAccessKey }
74
82
  : await (0, personalAccessKeyPrompt_1.personalAccessKeyPrompt)({
75
83
  env,
76
- account: providedAccountId,
84
+ account: parsedUserProvidedAccountId,
77
85
  });
78
86
  try {
79
87
  token = await (0, personalAccessKey_1.getAccessToken)(personalAccessKey, env);
@@ -101,24 +109,17 @@ async function handler(args) {
101
109
  successAuthMethod = auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.name;
102
110
  break;
103
111
  default:
104
- logger_1.logger.error((0, lang_1.i18n)('commands.auth.errors.unsupportedAuthType', {
105
- supportedProtocols: SUPPORTED_AUTHENTICATION_PROTOCOLS_TEXT,
106
- type: authType,
107
- }));
112
+ logger_1.uiLogger.error(en_1.commands.auth.errors.unsupportedAuthType(authType, SUPPORTED_AUTHENTICATION_PROTOCOLS_TEXT));
108
113
  break;
109
114
  }
110
115
  if (!successAuthMethod) {
111
- await (0, usageTracking_1.trackAuthAction)('auth', authType, TRACKING_STATUS.ERROR, providedAccountId);
116
+ await (0, usageTracking_1.trackAuthAction)('auth', authType, TRACKING_STATUS.ERROR, parsedUserProvidedAccountId);
112
117
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
113
118
  }
114
119
  const nameFromConfigData = configData && 'name' in configData ? configData.name : undefined;
115
120
  const accountName = (updatedConfig && updatedConfig.name) || validName || nameFromConfigData;
116
121
  await (0, setAsDefaultAccountPrompt_1.setAsDefaultAccountPrompt)(accountName);
117
- logger_1.logger.success((0, lang_1.i18n)('commands.auth.success.configFileUpdated', {
118
- configFilename: config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
119
- authType: successAuthMethod,
120
- accountName,
121
- }));
122
+ logger_1.uiLogger.success(en_1.commands.auth.success.configFileUpdated(accountName, config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME, successAuthMethod));
122
123
  (0, ui_1.uiFeatureHighlight)([
123
124
  'accountsUseCommand',
124
125
  'accountOption',
@@ -131,7 +132,7 @@ async function handler(args) {
131
132
  function authBuilder(yargs) {
132
133
  yargs.options({
133
134
  'auth-type': {
134
- describe: (0, lang_1.i18n)('commands.auth.options.authType.describe'),
135
+ describe: en_1.commands.auth.options.authType.describe,
135
136
  type: 'string',
136
137
  choices: [
137
138
  `${auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value}`,
@@ -140,7 +141,7 @@ function authBuilder(yargs) {
140
141
  default: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
141
142
  },
142
143
  account: {
143
- describe: (0, lang_1.i18n)('commands.auth.options.account.describe'),
144
+ describe: en_1.commands.auth.options.account.describe,
144
145
  type: 'string',
145
146
  alias: 'a',
146
147
  },
@@ -153,10 +154,7 @@ function authBuilder(yargs) {
153
154
  });
154
155
  return yargs;
155
156
  }
156
- const builder = (0, yargsUtils_1.makeYargsBuilder)(authBuilder, command, (0, lang_1.i18n)('commands.auth.verboseDescribe', {
157
- authMethod: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
158
- configName: config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
159
- }), {
157
+ const builder = (0, yargsUtils_1.makeYargsBuilder)(authBuilder, command, en_1.commands.auth.verboseDescribe(auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value, config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME), {
160
158
  useGlobalOptions: true,
161
159
  useConfigOptions: true,
162
160
  useTestingOptions: true,
package/commands/init.js CHANGED
@@ -13,13 +13,11 @@ const personalAccessKey_1 = require("@hubspot/local-dev-lib/personalAccessKey");
13
13
  const path_2 = require("@hubspot/local-dev-lib/path");
14
14
  const text_1 = require("@hubspot/local-dev-lib/text");
15
15
  const environments_1 = require("@hubspot/local-dev-lib/constants/environments");
16
- const logger_1 = require("@hubspot/local-dev-lib/logger");
17
16
  const getAccountIdentifier_1 = require("@hubspot/local-dev-lib/config/getAccountIdentifier");
18
17
  const commonOpts_1 = require("../lib/commonOpts");
19
18
  const yargsUtils_1 = require("../lib/yargsUtils");
20
19
  const process_1 = require("../lib/process");
21
20
  const index_1 = require("../lib/errorHandlers/index");
22
- const lang_1 = require("../lib/lang");
23
21
  const usageTracking_1 = require("../lib/usageTracking");
24
22
  const promptUtils_1 = require("../lib/prompts/promptUtils");
25
23
  const personalAccessKeyPrompt_1 = require("../lib/prompts/personalAccessKeyPrompt");
@@ -27,6 +25,9 @@ const accountNamePrompt_1 = require("../lib/prompts/accountNamePrompt");
27
25
  const oauth_1 = require("../lib/oauth");
28
26
  const exitCodes_1 = require("../lib/enums/exitCodes");
29
27
  const ui_1 = require("../lib/ui");
28
+ const logger_1 = require("../lib/ui/logger");
29
+ const en_1 = require("../lang/en");
30
+ const parsing_1 = require("../lib/parsing");
30
31
  const TRACKING_STATUS = {
31
32
  STARTED: 'started',
32
33
  ERROR: 'error',
@@ -61,9 +62,19 @@ const AUTH_TYPE_NAMES = {
61
62
  [auth_1.OAUTH_AUTH_METHOD.value]: auth_1.OAUTH_AUTH_METHOD.name,
62
63
  };
63
64
  const command = 'init';
64
- const describe = (0, lang_1.i18n)(`commands.init.describe`);
65
+ const describe = en_1.commands.init.describe;
65
66
  async function handler(args) {
66
- const { authType: authTypeFlagValue, c: configFlagValue, providedAccountId, disableTracking, useHiddenConfig, } = args;
67
+ const { authType: authTypeFlagValue, c: configFlagValue, disableTracking, useHiddenConfig, userProvidedAccount, } = args;
68
+ let parsedUserProvidedAccountId;
69
+ try {
70
+ if (userProvidedAccount) {
71
+ parsedUserProvidedAccountId = (0, parsing_1.parseStringToNumber)(userProvidedAccount);
72
+ }
73
+ }
74
+ catch (err) {
75
+ logger_1.uiLogger.error(en_1.commands.init.errors.invalidAccountIdProvided);
76
+ process.exit(exitCodes_1.EXIT_CODES.ERROR);
77
+ }
67
78
  const authType = (authTypeFlagValue && authTypeFlagValue.toLowerCase()) ||
68
79
  auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value;
69
80
  const configPath = (configFlagValue && path_1.default.join((0, path_2.getCwd)(), configFlagValue)) ||
@@ -76,28 +87,24 @@ async function handler(args) {
76
87
  }
77
88
  const env = args.qa ? environments_1.ENVIRONMENTS.QA : environments_1.ENVIRONMENTS.PROD;
78
89
  if ((0, config_1.configFileExists)(true)) {
79
- logger_1.logger.error((0, lang_1.i18n)(`commands.init.errors.globalConfigFileExists`, {
80
- accountAuthCommand: (0, ui_1.uiCommandReference)('hs account auth'),
81
- }));
90
+ logger_1.uiLogger.error(en_1.commands.init.errors.globalConfigFileExists);
82
91
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
83
92
  }
84
93
  if (fs_extra_1.default.existsSync(configPath)) {
85
- logger_1.logger.error((0, lang_1.i18n)(`commands.init.errors.configFileExists`, {
86
- configPath: configPath,
87
- }));
88
- logger_1.logger.info((0, lang_1.i18n)(`commands.init.logs.updateConfig`));
94
+ logger_1.uiLogger.error(en_1.commands.init.errors.configFileExists(configPath));
95
+ logger_1.uiLogger.info(en_1.commands.init.logs.updateConfig);
89
96
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
90
97
  }
91
98
  if (!disableTracking) {
92
- await (0, usageTracking_1.trackAuthAction)('init', authType, TRACKING_STATUS.STARTED, providedAccountId);
99
+ await (0, usageTracking_1.trackAuthAction)('init', authType, TRACKING_STATUS.STARTED, parsedUserProvidedAccountId);
93
100
  }
94
101
  const doesOtherConfigFileExist = (0, config_1.configFileExists)(!useHiddenConfig);
95
102
  if (doesOtherConfigFileExist) {
96
103
  const path = (0, config_1.getConfigPath)('', !useHiddenConfig);
97
- logger_1.logger.error((0, lang_1.i18n)(`commands.init.errors.bothConfigFilesNotAllowed`, { path: path }));
104
+ logger_1.uiLogger.error(en_1.commands.init.errors.bothConfigFilesNotAllowed(path));
98
105
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
99
106
  }
100
- (0, usageTracking_1.trackAuthAction)('init', authType, TRACKING_STATUS.STARTED, providedAccountId);
107
+ (0, usageTracking_1.trackAuthAction)('init', authType, TRACKING_STATUS.STARTED, parsedUserProvidedAccountId);
101
108
  (0, config_1.createEmptyConfigFile)({ path: configPath }, useHiddenConfig);
102
109
  //Needed to load deprecated config
103
110
  (0, config_1.loadConfig)(configPath, args);
@@ -106,7 +113,7 @@ async function handler(args) {
106
113
  let accountId;
107
114
  let name;
108
115
  if (authType === auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
109
- const personalAccessKeyResult = await personalAccessKeyConfigCreationFlow(env, providedAccountId);
116
+ const personalAccessKeyResult = await personalAccessKeyConfigCreationFlow(env, parsedUserProvidedAccountId);
110
117
  if (personalAccessKeyResult) {
111
118
  accountId = (0, getAccountIdentifier_1.getAccountIdentifier)(personalAccessKeyResult);
112
119
  name = personalAccessKeyResult.name;
@@ -124,14 +131,9 @@ async function handler(args) {
124
131
  catch (e) {
125
132
  (0, index_1.debugError)(e);
126
133
  }
127
- logger_1.logger.log('');
128
- logger_1.logger.success((0, lang_1.i18n)(`commands.init.success.configFileCreated`, {
129
- configPath: configPath,
130
- }));
131
- logger_1.logger.success((0, lang_1.i18n)(`commands.init.success.configFileUpdated`, {
132
- authType: AUTH_TYPE_NAMES[authType],
133
- account: name || accountId,
134
- }));
134
+ logger_1.uiLogger.log('');
135
+ logger_1.uiLogger.success(en_1.commands.init.success.configFileCreated(configPath));
136
+ logger_1.uiLogger.success(en_1.commands.init.success.configFileUpdated(AUTH_TYPE_NAMES[authType], name || accountId));
135
137
  (0, ui_1.uiFeatureHighlight)([
136
138
  'getStartedCommand',
137
139
  'helpCommand',
@@ -146,7 +148,7 @@ async function handler(args) {
146
148
  catch (err) {
147
149
  (0, index_1.logError)(err);
148
150
  if (!disableTracking) {
149
- await (0, usageTracking_1.trackAuthAction)('init', authType, TRACKING_STATUS.ERROR, providedAccountId);
151
+ await (0, usageTracking_1.trackAuthAction)('init', authType, TRACKING_STATUS.ERROR, parsedUserProvidedAccountId);
150
152
  }
151
153
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
152
154
  }
@@ -154,7 +156,7 @@ async function handler(args) {
154
156
  function initBuilder(yargs) {
155
157
  yargs.options({
156
158
  'auth-type': {
157
- describe: (0, lang_1.i18n)(`commands.init.options.authType.describe`),
159
+ describe: en_1.commands.init.options.authType.describe,
158
160
  type: 'string',
159
161
  choices: [
160
162
  `${auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value}`,
@@ -163,7 +165,7 @@ function initBuilder(yargs) {
163
165
  default: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
164
166
  },
165
167
  account: {
166
- describe: (0, lang_1.i18n)(`commands.init.options.account.describe`),
168
+ describe: en_1.commands.init.options.account.describe,
167
169
  type: 'string',
168
170
  alias: 'a',
169
171
  },
@@ -176,11 +178,7 @@ function initBuilder(yargs) {
176
178
  yargs.conflicts('use-hidden-config', 'config');
177
179
  return yargs;
178
180
  }
179
- const builder = (0, yargsUtils_1.makeYargsBuilder)(initBuilder, command, (0, lang_1.i18n)(`commands.init.verboseDescribe`, {
180
- command: (0, ui_1.uiCommandReference)('hs auth'),
181
- configName: config_2.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
182
- authMethod: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
183
- }), {
181
+ const builder = (0, yargsUtils_1.makeYargsBuilder)(initBuilder, command, en_1.commands.init.verboseDescribe(config_2.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME, (0, ui_1.uiCommandReference)('hs auth'), auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value), {
184
182
  useGlobalOptions: true,
185
183
  useConfigOptions: true,
186
184
  useTestingOptions: true,
@@ -19,7 +19,7 @@ const process_1 = require("../../../lib/process");
19
19
  const accountTypes_1 = require("../../../lib/accountTypes");
20
20
  const ensureProjectExists_1 = require("../../../lib/projects/ensureProjectExists");
21
21
  async function deprecatedProjectDevFlow({ args, accountId, projectConfig, projectDir, }) {
22
- const { providedAccountId, derivedAccountId } = args;
22
+ const { userProvidedAccount, derivedAccountId } = args;
23
23
  const env = (0, environment_1.getValidEnv)((0, config_1.getEnv)(derivedAccountId));
24
24
  const components = await (0, structure_1.findProjectComponents)(projectDir);
25
25
  const runnableComponents = components.filter(component => component.runnable);
@@ -65,11 +65,11 @@ async function deprecatedProjectDevFlow({ args, accountId, projectConfig, projec
65
65
  }
66
66
  // targetProjectAccountId and targetTestingAccountId are set to null if --account flag is not provided.
67
67
  // By setting them to null, we can later check if they need to be assigned based on the default account configuration and the type of app.
68
- let targetProjectAccountId = providedAccountId ? derivedAccountId : null;
68
+ let targetProjectAccountId = userProvidedAccount ? derivedAccountId : null;
69
69
  // The account that we are locally testing against
70
- let targetTestingAccountId = providedAccountId ? derivedAccountId : null;
70
+ let targetTestingAccountId = userProvidedAccount ? derivedAccountId : null;
71
71
  // Check that the default account or flag option is valid for the type of app in this project
72
- if (providedAccountId) {
72
+ if (userProvidedAccount) {
73
73
  (0, helpers_1.checkIfAccountFlagIsSupported)(accountConfig, hasPublicApps);
74
74
  if (hasPublicApps) {
75
75
  targetProjectAccountId = accountConfig.parentAccountId || null;
@@ -15,19 +15,19 @@ const en_1 = require("../../../lang/en");
15
15
  const logger_1 = require("../../../lib/ui/logger");
16
16
  const command = 'dev';
17
17
  const describe = (0, ui_1.uiBetaTag)(en_1.commands.project.dev.describe, false);
18
- function validateAccountFlags(testingAccount, projectAccount, providedAccountId, useV3) {
18
+ function validateAccountFlags(testingAccount, projectAccount, userProvidedAccount, useV3) {
19
19
  // Legacy projects do not support targetTestingAccount and targetProjectAccount
20
20
  if (testingAccount && projectAccount && !useV3) {
21
21
  logger_1.uiLogger.error(en_1.commands.project.dev.errors.unsupportedAccountFlagLegacy);
22
22
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
23
23
  }
24
- if (providedAccountId && useV3) {
24
+ if (userProvidedAccount && useV3) {
25
25
  logger_1.uiLogger.error(en_1.commands.project.dev.errors.unsupportedAccountFlagV3);
26
26
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
27
27
  }
28
28
  }
29
29
  async function handler(args) {
30
- const { derivedAccountId, providedAccountId, testingAccount, projectAccount, } = args;
30
+ const { derivedAccountId, userProvidedAccount, testingAccount, projectAccount, } = args;
31
31
  const { projectConfig, projectDir } = await (0, config_2.getProjectConfig)();
32
32
  (0, config_2.validateProjectConfig)(projectConfig, projectDir);
33
33
  const useV3 = (0, buildAndDeploy_1.useV3Api)(projectConfig.platformVersion);
@@ -35,9 +35,9 @@ async function handler(args) {
35
35
  logger_1.uiLogger.error(en_1.commands.project.dev.errors.noProjectConfig);
36
36
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
37
37
  }
38
- validateAccountFlags(testingAccount, projectAccount, providedAccountId, useV3);
38
+ validateAccountFlags(testingAccount, projectAccount, userProvidedAccount, useV3);
39
39
  let targetProjectAccountId = (projectAccount && (0, config_1.getAccountId)(projectAccount)) ||
40
- (providedAccountId && derivedAccountId);
40
+ (userProvidedAccount && derivedAccountId);
41
41
  let profile;
42
42
  if (!targetProjectAccountId && (0, buildAndDeploy_1.useV3Api)(projectConfig.platformVersion)) {
43
43
  if (args.profile) {
@@ -19,10 +19,10 @@ const yargsUtils_1 = require("../../lib/yargsUtils");
19
19
  const command = 'delete';
20
20
  const describe = (0, ui_1.uiBetaTag)((0, lang_1.i18n)(`commands.sandbox.subcommands.delete.describe`), false);
21
21
  async function handler(args) {
22
- const { providedAccountId, force } = args;
23
- (0, usageTracking_1.trackCommandUsage)('sandbox-delete', {}, providedAccountId);
22
+ const { userProvidedAccount, derivedAccountId, force } = args;
23
+ (0, usageTracking_1.trackCommandUsage)('sandbox-delete', {}, derivedAccountId);
24
24
  let accountPrompt;
25
- if (!providedAccountId) {
25
+ if (!userProvidedAccount) {
26
26
  if (!force) {
27
27
  accountPrompt = await (0, sandboxesPrompt_1.deleteSandboxPrompt)();
28
28
  }
@@ -40,7 +40,7 @@ async function handler(args) {
40
40
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
41
41
  }
42
42
  }
43
- const sandboxAccountId = (0, config_1.getAccountId)(providedAccountId || accountPrompt.account);
43
+ const sandboxAccountId = (0, config_1.getAccountId)(userProvidedAccount || accountPrompt.account);
44
44
  if (!sandboxAccountId) {
45
45
  logger_1.logger.error((0, lang_1.i18n)(`commands.sandbox.subcommands.delete.failure.noSandboxAccountId`));
46
46
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
@@ -114,7 +114,7 @@ async function handler(args) {
114
114
  : `commands.sandbox.subcommands.delete.success.delete`;
115
115
  logger_1.logger.log('');
116
116
  logger_1.logger.success((0, lang_1.i18n)(deleteKey, {
117
- account: providedAccountId || accountPrompt.account,
117
+ account: userProvidedAccount || accountPrompt.account,
118
118
  sandboxHubId: sandboxAccountId || '',
119
119
  }));
120
120
  logger_1.logger.log('');
@@ -15,6 +15,9 @@ const usageTracking_1 = require("../../lib/usageTracking");
15
15
  const validation_1 = require("../../lib/validation");
16
16
  const en_1 = require("../../lang/en");
17
17
  const createDeveloperTestAccountConfigPrompt_1 = require("../../lib/prompts/createDeveloperTestAccountConfigPrompt");
18
+ const errorHandlers_1 = require("../../lib/errorHandlers");
19
+ const polling_1 = require("../../lib/polling");
20
+ const SpinniesManager_1 = __importDefault(require("../../lib/ui/SpinniesManager"));
18
21
  const command = 'create';
19
22
  const describe = en_1.commands.testAccount.create.describe;
20
23
  async function handler(args) {
@@ -62,6 +65,13 @@ async function handler(args) {
62
65
  testAccountConfig = await (0, createDeveloperTestAccountConfigPrompt_1.createDeveloperTestAccountConfigPrompt)();
63
66
  }
64
67
  const jsonOutput = {};
68
+ let testAccountId;
69
+ SpinniesManager_1.default.init({
70
+ succeedColor: 'white',
71
+ });
72
+ SpinniesManager_1.default.add('createTestAccount', {
73
+ text: en_1.commands.testAccount.create.polling.start(testAccountConfig.accountName),
74
+ });
65
75
  try {
66
76
  const { data } = await (0, developerTestAccounts_1.createDeveloperTestAccount)(derivedAccountId, testAccountConfig);
67
77
  if (formatOutputAsJson) {
@@ -69,12 +79,27 @@ async function handler(args) {
69
79
  jsonOutput.accountId = data.id;
70
80
  jsonOutput.personalAccessKey = data.personalAccessKey;
71
81
  }
72
- logger_1.uiLogger.success(en_1.commands.testAccount.create.success.configFileUpdated(data.accountName, data.id));
82
+ testAccountId = data.id;
73
83
  }
74
84
  catch (err) {
75
- logger_1.uiLogger.error(en_1.commands.testAccount.create.errors.failedToCreate);
85
+ (0, errorHandlers_1.logError)(err);
76
86
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
77
87
  }
88
+ SpinniesManager_1.default.update('createTestAccount', {
89
+ text: en_1.commands.testAccount.create.polling.syncing,
90
+ });
91
+ try {
92
+ await (0, polling_1.poll)(() => (0, developerTestAccounts_1.fetchDeveloperTestAccountGateSyncStatus)(derivedAccountId, testAccountId), {
93
+ successStates: ['SUCCESS'],
94
+ errorStates: [],
95
+ });
96
+ }
97
+ catch (err) {
98
+ (0, errorHandlers_1.logError)(err);
99
+ }
100
+ SpinniesManager_1.default.succeed('createTestAccount', {
101
+ text: en_1.commands.testAccount.create.polling.success(testAccountConfig.accountName, testAccountId),
102
+ });
78
103
  if (formatOutputAsJson) {
79
104
  logger_1.uiLogger.json(jsonOutput);
80
105
  }
package/lang/en.d.ts CHANGED
@@ -189,8 +189,11 @@ Global configuration replaces hubspot.config.yml, and you will be prompted to mi
189
189
  };
190
190
  };
191
191
  readonly auth: {
192
- readonly describe: (configName: string) => string;
192
+ readonly describe: "Configure authentication for your HubSpot account.";
193
+ readonly verboseDescribe: (configName: string, authMethod: string) => string;
193
194
  readonly errors: {
195
+ readonly invalidAccountIdProvided: "--account must be a number.";
196
+ readonly globalConfigFileExists: (accountAuthCommand: string) => string;
194
197
  readonly noConfigFileFound: "No config file was found. To create a new config file, use the \"hs init\" command.";
195
198
  readonly unsupportedAuthType: (type: string, supportedProtocols: string) => string;
196
199
  };
@@ -735,7 +738,8 @@ Global configuration replaces hubspot.config.yml, and you will be prompted to mi
735
738
  };
736
739
  };
737
740
  readonly init: {
738
- readonly describe: (configName: string) => string;
741
+ readonly describe: "Create a CLI config file and configure authentication for your HubSpot account.";
742
+ readonly verboseDescribe: (configName: string, command: string, authMethod: string) => string;
739
743
  readonly options: {
740
744
  readonly authType: {
741
745
  readonly describe: "Authentication mechanism";
@@ -750,14 +754,16 @@ Global configuration replaces hubspot.config.yml, and you will be prompted to mi
750
754
  };
751
755
  readonly success: {
752
756
  readonly configFileCreated: (configPath: string) => string;
753
- readonly configFileUpdated: (account: string, authType: string) => string;
757
+ readonly configFileUpdated: (authType: string, account: string | number) => string;
754
758
  };
755
759
  readonly logs: {
756
760
  readonly updateConfig: "To update an existing config file, use the \"hs auth\" command.";
757
761
  };
758
762
  readonly errors: {
763
+ readonly invalidAccountIdProvided: "--account must be a number.";
759
764
  readonly configFileExists: (configPath: string) => string;
760
765
  readonly bothConfigFilesNotAllowed: (path: string) => string;
766
+ readonly globalConfigFileExists: `You are using our new global configuration for account management, which is not compatible with this command. Please use ${string} instead.`;
761
767
  };
762
768
  };
763
769
  readonly lint: {
@@ -1796,10 +1802,11 @@ ${string}`;
1796
1802
  readonly errors: {
1797
1803
  readonly configFileNotFound: (configPath: string) => string;
1798
1804
  readonly configFileParseFailed: (configPath: string) => string;
1799
- readonly failedToCreate: "Failed to create test account";
1800
1805
  };
1801
- readonly success: {
1802
- readonly configFileUpdated: (testAccountName: string, testAccountId: number) => string;
1806
+ readonly polling: {
1807
+ readonly start: (testAccountName: string) => string;
1808
+ readonly syncing: "Test account created! Syncing account data... (may take a few minutes - you can exit and the sync will continue)";
1809
+ readonly success: (testAccountName: string, testAccountId: number) => string;
1803
1810
  };
1804
1811
  readonly options: {
1805
1812
  readonly configPath: "The path to the test account config";
@@ -2426,6 +2433,12 @@ ${string}`;
2426
2433
  };
2427
2434
  };
2428
2435
  export declare const lib: {
2436
+ readonly parsing: {
2437
+ readonly unableToParseStringToNumber: "Unable to parse string to number";
2438
+ };
2439
+ readonly configMiddleWare: {
2440
+ readonly invalidAccountIdEnvironmentVariable: "Unable to parse `HUBSPOT_ACCOUNT_ID` environment variable into a number";
2441
+ };
2429
2442
  readonly process: {
2430
2443
  readonly exitDebug: (signal: string) => string;
2431
2444
  };
package/lang/en.js CHANGED
@@ -196,8 +196,11 @@ exports.commands = {
196
196
  },
197
197
  },
198
198
  auth: {
199
- describe: (configName) => `Configure authentication for your HubSpot account. This will update the ${configName} file that stores your account information.`,
199
+ describe: 'Configure authentication for your HubSpot account.',
200
+ verboseDescribe: (configName, authMethod) => `Configure authentication for a HubSpot account. This will update the ${configName} file that stores your account information.\n\nThe recommended authentication method is ${chalk_1.default.bold(authMethod)}, which uses an access token tied to a specific user account.`,
200
201
  errors: {
202
+ invalidAccountIdProvided: `--account must be a number.`,
203
+ globalConfigFileExists: (accountAuthCommand) => `You are using our new global configuration for account management, which is not compatible with this command. Please use ${(0, ui_1.uiCommandReference)(accountAuthCommand)} instead.`,
201
204
  noConfigFileFound: 'No config file was found. To create a new config file, use the "hs init" command.',
202
205
  unsupportedAuthType: (type, supportedProtocols) => `Unsupported auth type: ${type}. The only supported authentication protocols are ${supportedProtocols}.`,
203
206
  },
@@ -744,7 +747,8 @@ exports.commands = {
744
747
  },
745
748
  },
746
749
  init: {
747
- describe: (configName) => `Configure authentication for your HubSpot account. This will create a ${configName} file to store your account information.`,
750
+ describe: 'Create a CLI config file and configure authentication for your HubSpot account.',
751
+ verboseDescribe: (configName, command, authMethod) => `Configure authentication for a HubSpot account. This will create a ${configName} file to store your account information. To configure authentication for additional accounts, run ${command}.\n\nThe recommended authentication method is ${chalk_1.default.bold(authMethod)}, which uses an access token tied to a specific user account.`,
748
752
  options: {
749
753
  authType: {
750
754
  describe: 'Authentication mechanism',
@@ -759,14 +763,16 @@ exports.commands = {
759
763
  },
760
764
  success: {
761
765
  configFileCreated: (configPath) => `Created config file "${configPath}"`,
762
- configFileUpdated: (account, authType) => `Connected account "${account}" using "${authType}" and set it as the default account`,
766
+ configFileUpdated: (authType, account) => `Connected account "${account}" using "${authType}" and set it as the default account`,
763
767
  },
764
768
  logs: {
765
769
  updateConfig: 'To update an existing config file, use the "hs auth" command.',
766
770
  },
767
771
  errors: {
772
+ invalidAccountIdProvided: `--account must be a number.`,
768
773
  configFileExists: (configPath) => `The config file ${configPath} already exists.`,
769
774
  bothConfigFilesNotAllowed: (path) => `Unable to create config file, because there is an existing one at "${path}". To create a new config file, delete the existing one and try again.`,
775
+ globalConfigFileExists: `You are using our new global configuration for account management, which is not compatible with this command. Please use ${(0, ui_1.uiCommandReference)('hs account auth')} instead.`,
770
776
  },
771
777
  },
772
778
  lint: {
@@ -1794,10 +1800,11 @@ exports.commands = {
1794
1800
  errors: {
1795
1801
  configFileNotFound: (configPath) => `No test account config file exists at ${configPath}. Create a test account config file with the ${(0, ui_1.uiCommandReference)('hs test-account create-config')} command.`,
1796
1802
  configFileParseFailed: (configPath) => `Failed to parse test account config file at ${configPath}`,
1797
- failedToCreate: 'Failed to create test account',
1798
1803
  },
1799
- success: {
1800
- configFileUpdated: (testAccountName, testAccountId) => `Test account "${testAccountName}" successfully created with id ${testAccountId}`,
1804
+ polling: {
1805
+ start: (testAccountName) => `Creating test account "${chalk_1.default.bold(testAccountName)}"...`,
1806
+ syncing: 'Test account created! Syncing account data... (may take a few minutes - you can exit and the sync will continue)',
1807
+ success: (testAccountName, testAccountId) => `Test account "${chalk_1.default.bold(testAccountName)}" successfully created with id: ${chalk_1.default.bold(testAccountId)}`,
1801
1808
  },
1802
1809
  options: {
1803
1810
  configPath: 'The path to the test account config',
@@ -2424,6 +2431,12 @@ exports.commands = {
2424
2431
  },
2425
2432
  };
2426
2433
  exports.lib = {
2434
+ parsing: {
2435
+ unableToParseStringToNumber: 'Unable to parse string to number',
2436
+ },
2437
+ configMiddleWare: {
2438
+ invalidAccountIdEnvironmentVariable: 'Unable to parse `HUBSPOT_ACCOUNT_ID` environment variable into a number',
2439
+ },
2427
2440
  process: {
2428
2441
  exitDebug: (signal) => `Attempting to gracefully exit. Triggered by ${signal}`,
2429
2442
  },
package/lib/commonOpts.js CHANGED
@@ -136,7 +136,7 @@ async function addCustomHelpOutput(yargs, command, describe) {
136
136
  function setLogLevel(options) {
137
137
  const { debug, networkDebug, json } = options;
138
138
  if (json) {
139
- (0, logger_1.setLogLevel)(logger_1.LOG_LEVEL.NONE);
139
+ (0, logger_1.setLogLevel)(logger_1.LOG_LEVEL.ERROR);
140
140
  }
141
141
  else if (debug) {
142
142
  (0, logger_1.setLogLevel)(logger_1.LOG_LEVEL.DEBUG);
@@ -109,7 +109,7 @@ describe('lib/middleware/configMiddleware', () => {
109
109
  $0: 'hs',
110
110
  };
111
111
  await (0, configMiddleware_1.injectAccountIdMiddleware)(argv);
112
- expect(argv.providedAccountId).toBeUndefined();
112
+ expect(argv.userProvidedAccount).toBeUndefined();
113
113
  expect(argv.derivedAccountId).toBe(123);
114
114
  expect(getAccountIdSpy).not.toHaveBeenCalled();
115
115
  process.env = originalEnv;
@@ -123,7 +123,7 @@ describe('lib/middleware/configMiddleware', () => {
123
123
  $0: 'hs',
124
124
  };
125
125
  await (0, configMiddleware_1.injectAccountIdMiddleware)(argv);
126
- expect(argv.providedAccountId).toBe('test-account');
126
+ expect(argv.userProvidedAccount).toBe('test-account');
127
127
  expect(argv.derivedAccountId).toBe(456);
128
128
  expect(getAccountIdSpy).toHaveBeenCalledWith('test-account');
129
129
  });
@@ -11,6 +11,9 @@ const exitCodes_1 = require("../enums/exitCodes");
11
11
  const lang_1 = require("../lang");
12
12
  const ui_1 = require("../ui");
13
13
  const utils_1 = require("./utils");
14
+ const parsing_1 = require("../parsing");
15
+ const logger_2 = require("../ui/logger");
16
+ const en_1 = require("../../lang/en");
14
17
  function handleDeprecatedEnvVariables(argv) {
15
18
  // HUBSPOT_PORTAL_ID is deprecated, but we'll still support it for now
16
19
  // The HubSpot GH Deploy Action still uses HUBSPOT_PORTAL_ID
@@ -29,9 +32,14 @@ function handleDeprecatedEnvVariables(argv) {
29
32
  async function injectAccountIdMiddleware(argv) {
30
33
  const { account } = argv;
31
34
  // Preserves the original --account flag for certain commands.
32
- argv.providedAccountId = account;
35
+ argv.userProvidedAccount = account;
33
36
  if (argv.useEnv && process.env.HUBSPOT_ACCOUNT_ID) {
34
- argv.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10);
37
+ try {
38
+ argv.derivedAccountId = (0, parsing_1.parseStringToNumber)(process.env.HUBSPOT_ACCOUNT_ID);
39
+ }
40
+ catch (err) {
41
+ logger_2.uiLogger.error(en_1.lib.configMiddleWare.invalidAccountIdEnvironmentVariable);
42
+ }
35
43
  }
36
44
  else {
37
45
  argv.derivedAccountId = (0, config_1.getAccountId)(account);
@@ -0,0 +1 @@
1
+ export declare function parseStringToNumber(maybeNumber: string): number;
package/lib/parsing.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseStringToNumber = parseStringToNumber;
4
+ const en_1 = require("../lang/en");
5
+ function parseStringToNumber(maybeNumber) {
6
+ const result = parseInt(maybeNumber, 10);
7
+ if (Number.isNaN(result) || !/^-?\d+$/.test(maybeNumber)) {
8
+ throw new Error(en_1.lib.parsing.unableToParseStringToNumber);
9
+ }
10
+ return result;
11
+ }
@@ -29,7 +29,7 @@ async function personalAccessKeyPrompt({ env, account, }) {
29
29
  if (account) {
30
30
  url = `${websiteOrigin}/personal-access-key/${account}`;
31
31
  }
32
- const { personalAcessKeyBrowserOpenPrep: choice } = await (0, promptUtils_1.promptUser)([
32
+ const { personalAccessKeyBrowserOpenPrep: choice } = await (0, promptUtils_1.promptUser)([
33
33
  PERSONAL_ACCESS_KEY_BROWSER_OPEN_PREP,
34
34
  ]);
35
35
  if (!choice) {
@@ -94,7 +94,7 @@ const CLIENT_SECRET = {
94
94
  },
95
95
  };
96
96
  const PERSONAL_ACCESS_KEY_BROWSER_OPEN_PREP = {
97
- name: 'personalAcessKeyBrowserOpenPrep',
97
+ name: 'personalAccessKeyBrowserOpenPrep',
98
98
  type: 'list',
99
99
  message: 'Choose your preferred method of authentication',
100
100
  choices: Object.values(en_1.lib.prompts.personalAccessKeyPrompt.personalAccessKeyPromptChoices),
@@ -4,7 +4,7 @@ export declare function validateAccount(options: Arguments<{
4
4
  account?: string;
5
5
  accountId?: string;
6
6
  derivedAccountId?: number;
7
- providedAccountId?: string;
7
+ userProvidedAccount?: string;
8
8
  }>): Promise<boolean>;
9
9
  export declare function validateCmsPublishMode(options: Arguments<{
10
10
  cmsPublishMode?: CmsPublishMode;
package/lib/validation.js CHANGED
@@ -50,18 +50,18 @@ const path_1 = require("@hubspot/local-dev-lib/path");
50
50
  const commonOpts_1 = require("./commonOpts");
51
51
  const index_1 = require("./errorHandlers/index");
52
52
  async function validateAccount(options) {
53
- const { derivedAccountId, providedAccountId } = options;
53
+ const { derivedAccountId, userProvidedAccount } = options;
54
54
  const accountId = (0, config_1.getAccountId)(derivedAccountId);
55
55
  if (!accountId) {
56
- if (providedAccountId) {
57
- logger_1.logger.error(`The account "${providedAccountId}" could not be found in the config`);
56
+ if (userProvidedAccount) {
57
+ logger_1.logger.error(`The account "${userProvidedAccount}" could not be found in the config`);
58
58
  }
59
59
  else {
60
60
  logger_1.logger.error('An account needs to be supplied either via "--account" or through setting a "defaultPortal"');
61
61
  }
62
62
  return false;
63
63
  }
64
- if (providedAccountId && (0, config_1.loadConfigFromEnvironment)()) {
64
+ if (userProvidedAccount && (0, config_1.loadConfigFromEnvironment)()) {
65
65
  throw new Error('Cannot specify an account when environment variables are supplied. Please unset the environment variables or do not use the "--account" flag.');
66
66
  }
67
67
  const accountConfig = (0, config_1.getAccountConfig)(accountId);
@@ -14,17 +14,17 @@ declare const inputSchemaZodObject: z.ZodObject<{
14
14
  absoluteCurrentWorkingDirectory: string;
15
15
  destination: string;
16
16
  auth?: "oauth" | "static" | undefined;
17
- name?: string | undefined;
18
17
  distribution?: "marketplace" | "private" | undefined;
19
18
  features?: ("card" | "settings" | "app-function" | "webhooks")[] | undefined;
19
+ name?: string | undefined;
20
20
  }, {
21
21
  projectBase: "app" | "empty";
22
22
  absoluteCurrentWorkingDirectory: string;
23
23
  destination: string;
24
24
  auth?: "oauth" | "static" | undefined;
25
- name?: string | undefined;
26
25
  distribution?: "marketplace" | "private" | undefined;
27
26
  features?: ("card" | "settings" | "app-function" | "webhooks")[] | undefined;
27
+ name?: string | undefined;
28
28
  }>;
29
29
  export type CreateProjectInputSchema = z.infer<typeof inputSchemaZodObject>;
30
30
  export declare class CreateProjectTool extends Tool<CreateProjectInputSchema> {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@hubspot/cli",
3
- "version": "7.7.16-experimental.1",
3
+ "version": "7.7.16-experimental.3",
4
4
  "description": "The official CLI for developing on HubSpot",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "https://github.com/HubSpot/hubspot-cli",
7
7
  "dependencies": {
8
- "@hubspot/local-dev-lib": "3.10.0-beta.0",
8
+ "@hubspot/local-dev-lib": "3.11.0",
9
9
  "@hubspot/project-parsing-lib": "0.3.2",
10
10
  "@hubspot/serverless-dev-runtime": "7.0.6",
11
11
  "@hubspot/theme-preview-dev-server": "0.0.10",
package/types/Yargs.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Options, CommandModule, Argv } from 'yargs';
2
2
  import { CmsPublishMode } from '@hubspot/local-dev-lib/types/Files';
3
3
  export type CommonArgs = {
4
4
  derivedAccountId: number;
5
- providedAccountId?: number;
5
+ userProvidedAccount?: string;
6
6
  d: boolean;
7
7
  debug: boolean;
8
8
  };