@hubspot/local-dev-lib 0.5.0-experimental.0 → 0.5.0-experimental.1

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.
package/config/index.d.ts CHANGED
@@ -23,7 +23,7 @@ export declare function renameConfigAccount(currentName: string, newName: string
23
23
  export declare function removeAccountFromConfig(accountId: number): void;
24
24
  export declare function updateHttpTimeout(timeout: string | number): void;
25
25
  export declare function updateAllowUsageTracking(isAllowed: boolean): void;
26
- export declare function updateAllowAutoUpdates(enabled: boolean): void;
26
+ export declare function updateAllowAutoUpdates(isEnabled: boolean): void;
27
27
  export declare function updateAutoOpenBrowser(isEnabled: boolean): void;
28
28
  export declare function updateDefaultCmsPublishMode(cmsPublishMode: CmsPublishMode): void;
29
29
  export declare function isConfigFlagEnabled(flag: ConfigFlag, defaultValue?: boolean): boolean;
package/config/index.js CHANGED
@@ -12,6 +12,8 @@ const files_1 = require("../constants/files");
12
12
  const lang_1 = require("../utils/lang");
13
13
  const defaultAccountOverride_1 = require("./defaultAccountOverride");
14
14
  const environment_1 = require("../lib/environment");
15
+ const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
16
+ const config_2 = require("../constants/config");
15
17
  function localConfigFileExists() {
16
18
  return Boolean((0, utils_1.getLocalConfigFilePath)());
17
19
  }
@@ -27,7 +29,7 @@ function getConfigDefaultFilePath() {
27
29
  }
28
30
  const localConfigFilePath = (0, utils_1.getLocalConfigFilePath)();
29
31
  if (!localConfigFilePath) {
30
- throw new Error((0, lang_1.i18n)('config.getDefaultConfigFilePath.error'));
32
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getDefaultConfigFilePath.error'), config_2.HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
31
33
  }
32
34
  return localConfigFilePath;
33
35
  }
@@ -37,14 +39,22 @@ function getConfigFilePath() {
37
39
  }
38
40
  exports.getConfigFilePath = getConfigFilePath;
39
41
  function getConfig() {
40
- const { useEnvironmentConfig } = (0, utils_1.getConfigPathEnvironmentVariables)();
41
- if (useEnvironmentConfig) {
42
- return (0, utils_1.buildConfigFromEnvironment)();
42
+ let pathToRead;
43
+ try {
44
+ const { useEnvironmentConfig } = (0, utils_1.getConfigPathEnvironmentVariables)();
45
+ if (useEnvironmentConfig) {
46
+ return (0, utils_1.buildConfigFromEnvironment)();
47
+ }
48
+ pathToRead = getConfigFilePath();
49
+ logger_1.logger.debug((0, lang_1.i18n)('config.getConfig.reading', { path: pathToRead }));
50
+ const configFileSource = (0, utils_1.readConfigFile)(pathToRead);
51
+ return (0, utils_1.parseConfig)(configFileSource, pathToRead);
52
+ }
53
+ catch (err) {
54
+ throw new HubSpotConfigError_1.HubSpotConfigError(pathToRead
55
+ ? (0, lang_1.i18n)('config.getConfig.errorWithPath', { path: pathToRead })
56
+ : (0, lang_1.i18n)('config.getConfig.error'), config_2.HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ, { cause: err });
43
57
  }
44
- const pathToRead = getConfigFilePath();
45
- logger_1.logger.debug((0, lang_1.i18n)('config.getConfig', { path: pathToRead }));
46
- const configFileSource = (0, utils_1.readConfigFile)(pathToRead);
47
- return (0, utils_1.parseConfig)(configFileSource);
48
58
  }
49
59
  exports.getConfig = getConfig;
50
60
  function isConfigValid() {
@@ -103,7 +113,7 @@ function getConfigAccountById(accountId) {
103
113
  const { accounts } = getConfig();
104
114
  const account = (0, utils_1.getConfigAccountByIdentifier)(accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountId);
105
115
  if (!account) {
106
- throw new Error((0, lang_1.i18n)('config.getConfigAccountById.error', { accountId }));
116
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getConfigAccountById.error', { accountId }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
107
117
  }
108
118
  return account;
109
119
  }
@@ -112,7 +122,7 @@ function getConfigAccountByName(accountName) {
112
122
  const { accounts } = getConfig();
113
123
  const account = (0, utils_1.getConfigAccountByIdentifier)(accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, accountName);
114
124
  if (!account) {
115
- throw new Error((0, lang_1.i18n)('config.getConfigAccountByName.error', { accountName }));
125
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getConfigAccountByName.error', { accountName }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
116
126
  }
117
127
  return account;
118
128
  }
@@ -130,13 +140,13 @@ function getConfigDefaultAccount() {
130
140
  defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
131
141
  }
132
142
  if (!defaultAccountToUse) {
133
- throw new Error((0, lang_1.i18n)('config.getConfigDefaultAccount.fieldMissingError'));
143
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getConfigDefaultAccount.fieldMissingError'), config_2.HUBSPOT_CONFIG_ERROR_TYPES.NO_DEFAULT_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
134
144
  }
135
145
  const account = (0, utils_1.getConfigAccountByInferredIdentifier)(accounts, defaultAccountToUse);
136
146
  if (!account) {
137
- throw new Error((0, lang_1.i18n)('config.getConfigDefaultAccount.accountMissingError', {
147
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getConfigDefaultAccount.accountMissingError', {
138
148
  defaultAccountToUse,
139
- }));
149
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
140
150
  }
141
151
  return account;
142
152
  }
@@ -174,14 +184,14 @@ function getConfigAccountEnvironment(identifier) {
174
184
  exports.getConfigAccountEnvironment = getConfigAccountEnvironment;
175
185
  function addConfigAccount(accountToAdd) {
176
186
  if (!(0, utils_1.isConfigAccountValid)(accountToAdd)) {
177
- throw new Error((0, lang_1.i18n)('config.addConfigAccount.invalidAccount'));
187
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.addConfigAccount.invalidAccount'), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
178
188
  }
179
189
  const config = getConfig();
180
190
  const accountInConfig = (0, utils_1.getConfigAccountByIdentifier)(config.accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountToAdd.accountId);
181
191
  if (accountInConfig) {
182
- throw new Error((0, lang_1.i18n)('config.addConfigAccount.duplicateAccount', {
192
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.addConfigAccount.duplicateAccount', {
183
193
  accountId: accountToAdd.accountId,
184
- }));
194
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
185
195
  }
186
196
  config.accounts.push(accountToAdd);
187
197
  (0, utils_1.writeConfigFile)(config, getConfigFilePath());
@@ -189,14 +199,16 @@ function addConfigAccount(accountToAdd) {
189
199
  exports.addConfigAccount = addConfigAccount;
190
200
  function updateConfigAccount(updatedAccount) {
191
201
  if (!(0, utils_1.isConfigAccountValid)(updatedAccount)) {
192
- throw new Error((0, lang_1.i18n)('config.updateConfigAccount.invalidAccount'));
202
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateConfigAccount.invalidAccount', {
203
+ name: updatedAccount.name,
204
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
193
205
  }
194
206
  const config = getConfig();
195
207
  const accountIndex = (0, utils_1.getConfigAccountIndexById)(config.accounts, updatedAccount.accountId);
196
208
  if (accountIndex < 0) {
197
- throw new Error((0, lang_1.i18n)('config.updateConfigAccount.accountNotFound', {
209
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateConfigAccount.accountNotFound', {
198
210
  accountId: updatedAccount.accountId,
199
- }));
211
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
200
212
  }
201
213
  config.accounts[accountIndex] = updatedAccount;
202
214
  (0, utils_1.writeConfigFile)(config, getConfigFilePath());
@@ -206,9 +218,9 @@ function setConfigAccountAsDefault(identifier) {
206
218
  const config = getConfig();
207
219
  const account = (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
208
220
  if (!account) {
209
- throw new Error((0, lang_1.i18n)('config.setConfigAccountAsDefault.accountNotFound', {
221
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.setConfigAccountAsDefault.accountNotFound', {
210
222
  accountId: identifier,
211
- }));
223
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
212
224
  }
213
225
  config.defaultAccount = account.accountId;
214
226
  (0, utils_1.writeConfigFile)(config, getConfigFilePath());
@@ -218,15 +230,16 @@ function renameConfigAccount(currentName, newName) {
218
230
  const config = getConfig();
219
231
  const account = (0, utils_1.getConfigAccountByIdentifier)(config.accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, currentName);
220
232
  if (!account) {
221
- throw new Error((0, lang_1.i18n)('config.renameConfigAccount.accountNotFound', {
233
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.renameConfigAccount.accountNotFound', {
222
234
  currentName,
223
- }));
235
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
224
236
  }
225
237
  const duplicateAccount = (0, utils_1.getConfigAccountByIdentifier)(config.accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, newName);
226
238
  if (duplicateAccount) {
227
- throw new Error((0, lang_1.i18n)('config.renameConfigAccount.duplicateAccount', {
239
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.renameConfigAccount.duplicateAccount', {
240
+ currentName,
228
241
  newName,
229
- }));
242
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
230
243
  }
231
244
  account.name = newName;
232
245
  (0, utils_1.writeConfigFile)(config, getConfigFilePath());
@@ -236,9 +249,9 @@ function removeAccountFromConfig(accountId) {
236
249
  const config = getConfig();
237
250
  const index = (0, utils_1.getConfigAccountIndexById)(config.accounts, accountId);
238
251
  if (index < 0) {
239
- throw new Error((0, lang_1.i18n)('config.removeAccountFromConfig.accountNotFound', {
252
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.removeAccountFromConfig.accountNotFound', {
240
253
  accountId,
241
- }));
254
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
242
255
  }
243
256
  config.accounts.splice(index, 1);
244
257
  if (config.defaultAccount === accountId) {
@@ -250,9 +263,10 @@ exports.removeAccountFromConfig = removeAccountFromConfig;
250
263
  function updateHttpTimeout(timeout) {
251
264
  const parsedTimeout = typeof timeout === 'string' ? parseInt(timeout) : timeout;
252
265
  if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
253
- throw new Error((0, lang_1.i18n)('config.updateHttpTimeout.invalidTimeout', {
266
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateHttpTimeout.invalidTimeout', {
254
267
  minTimeout: config_1.MIN_HTTP_TIMEOUT,
255
- }));
268
+ timeout: parsedTimeout,
269
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
256
270
  }
257
271
  const config = getConfig();
258
272
  config.httpTimeout = parsedTimeout;
@@ -260,22 +274,32 @@ function updateHttpTimeout(timeout) {
260
274
  }
261
275
  exports.updateHttpTimeout = updateHttpTimeout;
262
276
  function updateAllowUsageTracking(isAllowed) {
277
+ if (typeof isAllowed !== 'boolean') {
278
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateAllowUsageTracking.invalidInput', {
279
+ isAllowed: `${isAllowed}`,
280
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
281
+ }
263
282
  const config = getConfig();
264
283
  config.allowUsageTracking = isAllowed;
265
284
  (0, utils_1.writeConfigFile)(config, getConfigFilePath());
266
285
  }
267
286
  exports.updateAllowUsageTracking = updateAllowUsageTracking;
268
- function updateAllowAutoUpdates(enabled) {
287
+ function updateAllowAutoUpdates(isEnabled) {
288
+ if (typeof isEnabled !== 'boolean') {
289
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateAllowAutoUpdates.invalidInput', {
290
+ isEnabled: `${isEnabled}`,
291
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
292
+ }
269
293
  const config = getConfig();
270
- config.allowAutoUpdates = enabled;
294
+ config.allowAutoUpdates = isEnabled;
271
295
  (0, utils_1.writeConfigFile)(config, getConfigFilePath());
272
296
  }
273
297
  exports.updateAllowAutoUpdates = updateAllowAutoUpdates;
274
298
  function updateAutoOpenBrowser(isEnabled) {
275
299
  if (typeof isEnabled !== 'boolean') {
276
- throw new Error((0, lang_1.i18n)('config.updateAutoOpenBrowser.invalidInput', {
300
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateAutoOpenBrowser.invalidInput', {
277
301
  isEnabled: `${isEnabled}`,
278
- }));
302
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
279
303
  }
280
304
  const config = getConfig();
281
305
  config.autoOpenBrowser = isEnabled;
@@ -285,7 +309,9 @@ exports.updateAutoOpenBrowser = updateAutoOpenBrowser;
285
309
  function updateDefaultCmsPublishMode(cmsPublishMode) {
286
310
  if (!cmsPublishMode ||
287
311
  !Object.values(files_1.CMS_PUBLISH_MODE).includes(cmsPublishMode)) {
288
- throw new Error((0, lang_1.i18n)('config.updateDefaultCmsPublishMode.invalidCmsPublishMode'));
312
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateDefaultCmsPublishMode.invalidCmsPublishMode', {
313
+ cmsPublishMode,
314
+ }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
289
315
  }
290
316
  const config = getConfig();
291
317
  config.defaultCmsPublishMode = cmsPublishMode;
package/config/migrate.js CHANGED
@@ -10,7 +10,7 @@ const config_1 = require("../constants/config");
10
10
  const utils_1 = require("./utils");
11
11
  function getConfigAtPath(path) {
12
12
  const configFileSource = (0, utils_1.readConfigFile)(path);
13
- return (0, utils_1.parseConfig)(configFileSource);
13
+ return (0, utils_1.parseConfig)(configFileSource, path);
14
14
  }
15
15
  exports.getConfigAtPath = getConfigAtPath;
16
16
  function migrateConfigAtPath(path) {
package/config/utils.d.ts CHANGED
@@ -62,7 +62,7 @@ export declare function formatConfigForWrite(config: HubSpotConfig): {
62
62
  };
63
63
  export declare function writeConfigFile(config: HubSpotConfig, configPath: string): void;
64
64
  export declare function normalizeParsedConfig(parsedConfig: HubSpotConfig & DeprecatedHubSpotConfigFields): HubSpotConfig;
65
- export declare function parseConfig(configSource: string): HubSpotConfig;
65
+ export declare function parseConfig(configSource: string, configPath: string): HubSpotConfig;
66
66
  export declare function buildConfigFromEnvironment(): HubSpotConfig;
67
67
  export declare function getAccountIdentifierAndType(accountIdentifier: string | number): {
68
68
  identifier: string | number;
package/config/utils.js CHANGED
@@ -15,6 +15,7 @@ const environment_1 = require("../lib/environment");
15
15
  const path_1 = require("../lib/path");
16
16
  const files_1 = require("../constants/files");
17
17
  const lang_1 = require("../utils/lang");
18
+ const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
18
19
  function getGlobalConfigFilePath() {
19
20
  return config_1.GLOBAL_CONFIG_PATH;
20
21
  }
@@ -35,7 +36,7 @@ function getConfigPathEnvironmentVariables() {
35
36
  const useEnvironmentConfig = process.env[config_1.ENVIRONMENT_VARIABLES.USE_ENVIRONMENT_HUBSPOT_CONFIG] ===
36
37
  'true';
37
38
  if (configFilePathFromEnvironment && useEnvironmentConfig) {
38
- throw new Error((0, lang_1.i18n)('config.utils.getConfigPathEnvironmentVariables.invalidEnvironmentVariables'));
39
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.utils.getConfigPathEnvironmentVariables.invalidEnvironmentVariables'), config_1.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
39
40
  }
40
41
  return {
41
42
  configFilePathFromEnvironment,
@@ -163,13 +164,13 @@ function normalizeParsedConfig(parsedConfig) {
163
164
  return parsedConfig;
164
165
  }
165
166
  exports.normalizeParsedConfig = normalizeParsedConfig;
166
- function parseConfig(configSource) {
167
+ function parseConfig(configSource, configPath) {
167
168
  let parsedYaml;
168
169
  try {
169
170
  parsedYaml = js_yaml_1.default.load(configSource);
170
171
  }
171
172
  catch (err) {
172
- throw new Error((0, lang_1.i18n)('config.utils.parseConfig.error'), { cause: err });
173
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.utils.parseConfig.error', { configPath: configPath }), config_1.HUBSPOT_CONFIG_ERROR_TYPES.YAML_PARSING, config_1.HUBSPOT_CONFIG_OPERATIONS.READ, { cause: err });
173
174
  }
174
175
  return normalizeParsedConfig(parsedYaml);
175
176
  }
@@ -188,7 +189,7 @@ function buildConfigFromEnvironment() {
188
189
  const allowUsageTrackingVar = process.env[config_1.ENVIRONMENT_VARIABLES.ALLOW_USAGE_TRACKING];
189
190
  const defaultCmsPublishModeVar = process.env[config_1.ENVIRONMENT_VARIABLES.DEFAULT_CMS_PUBLISH_MODE];
190
191
  if (!accountIdVar) {
191
- throw new Error((0, lang_1.i18n)('config.utils.buildConfigFromEnvironment.missingAccountId'));
192
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.utils.buildConfigFromEnvironment.missingAccountId'), config_1.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
192
193
  }
193
194
  const accountId = parseInt(accountIdVar);
194
195
  const httpTimeout = httpTimeoutVar ? parseInt(httpTimeoutVar) : undefined;
@@ -242,7 +243,7 @@ function buildConfigFromEnvironment() {
242
243
  };
243
244
  }
244
245
  else {
245
- throw new Error((0, lang_1.i18n)('config.utils.buildConfigFromEnvironment.invalidAuthType'));
246
+ throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.utils.buildConfigFromEnvironment.invalidAuthType'), config_1.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
246
247
  }
247
248
  return {
248
249
  accounts: [account],
@@ -56,3 +56,16 @@ export declare const ACCOUNT_IDENTIFIERS: {
56
56
  readonly ACCOUNT_ID: "accountId";
57
57
  readonly NAME: "name";
58
58
  };
59
+ export declare const HUBSPOT_CONFIG_ERROR_TYPES: {
60
+ readonly CONFIG_NOT_FOUND: "CONFIG_NOT_FOUND";
61
+ readonly ACCOUNT_NOT_FOUND: "ACCOUNT_NOT_FOUND";
62
+ readonly NO_DEFAULT_ACCOUNT: "NO_DEFAULT_ACCOUNT";
63
+ readonly INVALID_ENVIRONMENT_VARIABLES: "ENVIRONMENT_VARIABLES";
64
+ readonly YAML_PARSING: "YAML_PARSING";
65
+ readonly INVALID_ACCOUNT: "INVALID_ACCOUNT";
66
+ readonly INVALID_FIELD: "INVALID_FIELD";
67
+ };
68
+ export declare const HUBSPOT_CONFIG_OPERATIONS: {
69
+ readonly READ: "READ";
70
+ readonly WRITE: "WRITE";
71
+ };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ACCOUNT_IDENTIFIERS = exports.ENVIRONMENT_VARIABLES = exports.CONFIG_FLAGS = exports.HUBSPOT_ACCOUNT_TYPE_STRINGS = exports.HUBSPOT_ACCOUNT_TYPES = exports.MIN_HTTP_TIMEOUT = exports.DEFAULT_PORTAL = exports.DEFAULT_ACCOUNT = exports.ALLOW_AUTO_UPDATES = exports.AUTO_OPEN_BROWSER = exports.ALLOW_USAGE_TRACKING = exports.HTTP_USE_LOCALHOST = exports.ENV = exports.HTTP_TIMEOUT = exports.DEFAULT_CMS_PUBLISH_MODE = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID = exports.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME = exports.STATE_FILE_PATH = exports.GLOBAL_CONFIG_PATH = exports.HUBSPOT_STATE_FILE = exports.HUBSPOT_CONFIGURATION_FILE = exports.HUBSPOT_CONFIGURATION_FOLDER = exports.ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME = exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = void 0;
6
+ exports.HUBSPOT_CONFIG_OPERATIONS = exports.HUBSPOT_CONFIG_ERROR_TYPES = exports.ACCOUNT_IDENTIFIERS = exports.ENVIRONMENT_VARIABLES = exports.CONFIG_FLAGS = exports.HUBSPOT_ACCOUNT_TYPE_STRINGS = exports.HUBSPOT_ACCOUNT_TYPES = exports.MIN_HTTP_TIMEOUT = exports.DEFAULT_PORTAL = exports.DEFAULT_ACCOUNT = exports.ALLOW_AUTO_UPDATES = exports.AUTO_OPEN_BROWSER = exports.ALLOW_USAGE_TRACKING = exports.HTTP_USE_LOCALHOST = exports.ENV = exports.HTTP_TIMEOUT = exports.DEFAULT_CMS_PUBLISH_MODE = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID = exports.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME = exports.STATE_FILE_PATH = exports.GLOBAL_CONFIG_PATH = exports.HUBSPOT_STATE_FILE = exports.HUBSPOT_CONFIGURATION_FILE = exports.HUBSPOT_CONFIGURATION_FOLDER = exports.ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME = exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = void 0;
7
7
  const lang_1 = require("../utils/lang");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const os_1 = __importDefault(require("os"));
@@ -65,3 +65,16 @@ exports.ACCOUNT_IDENTIFIERS = {
65
65
  ACCOUNT_ID: 'accountId',
66
66
  NAME: 'name',
67
67
  };
68
+ exports.HUBSPOT_CONFIG_ERROR_TYPES = {
69
+ CONFIG_NOT_FOUND: 'CONFIG_NOT_FOUND',
70
+ ACCOUNT_NOT_FOUND: 'ACCOUNT_NOT_FOUND',
71
+ NO_DEFAULT_ACCOUNT: 'NO_DEFAULT_ACCOUNT',
72
+ INVALID_ENVIRONMENT_VARIABLES: 'ENVIRONMENT_VARIABLES',
73
+ YAML_PARSING: 'YAML_PARSING',
74
+ INVALID_ACCOUNT: 'INVALID_ACCOUNT',
75
+ INVALID_FIELD: 'INVALID_FIELD',
76
+ };
77
+ exports.HUBSPOT_CONFIG_OPERATIONS = {
78
+ READ: 'READ',
79
+ WRITE: 'WRITE',
80
+ };
package/errors/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { HubSpotHttpError } from '../models/HubSpotHttpError';
2
2
  import { BaseError } from '../types/Error';
3
3
  import { FileSystemError } from '../models/FileSystemError';
4
+ import { HubSpotConfigError } from '../models/HubSpotConfigError';
4
5
  export declare function isSpecifiedError(err: unknown, { statusCode, category, subCategory, errorType, code, }: {
5
6
  statusCode?: number;
6
7
  category?: string;
@@ -17,3 +18,4 @@ export declare function isHubSpotHttpError(error?: unknown): error is HubSpotHtt
17
18
  export declare function isGithubRateLimitError(err: unknown): boolean;
18
19
  export declare function isSystemError(err: unknown): err is BaseError;
19
20
  export declare function isFileSystemError(err: unknown): err is FileSystemError;
21
+ export declare function isHubSpotConfigError(err: unknown): err is HubSpotConfigError;
package/errors/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFileSystemError = exports.isSystemError = exports.isGithubRateLimitError = exports.isHubSpotHttpError = exports.isValidationError = exports.isAuthError = exports.isTimeoutError = exports.isGatingError = exports.isMissingScopeError = exports.isSpecifiedError = void 0;
3
+ exports.isHubSpotConfigError = exports.isFileSystemError = exports.isSystemError = exports.isGithubRateLimitError = exports.isHubSpotHttpError = exports.isValidationError = exports.isAuthError = exports.isTimeoutError = exports.isGatingError = exports.isMissingScopeError = exports.isSpecifiedError = void 0;
4
4
  const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
5
5
  const FileSystemError_1 = require("../models/FileSystemError");
6
+ const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
6
7
  function isSpecifiedError(err, { statusCode, category, subCategory, errorType, code, }) {
7
8
  if (!isHubSpotHttpError(err)) {
8
9
  return false;
@@ -70,3 +71,7 @@ function isFileSystemError(err) {
70
71
  return err instanceof FileSystemError_1.FileSystemError;
71
72
  }
72
73
  exports.isFileSystemError = isFileSystemError;
74
+ function isHubSpotConfigError(err) {
75
+ return err instanceof HubSpotConfigError_1.HubSpotConfigError;
76
+ }
77
+ exports.isHubSpotConfigError = isHubSpotConfigError;
package/lang/en.json CHANGED
@@ -244,9 +244,13 @@
244
244
  },
245
245
  "config": {
246
246
  "getDefaultConfigFilePath": {
247
- "error": "Error getting config file path: no config file found"
247
+ "error": "Attempted to get config file path, but no config file was found."
248
+ },
249
+ "getConfig": {
250
+ "reading": "Reading config from {{ path }}",
251
+ "error": "No config file found.",
252
+ "errorWithPath": "No config file found at {{ path }}."
248
253
  },
249
- "getConfig": "Reading config from {{ path }}",
250
254
  "isConfigValid": {
251
255
  "missingAccounts": "Invalid config: no accounts found",
252
256
  "duplicateAccountIds": "Invalid config: multiple accounts with accountId: {{ accountId }}",
@@ -254,35 +258,35 @@
254
258
  "invalidAccountName": "Invalid config: account name {{ accountName }} contains spaces"
255
259
  },
256
260
  "getConfigAccountById": {
257
- "error": "Error getting config account: no account with id {{ accountId }} exists in config"
261
+ "error": "No account with id {{ accountId }} exists in config"
258
262
  },
259
263
  "getConfigAccountByName": {
260
- "error": "Error getting config account: no account with name {{ accountName }} exists in config"
264
+ "error": "No account with name {{ accountName }} exists in config"
261
265
  },
262
266
  "getConfigDefaultAccount": {
263
- "fieldMissingError": "Error getting config default account: no default account field found in config",
264
- "accountMissingError": "Error getting config default account: default account is set to {{ defaultAccount }} but no account with that id exists in config"
267
+ "fieldMissingError": "Attempted to get default account, but no default account was found in config",
268
+ "accountMissingError": "Default account is set to {{ defaultAccount }}, but no account with that id exists in config"
265
269
  },
266
270
  "addConfigAccount": {
267
- "invalidAccount": "Error adding config account: account is invalid",
268
- "duplicateAccount": "Error adding config account: account with id {{ accountId }} already exists in config"
271
+ "invalidAccount": "Attempting to add account, but account is invalid",
272
+ "duplicateAccount": "Attempting to add account, but account with id {{ accountId }} already exists in config"
269
273
  },
270
274
  "updateConfigAccount": {
271
- "invalidAccount": "Error updating config account: account is invalid",
272
- "accountNotFound": "Error updating config account: account with id {{ accountId }} not found in config"
275
+ "invalidAccount": "Attempting to update account {{ name }}, but account is invalid",
276
+ "accountNotFound": "Attempting to update account with id {{ id }}, but that account was not found in config"
273
277
  },
274
278
  "setConfigAccountAsDefault": {
275
- "accountNotFound": "Error setting config default account: account with id {{ accountId }} not found in config"
279
+ "accountNotFound": "Attempted to set account with id {{ accountId }} as default, but that account was not found in config"
276
280
  },
277
281
  "renameConfigAccount": {
278
- "accountNotFound": "Error renaming config account: account with name {{ currentName }} not found in config",
279
- "duplicateAccount": "Error renaming config account: account with name {{ newName}} already exists in config"
282
+ "accountNotFound": "Attempted to rename account with name {{ currentName }}, but that account was not found in config",
283
+ "duplicateAccount": "Attempted to rename account {{ currentName }} to {{ newName }}, but an account with that name already exists in config"
280
284
  },
281
285
  "removeAccountFromConfig": {
282
- "accountNotFound": "Error removing config account: account with id {{ accountId }} not found in config"
286
+ "accountNotFound": "Attempted to remove account with id {{ accountId }}, but that account was not found in config"
283
287
  },
284
288
  "updateHttpTimeout": {
285
- "invalidTimeout": "Error updating config http timeout: timeout must be greater than {{ minTimeout }}"
289
+ "invalidTimeout": "HTTP timeout must be greater than {{ minTimeout }}. Received {{ timeout }}"
286
290
  },
287
291
  "updateDefaultCmsPublishMode": {
288
292
  "invalidCmsPublishMode": "Error updating config default CMS publish mode: CMS publish can only be set to 'draft' or 'publish'"
@@ -297,14 +301,14 @@
297
301
  "missingPersonalAccessKey": "Invalid config: account {{ accountId }} has authType of personalAccessKey but is missing the personalAccessKey field"
298
302
  },
299
303
  "getConfigPathEnvironmentVariables": {
300
- "invalidEnvironmentVariables": "Error loading config: USE_ENVIRONMENT_HUBSPOT_CONFIG and HUBSPOT_CONFIG_PATH cannot both be set simultaneously"
304
+ "invalidEnvironmentVariables": "USE_ENVIRONMENT_HUBSPOT_CONFIG and HUBSPOT_CONFIG_PATH cannot both be set simultaneously"
301
305
  },
302
306
  "parseConfig": {
303
- "error": "An error occurred parsing the config file."
307
+ "error": "File could not be parsed. Confirm that your config file {{ configPath }} is valid YAML."
304
308
  },
305
309
  "buildConfigFromEnvironment": {
306
- "missingAccountId": "Error loading config from environment: HUBSPOT_ACCOUNT_ID not set",
307
- "invalidAuthType": "Error loading config from environment: auth is invalid. Use HUBSPOT_CLIENT_ID, HUBSPOT_CLIENT_SECRET, and HUBSPOT_REFRESH_TOKEN to authenticate with Oauth2, PERSONAL_ACCESS_KEY to authenticate with Personal Access Key, or API_KEY to authenticate with API Key."
310
+ "missingAccountId": "HUBSPOT_ACCOUNT_ID is required, but not currently set",
311
+ "invalidAuthType": "Auth type is invalid. Use HUBSPOT_CLIENT_ID, HUBSPOT_CLIENT_SECRET, and HUBSPOT_REFRESH_TOKEN to authenticate with Oauth2, PERSONAL_ACCESS_KEY to authenticate with Personal Access Key, or API_KEY to authenticate with API Key."
308
312
  }
309
313
  },
310
314
  "defaultAccountOverride": {
@@ -313,6 +317,12 @@
313
317
  "readFileError": "Error reading account override file."
314
318
  }
315
319
  },
320
+ "updateAllowUsageTracking": {
321
+ "invalidInput": "Unable to update allowUsageTracking. The value {{ isAllowed }} is invalid. The value must be a boolean."
322
+ },
323
+ "updateAllowAutoUpdates": {
324
+ "invalidInput": "Unable to update allowAutoUpdates. The value {{ isEnabled }} is invalid. The value must be a boolean."
325
+ },
316
326
  "updateAutoOpenBrowser": {
317
327
  "invalidInput": "Unable to update autoOpenBrowser. The value {{ isEnabled }} is invalid. The value must be a boolean."
318
328
  },
@@ -367,6 +377,9 @@
367
377
  "missingRefreshToken": "The account {{ accountId }} has not been authenticated with Oauth2",
368
378
  "auth": "Error while retrieving new token: {{ token }}"
369
379
  }
380
+ },
381
+ "HubSpotConfigError": {
382
+ "baseMessage": "An error occurred while {{ operation }} your HubSpot config {{ configType }}: {{ message }}"
370
383
  }
371
384
  },
372
385
  "utils": {
@@ -0,0 +1,6 @@
1
+ import { HubSpotConfigErrorType, HubSpotConfigOperation } from '../types/Config';
2
+ export declare class HubSpotConfigError extends Error {
3
+ type: HubSpotConfigErrorType;
4
+ operation: HubSpotConfigOperation;
5
+ constructor(message: string, type: HubSpotConfigErrorType, operation: HubSpotConfigOperation, options?: ErrorOptions);
6
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HubSpotConfigError = void 0;
4
+ const config_1 = require("../constants/config");
5
+ const lang_1 = require("../utils/lang");
6
+ const NAME = 'HubSpotConfigError';
7
+ function isEnvironmentError(type) {
8
+ return type === config_1.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES;
9
+ }
10
+ class HubSpotConfigError extends Error {
11
+ type;
12
+ operation;
13
+ constructor(message, type, operation, options) {
14
+ const configType = isEnvironmentError(type)
15
+ ? 'environment variables'
16
+ : 'file';
17
+ const operationText = operation === config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE ? 'writing to' : 'reading';
18
+ const withBaseMessage = (0, lang_1.i18n)('models.HubSpotConfigError.baseMessage', {
19
+ configType,
20
+ message,
21
+ operation: operationText,
22
+ });
23
+ super(withBaseMessage, options);
24
+ this.name = NAME;
25
+ this.type = type;
26
+ this.operation = operation;
27
+ }
28
+ }
29
+ exports.HubSpotConfigError = HubSpotConfigError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "0.5.0-experimental.0",
3
+ "version": "0.5.0-experimental.1",
4
4
  "description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
5
5
  "repository": {
6
6
  "type": "git",
package/types/Config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CONFIG_FLAGS } from '../constants/config';
1
+ import { CONFIG_FLAGS, HUBSPOT_CONFIG_ERROR_TYPES, HUBSPOT_CONFIG_OPERATIONS } from '../constants/config';
2
2
  import { ENVIRONMENTS } from '../constants/environments';
3
3
  import { DeprecatedHubSpotConfigAccountFields, HubSpotConfigAccount } from './Accounts';
4
4
  import { CmsPublishMode } from './Files';
@@ -32,3 +32,5 @@ export type ConfigFlag = ValueOf<typeof CONFIG_FLAGS>;
32
32
  export type CLIState = {
33
33
  mcpTotalToolCalls: number;
34
34
  };
35
+ export type HubSpotConfigErrorType = ValueOf<typeof HUBSPOT_CONFIG_ERROR_TYPES>;
36
+ export type HubSpotConfigOperation = ValueOf<typeof HUBSPOT_CONFIG_OPERATIONS>;