@hubspot/local-dev-lib 1.13.1 → 2.0.0

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.
Files changed (104) hide show
  1. package/api/appsDev.d.ts +6 -5
  2. package/api/appsDev.js +6 -10
  3. package/api/customObjects.d.ts +7 -6
  4. package/api/customObjects.js +13 -16
  5. package/api/designManager.d.ts +3 -2
  6. package/api/designManager.js +5 -8
  7. package/api/developerTestAccounts.d.ts +5 -4
  8. package/api/developerTestAccounts.js +9 -10
  9. package/api/fileManager.d.ts +5 -4
  10. package/api/fileManager.js +9 -9
  11. package/api/fileMapper.d.ts +8 -8
  12. package/api/fileMapper.js +16 -16
  13. package/api/fileTransport.d.ts +4 -3
  14. package/api/fileTransport.js +5 -5
  15. package/api/functions.d.ts +6 -5
  16. package/api/functions.js +11 -14
  17. package/api/github.d.ts +6 -6
  18. package/api/github.js +5 -5
  19. package/api/hubdb.d.ts +9 -8
  20. package/api/hubdb.js +17 -20
  21. package/api/lighthouseScore.d.ts +4 -3
  22. package/api/lighthouseScore.js +7 -10
  23. package/api/localDevAuth.d.ts +5 -4
  24. package/api/localDevAuth.js +8 -9
  25. package/api/marketplaceValidation.d.ts +4 -3
  26. package/api/marketplaceValidation.js +4 -7
  27. package/api/projects.d.ts +31 -30
  28. package/api/projects.js +52 -52
  29. package/api/sandboxHubs.d.ts +5 -4
  30. package/api/sandboxHubs.js +9 -10
  31. package/api/sandboxSync.d.ts +4 -4
  32. package/api/sandboxSync.js +5 -14
  33. package/api/secrets.d.ts +5 -4
  34. package/api/secrets.js +9 -12
  35. package/api/validateHubl.d.ts +2 -1
  36. package/api/validateHubl.js +3 -6
  37. package/config/CLIConfiguration.d.ts +3 -3
  38. package/config/CLIConfiguration.js +22 -20
  39. package/config/configFile.js +7 -14
  40. package/config/config_DEPRECATED.js +5 -2
  41. package/config/index.js +45 -48
  42. package/errors/errors_DEPRECATED.js +2 -2
  43. package/errors/index.d.ts +18 -0
  44. package/errors/index.js +63 -0
  45. package/http/addQueryParams.d.ts +2 -0
  46. package/http/addQueryParams.js +14 -0
  47. package/http/getAxiosConfig.d.ts +2 -2
  48. package/http/getAxiosConfig.js +10 -2
  49. package/http/index.d.ts +9 -14
  50. package/http/index.js +28 -53
  51. package/http/unauthed.d.ts +15 -0
  52. package/http/unauthed.js +38 -0
  53. package/lang/en.json +1 -2
  54. package/lang/lang/en.json +1 -2
  55. package/lib/archive.js +11 -10
  56. package/lib/cms/functions.js +18 -17
  57. package/lib/cms/handleFieldsJS.js +8 -7
  58. package/lib/cms/modules.js +4 -5
  59. package/lib/cms/processFieldsJs.js +8 -7
  60. package/lib/cms/templates.js +2 -3
  61. package/lib/cms/uploadFolder.js +16 -14
  62. package/lib/cms/validate.js +1 -1
  63. package/lib/cms/watch.js +16 -9
  64. package/lib/customObjects.js +4 -15
  65. package/lib/fileManager.js +22 -21
  66. package/lib/fileMapper.js +24 -31
  67. package/lib/fs.js +2 -2
  68. package/lib/github.js +21 -21
  69. package/lib/gitignore.js +2 -2
  70. package/lib/hubdb.d.ts +3 -2
  71. package/lib/hubdb.js +11 -9
  72. package/lib/notify.js +2 -2
  73. package/lib/oauth.d.ts +1 -1
  74. package/lib/oauth.js +8 -17
  75. package/lib/personalAccessKey.js +16 -21
  76. package/lib/portManager.js +2 -2
  77. package/lib/trackUsage.js +3 -3
  78. package/models/FileSystemError.d.ts +6 -0
  79. package/models/FileSystemError.js +47 -0
  80. package/models/HubSpotHttpError.d.ts +24 -0
  81. package/models/HubSpotHttpError.js +197 -0
  82. package/models/OAuth2Manager.d.ts +1 -2
  83. package/models/OAuth2Manager.js +13 -28
  84. package/package.json +2 -1
  85. package/types/Error.d.ts +7 -5
  86. package/types/Files.d.ts +4 -4
  87. package/types/Http.d.ts +6 -10
  88. package/types/Sandbox.d.ts +0 -5
  89. package/utils/PortManagerServer.d.ts +3 -3
  90. package/utils/PortManagerServer.js +9 -9
  91. package/utils/cms/modules.js +2 -2
  92. package/utils/detectPort.js +3 -3
  93. package/errors/apiErrors.d.ts +0 -25
  94. package/errors/apiErrors.js +0 -176
  95. package/errors/fileSystemErrors.d.ts +0 -6
  96. package/errors/fileSystemErrors.js +0 -35
  97. package/errors/standardErrors.d.ts +0 -20
  98. package/errors/standardErrors.js +0 -62
  99. package/lib/developerTestAccounts.d.ts +0 -4
  100. package/lib/developerTestAccounts.js +0 -35
  101. package/lib/sandboxes.d.ts +0 -14
  102. package/lib/sandboxes.js +0 -70
  103. package/models/HubSpotAuthError.d.ts +0 -12
  104. package/models/HubSpotAuthError.js +0 -20
@@ -1,4 +1,4 @@
1
- import { InitiateSyncResponse, FetchTypesResponse, TaskRequestData, SyncTaskStatusType } from '../types/Sandbox';
2
- export declare function initiateSync(fromHubId: number, toHubId: number, tasks: Array<TaskRequestData>, sandboxHubId: number): Promise<InitiateSyncResponse>;
3
- export declare function fetchTaskStatus(accountId: number, taskId: number): Promise<SyncTaskStatusType>;
4
- export declare function fetchTypes(accountId: number, toHubId: number): Promise<FetchTypesResponse>;
1
+ import { AxiosPromise } from 'axios';
2
+ import { InitiateSyncResponse, FetchTypesResponse, TaskRequestData } from '../types/Sandbox';
3
+ export declare function initiateSync(fromHubId: number, toHubId: number, tasks: Array<TaskRequestData>, sandboxHubId: number): AxiosPromise<InitiateSyncResponse>;
4
+ export declare function fetchTypes(accountId: number, toHubId: number): AxiosPromise<FetchTypesResponse>;
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fetchTypes = exports.fetchTaskStatus = exports.initiateSync = void 0;
7
- const http_1 = __importDefault(require("../http"));
3
+ exports.fetchTypes = exports.initiateSync = void 0;
4
+ const http_1 = require("../http");
8
5
  const api_1 = require("../constants/api");
9
6
  const SANDBOXES_SYNC_API_PATH = 'sandboxes-sync/v1';
10
- async function initiateSync(fromHubId, toHubId, tasks, sandboxHubId) {
11
- return http_1.default.post(fromHubId, {
7
+ function initiateSync(fromHubId, toHubId, tasks, sandboxHubId) {
8
+ return http_1.http.post(fromHubId, {
12
9
  data: {
13
10
  command: 'SYNC',
14
11
  fromHubId,
@@ -21,14 +18,8 @@ async function initiateSync(fromHubId, toHubId, tasks, sandboxHubId) {
21
18
  });
22
19
  }
23
20
  exports.initiateSync = initiateSync;
24
- async function fetchTaskStatus(accountId, taskId) {
25
- return http_1.default.get(accountId, {
26
- url: `${SANDBOXES_SYNC_API_PATH}/tasks/${taskId}/status`,
27
- });
28
- }
29
- exports.fetchTaskStatus = fetchTaskStatus;
30
21
  async function fetchTypes(accountId, toHubId) {
31
- return http_1.default.get(accountId, {
22
+ return http_1.http.get(accountId, {
32
23
  url: `${SANDBOXES_SYNC_API_PATH}/types${toHubId ? `?toHubId=${toHubId}` : ''}`,
33
24
  });
34
25
  }
package/api/secrets.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { AxiosPromise } from 'axios';
1
2
  import { FetchSecretsResponse } from '../types/Secrets';
2
- export declare function addSecret(accountId: number, key: string, value: string): Promise<void>;
3
- export declare function updateSecret(accountId: number, key: string, value: string): Promise<void>;
4
- export declare function deleteSecret(accountId: number, key: string): Promise<void>;
5
- export declare function fetchSecrets(accountId: number): Promise<FetchSecretsResponse>;
3
+ export declare function addSecret(accountId: number, key: string, value: string): AxiosPromise<void>;
4
+ export declare function updateSecret(accountId: number, key: string, value: string): AxiosPromise<void>;
5
+ export declare function deleteSecret(accountId: number, key: string): AxiosPromise<void>;
6
+ export declare function fetchSecrets(accountId: number): AxiosPromise<FetchSecretsResponse>;
package/api/secrets.js CHANGED
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchSecrets = exports.deleteSecret = exports.updateSecret = exports.addSecret = void 0;
7
- const http_1 = __importDefault(require("../http"));
4
+ const http_1 = require("../http");
8
5
  const SECRETS_API_PATH = 'cms/v3/functions/secrets';
9
- async function addSecret(accountId, key, value) {
10
- return http_1.default.post(accountId, {
6
+ function addSecret(accountId, key, value) {
7
+ return http_1.http.post(accountId, {
11
8
  url: SECRETS_API_PATH,
12
9
  data: {
13
10
  key,
@@ -16,8 +13,8 @@ async function addSecret(accountId, key, value) {
16
13
  });
17
14
  }
18
15
  exports.addSecret = addSecret;
19
- async function updateSecret(accountId, key, value) {
20
- return http_1.default.put(accountId, {
16
+ function updateSecret(accountId, key, value) {
17
+ return http_1.http.put(accountId, {
21
18
  url: SECRETS_API_PATH,
22
19
  data: {
23
20
  key,
@@ -26,14 +23,14 @@ async function updateSecret(accountId, key, value) {
26
23
  });
27
24
  }
28
25
  exports.updateSecret = updateSecret;
29
- async function deleteSecret(accountId, key) {
30
- return http_1.default.delete(accountId, {
26
+ function deleteSecret(accountId, key) {
27
+ return http_1.http.delete(accountId, {
31
28
  url: `${SECRETS_API_PATH}/${key}`,
32
29
  });
33
30
  }
34
31
  exports.deleteSecret = deleteSecret;
35
- async function fetchSecrets(accountId) {
36
- return http_1.default.get(accountId, {
32
+ function fetchSecrets(accountId) {
33
+ return http_1.http.get(accountId, {
37
34
  url: `${SECRETS_API_PATH}`,
38
35
  });
39
36
  }
@@ -1,2 +1,3 @@
1
+ import { AxiosPromise } from 'axios';
1
2
  import { Validation, HublValidationOptions } from '../types/HublValidation';
2
- export declare function validateHubl(accountId: number, sourceCode: string, hublValidationOptions?: HublValidationOptions): Promise<Validation>;
3
+ export declare function validateHubl(accountId: number, sourceCode: string, hublValidationOptions?: HublValidationOptions): AxiosPromise<Validation>;
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.validateHubl = void 0;
7
- const http_1 = __importDefault(require("../http"));
4
+ const http_1 = require("../http");
8
5
  const HUBL_VALIDATE_API_PATH = 'cos-rendering/v1/internal/validate';
9
- async function validateHubl(accountId, sourceCode, hublValidationOptions) {
10
- return http_1.default.post(accountId, {
6
+ function validateHubl(accountId, sourceCode, hublValidationOptions) {
7
+ return http_1.http.post(accountId, {
11
8
  url: HUBL_VALIDATE_API_PATH,
12
9
  data: {
13
10
  template_source: sourceCode,
@@ -1,7 +1,7 @@
1
1
  import { CLIConfig_NEW, Environment } from '../types/Config';
2
2
  import { CLIAccount_NEW, FlatAccountFields_NEW, AccountType } from '../types/Accounts';
3
3
  import { CLIOptions } from '../types/CLIOptions';
4
- declare class CLIConfiguration {
4
+ declare class _CLIConfiguration {
5
5
  options: CLIOptions;
6
6
  useEnvConfig: boolean;
7
7
  config: CLIConfig_NEW | null;
@@ -57,5 +57,5 @@ declare class CLIConfiguration {
57
57
  updateAllowUsageTracking(isEnabled: boolean): CLIConfig_NEW | null;
58
58
  isTrackingAllowed(): boolean;
59
59
  }
60
- declare const _default: CLIConfiguration;
61
- export default _default;
60
+ export declare const CLIConfiguration: _CLIConfiguration;
61
+ export {};
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLIConfiguration = void 0;
3
4
  const logger_1 = require("../lib/logger");
4
- const standardErrors_1 = require("../errors/standardErrors");
5
5
  const environment_1 = require("./environment");
6
6
  const environment_2 = require("../lib/environment");
7
7
  const configFile_1 = require("./configFile");
@@ -12,7 +12,7 @@ const config_1 = require("../constants/config");
12
12
  const files_1 = require("../constants/files");
13
13
  const lang_1 = require("../utils/lang");
14
14
  const i18nKey = 'config.cliConfiguration';
15
- class CLIConfiguration {
15
+ class _CLIConfiguration {
16
16
  options;
17
17
  useEnvConfig;
18
18
  config;
@@ -249,7 +249,7 @@ class CLIConfiguration {
249
249
  updateAccount(updatedAccountFields, writeUpdate = true) {
250
250
  const { accountId, accountType, apiKey, authType, clientId, clientSecret, defaultMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
251
251
  if (!accountId) {
252
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAccount.errors.accountIdRequired`);
252
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAccount.errors.accountIdRequired`));
253
253
  }
254
254
  if (!this.config) {
255
255
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.noConfigToUpdate`));
@@ -323,11 +323,11 @@ class CLIConfiguration {
323
323
  */
324
324
  updateDefaultAccount(defaultAccount) {
325
325
  if (!this.config) {
326
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
326
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
327
327
  }
328
328
  if (!defaultAccount ||
329
329
  (typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')) {
330
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`);
330
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`));
331
331
  }
332
332
  this.config.defaultAccount = defaultAccount;
333
333
  return this.write();
@@ -337,7 +337,7 @@ class CLIConfiguration {
337
337
  */
338
338
  renameAccount(currentName, newName) {
339
339
  if (!this.config) {
340
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
340
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
341
341
  }
342
342
  const accountId = this.getAccountId(currentName);
343
343
  let accountConfigToRename = null;
@@ -345,9 +345,9 @@ class CLIConfiguration {
345
345
  accountConfigToRename = this.getAccount(accountId);
346
346
  }
347
347
  if (!accountConfigToRename) {
348
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.renameAccount.errors.invalidName`, {
348
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.renameAccount.errors.invalidName`, {
349
349
  currentName,
350
- });
350
+ }));
351
351
  }
352
352
  if (accountId) {
353
353
  this.updateAccount({ accountId, name: newName, env: this.getEnv() });
@@ -362,11 +362,13 @@ class CLIConfiguration {
362
362
  */
363
363
  removeAccountFromConfig(nameOrId) {
364
364
  if (!this.config) {
365
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
365
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
366
366
  }
367
367
  const accountId = this.getAccountId(nameOrId);
368
368
  if (!accountId) {
369
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, { nameOrId });
369
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, {
370
+ nameOrId,
371
+ }));
370
372
  }
371
373
  let removedAccountIsDefault = false;
372
374
  const accountConfig = this.getAccount(accountId);
@@ -386,14 +388,14 @@ class CLIConfiguration {
386
388
  */
387
389
  updateDefaultMode(defaultMode) {
388
390
  if (!this.config) {
389
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
391
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
390
392
  }
391
393
  const ALL_MODES = Object.values(files_1.MODE);
392
394
  if (!defaultMode || !ALL_MODES.find(m => m === defaultMode)) {
393
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultMode.errors.invalidMode`, {
395
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultMode.errors.invalidMode`, {
394
396
  defaultMode,
395
397
  validModes: (0, text_1.commaSeparatedValues)(ALL_MODES),
396
- });
398
+ }));
397
399
  }
398
400
  this.config.defaultMode = defaultMode;
399
401
  return this.write();
@@ -403,14 +405,14 @@ class CLIConfiguration {
403
405
  */
404
406
  updateHttpTimeout(timeout) {
405
407
  if (!this.config) {
406
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
408
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
407
409
  }
408
410
  const parsedTimeout = parseInt(timeout);
409
411
  if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
410
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
412
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
411
413
  timeout,
412
414
  minTimeout: config_1.MIN_HTTP_TIMEOUT,
413
- });
415
+ }));
414
416
  }
415
417
  this.config.httpTimeout = parsedTimeout;
416
418
  return this.write();
@@ -420,12 +422,12 @@ class CLIConfiguration {
420
422
  */
421
423
  updateAllowUsageTracking(isEnabled) {
422
424
  if (!this.config) {
423
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
425
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
424
426
  }
425
427
  if (typeof isEnabled !== 'boolean') {
426
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
428
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
427
429
  isEnabled: `${isEnabled}`,
428
- });
430
+ }));
429
431
  }
430
432
  this.config.allowUsageTracking = isEnabled;
431
433
  return this.write();
@@ -437,4 +439,4 @@ class CLIConfiguration {
437
439
  return this.config.allowUsageTracking !== false;
438
440
  }
439
441
  }
440
- exports.default = new CLIConfiguration();
442
+ exports.CLIConfiguration = new _CLIConfiguration();
@@ -9,11 +9,10 @@ const path_1 = __importDefault(require("path"));
9
9
  const os_1 = __importDefault(require("os"));
10
10
  const js_yaml_1 = __importDefault(require("js-yaml"));
11
11
  const logger_1 = require("../lib/logger");
12
- const fileSystemErrors_1 = require("../errors/fileSystemErrors");
13
- const standardErrors_1 = require("../errors/standardErrors");
14
12
  const config_1 = require("../constants/config");
15
13
  const configUtils_1 = require("./configUtils");
16
14
  const lang_1 = require("../utils/lang");
15
+ const FileSystemError_1 = require("../models/FileSystemError");
17
16
  const i18nKey = 'config.configFile';
18
17
  function getConfigFilePath() {
19
18
  return path_1.default.join(os_1.default.homedir(), config_1.HUBSPOT_CONFIGURATION_FOLDER, config_1.HUBSPOT_CONFIGURATION_FILE);
@@ -44,9 +43,9 @@ function readConfigFile(configPath) {
44
43
  }
45
44
  catch (err) {
46
45
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorReading`, { configPath }));
47
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
46
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
48
47
  filepath: configPath,
49
- read: true,
48
+ operation: 'read',
50
49
  });
51
50
  }
52
51
  return source;
@@ -61,7 +60,7 @@ function parseConfig(configSource) {
61
60
  parsed = js_yaml_1.default.load(configSource);
62
61
  }
63
62
  catch (err) {
64
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.parsing`, {}, err);
63
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.parsing`), { cause: err });
65
64
  }
66
65
  return parsed;
67
66
  }
@@ -86,13 +85,7 @@ exports.loadConfigFromFile = loadConfigFromFile;
86
85
  * @throws {Error}
87
86
  */
88
87
  function writeConfigToFile(config) {
89
- let source;
90
- try {
91
- source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
92
- }
93
- catch (err) {
94
- (0, standardErrors_1.throwError)(err);
95
- }
88
+ const source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
96
89
  const configPath = getConfigFilePath();
97
90
  try {
98
91
  fs_extra_1.default.ensureFileSync(configPath);
@@ -100,9 +93,9 @@ function writeConfigToFile(config) {
100
93
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.writeSuccess`, { configPath }));
101
94
  }
102
95
  catch (err) {
103
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
96
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
104
97
  filepath: configPath,
105
- write: true,
98
+ operation: 'write',
106
99
  });
107
100
  }
108
101
  }
@@ -175,7 +175,7 @@ function writeConfig(options = {}) {
175
175
  catch (err) {
176
176
  (0, errors_DEPRECATED_1.logFileSystemErrorInstance)(err, {
177
177
  filepath: configPath || '',
178
- write: true,
178
+ operation: 'write',
179
179
  });
180
180
  }
181
181
  }
@@ -193,7 +193,10 @@ function readConfigFile() {
193
193
  catch (err) {
194
194
  error = err;
195
195
  logger_1.logger.error('Config file could not be read "%s"', _configPath);
196
- (0, errors_DEPRECATED_1.logFileSystemErrorInstance)(error, { filepath: _configPath, read: true });
196
+ (0, errors_DEPRECATED_1.logFileSystemErrorInstance)(error, {
197
+ filepath: _configPath,
198
+ operation: 'read',
199
+ });
197
200
  }
198
201
  return { source: source && source.toString(), error };
199
202
  }
package/config/index.js CHANGED
@@ -22,48 +22,45 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.updateDefaultMode = exports.findConfig = exports.setConfigPath = exports.setConfig = exports.getOrderedConfig = exports.getOrderedAccount = exports.getConfigAccountId = exports.getConfigDefaultAccount = exports.getConfigAccounts = exports.getAccountType = exports.getEnv = exports.isTrackingAllowed = exports.isConfigFlagEnabled = exports.deleteConfigFile = exports.updateAllowUsageTracking = exports.updateHttpTimeout = exports.deleteAccount = exports.removeSandboxAccountFromConfig = exports.getAccountId = exports.renameAccount = exports.updateDefaultAccount = exports.updateAccountConfig = exports.accountNameExistsInConfig = exports.getAccountConfig = exports.getConfigPath = exports.writeConfig = exports.getConfig = exports.deleteEmptyConfigFile = exports.createEmptyConfigFile = exports.loadConfigFromEnvironment = exports.validateConfig = exports.getAndLoadConfigIfNeeded = exports.loadConfig = void 0;
30
27
  const config_DEPRECATED = __importStar(require("./config_DEPRECATED"));
31
- const CLIConfiguration_1 = __importDefault(require("./CLIConfiguration"));
28
+ const CLIConfiguration_1 = require("./CLIConfiguration");
32
29
  const configFile_1 = require("./configFile");
33
30
  const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
34
31
  // Use new config if it exists
35
32
  function loadConfig(path, options = {}) {
36
33
  // Attempt to load the root config
37
34
  if ((0, configFile_1.configFileExists)()) {
38
- return CLIConfiguration_1.default.init(options);
35
+ return CLIConfiguration_1.CLIConfiguration.init(options);
39
36
  }
40
37
  return config_DEPRECATED.loadConfig(path, options);
41
38
  }
42
39
  exports.loadConfig = loadConfig;
43
40
  function getAndLoadConfigIfNeeded(options) {
44
- if (CLIConfiguration_1.default.isActive()) {
45
- return CLIConfiguration_1.default.config;
41
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
42
+ return CLIConfiguration_1.CLIConfiguration.config;
46
43
  }
47
44
  return config_DEPRECATED.getAndLoadConfigIfNeeded(options);
48
45
  }
49
46
  exports.getAndLoadConfigIfNeeded = getAndLoadConfigIfNeeded;
50
47
  function validateConfig() {
51
- if (CLIConfiguration_1.default.isActive()) {
52
- return CLIConfiguration_1.default.validate();
48
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
49
+ return CLIConfiguration_1.CLIConfiguration.validate();
53
50
  }
54
51
  return config_DEPRECATED.validateConfig();
55
52
  }
56
53
  exports.validateConfig = validateConfig;
57
54
  function loadConfigFromEnvironment() {
58
- if (CLIConfiguration_1.default.isActive()) {
59
- return CLIConfiguration_1.default.useEnvConfig;
55
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
56
+ return CLIConfiguration_1.CLIConfiguration.useEnvConfig;
60
57
  }
61
58
  return Boolean(config_DEPRECATED.loadConfigFromEnvironment());
62
59
  }
63
60
  exports.loadConfigFromEnvironment = loadConfigFromEnvironment;
64
61
  function createEmptyConfigFile(options = {}, useRootConfig = false) {
65
62
  if (useRootConfig) {
66
- CLIConfiguration_1.default.write({ accounts: [] });
63
+ CLIConfiguration_1.CLIConfiguration.write({ accounts: [] });
67
64
  }
68
65
  else {
69
66
  return config_DEPRECATED.createEmptyConfigFile(options);
@@ -71,25 +68,25 @@ function createEmptyConfigFile(options = {}, useRootConfig = false) {
71
68
  }
72
69
  exports.createEmptyConfigFile = createEmptyConfigFile;
73
70
  function deleteEmptyConfigFile() {
74
- if (CLIConfiguration_1.default.isActive()) {
75
- return CLIConfiguration_1.default.delete();
71
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
72
+ return CLIConfiguration_1.CLIConfiguration.delete();
76
73
  }
77
74
  return config_DEPRECATED.deleteEmptyConfigFile();
78
75
  }
79
76
  exports.deleteEmptyConfigFile = deleteEmptyConfigFile;
80
77
  function getConfig() {
81
- if (CLIConfiguration_1.default.isActive()) {
82
- return CLIConfiguration_1.default.config;
78
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
79
+ return CLIConfiguration_1.CLIConfiguration.config;
83
80
  }
84
81
  return config_DEPRECATED.getConfig();
85
82
  }
86
83
  exports.getConfig = getConfig;
87
84
  function writeConfig(options = {}) {
88
- if (CLIConfiguration_1.default.isActive()) {
85
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
89
86
  const config = options.source
90
87
  ? JSON.parse(options.source)
91
88
  : undefined;
92
- CLIConfiguration_1.default.write(config);
89
+ CLIConfiguration_1.CLIConfiguration.write(config);
93
90
  }
94
91
  else {
95
92
  config_DEPRECATED.writeConfig(options);
@@ -97,30 +94,30 @@ function writeConfig(options = {}) {
97
94
  }
98
95
  exports.writeConfig = writeConfig;
99
96
  function getConfigPath(path) {
100
- if (CLIConfiguration_1.default.isActive()) {
97
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
101
98
  return (0, configFile_1.getConfigFilePath)();
102
99
  }
103
100
  return config_DEPRECATED.getConfigPath(path);
104
101
  }
105
102
  exports.getConfigPath = getConfigPath;
106
103
  function getAccountConfig(accountId) {
107
- if (CLIConfiguration_1.default.isActive()) {
108
- return CLIConfiguration_1.default.getConfigForAccount(accountId);
104
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
105
+ return CLIConfiguration_1.CLIConfiguration.getConfigForAccount(accountId);
109
106
  }
110
107
  return config_DEPRECATED.getAccountConfig(accountId) || null;
111
108
  }
112
109
  exports.getAccountConfig = getAccountConfig;
113
110
  function accountNameExistsInConfig(name) {
114
- if (CLIConfiguration_1.default.isActive()) {
115
- return CLIConfiguration_1.default.isAccountInConfig(name);
111
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
112
+ return CLIConfiguration_1.CLIConfiguration.isAccountInConfig(name);
116
113
  }
117
114
  return config_DEPRECATED.accountNameExistsInConfig(name);
118
115
  }
119
116
  exports.accountNameExistsInConfig = accountNameExistsInConfig;
120
117
  function updateAccountConfig(configOptions) {
121
118
  const accountIdentifier = (0, getAccountIdentifier_1.getAccountIdentifier)(configOptions);
122
- if (CLIConfiguration_1.default.isActive()) {
123
- return CLIConfiguration_1.default.updateAccount({
119
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
120
+ return CLIConfiguration_1.CLIConfiguration.updateAccount({
124
121
  ...configOptions,
125
122
  accountId: accountIdentifier,
126
123
  });
@@ -132,8 +129,8 @@ function updateAccountConfig(configOptions) {
132
129
  }
133
130
  exports.updateAccountConfig = updateAccountConfig;
134
131
  function updateDefaultAccount(nameOrId) {
135
- if (CLIConfiguration_1.default.isActive()) {
136
- CLIConfiguration_1.default.updateDefaultAccount(nameOrId);
132
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
133
+ CLIConfiguration_1.CLIConfiguration.updateDefaultAccount(nameOrId);
137
134
  }
138
135
  else {
139
136
  config_DEPRECATED.updateDefaultAccount(nameOrId);
@@ -141,8 +138,8 @@ function updateDefaultAccount(nameOrId) {
141
138
  }
142
139
  exports.updateDefaultAccount = updateDefaultAccount;
143
140
  async function renameAccount(currentName, newName) {
144
- if (CLIConfiguration_1.default.isActive()) {
145
- CLIConfiguration_1.default.renameAccount(currentName, newName);
141
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
142
+ CLIConfiguration_1.CLIConfiguration.renameAccount(currentName, newName);
146
143
  }
147
144
  else {
148
145
  config_DEPRECATED.renameAccount(currentName, newName);
@@ -150,22 +147,22 @@ async function renameAccount(currentName, newName) {
150
147
  }
151
148
  exports.renameAccount = renameAccount;
152
149
  function getAccountId(nameOrId) {
153
- if (CLIConfiguration_1.default.isActive()) {
154
- return CLIConfiguration_1.default.getAccountId(nameOrId);
150
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
151
+ return CLIConfiguration_1.CLIConfiguration.getAccountId(nameOrId);
155
152
  }
156
153
  return config_DEPRECATED.getAccountId(nameOrId) || null;
157
154
  }
158
155
  exports.getAccountId = getAccountId;
159
156
  function removeSandboxAccountFromConfig(nameOrId) {
160
- if (CLIConfiguration_1.default.isActive()) {
161
- return CLIConfiguration_1.default.removeAccountFromConfig(nameOrId);
157
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
158
+ return CLIConfiguration_1.CLIConfiguration.removeAccountFromConfig(nameOrId);
162
159
  }
163
160
  return config_DEPRECATED.removeSandboxAccountFromConfig(nameOrId);
164
161
  }
165
162
  exports.removeSandboxAccountFromConfig = removeSandboxAccountFromConfig;
166
163
  async function deleteAccount(accountName) {
167
- if (CLIConfiguration_1.default.isActive()) {
168
- CLIConfiguration_1.default.removeAccountFromConfig(accountName);
164
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
165
+ CLIConfiguration_1.CLIConfiguration.removeAccountFromConfig(accountName);
169
166
  }
170
167
  else {
171
168
  config_DEPRECATED.deleteAccount(accountName);
@@ -173,8 +170,8 @@ async function deleteAccount(accountName) {
173
170
  }
174
171
  exports.deleteAccount = deleteAccount;
175
172
  function updateHttpTimeout(timeout) {
176
- if (CLIConfiguration_1.default.isActive()) {
177
- CLIConfiguration_1.default.updateHttpTimeout(timeout);
173
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
174
+ CLIConfiguration_1.CLIConfiguration.updateHttpTimeout(timeout);
178
175
  }
179
176
  else {
180
177
  config_DEPRECATED.updateHttpTimeout(timeout);
@@ -182,8 +179,8 @@ function updateHttpTimeout(timeout) {
182
179
  }
183
180
  exports.updateHttpTimeout = updateHttpTimeout;
184
181
  function updateAllowUsageTracking(isEnabled) {
185
- if (CLIConfiguration_1.default.isActive()) {
186
- CLIConfiguration_1.default.updateAllowUsageTracking(isEnabled);
182
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
183
+ CLIConfiguration_1.CLIConfiguration.updateAllowUsageTracking(isEnabled);
187
184
  }
188
185
  else {
189
186
  config_DEPRECATED.updateAllowUsageTracking(isEnabled);
@@ -191,7 +188,7 @@ function updateAllowUsageTracking(isEnabled) {
191
188
  }
192
189
  exports.updateAllowUsageTracking = updateAllowUsageTracking;
193
190
  function deleteConfigFile() {
194
- if (CLIConfiguration_1.default.isActive()) {
191
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
195
192
  (0, configFile_1.deleteConfigFile)();
196
193
  }
197
194
  else {
@@ -200,29 +197,29 @@ function deleteConfigFile() {
200
197
  }
201
198
  exports.deleteConfigFile = deleteConfigFile;
202
199
  function isConfigFlagEnabled(flag) {
203
- if (CLIConfiguration_1.default.isActive()) {
204
- return CLIConfiguration_1.default.isConfigFlagEnabled(flag);
200
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
201
+ return CLIConfiguration_1.CLIConfiguration.isConfigFlagEnabled(flag);
205
202
  }
206
203
  return config_DEPRECATED.isConfigFlagEnabled(flag);
207
204
  }
208
205
  exports.isConfigFlagEnabled = isConfigFlagEnabled;
209
206
  function isTrackingAllowed() {
210
- if (CLIConfiguration_1.default.isActive()) {
211
- return CLIConfiguration_1.default.isTrackingAllowed();
207
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
208
+ return CLIConfiguration_1.CLIConfiguration.isTrackingAllowed();
212
209
  }
213
210
  return config_DEPRECATED.isTrackingAllowed();
214
211
  }
215
212
  exports.isTrackingAllowed = isTrackingAllowed;
216
213
  function getEnv(nameOrId) {
217
- if (CLIConfiguration_1.default.isActive()) {
218
- return CLIConfiguration_1.default.getEnv(nameOrId);
214
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
215
+ return CLIConfiguration_1.CLIConfiguration.getEnv(nameOrId);
219
216
  }
220
217
  return config_DEPRECATED.getEnv(nameOrId);
221
218
  }
222
219
  exports.getEnv = getEnv;
223
220
  function getAccountType(accountType, sandboxAccountType) {
224
- if (CLIConfiguration_1.default.isActive()) {
225
- return CLIConfiguration_1.default.getAccountType(accountType, sandboxAccountType);
221
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
222
+ return CLIConfiguration_1.CLIConfiguration.getAccountType(accountType, sandboxAccountType);
226
223
  }
227
224
  return config_DEPRECATED.getAccountType(accountType, sandboxAccountType);
228
225
  }
@@ -37,10 +37,10 @@ function logErrorInstance(error, context) {
37
37
  exports.logErrorInstance = logErrorInstance;
38
38
  function logFileSystemErrorInstance(error, context) {
39
39
  let fileAction = '';
40
- if (context.read) {
40
+ if (context.operation === 'read') {
41
41
  fileAction = 'reading from';
42
42
  }
43
- else if (context.write) {
43
+ else if (context.operation === 'write') {
44
44
  fileAction = 'writing to';
45
45
  }
46
46
  else {
@@ -0,0 +1,18 @@
1
+ import { HubSpotHttpError } from '../models/HubSpotHttpError';
2
+ import { BaseError } from '../types/Error';
3
+ import { FileSystemError } from '../models/FileSystemError';
4
+ export declare function isSpecifiedError(err: unknown, { statusCode, category, subCategory, errorType, code, }: {
5
+ statusCode?: number;
6
+ category?: string;
7
+ subCategory?: string;
8
+ errorType?: string;
9
+ code?: string;
10
+ }): err is HubSpotHttpError;
11
+ export declare function isMissingScopeError(err: unknown): err is HubSpotHttpError;
12
+ export declare function isGatingError(err: unknown): err is HubSpotHttpError;
13
+ export declare function isTimeoutError(err: unknown): err is HubSpotHttpError;
14
+ export declare function isAuthError(err: unknown): err is HubSpotHttpError;
15
+ export declare function isValidationError(err: unknown): boolean;
16
+ export declare function isHubSpotHttpError(error?: unknown): error is HubSpotHttpError;
17
+ export declare function isSystemError(err: unknown): err is BaseError;
18
+ export declare function isFileSystemError(err: unknown): err is FileSystemError;