@hubspot/local-dev-lib 0.5.0-experimental.12 → 0.5.0-experimental.14

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
@@ -1,5 +1,5 @@
1
1
  import { HubSpotConfigAccount } from '../types/Accounts';
2
- import { HubSpotConfig, ConfigFlag } from '../types/Config';
2
+ import { HubSpotConfig, ConfigFlag, HubSpotConfigValidationResult } from '../types/Config';
3
3
  import { CmsPublishMode } from '../types/Files';
4
4
  import { Environment } from '../types/Config';
5
5
  export declare function getGlobalConfigFilePath(): string;
@@ -9,7 +9,7 @@ export declare function globalConfigFileExists(): boolean;
9
9
  export declare function configFileExists(): boolean;
10
10
  export declare function getConfigFilePath(): string;
11
11
  export declare function getConfig(): HubSpotConfig;
12
- export declare function isConfigValid(): boolean;
12
+ export declare function validateConfig(): HubSpotConfigValidationResult;
13
13
  export declare function createEmptyConfigFile(useGlobalConfig?: boolean): void;
14
14
  export declare function deleteConfigFileIfEmpty(): void;
15
15
  export declare function getConfigAccountById(accountId: number): HubSpotConfigAccount;
package/config/index.js CHANGED
@@ -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.removeLocalStateFlag = exports.addLocalStateFlag = exports.hasLocalStateFlag = exports.isConfigFlagEnabled = exports.updateDefaultCmsPublishMode = exports.updateAutoOpenBrowser = exports.updateAllowAutoUpdates = exports.updateAllowUsageTracking = exports.updateHttpTimeout = exports.removeAccountFromConfig = exports.renameConfigAccount = exports.setConfigAccountAsDefault = exports.updateConfigAccount = exports.addConfigAccount = exports.getConfigAccountEnvironment = exports.getAllConfigAccounts = exports.getConfigDefaultAccountIfExists = exports.getConfigDefaultAccount = exports.getConfigAccountIfExists = exports.getConfigAccountByName = exports.getConfigAccountById = exports.deleteConfigFileIfEmpty = exports.createEmptyConfigFile = exports.isConfigValid = exports.getConfig = exports.getConfigFilePath = exports.configFileExists = exports.globalConfigFileExists = exports.localConfigFileExists = exports.getLocalConfigFilePathIfExists = exports.getGlobalConfigFilePath = void 0;
6
+ exports.removeLocalStateFlag = exports.addLocalStateFlag = exports.hasLocalStateFlag = exports.isConfigFlagEnabled = exports.updateDefaultCmsPublishMode = exports.updateAutoOpenBrowser = exports.updateAllowAutoUpdates = exports.updateAllowUsageTracking = exports.updateHttpTimeout = exports.removeAccountFromConfig = exports.renameConfigAccount = exports.setConfigAccountAsDefault = exports.updateConfigAccount = exports.addConfigAccount = exports.getConfigAccountEnvironment = exports.getAllConfigAccounts = exports.getConfigDefaultAccountIfExists = exports.getConfigDefaultAccount = exports.getConfigAccountIfExists = exports.getConfigAccountByName = exports.getConfigAccountById = exports.deleteConfigFileIfEmpty = exports.createEmptyConfigFile = exports.validateConfig = exports.getConfig = exports.getConfigFilePath = exports.configFileExists = exports.globalConfigFileExists = exports.localConfigFileExists = exports.getLocalConfigFilePathIfExists = exports.getGlobalConfigFilePath = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const findup_sync_1 = __importDefault(require("findup-sync"));
9
9
  const config_1 = require("../constants/config");
@@ -81,44 +81,45 @@ function getConfig() {
81
81
  }
82
82
  }
83
83
  exports.getConfig = getConfig;
84
- function isConfigValid() {
84
+ function validateConfig() {
85
85
  const config = getConfig();
86
86
  if (config.accounts.length === 0) {
87
- logger_1.logger.debug((0, lang_1.i18n)('config.isConfigValid.missingAccounts'));
88
- return false;
87
+ return {
88
+ isValid: false,
89
+ errors: [(0, lang_1.i18n)('config.validateConfig.missingAccounts')],
90
+ };
89
91
  }
90
92
  const accountIdsMap = {};
91
93
  const accountNamesMap = {};
92
- return config.accounts.every(account => {
93
- if (!(0, utils_1.isConfigAccountValid)(account)) {
94
- return false;
94
+ const validationErrors = [];
95
+ config.accounts.forEach(account => {
96
+ const accountValidationResult = (0, utils_1.validateConfigAccount)(account);
97
+ if (!accountValidationResult.isValid) {
98
+ validationErrors.push(...accountValidationResult.errors);
95
99
  }
96
100
  if (accountIdsMap[account.accountId]) {
97
- logger_1.logger.debug((0, lang_1.i18n)('config.isConfigValid.duplicateAccountIds', {
101
+ validationErrors.push((0, lang_1.i18n)('config.validateConfig.duplicateAccountIds', {
98
102
  accountId: account.accountId,
99
103
  }));
100
- return false;
101
104
  }
102
105
  if (account.name) {
103
106
  if (accountNamesMap[account.name.toLowerCase()]) {
104
- logger_1.logger.debug((0, lang_1.i18n)('config.isConfigValid.duplicateAccountNames', {
107
+ validationErrors.push((0, lang_1.i18n)('config.validateConfig.duplicateAccountNames', {
105
108
  accountName: account.name,
106
109
  }));
107
- return false;
108
110
  }
109
111
  if (/\s+/.test(account.name)) {
110
- logger_1.logger.debug((0, lang_1.i18n)('config.isConfigValid.invalidAccountName', {
112
+ validationErrors.push((0, lang_1.i18n)('config.validateConfig.invalidAccountName', {
111
113
  accountName: account.name,
112
114
  }));
113
- return false;
114
115
  }
115
116
  accountNamesMap[account.name] = true;
116
117
  }
117
118
  accountIdsMap[account.accountId] = true;
118
- return true;
119
119
  });
120
+ return { isValid: validationErrors.length === 0, errors: validationErrors };
120
121
  }
121
- exports.isConfigValid = isConfigValid;
122
+ exports.validateConfig = validateConfig;
122
123
  function createEmptyConfigFile(useGlobalConfig = false) {
123
124
  const { configFilePathFromEnvironment } = (0, utils_1.getConfigPathEnvironmentVariables)();
124
125
  const defaultPath = useGlobalConfig
@@ -222,7 +223,7 @@ function getConfigAccountEnvironment(identifier) {
222
223
  }
223
224
  exports.getConfigAccountEnvironment = getConfigAccountEnvironment;
224
225
  function addConfigAccount(accountToAdd) {
225
- if (!(0, utils_1.isConfigAccountValid)(accountToAdd)) {
226
+ if (!(0, utils_1.validateConfigAccount)(accountToAdd)) {
226
227
  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);
227
228
  }
228
229
  const config = getConfig();
@@ -237,7 +238,7 @@ function addConfigAccount(accountToAdd) {
237
238
  }
238
239
  exports.addConfigAccount = addConfigAccount;
239
240
  function updateConfigAccount(updatedAccount) {
240
- if (!(0, utils_1.isConfigAccountValid)(updatedAccount)) {
241
+ if (!(0, utils_1.validateConfigAccount)(updatedAccount)) {
241
242
  throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateConfigAccount.invalidAccount', {
242
243
  name: updatedAccount.name,
243
244
  }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
@@ -258,7 +259,7 @@ function setConfigAccountAsDefault(identifier) {
258
259
  const account = (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
259
260
  if (!account) {
260
261
  throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.setConfigAccountAsDefault.accountNotFound', {
261
- accountId: identifier,
262
+ identifier,
262
263
  }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
263
264
  }
264
265
  config.defaultAccount = account.accountId;
package/config/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ACCOUNT_IDENTIFIERS } from '../constants/config';
2
- import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType } from '../types/Config';
2
+ import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType, HubSpotConfigValidationResult } from '../types/Config';
3
3
  import { HubSpotConfigAccount, AccountType, TokenInfo } from '../types/Accounts';
4
4
  import { ValueOf } from '../types/Utils';
5
5
  export declare function getLocalConfigDefaultFilePath(): string;
@@ -70,7 +70,7 @@ export declare function getAccountIdentifierAndType(accountIdentifier: string |
70
70
  export declare function getConfigAccountByIdentifier(accounts: Array<HubSpotConfigAccount>, identifierFieldName: ValueOf<typeof ACCOUNT_IDENTIFIERS>, identifier: string | number): HubSpotConfigAccount | undefined;
71
71
  export declare function getConfigAccountByInferredIdentifier(accounts: Array<HubSpotConfigAccount>, accountIdentifier: string | number): HubSpotConfigAccount | undefined;
72
72
  export declare function getConfigAccountIndexById(accounts: Array<HubSpotConfigAccount>, id: number): number;
73
- export declare function isConfigAccountValid(account: Partial<HubSpotConfigAccount>): boolean;
73
+ export declare function validateConfigAccount(account: Partial<HubSpotConfigAccount>): HubSpotConfigValidationResult;
74
74
  export declare function handleConfigFileSystemError(error: unknown, path: string): {
75
75
  message?: string;
76
76
  type: HubSpotConfigErrorType;
package/config/utils.js CHANGED
@@ -3,13 +3,12 @@ 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.handleConfigFileSystemError = exports.isConfigAccountValid = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = exports.normalizeParsedConfig = exports.writeConfigFile = exports.formatConfigForWrite = exports.removeUndefinedFieldsFromConfigAccount = exports.readConfigFile = exports.doesConfigFileExistAtPath = exports.getConfigPathEnvironmentVariables = exports.getLocalConfigDefaultFilePath = void 0;
6
+ exports.handleConfigFileSystemError = exports.validateConfigAccount = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = exports.normalizeParsedConfig = exports.writeConfigFile = exports.formatConfigForWrite = exports.removeUndefinedFieldsFromConfigAccount = exports.readConfigFile = exports.doesConfigFileExistAtPath = exports.getConfigPathEnvironmentVariables = exports.getLocalConfigDefaultFilePath = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const js_yaml_1 = __importDefault(require("js-yaml"));
9
9
  const config_1 = require("../constants/config");
10
10
  const auth_1 = require("../constants/auth");
11
11
  const FileSystemError_1 = require("../models/FileSystemError");
12
- const logger_1 = require("../lib/logger");
13
12
  const environment_1 = require("../lib/environment");
14
13
  const path_1 = require("../lib/path");
15
14
  const files_1 = require("../constants/files");
@@ -271,57 +270,61 @@ function getConfigAccountByIdentifier(accounts, identifierFieldName, identifier)
271
270
  exports.getConfigAccountByIdentifier = getConfigAccountByIdentifier;
272
271
  function getConfigAccountByInferredIdentifier(accounts, accountIdentifier) {
273
272
  const { identifier, identifierType } = getAccountIdentifierAndType(accountIdentifier);
274
- return accounts.find(account => account[identifierType] === identifier);
273
+ const account = getConfigAccountByIdentifier(accounts, identifierType, identifier);
274
+ if (account) {
275
+ return account;
276
+ }
277
+ // Fallback to handle accounts with numbers as names
278
+ return getConfigAccountByIdentifier(accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, String(accountIdentifier));
275
279
  }
276
280
  exports.getConfigAccountByInferredIdentifier = getConfigAccountByInferredIdentifier;
277
281
  function getConfigAccountIndexById(accounts, id) {
278
282
  return accounts.findIndex(account => account.accountId === id);
279
283
  }
280
284
  exports.getConfigAccountIndexById = getConfigAccountIndexById;
281
- function isConfigAccountValid(account) {
285
+ function validateConfigAccount(account) {
286
+ const validationErrors = [];
282
287
  if (!account || typeof account !== 'object') {
283
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAccount'));
284
- return false;
288
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAccount'));
289
+ return { isValid: false, errors: validationErrors };
285
290
  }
286
291
  if (!account.accountId) {
287
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAccountId'));
288
- return false;
292
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAccountId'));
293
+ return { isValid: false, errors: validationErrors };
289
294
  }
290
295
  if (!account.authType) {
291
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAuthType', {
296
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAuthType', {
292
297
  accountId: account.accountId,
293
298
  }));
294
- return false;
299
+ return { isValid: false, errors: validationErrors };
295
300
  }
296
- let valid = false;
297
301
  if (account.authType === auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
298
- valid =
299
- 'personalAccessKey' in account && Boolean(account.personalAccessKey);
300
- if (!valid) {
301
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingPersonalAccessKey', {
302
+ const isValidPersonalAccessKeyAccount = 'personalAccessKey' in account && Boolean(account.personalAccessKey);
303
+ if (!isValidPersonalAccessKeyAccount) {
304
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingPersonalAccessKey', {
302
305
  accountId: account.accountId,
303
306
  }));
304
307
  }
305
308
  }
306
309
  if (account.authType === auth_1.OAUTH_AUTH_METHOD.value) {
307
- valid = 'auth' in account && Boolean(account.auth);
308
- if (!valid) {
309
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAuth', {
310
+ const isValidOAuthAccount = 'auth' in account && Boolean(account.auth);
311
+ if (!isValidOAuthAccount) {
312
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAuth', {
310
313
  accountId: account.accountId,
311
314
  }));
312
315
  }
313
316
  }
314
317
  if (account.authType === auth_1.API_KEY_AUTH_METHOD.value) {
315
- valid = 'apiKey' in account && Boolean(account.apiKey);
316
- if (!valid) {
317
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingApiKey', {
318
+ const isValidAPIKeyAccount = 'apiKey' in account && Boolean(account.apiKey);
319
+ if (!isValidAPIKeyAccount) {
320
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingApiKey', {
318
321
  accountId: account.accountId,
319
322
  }));
320
323
  }
321
324
  }
322
- return valid;
325
+ return { isValid: validationErrors.length === 0, errors: validationErrors };
323
326
  }
324
- exports.isConfigAccountValid = isConfigAccountValid;
327
+ exports.validateConfigAccount = validateConfigAccount;
325
328
  function handleConfigFileSystemError(error, path) {
326
329
  let message;
327
330
  let type = config_1.HUBSPOT_CONFIG_ERROR_TYPES.UNKNOWN;
package/lang/en.json CHANGED
@@ -251,11 +251,11 @@
251
251
  "error": "No config file found.",
252
252
  "errorWithPath": "No config file found at {{ path }}."
253
253
  },
254
- "isConfigValid": {
255
- "missingAccounts": "Invalid config: no accounts found",
256
- "duplicateAccountIds": "Invalid config: multiple accounts with accountId: {{ accountId }}",
257
- "duplicateAccountNames": "Invalid config: multiple accounts with name: {{ accountName }}",
258
- "invalidAccountName": "Invalid config: account name {{ accountName }} contains spaces"
254
+ "validateConfig": {
255
+ "missingAccounts": "No accounts found",
256
+ "duplicateAccountIds": "Multiple accounts with accountId: {{ accountId }}",
257
+ "duplicateAccountNames": "Multiple accounts with name: {{ accountName }}",
258
+ "invalidAccountName": "Account name {{ accountName }} contains spaces"
259
259
  },
260
260
  "getConfigAccountById": {
261
261
  "error": "No account with id {{ accountId }} exists in config"
@@ -276,7 +276,7 @@
276
276
  "accountNotFound": "Attempting to update account with id {{ id }}, but that account was not found in config"
277
277
  },
278
278
  "setConfigAccountAsDefault": {
279
- "accountNotFound": "Attempted to set account with id {{ accountId }} as default, but that account was not found in config"
279
+ "accountNotFound": "Attempted to set account with identifier {{ identifier }} as default, but that account was not found in config"
280
280
  },
281
281
  "renameConfigAccount": {
282
282
  "accountNotFound": "Attempted to rename account with name {{ currentName }}, but that account was not found in config",
@@ -299,13 +299,13 @@
299
299
  "configNotFoundError": "No config file found at {{ path }}.",
300
300
  "insufficientPermissionsError": "Insufficient permissions to access config file at {{ path }}"
301
301
  },
302
- "isConfigAccountValid": {
303
- "missingAccount": "Invalid config: at least one account in config is missing data",
304
- "missingAuthType": "Invalid config: account {{ accountId }} has no authType",
305
- "missingAccountId": "Invalid config: at least one account in config is missing accountId",
306
- "missingApiKey": "Invalid config: account {{ accountId }} has authType of apikey but is missing the apiKey field",
307
- "missingAuth": "Invalid config: account {{ accountId }} has authtype of oauth2 but is missing auth data",
308
- "missingPersonalAccessKey": "Invalid config: account {{ accountId }} has authType of personalAccessKey but is missing the personalAccessKey field"
302
+ "validateConfigAccount": {
303
+ "missingAccount": "At least one account in config is missing data",
304
+ "missingAuthType": "Account {{ accountId }} has no authType",
305
+ "missingAccountId": "At least one account in config is missing accountId",
306
+ "missingApiKey": "Account {{ accountId }} has authType of apikey but is missing the apiKey field",
307
+ "missingAuth": "Account {{ accountId }} has authtype of oauth2 but is missing auth data",
308
+ "missingPersonalAccessKey": "Account {{ accountId }} has authType of personalAccessKey but is missing the personalAccessKey field"
309
309
  },
310
310
  "getConfigPathEnvironmentVariables": {
311
311
  "invalidEnvironmentVariables": "USE_ENVIRONMENT_HUBSPOT_CONFIG and HUBSPOT_CONFIG_PATH cannot both be set simultaneously"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "0.5.0-experimental.12",
3
+ "version": "0.5.0-experimental.14",
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
@@ -34,3 +34,7 @@ export type HubSpotState = {
34
34
  };
35
35
  export type HubSpotConfigErrorType = ValueOf<typeof HUBSPOT_CONFIG_ERROR_TYPES>;
36
36
  export type HubSpotConfigOperation = ValueOf<typeof HUBSPOT_CONFIG_OPERATIONS>;
37
+ export type HubSpotConfigValidationResult = {
38
+ isValid: boolean;
39
+ errors: Array<string>;
40
+ };