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

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
+ logger_1.logger.debug((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
+ logger_1.logger.debug((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);
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");
@@ -278,50 +277,49 @@ function getConfigAccountIndexById(accounts, id) {
278
277
  return accounts.findIndex(account => account.accountId === id);
279
278
  }
280
279
  exports.getConfigAccountIndexById = getConfigAccountIndexById;
281
- function isConfigAccountValid(account) {
280
+ function validateConfigAccount(account) {
281
+ const validationErrors = [];
282
282
  if (!account || typeof account !== 'object') {
283
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAccount'));
284
- return false;
283
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAccount'));
284
+ return { isValid: false, errors: validationErrors };
285
285
  }
286
286
  if (!account.accountId) {
287
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAccountId'));
288
- return false;
287
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAccountId'));
288
+ return { isValid: false, errors: validationErrors };
289
289
  }
290
290
  if (!account.authType) {
291
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAuthType', {
291
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAuthType', {
292
292
  accountId: account.accountId,
293
293
  }));
294
- return false;
294
+ return { isValid: false, errors: validationErrors };
295
295
  }
296
- let valid = false;
297
296
  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', {
297
+ const isValidPersonalAccessKeyAccount = 'personalAccessKey' in account && Boolean(account.personalAccessKey);
298
+ if (!isValidPersonalAccessKeyAccount) {
299
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingPersonalAccessKey', {
302
300
  accountId: account.accountId,
303
301
  }));
304
302
  }
305
303
  }
306
304
  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', {
305
+ const isValidOAuthAccount = 'auth' in account && Boolean(account.auth);
306
+ if (!isValidOAuthAccount) {
307
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAuth', {
310
308
  accountId: account.accountId,
311
309
  }));
312
310
  }
313
311
  }
314
312
  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', {
313
+ const isValidAPIKeyAccount = 'apiKey' in account && Boolean(account.apiKey);
314
+ if (!isValidAPIKeyAccount) {
315
+ validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingApiKey', {
318
316
  accountId: account.accountId,
319
317
  }));
320
318
  }
321
319
  }
322
- return valid;
320
+ return { isValid: validationErrors.length === 0, errors: validationErrors };
323
321
  }
324
- exports.isConfigAccountValid = isConfigAccountValid;
322
+ exports.validateConfigAccount = validateConfigAccount;
325
323
  function handleConfigFileSystemError(error, path) {
326
324
  let message;
327
325
  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"
@@ -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.13",
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
+ };