@hubspot/local-dev-lib 1.13.1 → 2.0.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.
Files changed (105) 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 +29 -13
  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.d.ts +7 -1
  57. package/lib/cms/functions.js +22 -18
  58. package/lib/cms/handleFieldsJS.js +8 -7
  59. package/lib/cms/modules.js +4 -5
  60. package/lib/cms/processFieldsJs.js +8 -7
  61. package/lib/cms/templates.js +2 -3
  62. package/lib/cms/uploadFolder.js +16 -14
  63. package/lib/cms/validate.js +1 -1
  64. package/lib/cms/watch.js +16 -9
  65. package/lib/customObjects.js +4 -15
  66. package/lib/fileManager.js +22 -21
  67. package/lib/fileMapper.js +24 -31
  68. package/lib/fs.js +2 -2
  69. package/lib/github.js +21 -21
  70. package/lib/gitignore.js +2 -2
  71. package/lib/hubdb.d.ts +3 -2
  72. package/lib/hubdb.js +11 -9
  73. package/lib/notify.js +2 -2
  74. package/lib/oauth.d.ts +1 -1
  75. package/lib/oauth.js +8 -17
  76. package/lib/personalAccessKey.js +16 -21
  77. package/lib/portManager.js +2 -2
  78. package/lib/trackUsage.js +3 -3
  79. package/models/FileSystemError.d.ts +6 -0
  80. package/models/FileSystemError.js +47 -0
  81. package/models/HubSpotHttpError.d.ts +24 -0
  82. package/models/HubSpotHttpError.js +197 -0
  83. package/models/OAuth2Manager.d.ts +1 -2
  84. package/models/OAuth2Manager.js +13 -28
  85. package/package.json +2 -1
  86. package/types/Error.d.ts +7 -5
  87. package/types/Files.d.ts +4 -4
  88. package/types/Http.d.ts +6 -10
  89. package/types/Sandbox.d.ts +0 -5
  90. package/utils/PortManagerServer.d.ts +3 -3
  91. package/utils/PortManagerServer.js +9 -9
  92. package/utils/cms/modules.js +2 -2
  93. package/utils/detectPort.js +3 -3
  94. package/errors/apiErrors.d.ts +0 -25
  95. package/errors/apiErrors.js +0 -176
  96. package/errors/fileSystemErrors.d.ts +0 -6
  97. package/errors/fileSystemErrors.js +0 -35
  98. package/errors/standardErrors.d.ts +0 -20
  99. package/errors/standardErrors.js +0 -62
  100. package/lib/developerTestAccounts.d.ts +0 -4
  101. package/lib/developerTestAccounts.js +0 -35
  102. package/lib/sandboxes.d.ts +0 -14
  103. package/lib/sandboxes.js +0 -70
  104. package/models/HubSpotAuthError.d.ts +0 -12
  105. package/models/HubSpotAuthError.js +0 -20
package/lib/fileMapper.js CHANGED
@@ -11,12 +11,11 @@ const p_queue_1 = __importDefault(require("p-queue"));
11
11
  const path_2 = require("./path");
12
12
  const logger_1 = require("./logger");
13
13
  const fileMapper_1 = require("../api/fileMapper");
14
- const standardErrors_1 = require("../errors/standardErrors");
15
14
  const extensions_1 = require("../constants/extensions");
16
15
  const files_1 = require("../constants/files");
17
- const fileSystemErrors_1 = require("../errors/fileSystemErrors");
18
- const apiErrors_1 = require("../errors/apiErrors");
16
+ const errors_1 = require("../errors");
19
17
  const lang_1 = require("../utils/lang");
18
+ const FileSystemError_1 = require("../models/FileSystemError");
20
19
  const i18nKey = 'lib.fileMapper';
21
20
  const queue = new p_queue_1.default({
22
21
  concurrency: 10,
@@ -77,9 +76,9 @@ function validateFileMapperNode(node) {
77
76
  catch (err) {
78
77
  json = node;
79
78
  }
80
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidNode`, {
79
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidNode`, {
81
80
  json: JSON.stringify(json),
82
- });
81
+ }));
83
82
  }
84
83
  function getTypeDataFromPath(src) {
85
84
  const isModule = isPathToModule(src);
@@ -125,10 +124,10 @@ async function writeUtimes(accountId, filepath, node) {
125
124
  await fs_extra_1.default.utimes(filepath, atime, mtime);
126
125
  }
127
126
  catch (err) {
128
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
127
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
129
128
  filepath,
130
129
  accountId,
131
- write: true,
130
+ operation: 'write',
132
131
  });
133
132
  }
134
133
  }
@@ -151,15 +150,9 @@ async function fetchAndWriteFileStream(accountId, srcPath, filepath, mode, optio
151
150
  return;
152
151
  }
153
152
  if (!(0, path_2.isAllowedExtension)(srcPath, Array.from(extensions_1.JSR_ALLOWED_EXTENSIONS))) {
154
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidFileType`, { srcPath });
155
- }
156
- let node;
157
- try {
158
- node = await (0, fileMapper_1.fetchFileStream)(accountId, srcPath, filepath, getFileMapperQueryValues(mode, options));
159
- }
160
- catch (err) {
161
- (0, standardErrors_1.throwError)(err);
153
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidFileType`, { srcPath }));
162
154
  }
155
+ const node = await (0, fileMapper_1.fetchFileStream)(accountId, srcPath, filepath, getFileMapperQueryValues(mode, options));
163
156
  await writeUtimes(accountId, filepath, node);
164
157
  }
165
158
  // Writes an individual file or folder (not recursive). If file source is missing, the
@@ -188,21 +181,20 @@ async function writeFileMapperNode(accountId, filepath, node, mode, options = {}
188
181
  }));
189
182
  }
190
183
  catch (err) {
191
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
184
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
192
185
  filepath: localFilepath,
193
186
  accountId,
194
- write: true,
187
+ operation: 'write',
195
188
  });
196
- return false;
197
189
  }
198
190
  return true;
199
191
  }
200
192
  async function downloadFile(accountId, src, destPath, mode, options = {}) {
201
193
  const { isFile, isHubspot } = getTypeDataFromPath(src);
194
+ if (!isFile) {
195
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidRequest`, { src }));
196
+ }
202
197
  try {
203
- if (!isFile) {
204
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidRequest`, { src });
205
- }
206
198
  const dest = path_1.default.resolve(destPath);
207
199
  const cwd = (0, path_2.getCwd)();
208
200
  let filepath;
@@ -232,24 +224,24 @@ async function downloadFile(accountId, src, destPath, mode, options = {}) {
232
224
  }
233
225
  catch (err) {
234
226
  const error = err;
235
- if (isHubspot && (0, apiErrors_1.isTimeoutError)(error)) {
236
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.assetTimeout`, {}, error);
227
+ if (isHubspot && (0, errors_1.isTimeoutError)(error)) {
228
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.assetTimeout`), { cause: error });
237
229
  }
238
230
  else {
239
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.failedToFetchFile`, { src, dest: destPath }, error);
231
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.failedToFetchFile`, { src, dest: destPath }), { cause: error });
240
232
  }
241
233
  }
242
234
  }
243
235
  async function fetchFolderFromApi(accountId, src, mode, options = {}) {
244
236
  const { isRoot, isFolder, isHubspot } = getTypeDataFromPath(src);
245
237
  if (!isFolder) {
246
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidFetchFolderRequest`, {
238
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidFetchFolderRequest`, {
247
239
  src,
248
- });
240
+ }));
249
241
  }
250
242
  const srcPath = isRoot ? '@root' : src;
251
243
  const queryValues = getFileMapperQueryValues(mode, options);
252
- const node = isHubspot
244
+ const { data: node } = isHubspot
253
245
  ? await (0, fileMapper_1.downloadDefault)(accountId, srcPath, queryValues)
254
246
  : await (0, fileMapper_1.download)(accountId, srcPath, queryValues);
255
247
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.folderFetch`, { src, accountId }));
@@ -289,16 +281,17 @@ async function downloadFolder(accountId, src, destPath, mode, options = {}) {
289
281
  }));
290
282
  }
291
283
  else {
292
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.incompleteFetch`, { src });
284
+ // TODO: Fix this exception. It is triggering the catch block so this error is being rewritten
285
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.incompleteFetch`, { src }));
293
286
  }
294
287
  }
295
288
  catch (err) {
296
289
  const error = err;
297
- if ((0, apiErrors_1.isTimeoutError)(error)) {
298
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.assetTimeout`, {}, error);
290
+ if ((0, errors_1.isTimeoutError)(error)) {
291
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.assetTimeout`), { cause: error });
299
292
  }
300
293
  else {
301
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.failedToFetchFolder`, { src, dest: destPath }, err);
294
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.failedToFetchFolder`, { src, dest: destPath }), { cause: err });
302
295
  }
303
296
  }
304
297
  }
package/lib/fs.js CHANGED
@@ -7,7 +7,7 @@ exports.walk = exports.flattenAndRemoveSymlinks = exports.getFileInfoAsync = voi
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const files_1 = require("../constants/files");
10
- const standardErrors_1 = require("../errors/standardErrors");
10
+ const FileSystemError_1 = require("../models/FileSystemError");
11
11
  function getFileInfoAsync(dir, file) {
12
12
  return new Promise((resolve, reject) => {
13
13
  const filepath = path_1.default.join(dir, file);
@@ -65,7 +65,7 @@ async function walk(dir) {
65
65
  .then(processFiles)
66
66
  .then(flattenAndRemoveSymlinks)
67
67
  .catch(err => {
68
- (0, standardErrors_1.throwError)(err);
68
+ throw new FileSystemError_1.FileSystemError({ cause: err });
69
69
  });
70
70
  }
71
71
  exports.walk = walk;
package/lib/github.js CHANGED
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.listGithubRepoContents = exports.downloadGithubRepoContents = exports.fetchGitHubRepoContentFromDownloadUrl = exports.cloneGithubRepo = exports.fetchReleaseData = exports.fetchFileFromRepository = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const standardErrors_1 = require("../errors/standardErrors");
10
9
  const archive_1 = require("./archive");
11
10
  const logger_1 = require("./logger");
12
11
  const github_1 = require("../api/github");
13
12
  const lang_1 = require("../utils/lang");
13
+ const errors_1 = require("../errors");
14
14
  const i18nKey = 'lib.github';
15
15
  async function fetchFileFromRepository(repoPath, filePath, ref) {
16
16
  try {
@@ -21,7 +21,9 @@ async function fetchFileFromRepository(repoPath, filePath, ref) {
21
21
  return data;
22
22
  }
23
23
  catch (err) {
24
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.fetchFileFromRepository.errors.fetchFail`, {}, err);
24
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.fetchFileFromRepository.errors.fetchFail`), {
25
+ cause: err,
26
+ });
25
27
  }
26
28
  }
27
29
  exports.fetchFileFromRepository = fetchFileFromRepository;
@@ -38,7 +40,9 @@ async function fetchReleaseData(repoPath, tag) {
38
40
  return data;
39
41
  }
40
42
  catch (err) {
41
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.fetchReleaseData.errors.fetchFail`, { tag: tag || 'latest' }, err);
43
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.fetchReleaseData.errors.fetchFail`, {
44
+ tag: tag || 'latest',
45
+ }), { cause: err });
42
46
  }
43
47
  }
44
48
  exports.fetchReleaseData = fetchReleaseData;
@@ -65,7 +69,9 @@ async function downloadGithubRepoZip(repoPath, isRelease = false, options = {})
65
69
  return data;
66
70
  }
67
71
  catch (err) {
68
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.downloadGithubRepoZip.errors.fetchFail`, {}, err);
72
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoZip.errors.fetchFail`), {
73
+ cause: err,
74
+ });
69
75
  }
70
76
  }
71
77
  async function cloneGithubRepo(repoPath, dest, options = {}) {
@@ -95,7 +101,7 @@ async function fetchGitHubRepoContentFromDownloadUrl(dest, downloadUrl) {
95
101
  else {
96
102
  fileContents = resp.data;
97
103
  }
98
- await fs_extra_1.default.outputFileSync(dest, fileContents);
104
+ fs_extra_1.default.outputFileSync(dest, fileContents);
99
105
  }
100
106
  exports.fetchGitHubRepoContentFromDownloadUrl = fetchGitHubRepoContentFromDownloadUrl;
101
107
  // Writes files from a public repository to the destination folder
@@ -131,15 +137,12 @@ async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filt
131
137
  await Promise.all(contentPromises);
132
138
  }
133
139
  catch (e) {
134
- const error = e;
135
- if (error?.error?.message) {
136
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
137
- errorMessage: error.error.message,
138
- }, error);
139
- }
140
- else {
141
- (0, standardErrors_1.throwError)(error);
140
+ if ((0, errors_1.isSystemError)(e) && e?.error?.message) {
141
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
142
+ errorMessage: e.error.message,
143
+ }), { cause: e });
142
144
  }
145
+ throw e;
143
146
  }
144
147
  }
145
148
  exports.downloadGithubRepoContents = downloadGithubRepoContents;
@@ -153,15 +156,12 @@ async function listGithubRepoContents(repoPath, contentPath, fileFilter) {
153
156
  return filteredFiles;
154
157
  }
155
158
  catch (e) {
156
- const error = e;
157
- if (error?.response?.data?.message) {
158
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
159
- errorMessage: error.response.data.message,
160
- });
161
- }
162
- else {
163
- (0, standardErrors_1.throwError)(error);
159
+ if ((0, errors_1.isHubSpotHttpError)(e) && e.data.message) {
160
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
161
+ errorMessage: e.data.message,
162
+ }));
164
163
  }
164
+ throw e;
165
165
  }
166
166
  }
167
167
  exports.listGithubRepoContents = listGithubRepoContents;
package/lib/gitignore.js CHANGED
@@ -8,7 +8,7 @@ const fs_extra_1 = require("fs-extra");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const git_1 = require("../utils/git");
10
10
  const config_1 = require("../constants/config");
11
- const standardErrors_1 = require("../errors/standardErrors");
11
+ const lang_1 = require("../utils/lang");
12
12
  const i18nKey = 'lib.gitignore';
13
13
  const GITIGNORE_FILE = '.gitignore';
14
14
  function checkAndAddConfigToGitignore(configPath) {
@@ -26,7 +26,7 @@ function checkAndAddConfigToGitignore(configPath) {
26
26
  (0, fs_extra_1.writeFileSync)(gitignoreFilePath, updatedContents);
27
27
  }
28
28
  catch (e) {
29
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.configIgnore`, {}, e);
29
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.configIgnore`), { cause: e });
30
30
  }
31
31
  }
32
32
  exports.checkAndAddConfigToGitignore = checkAndAddConfigToGitignore;
package/lib/hubdb.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Row } from '../types/Hubdb';
1
+ import { AxiosResponse } from 'axios';
2
+ import { Row, Table } from '../types/Hubdb';
2
3
  export declare function addRowsToHubDbTable(accountId: number, tableId: string, rows?: Array<Row>): Promise<{
3
4
  tableId: string;
4
5
  rowCount: number;
@@ -7,7 +8,7 @@ export declare function createHubDbTable(accountId: number, src: string): Promis
7
8
  tableId: string;
8
9
  rowCount: number;
9
10
  }>;
10
- export declare function updateHubDbTable(accountId: number, tableId: string, src: string): Promise<unknown>;
11
+ export declare function updateHubDbTable(accountId: number, tableId: string, src: string): Promise<AxiosResponse<Table, any>>;
11
12
  export declare function downloadHubDbTable(accountId: number, tableId: string, dest: string): Promise<{
12
13
  filePath: string;
13
14
  }>;
package/lib/hubdb.js CHANGED
@@ -9,11 +9,11 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const prettier_1 = __importDefault(require("prettier"));
10
10
  const hubdb_1 = require("../api/hubdb");
11
11
  const path_2 = require("./path");
12
- const standardErrors_1 = require("../errors/standardErrors");
12
+ const lang_1 = require("../utils/lang");
13
13
  const i18nKey = 'lib.hubdb';
14
14
  function validateJsonPath(src) {
15
15
  if (path_1.default.extname(src) !== '.json') {
16
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidJsonPath`);
16
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidJsonPath`));
17
17
  }
18
18
  }
19
19
  function validateJsonFile(src) {
@@ -22,10 +22,12 @@ function validateJsonFile(src) {
22
22
  stats = fs_extra_1.default.statSync(src);
23
23
  }
24
24
  catch (err) {
25
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidJsonFile`, { src }, err);
25
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidJsonFile`, { src }), {
26
+ cause: err,
27
+ });
26
28
  }
27
29
  if (!stats.isFile()) {
28
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidJsonFile`, { src });
30
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidJsonFile`, { src }));
29
31
  }
30
32
  validateJsonPath(src);
31
33
  }
@@ -42,7 +44,7 @@ async function addRowsToHubDbTable(accountId, tableId, rows = []) {
42
44
  if (rowsToUpdate.length > 0) {
43
45
  await (0, hubdb_1.createRows)(accountId, tableId, rowsToUpdate);
44
46
  }
45
- const { rowCount } = await (0, hubdb_1.publishTable)(accountId, tableId);
47
+ const { data: { rowCount }, } = await (0, hubdb_1.publishTable)(accountId, tableId);
46
48
  return {
47
49
  tableId,
48
50
  rowCount,
@@ -53,7 +55,7 @@ async function createHubDbTable(accountId, src) {
53
55
  validateJsonFile(src);
54
56
  const table = fs_extra_1.default.readJsonSync(src);
55
57
  const { rows, ...schema } = table;
56
- const { id } = await (0, hubdb_1.createTable)(accountId, schema);
58
+ const { data: { id }, } = await (0, hubdb_1.createTable)(accountId, schema);
57
59
  return addRowsToHubDbTable(accountId, id, rows);
58
60
  }
59
61
  exports.createHubDbTable = createHubDbTable;
@@ -96,15 +98,15 @@ async function fetchAllRows(accountId, tableId) {
96
98
  let rows = [];
97
99
  let after = null;
98
100
  do {
99
- const response = await (0, hubdb_1.fetchRows)(accountId, tableId, after ? { after } : undefined);
100
- const { paging, results } = response;
101
+ const axiosResponse = await (0, hubdb_1.fetchRows)(accountId, tableId, after ? { after } : undefined);
102
+ const { paging, results } = axiosResponse.data;
101
103
  rows = rows.concat(results);
102
104
  after = paging && paging.next ? paging.next.after : null;
103
105
  } while (after !== null);
104
106
  return rows;
105
107
  }
106
108
  async function downloadHubDbTable(accountId, tableId, dest) {
107
- const table = await (0, hubdb_1.fetchTable)(accountId, tableId);
109
+ const { data: table } = await (0, hubdb_1.fetchTable)(accountId, tableId);
108
110
  dest = path_1.default.resolve((0, path_2.getCwd)(), dest || `${table.name}.hubdb.json`);
109
111
  if (fs_extra_1.default.pathExistsSync(dest)) {
110
112
  validateJsonFile(dest);
package/lib/notify.js CHANGED
@@ -7,7 +7,7 @@ exports.triggerNotify = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const moment_1 = __importDefault(require("moment"));
9
9
  const debounce_1 = __importDefault(require("debounce"));
10
- const standardErrors_1 = require("../errors/standardErrors");
10
+ const lang_1 = require("../utils/lang");
11
11
  const i18nKey = 'utils.notify';
12
12
  const notifyQueue = [];
13
13
  const notifyPromises = [];
@@ -37,7 +37,7 @@ function notifyFilePath(filePathToNotify, outputToWrite) {
37
37
  fs_1.default.appendFileSync(filePathToNotify, outputToWrite);
38
38
  }
39
39
  catch (e) {
40
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.filePath`, { filePath: filePathToNotify }, e);
40
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.filePath`, { filePath: filePathToNotify }), { cause: e });
41
41
  }
42
42
  }
43
43
  }
package/lib/oauth.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import OAuth2Manager from '../models/OAuth2Manager';
1
+ import { OAuth2Manager } from '../models/OAuth2Manager';
2
2
  import { FlatAccountFields } from '../types/Accounts';
3
3
  export declare function getOauthManager(accountId: number, accountConfig: FlatAccountFields): OAuth2Manager | undefined;
4
4
  export declare function addOauthToAccountConfig(oauth: OAuth2Manager): void;
package/lib/oauth.js CHANGED
@@ -1,12 +1,8 @@
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.addOauthToAccountConfig = exports.getOauthManager = void 0;
7
- const OAuth2Manager_1 = __importDefault(require("../models/OAuth2Manager"));
4
+ const OAuth2Manager_1 = require("../models/OAuth2Manager");
8
5
  const auth_1 = require("../constants/auth");
9
- const standardErrors_1 = require("../errors/standardErrors");
10
6
  const logger_1 = require("./logger");
11
7
  const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
12
8
  const config_1 = require("../config");
@@ -21,23 +17,18 @@ function writeOauthTokenInfo(accountConfig) {
21
17
  }
22
18
  function getOauthManager(accountId, accountConfig) {
23
19
  if (!oauthManagers.has(accountId)) {
24
- oauthManagers.set(accountId, OAuth2Manager_1.default.fromConfig(accountConfig, () => writeOauthTokenInfo(accountConfig)));
20
+ oauthManagers.set(accountId, OAuth2Manager_1.OAuth2Manager.fromConfig(accountConfig, () => writeOauthTokenInfo(accountConfig)));
25
21
  }
26
22
  return oauthManagers.get(accountId);
27
23
  }
28
24
  exports.getOauthManager = getOauthManager;
29
25
  function addOauthToAccountConfig(oauth) {
30
26
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.addOauthToAccountConfig.init`));
31
- try {
32
- (0, config_1.updateAccountConfig)({
33
- ...oauth.account,
34
- authType: auth_1.AUTH_METHODS.oauth.value,
35
- });
36
- (0, config_1.writeConfig)();
37
- logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.addOauthToAccountConfig.success`));
38
- }
39
- catch (err) {
40
- (0, standardErrors_1.throwError)(err);
41
- }
27
+ (0, config_1.updateAccountConfig)({
28
+ ...oauth.account,
29
+ authType: auth_1.AUTH_METHODS.oauth.value,
30
+ });
31
+ (0, config_1.writeConfig)();
32
+ logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.addOauthToAccountConfig.success`));
42
33
  }
43
34
  exports.addOauthToAccountConfig = addOauthToAccountConfig;
@@ -7,33 +7,22 @@ exports.updateConfigWithAccessToken = exports.scopesOnAccessToken = exports.enab
7
7
  const moment_1 = __importDefault(require("moment"));
8
8
  const environments_1 = require("../constants/environments");
9
9
  const auth_1 = require("../constants/auth");
10
- const standardErrors_1 = require("../errors/standardErrors");
11
10
  const localDevAuth_1 = require("../api/localDevAuth");
12
11
  const sandboxHubs_1 = require("../api/sandboxHubs");
13
12
  const config_1 = require("../config");
14
13
  const config_2 = require("../constants/config");
15
14
  const developerTestAccounts_1 = require("../api/developerTestAccounts");
16
15
  const logger_1 = require("./logger");
17
- const apiErrors_1 = require("../errors/apiErrors");
16
+ const lang_1 = require("../utils/lang");
17
+ const errors_1 = require("../errors");
18
18
  const i18nKey = 'lib.personalAccessKey';
19
19
  const refreshRequests = new Map();
20
20
  function getRefreshKey(personalAccessKey, expiration) {
21
21
  return `${personalAccessKey}-${expiration || 'fresh'}`;
22
22
  }
23
23
  async function getAccessToken(personalAccessKey, env = environments_1.ENVIRONMENTS.PROD, accountId) {
24
- let response;
25
- try {
26
- response = await (0, localDevAuth_1.fetchAccessToken)(personalAccessKey, env, accountId);
27
- }
28
- catch (e) {
29
- const error = e;
30
- if (error.response) {
31
- (0, standardErrors_1.throwAuthErrorWithMessage)(`${i18nKey}.errors.invalidPersonalAccessKey`, { errorMessage: error.response.data.message || '' }, error);
32
- }
33
- else {
34
- (0, standardErrors_1.throwError)(e);
35
- }
36
- }
24
+ const axiosResponse = await (0, localDevAuth_1.fetchAccessToken)(personalAccessKey, env, accountId);
25
+ const response = axiosResponse.data;
37
26
  return {
38
27
  portalId: response.hubId,
39
28
  accessToken: response.oauthAccessToken,
@@ -86,7 +75,7 @@ async function getNewAccessToken(accountId, personalAccessKey, expiresAt, env) {
86
75
  async function getNewAccessTokenByAccountId(accountId) {
87
76
  const account = (0, config_1.getAccountConfig)(accountId);
88
77
  if (!account) {
89
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.accountNotFound`, { accountId });
78
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
90
79
  }
91
80
  const { auth, personalAccessKey, env } = account;
92
81
  const accessTokenResponse = await getNewAccessToken(accountId, personalAccessKey, auth?.tokenInfo?.expiresAt, env);
@@ -95,7 +84,7 @@ async function getNewAccessTokenByAccountId(accountId) {
95
84
  async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false) {
96
85
  const account = (0, config_1.getAccountConfig)(accountId);
97
86
  if (!account) {
98
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.accountNotFound`, { accountId });
87
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
99
88
  }
100
89
  const { auth, personalAccessKey, env } = account;
101
90
  const authTokenInfo = auth && auth.tokenInfo;
@@ -124,7 +113,7 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
124
113
  try {
125
114
  if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX ||
126
115
  accountType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
127
- const sandboxDataResponse = await (0, sandboxHubs_1.fetchSandboxHubData)(accessToken, portalId, accountEnv);
116
+ const { data: sandboxDataResponse } = await (0, sandboxHubs_1.fetchSandboxHubData)(accessToken, portalId, accountEnv);
128
117
  if (sandboxDataResponse.parentHubId) {
129
118
  parentAccountId = sandboxDataResponse.parentHubId;
130
119
  }
@@ -132,11 +121,14 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
132
121
  }
133
122
  catch (err) {
134
123
  // Log error but do not throw
135
- logger_1.logger.debug((0, apiErrors_1.getAxiosErrorWithContext)(err).message);
124
+ if ((0, errors_1.isHubSpotHttpError)(err)) {
125
+ logger_1.logger.debug(err.message);
126
+ }
127
+ logger_1.logger.debug(err);
136
128
  }
137
129
  try {
138
130
  if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST) {
139
- const developerTestAccountResponse = await (0, developerTestAccounts_1.fetchDeveloperTestAccountData)(accessToken, portalId, accountEnv);
131
+ const { data: developerTestAccountResponse } = await (0, developerTestAccounts_1.fetchDeveloperTestAccountData)(accessToken, portalId, accountEnv);
140
132
  if (developerTestAccountResponse) {
141
133
  parentAccountId = developerTestAccountResponse.parentPortalId;
142
134
  }
@@ -144,7 +136,10 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
144
136
  }
145
137
  catch (err) {
146
138
  // Log error but do not throw
147
- logger_1.logger.debug((0, apiErrors_1.getAxiosErrorWithContext)(err).message);
139
+ if ((0, errors_1.isHubSpotHttpError)(err)) {
140
+ logger_1.logger.debug(err.message);
141
+ }
142
+ logger_1.logger.debug(err);
148
143
  }
149
144
  const updatedConfig = (0, config_1.updateAccountConfig)({
150
145
  accountId: portalId,
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.portManagerHasActiveServers = exports.deleteServerInstance = exports.requestPorts = exports.stopPortManagerServer = exports.startPortManagerServer = exports.BASE_URL = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
- const PortManagerServer_1 = __importDefault(require("../utils/PortManagerServer"));
8
+ const PortManagerServer_1 = require("../utils/PortManagerServer");
9
9
  const detectPort_1 = require("../utils/detectPort");
10
10
  const ports_1 = require("../constants/ports");
11
11
  exports.BASE_URL = `http://localhost:${ports_1.PORT_MANAGER_SERVER_PORT}`;
@@ -16,7 +16,7 @@ async function isPortManagerServerRunning() {
16
16
  async function startPortManagerServer() {
17
17
  const isRunning = await isPortManagerServerRunning();
18
18
  if (!isRunning) {
19
- await PortManagerServer_1.default.init();
19
+ await PortManagerServer_1.PortManagerServer.init();
20
20
  }
21
21
  }
22
22
  exports.startPortManagerServer = startPortManagerServer;
package/lib/trackUsage.js CHANGED
@@ -7,7 +7,7 @@ exports.trackUsage = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const getAxiosConfig_1 = require("../http/getAxiosConfig");
9
9
  const logger_1 = require("./logger");
10
- const http_1 = __importDefault(require("../http"));
10
+ const http_1 = require("../http");
11
11
  const config_1 = require("../config");
12
12
  const fileMapper_1 = require("../api/fileMapper");
13
13
  const lang_1 = require("../utils/lang");
@@ -39,12 +39,12 @@ async function trackUsage(eventName, eventClass, meta = {}, accountId) {
39
39
  if (accountConfig && accountConfig.authType === 'personalaccesskey') {
40
40
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventAuthenticated`));
41
41
  try {
42
- const result = await http_1.default.post(accountId, {
42
+ await http_1.http.post(accountId, {
43
43
  url: `${path}/authenticated`,
44
44
  data: usageEvent,
45
45
  resolveWithFullResponse: true,
46
46
  });
47
- return result;
47
+ return;
48
48
  }
49
49
  catch (e) {
50
50
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.retryingEventUnauthenticated`));
@@ -0,0 +1,6 @@
1
+ import { FileSystemErrorContext } from '../types/Error';
2
+ export declare class FileSystemError extends Error {
3
+ private context;
4
+ constructor(options?: ErrorOptions, context?: FileSystemErrorContext);
5
+ toString(): string;
6
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileSystemError = void 0;
4
+ const lang_1 = require("../utils/lang");
5
+ const errors_1 = require("../errors");
6
+ const i18nKey = 'errors.fileSystemErrors';
7
+ class FileSystemError extends Error {
8
+ context;
9
+ constructor(options, context) {
10
+ super('', options);
11
+ this.name = 'FileSystemError';
12
+ this.context = context;
13
+ if (context) {
14
+ let fileAction = '';
15
+ if (context.operation === 'read') {
16
+ fileAction = (0, lang_1.i18n)(`${i18nKey}.readAction`);
17
+ }
18
+ else if (context.operation === 'write') {
19
+ fileAction = (0, lang_1.i18n)(`${i18nKey}.writeAction`);
20
+ }
21
+ else {
22
+ fileAction = (0, lang_1.i18n)(`${i18nKey}.otherAction`);
23
+ }
24
+ const filepath = context.filepath
25
+ ? `"${context.filepath}"`
26
+ : (0, lang_1.i18n)(`${i18nKey}.unknownFilepath`);
27
+ const messages = [
28
+ (0, lang_1.i18n)(`${i18nKey}.baseMessage`, { fileAction, filepath }),
29
+ ];
30
+ // Many `fs` errors will be `SystemError`s
31
+ if ((0, errors_1.isSystemError)(options?.cause)) {
32
+ messages.push((0, lang_1.i18n)(`${i18nKey}.baseMessage`, {
33
+ errorMessage: options?.cause?.message || '',
34
+ }));
35
+ }
36
+ this.message = messages.join(' ');
37
+ }
38
+ }
39
+ toString() {
40
+ let baseString = `${this.name}: ${this.message}`;
41
+ if (this.context) {
42
+ baseString = `${baseString} context: ${this.context}`;
43
+ }
44
+ return baseString;
45
+ }
46
+ }
47
+ exports.FileSystemError = FileSystemError;
@@ -0,0 +1,24 @@
1
+ import { HubSpotHttpErrorContext } from '../types/Error';
2
+ export declare class HubSpotHttpError<T = any> extends Error {
3
+ status?: number;
4
+ code?: string;
5
+ statusText?: string;
6
+ data?: T;
7
+ headers?: {
8
+ [key: string]: unknown;
9
+ };
10
+ method: string | undefined;
11
+ context: HubSpotHttpErrorContext | undefined;
12
+ derivedContext: HubSpotHttpErrorContext | undefined;
13
+ validationErrors: string[] | undefined;
14
+ detailedMessage?: string;
15
+ private divider;
16
+ cause: ErrorOptions['cause'];
17
+ constructor(message?: string, options?: ErrorOptions, context?: HubSpotHttpErrorContext);
18
+ updateContext(context: Partial<HubSpotHttpErrorContext>): void;
19
+ toString(): string;
20
+ formattedValidationErrors(): string;
21
+ private extractDerivedContext;
22
+ private parseValidationErrors;
23
+ private joinErrorMessages;
24
+ }