@hubspot/local-dev-lib 0.3.15 → 0.4.0-experimental.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +17 -0
  3. package/api/appsDev.d.ts +6 -0
  4. package/api/appsDev.js +29 -0
  5. package/api/customObjects.d.ts +8 -20
  6. package/api/customObjects.js +13 -16
  7. package/api/designManager.d.ts +4 -14
  8. package/api/designManager.js +5 -8
  9. package/api/devSecrets.d.ts +6 -0
  10. package/api/devSecrets.js +40 -0
  11. package/api/developerTestAccounts.d.ts +12 -5
  12. package/api/developerTestAccounts.js +22 -10
  13. package/api/fileManager.d.ts +5 -4
  14. package/api/fileManager.js +9 -9
  15. package/api/fileMapper.d.ts +8 -7
  16. package/api/fileMapper.js +16 -16
  17. package/api/fileTransport.d.ts +4 -3
  18. package/api/fileTransport.js +5 -5
  19. package/api/fireAlarm.d.ts +3 -0
  20. package/api/fireAlarm.js +11 -0
  21. package/api/functions.d.ts +7 -7
  22. package/api/functions.js +11 -14
  23. package/api/github.d.ts +8 -9
  24. package/api/github.js +30 -13
  25. package/api/hubdb.d.ts +11 -10
  26. package/api/hubdb.js +24 -21
  27. package/api/lighthouseScore.d.ts +4 -4
  28. package/api/lighthouseScore.js +7 -10
  29. package/api/localDevAuth.d.ts +9 -19
  30. package/api/localDevAuth.js +34 -9
  31. package/api/marketplaceValidation.d.ts +4 -4
  32. package/api/marketplaceValidation.js +4 -7
  33. package/api/projects.d.ts +47 -35
  34. package/api/projects.js +145 -57
  35. package/api/sandboxHubs.d.ts +6 -4
  36. package/api/sandboxHubs.js +9 -10
  37. package/api/sandboxSync.d.ts +4 -4
  38. package/api/sandboxSync.js +4 -13
  39. package/api/secrets.d.ts +6 -8
  40. package/api/secrets.js +9 -12
  41. package/api/validateHubl.d.ts +2 -1
  42. package/api/validateHubl.js +3 -6
  43. package/config/CLIConfiguration.d.ts +16 -9
  44. package/config/CLIConfiguration.js +148 -74
  45. package/config/configFile.js +8 -17
  46. package/config/configUtils.d.ts +2 -21
  47. package/config/configUtils.js +2 -2
  48. package/config/config_DEPRECATED.d.ts +10 -8
  49. package/config/config_DEPRECATED.js +62 -32
  50. package/config/getAccountIdentifier.d.ts +2 -0
  51. package/config/getAccountIdentifier.js +15 -0
  52. package/config/index.d.ts +14 -8
  53. package/config/index.js +108 -59
  54. package/config/migrate.d.ts +22 -0
  55. package/config/migrate.js +178 -0
  56. package/constants/config.d.ts +13 -1
  57. package/constants/config.js +19 -2
  58. package/constants/extensions.d.ts +1 -0
  59. package/constants/extensions.js +2 -1
  60. package/constants/files.d.ts +2 -2
  61. package/constants/files.js +3 -3
  62. package/constants/projects.d.ts +12 -0
  63. package/constants/projects.js +15 -0
  64. package/errors/errors_DEPRECATED.d.ts +1 -5
  65. package/errors/errors_DEPRECATED.js +2 -2
  66. package/errors/index.d.ts +18 -0
  67. package/errors/index.js +63 -0
  68. package/http/addQueryParams.d.ts +2 -0
  69. package/http/addQueryParams.js +14 -0
  70. package/http/getAxiosConfig.d.ts +2 -2
  71. package/http/getAxiosConfig.js +31 -2
  72. package/http/index.d.ts +10 -10
  73. package/http/index.js +80 -34
  74. package/http/unauthed.d.ts +14 -0
  75. package/http/unauthed.js +38 -0
  76. package/lang/en.json +384 -376
  77. package/lib/archive.d.ts +3 -6
  78. package/lib/archive.js +26 -20
  79. package/lib/cms/functions.d.ts +6 -9
  80. package/lib/cms/functions.js +24 -19
  81. package/lib/cms/handleFieldsJS.d.ts +2 -2
  82. package/lib/cms/handleFieldsJS.js +13 -9
  83. package/lib/cms/modules.d.ts +5 -13
  84. package/lib/cms/modules.js +40 -23
  85. package/lib/cms/processFieldsJs.js +8 -7
  86. package/lib/cms/templates.d.ts +42 -0
  87. package/lib/cms/templates.js +48 -5
  88. package/lib/cms/uploadFolder.d.ts +3 -18
  89. package/lib/cms/uploadFolder.js +19 -17
  90. package/lib/cms/validate.js +1 -1
  91. package/lib/cms/watch.d.ts +2 -15
  92. package/lib/cms/watch.js +31 -23
  93. package/lib/customObjects.js +4 -15
  94. package/lib/fileManager.js +22 -22
  95. package/lib/fileMapper.d.ts +4 -13
  96. package/lib/fileMapper.js +47 -50
  97. package/lib/fs.d.ts +1 -1
  98. package/lib/fs.js +10 -6
  99. package/lib/github.d.ts +11 -11
  100. package/lib/github.js +44 -30
  101. package/lib/gitignore.d.ts +1 -6
  102. package/lib/gitignore.js +2 -2
  103. package/lib/hubdb.d.ts +3 -2
  104. package/lib/hubdb.js +11 -9
  105. package/lib/notify.js +2 -2
  106. package/lib/oauth.d.ts +1 -1
  107. package/lib/oauth.js +9 -18
  108. package/lib/path.d.ts +3 -0
  109. package/lib/path.js +46 -1
  110. package/lib/personalAccessKey.d.ts +5 -17
  111. package/lib/personalAccessKey.js +42 -32
  112. package/lib/portManager.d.ts +3 -5
  113. package/lib/portManager.js +18 -6
  114. package/lib/text.d.ts +1 -1
  115. package/lib/text.js +3 -0
  116. package/lib/trackUsage.js +13 -7
  117. package/models/FileSystemError.d.ts +6 -0
  118. package/models/FileSystemError.js +47 -0
  119. package/models/HubSpotHttpError.d.ts +26 -0
  120. package/models/HubSpotHttpError.js +208 -0
  121. package/models/OAuth2Manager.d.ts +2 -27
  122. package/models/OAuth2Manager.js +14 -29
  123. package/package.json +38 -35
  124. package/types/Accounts.d.ts +98 -3
  125. package/types/Apps.d.ts +77 -0
  126. package/types/Apps.js +2 -0
  127. package/types/Archive.d.ts +9 -0
  128. package/types/Archive.js +2 -0
  129. package/types/Build.d.ts +4 -2
  130. package/types/ComponentStructure.d.ts +30 -10
  131. package/types/Config.d.ts +21 -2
  132. package/types/Deploy.d.ts +3 -2
  133. package/types/DesignManager.d.ts +15 -0
  134. package/types/DesignManager.js +2 -0
  135. package/types/DevSecrets.d.ts +5 -0
  136. package/types/DevSecrets.js +2 -0
  137. package/types/Error.d.ts +9 -5
  138. package/types/FieldsJS.d.ts +1 -0
  139. package/types/FieldsJS.js +2 -0
  140. package/types/FileManager.d.ts +1 -1
  141. package/types/Files.d.ts +43 -4
  142. package/types/FireAlarm.d.ts +9 -0
  143. package/types/FireAlarm.js +2 -0
  144. package/types/Functions.d.ts +52 -0
  145. package/types/Github.d.ts +13 -0
  146. package/types/Http.d.ts +12 -11
  147. package/types/Hubdb.d.ts +9 -0
  148. package/types/MarketplaceValidation.d.ts +7 -3
  149. package/types/Migration.d.ts +30 -0
  150. package/types/Migration.js +12 -0
  151. package/types/Modules.d.ts +11 -0
  152. package/types/PortManager.d.ts +7 -0
  153. package/types/Project.d.ts +30 -0
  154. package/types/Sandbox.d.ts +25 -36
  155. package/types/Schemas.d.ts +56 -0
  156. package/types/Secrets.d.ts +3 -0
  157. package/types/Secrets.js +2 -0
  158. package/types/developerTestAccounts.d.ts +11 -0
  159. package/utils/PortManagerServer.d.ts +6 -7
  160. package/utils/PortManagerServer.js +15 -9
  161. package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
  162. package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
  163. package/utils/cms/fieldsJS.d.ts +1 -2
  164. package/utils/cms/modules.js +2 -2
  165. package/utils/detectPort.js +3 -3
  166. package/errors/apiErrors.d.ts +0 -25
  167. package/errors/apiErrors.js +0 -186
  168. package/errors/fileSystemErrors.d.ts +0 -6
  169. package/errors/fileSystemErrors.js +0 -35
  170. package/errors/standardErrors.d.ts +0 -21
  171. package/errors/standardErrors.js +0 -52
  172. package/lang/lang/en.json +0 -391
  173. package/lib/developerTestAccounts.d.ts +0 -4
  174. package/lib/developerTestAccounts.js +0 -35
  175. package/lib/sandboxes.d.ts +0 -14
  176. package/lib/sandboxes.js +0 -70
  177. package/models/HubSpotAuthError.d.ts +0 -12
  178. 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,
@@ -44,14 +43,14 @@ function isPathToHubspot(filepath) {
44
43
  return /^(\/|\\)?@hubspot/i.test(filepath.trim());
45
44
  }
46
45
  exports.isPathToHubspot = isPathToHubspot;
47
- function useApiBuffer(mode) {
48
- return mode === files_1.MODE.draft;
46
+ function useApiBuffer(cmsPublishMode) {
47
+ return cmsPublishMode === files_1.CMS_PUBLISH_MODE.draft;
49
48
  }
50
- // Determines API param based on mode an options
51
- function getFileMapperQueryValues(mode, { staging, assetVersion } = {}) {
49
+ // Determines API param based on publish mode and options
50
+ function getFileMapperQueryValues(cmsPublishMode, { staging, assetVersion } = {}) {
52
51
  return {
53
52
  params: {
54
- buffer: useApiBuffer(mode),
53
+ buffer: useApiBuffer(cmsPublishMode),
55
54
  environmentId: staging ? 2 : 1,
56
55
  version: assetVersion,
57
56
  },
@@ -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
  }
@@ -142,7 +141,7 @@ async function skipExisting(filepath, overwrite = false) {
142
141
  }
143
142
  return false;
144
143
  }
145
- async function fetchAndWriteFileStream(accountId, srcPath, filepath, mode, options = {}) {
144
+ async function fetchAndWriteFileStream(accountId, srcPath, filepath, cmsPublishMode, options = {}) {
146
145
  if (typeof srcPath !== 'string' || !srcPath.trim()) {
147
146
  return;
148
147
  }
@@ -150,21 +149,15 @@ async function fetchAndWriteFileStream(accountId, srcPath, filepath, mode, optio
150
149
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.skippedExisting`, { filepath }));
151
150
  return;
152
151
  }
153
- if (!(0, path_2.isAllowedExtension)(srcPath)) {
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);
152
+ if (!(0, path_2.isAllowedExtension)(srcPath, Array.from(extensions_1.JSR_ALLOWED_EXTENSIONS))) {
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(cmsPublishMode, 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
166
159
  //file is fetched.
167
- async function writeFileMapperNode(accountId, filepath, node, mode, options = {}) {
160
+ async function writeFileMapperNode(accountId, filepath, node, cmsPublishMode, options = {}) {
168
161
  const localFilepath = (0, path_2.convertToLocalFileSystemPath)(path_1.default.resolve(filepath));
169
162
  if (await skipExisting(localFilepath, options.overwrite)) {
170
163
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.skippedExisting`, {
@@ -174,7 +167,7 @@ async function writeFileMapperNode(accountId, filepath, node, mode, options = {}
174
167
  }
175
168
  if (!node.folder) {
176
169
  try {
177
- await fetchAndWriteFileStream(accountId, node.path, localFilepath, mode, options);
170
+ await fetchAndWriteFileStream(accountId, node.path, localFilepath, cmsPublishMode, options);
178
171
  return true;
179
172
  }
180
173
  catch (err) {
@@ -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
- async function downloadFile(accountId, src, destPath, mode, options = {}) {
192
+ async function downloadFile(accountId, src, destPath, cmsPublishMode, 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;
@@ -222,7 +214,7 @@ async function downloadFile(accountId, src, destPath, mode, options = {}) {
222
214
  : path_1.default.resolve(cwd, dest, name);
223
215
  }
224
216
  const localFsPath = (0, path_2.convertToLocalFileSystemPath)(filepath);
225
- await fetchAndWriteFileStream(accountId, src, localFsPath, mode, options);
217
+ await fetchAndWriteFileStream(accountId, src, localFsPath, cmsPublishMode, options);
226
218
  await queue.onIdle();
227
219
  logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.completedFetch`, {
228
220
  src,
@@ -232,33 +224,33 @@ 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
- async function fetchFolderFromApi(accountId, src, mode, options = {}) {
235
+ async function fetchFolderFromApi(accountId, src, cmsPublishMode, 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
- const queryValues = getFileMapperQueryValues(mode, options);
252
- const node = isHubspot
243
+ const queryValues = getFileMapperQueryValues(cmsPublishMode, options);
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 }));
256
248
  return node;
257
249
  }
258
250
  exports.fetchFolderFromApi = fetchFolderFromApi;
259
- async function downloadFolder(accountId, src, destPath, mode, options = {}) {
251
+ async function downloadFolder(accountId, src, destPath, cmsPublishMode, options = {}) {
260
252
  try {
261
- const node = await fetchFolderFromApi(accountId, src, mode, options);
253
+ const node = await fetchFolderFromApi(accountId, src, cmsPublishMode, options);
262
254
  if (!node) {
263
255
  return;
264
256
  }
@@ -269,9 +261,13 @@ async function downloadFolder(accountId, src, destPath, mode, options = {}) {
269
261
  let success = true;
270
262
  recurseFolder(node, (childNode, filepath) => {
271
263
  queue.add(async () => {
272
- const succeeded = await writeFileMapperNode(accountId, filepath || '', childNode, mode, options);
264
+ const succeeded = await writeFileMapperNode(accountId, filepath || '', childNode, cmsPublishMode, options);
273
265
  if (succeeded === false) {
274
266
  success = false;
267
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errors.failedToFetchFile`, {
268
+ src: childNode.path,
269
+ dest: filepath || '',
270
+ }));
275
271
  }
276
272
  });
277
273
  return success;
@@ -285,16 +281,17 @@ async function downloadFolder(accountId, src, destPath, mode, options = {}) {
285
281
  }));
286
282
  }
287
283
  else {
288
- (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 }));
289
286
  }
290
287
  }
291
288
  catch (err) {
292
289
  const error = err;
293
- if ((0, apiErrors_1.isTimeoutError)(error)) {
294
- (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 });
295
292
  }
296
293
  else {
297
- (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 });
298
295
  }
299
296
  }
300
297
  }
@@ -305,16 +302,16 @@ async function downloadFolder(accountId, src, destPath, mode, options = {}) {
305
302
  * @param {FileMapperInputArguments} input
306
303
  * @returns {Promise}
307
304
  */
308
- async function downloadFileOrFolder(accountId, src, dest, mode, options = {}) {
305
+ async function downloadFileOrFolder(accountId, src, dest, cmsPublishMode, options = {}) {
309
306
  if (!src) {
310
307
  return;
311
308
  }
312
309
  const { isFile } = getTypeDataFromPath(src);
313
310
  if (isFile) {
314
- await downloadFile(accountId, src, dest, mode, options);
311
+ await downloadFile(accountId, src, dest, cmsPublishMode, options);
315
312
  }
316
313
  else {
317
- await downloadFolder(accountId, src, dest, mode, options);
314
+ await downloadFolder(accountId, src, dest, cmsPublishMode, options);
318
315
  }
319
316
  }
320
317
  exports.downloadFileOrFolder = downloadFileOrFolder;
package/lib/fs.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { FileData } from '../types/Files';
2
2
  export declare function getFileInfoAsync(dir: string, file: string): Promise<FileData>;
3
3
  export declare function flattenAndRemoveSymlinks(filesData: Array<FileData>): Array<string>;
4
- export declare function walk(dir: string): Promise<Array<string>>;
4
+ export declare function walk(dir: string, ignoreDirs?: string[]): Promise<Array<string>>;
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);
@@ -42,11 +42,11 @@ function flattenAndRemoveSymlinks(filesData) {
42
42
  }, []);
43
43
  }
44
44
  exports.flattenAndRemoveSymlinks = flattenAndRemoveSymlinks;
45
- const generateRecursiveFilePromise = async (dir, file) => {
45
+ const generateRecursiveFilePromise = async (dir, file, ignoreDirs) => {
46
46
  return getFileInfoAsync(dir, file).then(fileData => {
47
47
  return new Promise(resolve => {
48
48
  if (fileData.type === files_1.STAT_TYPES.DIRECTORY) {
49
- walk(fileData.filepath).then(files => {
49
+ walk(fileData.filepath, ignoreDirs).then(files => {
50
50
  resolve({ ...fileData, files });
51
51
  });
52
52
  }
@@ -56,16 +56,20 @@ const generateRecursiveFilePromise = async (dir, file) => {
56
56
  });
57
57
  });
58
58
  };
59
- async function walk(dir) {
59
+ async function walk(dir, ignoreDirs) {
60
60
  function processFiles(files) {
61
- return Promise.all(files.map(file => generateRecursiveFilePromise(dir, file)));
61
+ // If the directory is in the ignore list, return an empty array to skip the directory contents
62
+ if (ignoreDirs?.some(ignored => dir.includes(ignored))) {
63
+ return [];
64
+ }
65
+ return Promise.all(files.map(file => generateRecursiveFilePromise(dir, file, ignoreDirs)));
62
66
  }
63
67
  return fs_1.default.promises
64
68
  .readdir(dir)
65
69
  .then(processFiles)
66
70
  .then(flattenAndRemoveSymlinks)
67
71
  .catch(err => {
68
- (0, standardErrors_1.throwError)(err);
72
+ throw new FileSystemError_1.FileSystemError({ cause: err });
69
73
  });
70
74
  }
71
75
  exports.walk = walk;
package/lib/github.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  /// <reference types="node" />
2
- import { GithubReleaseData, GithubRepoFile } from '../types/Github';
3
- type RepoPath = `${string}/${string}`;
4
- export declare function fetchFileFromRepository(repoPath: RepoPath, filePath: string, ref: string): Promise<Buffer>;
2
+ /// <reference types="node" />
3
+ import { GithubReleaseData, GithubRepoFile, RepoPath, CloneGithubRepoOptions } from '../types/Github';
4
+ /**
5
+ * @deprecated Use `fetchRepoFile` instead - this util is a thin wrapper around it
6
+ */
7
+ export declare function fetchFileFromRepository<T = Buffer>(repoPath: RepoPath, filePath: string, ref: string): Promise<T>;
5
8
  export declare function fetchReleaseData(repoPath: RepoPath, tag?: string): Promise<GithubReleaseData>;
6
- type CloneGithubRepoOptions = {
7
- isRelease?: boolean;
8
- type?: string;
9
- branch?: string;
10
- tag?: string;
11
- sourceDir?: string;
12
- };
13
9
  export declare function cloneGithubRepo(repoPath: RepoPath, dest: string, options?: CloneGithubRepoOptions): Promise<boolean>;
10
+ export declare function fetchGitHubRepoContentFromDownloadUrl(dest: string, downloadUrl: string): Promise<void>;
11
+ /**
12
+ * Writes files from a public repository to the destination folder
13
+ @deprecated - This method fetches all the files individually, which can hit rate limits for unauthorized requests. Use `cloneGithubRepo` instead.
14
+ */
14
15
  export declare function downloadGithubRepoContents(repoPath: RepoPath, contentPath: string, dest: string, ref?: string, filter?: (contentPiecePath: string, downloadPath: string) => boolean): Promise<void>;
15
16
  export declare function listGithubRepoContents(repoPath: RepoPath, contentPath: string, fileFilter?: 'file' | 'dir'): Promise<GithubRepoFile[]>;
16
- export {};
package/lib/github.js CHANGED
@@ -3,15 +3,18 @@ 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.listGithubRepoContents = exports.downloadGithubRepoContents = exports.cloneGithubRepo = exports.fetchReleaseData = exports.fetchFileFromRepository = void 0;
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
+ /**
16
+ * @deprecated Use `fetchRepoFile` instead - this util is a thin wrapper around it
17
+ */
15
18
  async function fetchFileFromRepository(repoPath, filePath, ref) {
16
19
  try {
17
20
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.fetchFileFromRepository.fetching`, {
@@ -21,7 +24,9 @@ async function fetchFileFromRepository(repoPath, filePath, ref) {
21
24
  return data;
22
25
  }
23
26
  catch (err) {
24
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.fetchFileFromRepository.errors.fetchFail`, {}, err);
27
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.fetchFileFromRepository.errors.fetchFail`), {
28
+ cause: err,
29
+ });
25
30
  }
26
31
  }
27
32
  exports.fetchFileFromRepository = fetchFileFromRepository;
@@ -38,8 +43,9 @@ async function fetchReleaseData(repoPath, tag) {
38
43
  return data;
39
44
  }
40
45
  catch (err) {
41
- const error = err;
42
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.fetchReleaseData.errors.fetchFail`, { tag: tag || 'latest' }, error);
46
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.fetchReleaseData.errors.fetchFail`, {
47
+ tag: tag || 'latest',
48
+ }), { cause: err });
43
49
  }
44
50
  }
45
51
  exports.fetchReleaseData = fetchReleaseData;
@@ -66,18 +72,23 @@ async function downloadGithubRepoZip(repoPath, isRelease = false, options = {})
66
72
  return data;
67
73
  }
68
74
  catch (err) {
69
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.downloadGithubRepoZip.errors.fetchFail`, {}, err);
75
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoZip.errors.fetchFail`), {
76
+ cause: err,
77
+ });
70
78
  }
71
79
  }
72
80
  async function cloneGithubRepo(repoPath, dest, options = {}) {
73
- const { tag, isRelease, branch, sourceDir, type } = options;
81
+ const { tag, isRelease, branch, sourceDir, type, hideLogs } = options;
74
82
  const zip = await downloadGithubRepoZip(repoPath, isRelease, {
75
83
  tag,
76
84
  branch,
77
85
  });
78
86
  const repoName = repoPath.split('/')[1];
79
- const success = await (0, archive_1.extractZipArchive)(zip, repoName, dest, { sourceDir });
80
- if (success) {
87
+ const success = await (0, archive_1.extractZipArchive)(zip, repoName, dest, {
88
+ sourceDir,
89
+ hideLogs,
90
+ });
91
+ if (success && !hideLogs) {
81
92
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.cloneGithubRepo.success`, {
82
93
  type: type || '',
83
94
  dest,
@@ -88,12 +99,21 @@ async function cloneGithubRepo(repoPath, dest, options = {}) {
88
99
  exports.cloneGithubRepo = cloneGithubRepo;
89
100
  async function fetchGitHubRepoContentFromDownloadUrl(dest, downloadUrl) {
90
101
  const resp = await (0, github_1.fetchRepoFileByDownloadUrl)(downloadUrl);
91
- const fileContents = typeof resp.data === 'string'
92
- ? resp.data
93
- : JSON.stringify(resp.data, null, 2);
94
- fs_extra_1.default.outputFileSync(dest, fileContents, 'utf8');
102
+ const contentType = resp.headers['content-type'];
103
+ let fileContents;
104
+ if (contentType.startsWith('text')) {
105
+ fileContents = Buffer.from(resp.data).toString('utf8');
106
+ }
107
+ else {
108
+ fileContents = resp.data;
109
+ }
110
+ fs_extra_1.default.outputFileSync(dest, fileContents);
95
111
  }
96
- // Writes files from a public repository to the destination folder
112
+ exports.fetchGitHubRepoContentFromDownloadUrl = fetchGitHubRepoContentFromDownloadUrl;
113
+ /**
114
+ * Writes files from a public repository to the destination folder
115
+ @deprecated - This method fetches all the files individually, which can hit rate limits for unauthorized requests. Use `cloneGithubRepo` instead.
116
+ */
97
117
  async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filter) {
98
118
  fs_extra_1.default.ensureDirSync(path_1.default.dirname(dest));
99
119
  try {
@@ -126,15 +146,12 @@ async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filt
126
146
  await Promise.all(contentPromises);
127
147
  }
128
148
  catch (e) {
129
- const error = e;
130
- if (error?.error?.message) {
131
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
132
- errorMessage: error.error.message,
133
- }, error);
134
- }
135
- else {
136
- (0, standardErrors_1.throwError)(error);
149
+ if ((0, errors_1.isSystemError)(e) && e?.error?.message) {
150
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
151
+ errorMessage: e.error.message,
152
+ }), { cause: e });
137
153
  }
154
+ throw e;
138
155
  }
139
156
  }
140
157
  exports.downloadGithubRepoContents = downloadGithubRepoContents;
@@ -148,15 +165,12 @@ async function listGithubRepoContents(repoPath, contentPath, fileFilter) {
148
165
  return filteredFiles;
149
166
  }
150
167
  catch (e) {
151
- const error = e;
152
- if (error?.response?.data?.message) {
153
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
154
- errorMessage: error.response.data.message,
155
- });
156
- }
157
- else {
158
- (0, standardErrors_1.throwError)(error);
168
+ if ((0, errors_1.isHubSpotHttpError)(e) && e.data.message) {
169
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
170
+ errorMessage: e.data.message,
171
+ }));
159
172
  }
173
+ throw e;
160
174
  }
161
175
  }
162
176
  exports.listGithubRepoContents = listGithubRepoContents;
@@ -1,8 +1,3 @@
1
+ import { GitInclusionResult } from '../types/Config';
1
2
  export declare function checkAndAddConfigToGitignore(configPath: string): void;
2
- type GitInclusionResult = {
3
- inGit: boolean;
4
- configIgnored: boolean;
5
- gitignoreFiles: Array<string>;
6
- };
7
3
  export declare function checkGitInclusion(configPath: string): GitInclusionResult;
8
- export {};
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,14 +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.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
- const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
7
+ const getAccountIdentifier_1 = require("../config/getAccountIdentifier");
12
8
  const config_1 = require("../config");
13
9
  const lang_1 = require("../utils/lang");
14
10
  const i18nKey = 'lib.oauth';
@@ -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;