@hubspot/local-dev-lib 0.2.1 → 0.2.2-experimental.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 (189) 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 -7
  6. package/api/customObjects.js +13 -16
  7. package/api/designManager.d.ts +4 -13
  8. package/api/designManager.js +6 -9
  9. package/api/developerTestAccounts.d.ts +7 -0
  10. package/api/developerTestAccounts.js +48 -0
  11. package/api/fileManager.d.ts +5 -4
  12. package/api/fileManager.js +11 -11
  13. package/api/fileMapper.d.ts +8 -7
  14. package/api/fileMapper.js +17 -17
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/functions.d.ts +7 -4
  18. package/api/functions.js +22 -11
  19. package/api/github.d.ts +7 -9
  20. package/api/github.js +31 -13
  21. package/api/hubdb.d.ts +11 -10
  22. package/api/hubdb.js +28 -22
  23. package/api/lighthouseScore.d.ts +4 -4
  24. package/api/lighthouseScore.js +9 -12
  25. package/api/localDevAuth.d.ts +8 -16
  26. package/api/localDevAuth.js +34 -13
  27. package/api/marketplaceValidation.d.ts +4 -4
  28. package/api/marketplaceValidation.js +8 -11
  29. package/api/projects.d.ts +31 -24
  30. package/api/projects.js +164 -44
  31. package/api/sandboxHubs.d.ts +6 -4
  32. package/api/sandboxHubs.js +10 -11
  33. package/api/sandboxSync.d.ts +4 -4
  34. package/api/sandboxSync.js +4 -13
  35. package/api/secrets.d.ts +6 -8
  36. package/api/secrets.js +9 -12
  37. package/api/validateHubl.d.ts +2 -1
  38. package/api/validateHubl.js +3 -6
  39. package/config/CLIConfiguration.d.ts +15 -11
  40. package/config/CLIConfiguration.js +175 -90
  41. package/config/configFile.js +13 -21
  42. package/config/configUtils.d.ts +2 -21
  43. package/config/configUtils.js +5 -4
  44. package/config/config_DEPRECATED.d.ts +6 -8
  45. package/config/config_DEPRECATED.js +79 -25
  46. package/config/environment.js +5 -4
  47. package/config/getAccountIdentifier.d.ts +2 -0
  48. package/config/getAccountIdentifier.js +15 -0
  49. package/config/index.d.ts +13 -8
  50. package/config/index.js +97 -57
  51. package/config/migrate.d.ts +20 -0
  52. package/config/migrate.js +150 -0
  53. package/constants/config.d.ts +25 -1
  54. package/constants/config.js +32 -3
  55. package/constants/environments.d.ts +1 -0
  56. package/constants/environments.js +1 -0
  57. package/constants/extensions.d.ts +2 -0
  58. package/constants/extensions.js +3 -1
  59. package/constants/files.d.ts +2 -2
  60. package/constants/files.js +3 -3
  61. package/errors/errors_DEPRECATED.d.ts +1 -5
  62. package/errors/errors_DEPRECATED.js +2 -2
  63. package/errors/index.d.ts +18 -0
  64. package/errors/index.js +63 -0
  65. package/http/addQueryParams.d.ts +2 -0
  66. package/http/addQueryParams.js +14 -0
  67. package/http/getAxiosConfig.d.ts +6 -3
  68. package/http/getAxiosConfig.js +51 -7
  69. package/http/index.d.ts +11 -12
  70. package/http/index.js +35 -41
  71. package/http/unauthed.d.ts +14 -0
  72. package/http/unauthed.js +38 -0
  73. package/lang/en.json +384 -386
  74. package/lib/archive.d.ts +2 -8
  75. package/lib/archive.js +34 -30
  76. package/lib/cms/functions.d.ts +7 -12
  77. package/lib/cms/functions.js +49 -51
  78. package/lib/cms/handleFieldsJS.js +16 -14
  79. package/lib/cms/modules.d.ts +4 -15
  80. package/lib/cms/modules.js +81 -78
  81. package/lib/cms/processFieldsJs.js +10 -33
  82. package/lib/cms/templates.d.ts +43 -3
  83. package/lib/cms/templates.js +53 -11
  84. package/lib/cms/uploadFolder.d.ts +3 -14
  85. package/lib/cms/uploadFolder.js +58 -42
  86. package/lib/cms/validate.js +1 -1
  87. package/lib/cms/watch.d.ts +2 -18
  88. package/lib/cms/watch.js +63 -68
  89. package/lib/customObjects.js +4 -15
  90. package/lib/fileManager.d.ts +2 -6
  91. package/lib/fileManager.js +54 -65
  92. package/lib/fileMapper.d.ts +4 -15
  93. package/lib/fileMapper.js +67 -88
  94. package/lib/fs.d.ts +1 -1
  95. package/lib/fs.js +10 -6
  96. package/lib/github.d.ts +12 -14
  97. package/lib/github.js +70 -35
  98. package/lib/gitignore.d.ts +2 -0
  99. package/lib/gitignore.js +21 -4
  100. package/lib/hubdb.d.ts +3 -2
  101. package/lib/hubdb.js +11 -9
  102. package/{utils → lib}/notify.js +2 -2
  103. package/lib/oauth.d.ts +2 -5
  104. package/lib/oauth.js +14 -25
  105. package/lib/path.d.ts +3 -0
  106. package/lib/path.js +46 -1
  107. package/lib/personalAccessKey.d.ts +8 -11
  108. package/lib/personalAccessKey.js +76 -38
  109. package/lib/portManager.d.ts +3 -5
  110. package/lib/portManager.js +18 -6
  111. package/lib/trackUsage.js +18 -11
  112. package/lib/urls.js +5 -1
  113. package/models/FileSystemError.d.ts +6 -0
  114. package/models/FileSystemError.js +47 -0
  115. package/models/HubSpotHttpError.d.ts +24 -0
  116. package/models/HubSpotHttpError.js +197 -0
  117. package/models/OAuth2Manager.d.ts +5 -27
  118. package/models/OAuth2Manager.js +41 -64
  119. package/package.json +35 -35
  120. package/types/Accounts.d.ts +103 -3
  121. package/types/Apps.d.ts +77 -0
  122. package/types/Archive.d.ts +9 -0
  123. package/types/Archive.js +2 -0
  124. package/types/Build.d.ts +4 -2
  125. package/types/ComponentStructure.d.ts +30 -10
  126. package/types/Config.d.ts +19 -2
  127. package/types/Deploy.d.ts +3 -2
  128. package/types/DesignManager.d.ts +10 -0
  129. package/types/DesignManager.js +2 -0
  130. package/types/Error.d.ts +9 -5
  131. package/types/FieldsJS.d.ts +1 -0
  132. package/types/FieldsJS.js +2 -0
  133. package/types/FileManager.d.ts +1 -1
  134. package/types/Files.d.ts +43 -4
  135. package/types/Functions.d.ts +52 -0
  136. package/types/Github.d.ts +13 -0
  137. package/types/Http.d.ts +12 -11
  138. package/types/Hubdb.d.ts +9 -0
  139. package/types/MarketplaceValidation.d.ts +7 -3
  140. package/types/Migration.d.ts +28 -0
  141. package/types/Migration.js +10 -0
  142. package/types/Modules.d.ts +11 -0
  143. package/types/PortManager.d.ts +7 -0
  144. package/types/Project.d.ts +30 -0
  145. package/types/ProjectLog.d.ts +9 -0
  146. package/types/ProjectLog.js +2 -0
  147. package/types/Sandbox.d.ts +37 -47
  148. package/types/Schemas.d.ts +56 -0
  149. package/types/Secrets.d.ts +3 -0
  150. package/types/Secrets.js +2 -0
  151. package/types/developerTestAccounts.d.ts +13 -0
  152. package/types/developerTestAccounts.js +2 -0
  153. package/utils/PortManagerServer.d.ts +6 -7
  154. package/utils/PortManagerServer.js +22 -16
  155. package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
  156. package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
  157. package/utils/cms/fieldsJS.d.ts +1 -2
  158. package/utils/cms/modules.js +2 -2
  159. package/utils/detectPort.js +3 -3
  160. package/utils/git.d.ts +1 -7
  161. package/utils/git.js +2 -18
  162. package/errors/apiErrors.d.ts +0 -19
  163. package/errors/apiErrors.js +0 -179
  164. package/errors/fileSystemErrors.d.ts +0 -5
  165. package/errors/fileSystemErrors.js +0 -31
  166. package/errors/standardErrors.d.ts +0 -27
  167. package/errors/standardErrors.js +0 -59
  168. package/lang/lang/en.json +0 -401
  169. package/lib/logging/git.d.ts +0 -2
  170. package/lib/logging/git.js +0 -54
  171. package/lib/logging/logs.d.ts +0 -22
  172. package/lib/logging/logs.js +0 -86
  173. package/lib/logging/table.d.ts +0 -3
  174. package/lib/logging/table.js +0 -47
  175. package/lib/sandboxes.d.ts +0 -14
  176. package/lib/sandboxes.js +0 -71
  177. package/models/HubSpotAuthError.d.ts +0 -12
  178. package/models/HubSpotAuthError.js +0 -20
  179. package/types/LogCallbacks.d.ts +0 -7
  180. package/utils/logger.d.ts +0 -5
  181. package/utils/logger.js +0 -23
  182. package/utils/objectUtils.d.ts +0 -8
  183. package/utils/objectUtils.js +0 -33
  184. /package/{utils → lib}/escapeRegExp.d.ts +0 -0
  185. /package/{utils → lib}/escapeRegExp.js +0 -0
  186. /package/lib/{logging/logger.d.ts → logger.d.ts} +0 -0
  187. /package/lib/{logging/logger.js → logger.js} +0 -0
  188. /package/{utils → lib}/notify.d.ts +0 -0
  189. /package/types/{LogCallbacks.js → Apps.js} +0 -0
package/lib/cms/watch.js CHANGED
@@ -7,46 +7,50 @@ exports.watch = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const chokidar_1 = __importDefault(require("chokidar"));
9
9
  const p_queue_1 = __importDefault(require("p-queue"));
10
- const debounce_1 = require("debounce");
11
- const apiErrors_1 = require("../../errors/apiErrors");
10
+ const debounce_1 = __importDefault(require("debounce"));
12
11
  const handleFieldsJS_1 = require("./handleFieldsJS");
13
12
  const uploadFolder_1 = require("./uploadFolder");
14
13
  const ignoreRules_1 = require("../ignoreRules");
15
14
  const fileMapper_1 = require("../fileMapper");
16
15
  const fileMapper_2 = require("../../api/fileMapper");
17
- const escapeRegExp_1 = require("../../utils/escapeRegExp");
16
+ const escapeRegExp_1 = require("../escapeRegExp");
18
17
  const path_2 = require("../path");
19
- const notify_1 = require("../../utils/notify");
18
+ const notify_1 = require("../notify");
20
19
  const themes_1 = require("./themes");
21
- const logger_1 = require("../../utils/logger");
22
- const logger_2 = require("../../utils/logger");
20
+ const logger_1 = require("../logger");
21
+ const lang_1 = require("../../utils/lang");
22
+ const HubSpotHttpError_1 = require("../../models/HubSpotHttpError");
23
+ const errors_1 = require("../../errors");
23
24
  const i18nKey = 'lib.cms.watch';
24
- const watchCallbackKeys = [
25
- 'notifyOfThemePreview',
26
- 'uploadSuccess',
27
- 'deleteSuccess',
28
- 'folderUploadSuccess',
29
- 'ready',
30
- 'deleteSuccessWithType',
31
- ];
32
- const makeLogger = (logger_1.makeTypedLogger);
33
25
  const queue = new p_queue_1.default({
34
26
  concurrency: 10,
35
27
  });
36
- function _notifyOfThemePreview(filePath, accountId, logCallbacks) {
37
- const logger = makeLogger(logCallbacks);
28
+ function _notifyOfThemePreview(filePath, accountId) {
38
29
  if (queue.size > 0)
39
30
  return;
40
31
  const previewUrl = (0, themes_1.getThemePreviewUrl)(filePath, accountId);
41
32
  if (!previewUrl)
42
33
  return;
43
- logger('notifyOfThemePreview', `${i18nKey}.notifyOfThemePreview`, {
34
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.notifyOfThemePreview`, {
44
35
  previewUrl,
45
- });
36
+ }));
46
37
  }
47
- const notifyOfThemePreview = (0, debounce_1.debounce)(_notifyOfThemePreview, 1000);
48
- async function uploadFile(accountId, file, dest, options, mode = null, logCallbacks) {
49
- const logger = makeLogger(logCallbacks);
38
+ const notifyOfThemePreview = (0, debounce_1.default)(_notifyOfThemePreview, 1000);
39
+ const defaultOnUploadFileError = (file, dest, accountId) => (error) => {
40
+ const uploadFailedMessage = (0, lang_1.i18n)(`${i18nKey}.uploadFailed`, {
41
+ file,
42
+ dest,
43
+ });
44
+ logger_1.logger.debug(uploadFailedMessage);
45
+ throw new HubSpotHttpError_1.HubSpotHttpError(uploadFailedMessage, {
46
+ cause: error,
47
+ }, {
48
+ accountId,
49
+ request: dest,
50
+ payload: file,
51
+ });
52
+ };
53
+ async function uploadFile(accountId, file, dest, options, cmsPublishMode = null, onUploadFileError = defaultOnUploadFileError) {
50
54
  const src = options.src;
51
55
  const absoluteSrcPath = path_1.default.resolve((0, path_2.getCwd)(), file);
52
56
  const themeJsonPath = (0, themes_1.getThemeJSONPath)(absoluteSrcPath);
@@ -55,11 +59,11 @@ async function uploadFile(accountId, file, dest, options, mode = null, logCallba
55
59
  : path_1.default.dirname((0, path_2.getCwd)());
56
60
  const convertFields = (0, handleFieldsJS_1.isConvertableFieldJs)(src, file, options.commandOptions.convertFields);
57
61
  if (!(0, path_2.isAllowedExtension)(file) && !convertFields) {
58
- (0, logger_2.debug)(`${i18nKey}.skipUnsupportedExtension`, { file });
62
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.skipUnsupportedExtension`, { file }));
59
63
  return;
60
64
  }
61
65
  if ((0, ignoreRules_1.shouldIgnoreFile)(file)) {
62
- (0, logger_2.debug)(`${i18nKey}.skipIgnoreRule`, { file });
66
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.skipIgnoreRule`, { file }));
63
67
  return;
64
68
  }
65
69
  let fieldsJs = undefined;
@@ -71,57 +75,48 @@ async function uploadFile(accountId, file, dest, options, mode = null, logCallba
71
75
  dest = (0, path_2.convertToUnixPath)(path_1.default.join(path_1.default.dirname(dest), 'fields.json'));
72
76
  }
73
77
  const fileToUpload = convertFields && fieldsJs?.outputPath ? fieldsJs.outputPath : file;
74
- (0, logger_2.debug)(`${i18nKey}.uploadAttempt`, { file, dest });
75
- const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(mode, options);
78
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadAttempt`, { file, dest }));
79
+ const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(cmsPublishMode, options);
76
80
  queue.add(() => {
77
81
  return (0, fileMapper_2.upload)(accountId, fileToUpload, dest, apiOptions)
78
82
  .then(() => {
79
- logger('uploadSuccess', `${i18nKey}.uploadSuccess`, { file, dest });
80
- notifyOfThemePreview(file, accountId, logCallbacks);
83
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadSuccess`, { file, dest }));
84
+ notifyOfThemePreview(file, accountId);
81
85
  })
82
86
  .catch(() => {
83
- (0, logger_2.debug)(`${i18nKey}.uploadFailed`, { file, dest });
84
- (0, logger_2.debug)(`${i18nKey}.uploadRetry`, { file, dest });
85
- return (0, fileMapper_2.upload)(accountId, file, dest, apiOptions).catch((error) => {
86
- (0, logger_2.debug)(`${i18nKey}.uploadFailed`, {
87
- file,
88
- dest,
89
- });
90
- (0, apiErrors_1.throwApiUploadError)(error, {
91
- accountId,
92
- request: dest,
93
- payload: file,
94
- });
95
- });
87
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFailed`, { file, dest }));
88
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadRetry`, { file, dest }));
89
+ return (0, fileMapper_2.upload)(accountId, file, dest, apiOptions).catch(onUploadFileError(file, dest, accountId));
96
90
  });
97
91
  });
98
92
  }
99
- async function deleteRemoteFile(accountId, filePath, remoteFilePath, logCallbacks) {
100
- const logger = makeLogger(logCallbacks);
93
+ async function deleteRemoteFile(accountId, filePath, remoteFilePath) {
101
94
  if ((0, ignoreRules_1.shouldIgnoreFile)(filePath)) {
102
- (0, logger_2.debug)(`${i18nKey}.skipIgnoreRule`, { file: filePath });
95
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.skipIgnoreRule`, { file: filePath }));
103
96
  return;
104
97
  }
105
- (0, logger_2.debug)(`${i18nKey}.deleteAttempt`, { remoteFilePath });
98
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.deleteAttempt`, { remoteFilePath }));
106
99
  return queue.add(() => {
107
100
  return (0, fileMapper_2.deleteFile)(accountId, remoteFilePath)
108
101
  .then(() => {
109
- logger('deleteSuccess', `${i18nKey}.deleteSuccess`, { remoteFilePath });
110
- notifyOfThemePreview(filePath, accountId, logCallbacks);
102
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.deleteSuccess`, { remoteFilePath }));
103
+ notifyOfThemePreview(filePath, accountId);
111
104
  })
112
- .catch((error) => {
113
- (0, logger_2.debug)(`${i18nKey}.deleteFailed`, {
105
+ .catch(error => {
106
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.deleteFailed`, {
114
107
  remoteFilePath,
115
- });
116
- (0, apiErrors_1.throwApiError)(error, {
117
- accountId,
118
- request: remoteFilePath,
119
- });
108
+ }));
109
+ if ((0, errors_1.isHubSpotHttpError)(error)) {
110
+ error.updateContext({
111
+ accountId,
112
+ request: remoteFilePath,
113
+ });
114
+ }
115
+ throw error;
120
116
  });
121
117
  });
122
118
  }
123
- function watch(accountId, src, dest, { mode, remove, disableInitial, notify, commandOptions, filePaths, }, postInitialUploadCallback = null, onUploadFolderError, onQueueAddError, logCallbacks) {
124
- const logger = makeLogger(logCallbacks);
119
+ function watch(accountId, src, dest, { cmsPublishMode, remove, disableInitial, notify, commandOptions, filePaths, }, postInitialUploadCallback = null, onUploadFolderError, onQueueAddError, onUploadFileError) {
125
120
  const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
126
121
  if (notify) {
127
122
  (0, ignoreRules_1.ignoreFile)(notify);
@@ -136,12 +131,12 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
136
131
  }
137
132
  if (!disableInitial) {
138
133
  // Use uploadFolder so that failures of initial upload are retried
139
- const uploadFolderPromise = (0, uploadFolder_1.uploadFolder)(accountId, src, dest, {}, commandOptions, filePaths, mode || null).then(result => {
140
- logger('folderUploadSuccess', `${i18nKey}.folderUploadSuccess`, {
134
+ const uploadFolderPromise = (0, uploadFolder_1.uploadFolder)(accountId, src, dest, {}, commandOptions, filePaths, cmsPublishMode || null).then(result => {
135
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.folderUploadSuccess`, {
141
136
  src,
142
137
  dest,
143
138
  accountId,
144
- });
139
+ }));
145
140
  if (postInitialUploadCallback) {
146
141
  postInitialUploadCallback(result);
147
142
  }
@@ -151,14 +146,14 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
151
146
  }
152
147
  }
153
148
  watcher.on('ready', () => {
154
- logger('ready', `${i18nKey}.ready`, { src });
149
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.ready`, { src }));
155
150
  });
156
151
  watcher.on('add', async (filePath) => {
157
152
  const destPath = getDesignManagerPath(filePath);
158
153
  const uploadPromise = uploadFile(accountId, filePath, destPath, {
159
154
  src,
160
155
  commandOptions,
161
- }, mode, logCallbacks);
156
+ }, cmsPublishMode, onUploadFileError);
162
157
  (0, notify_1.triggerNotify)(notify, 'Added', filePath, uploadPromise);
163
158
  });
164
159
  if (remove) {
@@ -169,19 +164,19 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
169
164
  }
170
165
  const remotePath = getDesignManagerPath(filePath);
171
166
  if ((0, ignoreRules_1.shouldIgnoreFile)(filePath)) {
172
- (0, logger_2.debug)(`${i18nKey}.skipIgnoreRule`, { file: filePath });
167
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.skipIgnoreRule`, { file: filePath }));
173
168
  return;
174
169
  }
175
- (0, logger_2.debug)(`${i18nKey}.deleteAttemptWithType`, {
170
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.deleteAttemptWithType`, {
176
171
  type,
177
172
  remoteFilePath: remotePath,
178
- });
173
+ }));
179
174
  const queueAddPromise = queue.add(() => {
180
- const deletePromise = deleteRemoteFile(accountId, filePath, remotePath, logCallbacks).then(() => {
181
- logger('deleteSuccessWithType', `${i18nKey}.deleteSuccessWithType`, {
175
+ const deletePromise = deleteRemoteFile(accountId, filePath, remotePath).then(() => {
176
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.deleteSuccessWithType`, {
182
177
  type,
183
178
  remoteFilePath: remotePath,
184
- });
179
+ }));
185
180
  });
186
181
  if (onQueueAddError) {
187
182
  queueAddPromise.catch(onQueueAddError);
@@ -198,7 +193,7 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
198
193
  const uploadPromise = uploadFile(accountId, filePath, destPath, {
199
194
  src,
200
195
  commandOptions,
201
- }, mode, logCallbacks);
196
+ }, cmsPublishMode, onUploadFileError);
202
197
  (0, notify_1.triggerNotify)(notify, 'Changed', filePath, uploadPromise);
203
198
  });
204
199
  return watcher;
@@ -9,7 +9,6 @@ const path_1 = __importDefault(require("path"));
9
9
  const prettier_1 = __importDefault(require("prettier"));
10
10
  const path_2 = require("../lib/path");
11
11
  const customObjects_1 = require("../api/customObjects");
12
- const apiErrors_1 = require("../errors/apiErrors");
13
12
  function getResolvedPath(dest, name) {
14
13
  if (name)
15
14
  return path_1.default.resolve((0, path_2.getCwd)(), dest || '', `${name}.json`);
@@ -24,13 +23,8 @@ async function writeSchemaToDisk(schema, dest) {
24
23
  }
25
24
  exports.writeSchemaToDisk = writeSchemaToDisk;
26
25
  async function downloadSchemas(accountId, dest) {
27
- let response;
28
- try {
29
- response = await (0, customObjects_1.fetchObjectSchemas)(accountId);
30
- }
31
- catch (err) {
32
- (0, apiErrors_1.throwApiError)(err);
33
- }
26
+ const axiosResponse = await (0, customObjects_1.fetchObjectSchemas)(accountId);
27
+ const response = axiosResponse.data;
34
28
  if (response.results.length) {
35
29
  for (const schema of response.results) {
36
30
  await writeSchemaToDisk(schema, dest);
@@ -40,13 +34,8 @@ async function downloadSchemas(accountId, dest) {
40
34
  }
41
35
  exports.downloadSchemas = downloadSchemas;
42
36
  async function downloadSchema(accountId, schemaObjectType, dest) {
43
- let response;
44
- try {
45
- response = await (0, customObjects_1.fetchObjectSchema)(accountId, schemaObjectType);
46
- }
47
- catch (err) {
48
- (0, apiErrors_1.throwApiError)(err);
49
- }
37
+ const axiosResponse = await (0, customObjects_1.fetchObjectSchema)(accountId, schemaObjectType);
38
+ const response = axiosResponse.data;
50
39
  await writeSchemaToDisk(response, dest);
51
40
  return response;
52
41
  }
@@ -1,6 +1,2 @@
1
- import { LogCallbacksArg } from '../types/LogCallbacks';
2
- declare const uploadCallbackKeys: readonly ["uploadSuccess"];
3
- declare const downloadCallbackKeys: readonly ["skippedExisting", "fetchFolderStarted", "fetchFolderSuccess", "fetchFileStarted", "fetchFileSuccess"];
4
- export declare function uploadFolder(accountId: number, src: string, dest: string, logCallbacks?: LogCallbacksArg<typeof uploadCallbackKeys>): Promise<void>;
5
- export declare function downloadFileOrFolder(accountId: number, src: string, dest: string, overwrite?: boolean, includeArchived?: boolean, logCallbacks?: LogCallbacksArg<typeof downloadCallbackKeys>): Promise<void>;
6
- export {};
1
+ export declare function uploadFolder(accountId: number, src: string, dest: string): Promise<void>;
2
+ export declare function downloadFileOrFolder(accountId: number, src: string, dest: string, overwrite?: boolean, includeArchived?: boolean): Promise<void>;
@@ -9,25 +9,16 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const fileManager_1 = require("../api/fileManager");
11
11
  const fs_1 = require("./fs");
12
- const logger_1 = require("../utils/logger");
12
+ const logger_1 = require("./logger");
13
13
  const ignoreRules_1 = require("./ignoreRules");
14
- const http_1 = __importDefault(require("../http"));
15
- const escapeRegExp_1 = require("../utils/escapeRegExp");
14
+ const http_1 = require("../http");
15
+ const escapeRegExp_1 = require("./escapeRegExp");
16
16
  const path_2 = require("./path");
17
- const apiErrors_1 = require("../errors/apiErrors");
18
- const standardErrors_1 = require("../errors/standardErrors");
19
- const fileSystemErrors_1 = require("../errors/fileSystemErrors");
17
+ const lang_1 = require("../utils/lang");
18
+ const errors_1 = require("../errors");
19
+ const FileSystemError_1 = require("../models/FileSystemError");
20
20
  const i18nKey = 'lib.fileManager';
21
- const uploadCallbackKeys = ['uploadSuccess'];
22
- const downloadCallbackKeys = [
23
- 'skippedExisting',
24
- 'fetchFolderStarted',
25
- 'fetchFolderSuccess',
26
- 'fetchFileStarted',
27
- 'fetchFileSuccess',
28
- ];
29
- async function uploadFolder(accountId, src, dest, logCallbacks) {
30
- const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
21
+ async function uploadFolder(accountId, src, dest) {
31
22
  const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
32
23
  const files = await (0, fs_1.walk)(src);
33
24
  const filesToUpload = files.filter((0, ignoreRules_1.createIgnoreFilter)(false));
@@ -36,46 +27,48 @@ async function uploadFolder(accountId, src, dest, logCallbacks) {
36
27
  const file = filesToUpload[index];
37
28
  const relativePath = file.replace(regex, '');
38
29
  const destPath = (0, path_2.convertToUnixPath)(path_1.default.join(dest, relativePath));
39
- (0, logger_1.debug)(`${i18nKey}.uploadStarted`, {
30
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadStarted`, {
40
31
  file,
41
32
  destPath,
42
33
  accountId,
43
- });
34
+ }));
44
35
  try {
45
36
  await (0, fileManager_1.uploadFile)(accountId, file, destPath);
46
- logger('uploadSuccess', `${i18nKey}.uploadSuccess`, { file, destPath });
37
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadSuccess`, { file, destPath }));
47
38
  }
48
39
  catch (err) {
49
- const error = err;
50
- if ((0, standardErrors_1.isFatalError)(error)) {
51
- (0, standardErrors_1.throwError)(error);
40
+ if ((0, errors_1.isHubSpotHttpError)(err)) {
41
+ err.updateContext({
42
+ filepath: file,
43
+ dest: destPath,
44
+ });
45
+ throw err;
52
46
  }
53
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.uploadFailed`, {
47
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.uploadFailed`, {
54
48
  file,
55
49
  destPath,
56
- });
50
+ }));
57
51
  }
58
52
  }
59
53
  }
60
54
  exports.uploadFolder = uploadFolder;
61
- async function skipExisting(overwrite, filepath, logCallbacks) {
62
- const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
55
+ async function skipExisting(overwrite, filepath) {
63
56
  if (overwrite) {
64
57
  return false;
65
58
  }
66
59
  if (await fs_extra_1.default.pathExists(filepath)) {
67
- logger('skippedExisting', `${i18nKey}.skippedExisting`, { filepath });
60
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.skippedExisting`, { filepath }));
68
61
  return true;
69
62
  }
70
63
  return false;
71
64
  }
72
- async function downloadFile(accountId, file, dest, overwrite, logCallbacks) {
65
+ async function downloadFile(accountId, file, dest, overwrite) {
73
66
  const fileName = `${file.name}.${file.extension}`;
74
67
  const destPath = (0, path_2.convertToLocalFileSystemPath)(path_1.default.join(dest, fileName));
75
- if (await skipExisting(overwrite || false, destPath, logCallbacks)) {
68
+ if (await skipExisting(overwrite || false, destPath)) {
76
69
  return;
77
70
  }
78
- await http_1.default.getOctetStream(accountId, {
71
+ await http_1.http.getOctetStream(accountId, {
79
72
  baseURL: file.url,
80
73
  url: '',
81
74
  }, destPath);
@@ -86,7 +79,7 @@ async function fetchAllPagedFiles(accountId, folderId, includeArchived) {
86
79
  let count = 0;
87
80
  let offset = 0;
88
81
  while (totalFiles === null || count < totalFiles) {
89
- const response = await (0, fileManager_1.fetchFiles)(accountId, folderId, offset, includeArchived);
82
+ const { data: response } = await (0, fileManager_1.fetchFiles)(accountId, folderId, offset, includeArchived);
90
83
  if (totalFiles === null) {
91
84
  totalFiles = response.total_count;
92
85
  }
@@ -96,34 +89,33 @@ async function fetchAllPagedFiles(accountId, folderId, includeArchived) {
96
89
  }
97
90
  return files;
98
91
  }
99
- async function fetchFolderContents(accountId, folder, dest, overwrite, includeArchived, logCallbacks) {
92
+ async function fetchFolderContents(accountId, folder, dest, overwrite, includeArchived) {
100
93
  try {
101
94
  await fs_extra_1.default.ensureDir(dest);
102
95
  }
103
96
  catch (err) {
104
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
97
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
105
98
  dest,
106
99
  accountId,
107
- write: true,
100
+ operation: 'write',
108
101
  });
109
102
  }
110
103
  const files = await fetchAllPagedFiles(accountId, folder.id, includeArchived);
111
- (0, logger_1.debug)(`${i18nKey}.fetchingFiles`, {
104
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.fetchingFiles`, {
112
105
  fileCount: files.length,
113
106
  folderName: folder.name || '',
114
- });
107
+ }));
115
108
  for (const file of files) {
116
- await downloadFile(accountId, file, dest, overwrite, logCallbacks);
109
+ await downloadFile(accountId, file, dest, overwrite);
117
110
  }
118
- const { objects: folders } = await (0, fileManager_1.fetchFolders)(accountId, folder.id);
111
+ const { data: { objects: folders }, } = await (0, fileManager_1.fetchFolders)(accountId, folder.id);
119
112
  for (const folder of folders) {
120
113
  const nestedFolder = path_1.default.join(dest, folder.name);
121
- await fetchFolderContents(accountId, folder, nestedFolder, overwrite, includeArchived, logCallbacks);
114
+ await fetchFolderContents(accountId, folder, nestedFolder, overwrite, includeArchived);
122
115
  }
123
116
  }
124
117
  // Download a folder and write to local file system.
125
- async function downloadFolder(accountId, src, dest, folder, overwrite, includeArchived, logCallbacks) {
126
- const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
118
+ async function downloadFolder(accountId, src, dest, folder, overwrite, includeArchived) {
127
119
  let absolutePath;
128
120
  if (folder.name) {
129
121
  absolutePath = (0, path_2.convertToLocalFileSystemPath)(path_1.default.resolve((0, path_2.getCwd)(), dest, folder.name));
@@ -131,65 +123,62 @@ async function downloadFolder(accountId, src, dest, folder, overwrite, includeAr
131
123
  else {
132
124
  absolutePath = (0, path_2.convertToLocalFileSystemPath)(path_1.default.resolve((0, path_2.getCwd)(), dest));
133
125
  }
134
- logger('fetchFolderStarted', `${i18nKey}.fetchFolderStarted`, {
126
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.fetchFolderStarted`, {
135
127
  src,
136
128
  path: absolutePath,
137
129
  accountId,
138
- });
139
- await fetchFolderContents(accountId, folder, absolutePath, overwrite, includeArchived, logCallbacks);
140
- logger('fetchFolderSuccess', `${i18nKey}.fetchFolderSuccess`, {
130
+ }));
131
+ await fetchFolderContents(accountId, folder, absolutePath, overwrite, includeArchived);
132
+ logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.fetchFolderSuccess`, {
141
133
  src,
142
134
  dest,
143
- });
135
+ }));
144
136
  }
145
137
  // Download a single file and write to local file system.
146
- async function downloadSingleFile(accountId, src, dest, file, overwrite, includeArchived, logCallbacks) {
147
- const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
138
+ async function downloadSingleFile(accountId, src, dest, file, overwrite, includeArchived) {
148
139
  if (!includeArchived && file.archived) {
149
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.archivedFile`, { src });
140
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.archivedFile`, { src }));
150
141
  }
151
142
  if (file.hidden) {
152
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.hiddenFile`, { src });
143
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.hiddenFile`, { src }));
153
144
  }
154
- logger('fetchFileStarted', `${i18nKey}.fetchFileStarted`, {
145
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.fetchFileStarted`, {
155
146
  src,
156
147
  dest,
157
148
  accountId,
158
- });
159
- await downloadFile(accountId, file, dest, overwrite, logCallbacks);
160
- logger('fetchFileSuccess', `${i18nKey}.fetchFileSuccess`, {
149
+ }));
150
+ await downloadFile(accountId, file, dest, overwrite);
151
+ logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.fetchFileSuccess`, {
161
152
  src,
162
153
  dest,
163
- });
154
+ }));
164
155
  }
165
156
  // Lookup path in file manager and initiate download
166
- async function downloadFileOrFolder(accountId, src, dest, overwrite, includeArchived, logCallbacks) {
157
+ async function downloadFileOrFolder(accountId, src, dest, overwrite, includeArchived) {
167
158
  try {
168
159
  if (src == '/') {
169
160
  // Filemanager API treats 'None' as the root
170
161
  const rootFolder = { id: 'None', name: '' };
171
- await downloadFolder(accountId, src, dest, rootFolder, overwrite, includeArchived, logCallbacks);
162
+ await downloadFolder(accountId, src, dest, rootFolder, overwrite, includeArchived);
172
163
  }
173
164
  else {
174
- const { file, folder } = await (0, fileManager_1.fetchStat)(accountId, src);
165
+ const { data: { file, folder }, } = await (0, fileManager_1.fetchStat)(accountId, src);
175
166
  if (file) {
176
- await downloadSingleFile(accountId, src, dest, file, overwrite, includeArchived, logCallbacks);
167
+ await downloadSingleFile(accountId, src, dest, file, overwrite, includeArchived);
177
168
  }
178
169
  else if (folder) {
179
- await downloadFolder(accountId, src, dest, folder, overwrite, includeArchived, logCallbacks);
170
+ await downloadFolder(accountId, src, dest, folder, overwrite, includeArchived);
180
171
  }
181
172
  }
182
173
  }
183
174
  catch (err) {
184
- const error = err;
185
- if (error.isAxiosError) {
186
- (0, apiErrors_1.throwApiError)(err, {
175
+ if ((0, errors_1.isAuthError)(err)) {
176
+ err.updateContext({
187
177
  request: src,
188
178
  accountId,
189
179
  });
190
180
  }
191
- else
192
- (0, standardErrors_1.throwError)(error);
181
+ throw err;
193
182
  }
194
183
  }
195
184
  exports.downloadFileOrFolder = downloadFileOrFolder;
@@ -1,23 +1,13 @@
1
- import { FileMapperNode, Mode, FileMapperOptions, FileMapperInputOptions } from '../types/Files';
2
- import { LogCallbacksArg } from '../types/LogCallbacks';
3
- declare const filemapperCallbackKeys: readonly ["skippedExisting", "wroteFolder", "completedFetch", "folderFetch", "completedFolderFetch"];
1
+ import { FileMapperNode, CmsPublishMode, FileMapperOptions, FileMapperInputOptions, PathTypeData, RecursiveFileMapperCallback } from '../types/Files';
4
2
  export declare function isPathToFile(filepath: string): boolean;
5
3
  export declare function isPathToModule(filepath: string): boolean;
6
4
  export declare function isPathToRoot(filepath: string): boolean;
7
5
  export declare function isPathToHubspot(filepath: string): boolean;
8
- export declare function getFileMapperQueryValues(mode?: Mode | null, { staging, assetVersion }?: FileMapperInputOptions): FileMapperOptions;
9
- type PathTypeData = {
10
- isModule: boolean;
11
- isHubspot: boolean;
12
- isFile: boolean;
13
- isRoot: boolean;
14
- isFolder: boolean;
15
- };
6
+ export declare function getFileMapperQueryValues(cmsPublishMode?: CmsPublishMode | null, { staging, assetVersion }?: FileMapperInputOptions): FileMapperOptions;
16
7
  export declare function getTypeDataFromPath(src: string): PathTypeData;
17
- type RecursiveFileMapperCallback = (node: FileMapperNode, filepath?: string, depth?: number) => boolean;
18
8
  export declare function recurseFolder(node: FileMapperNode, callback: RecursiveFileMapperCallback, filepath?: string, depth?: number): boolean;
19
9
  export declare function writeUtimes(accountId: number, filepath: string, node: FileMapperNode): Promise<void>;
20
- export declare function fetchFolderFromApi(accountId: number, src: string, mode?: Mode, options?: FileMapperInputOptions, logCallbacks?: LogCallbacksArg<typeof filemapperCallbackKeys>): Promise<FileMapperNode>;
10
+ export declare function fetchFolderFromApi(accountId: number, src: string, cmsPublishMode?: CmsPublishMode, options?: FileMapperInputOptions): Promise<FileMapperNode>;
21
11
  /**
22
12
  * Fetch a file/folder and write to local file system.
23
13
  *
@@ -25,5 +15,4 @@ export declare function fetchFolderFromApi(accountId: number, src: string, mode?
25
15
  * @param {FileMapperInputArguments} input
26
16
  * @returns {Promise}
27
17
  */
28
- export declare function downloadFileOrFolder(accountId: number, src: string, dest: string, mode?: Mode, options?: FileMapperInputOptions, logCallbacks?: LogCallbacksArg<typeof filemapperCallbackKeys>): Promise<void>;
29
- export {};
18
+ export declare function downloadFileOrFolder(accountId: number, src: string, dest: string, cmsPublishMode?: CmsPublishMode, options?: FileMapperInputOptions): Promise<void>;