@hubspot/local-dev-lib 1.13.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/appsDev.d.ts +6 -5
- package/api/appsDev.js +6 -10
- package/api/customObjects.d.ts +7 -6
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +3 -2
- package/api/designManager.js +5 -8
- package/api/developerTestAccounts.d.ts +5 -4
- package/api/developerTestAccounts.js +9 -10
- package/api/fileManager.d.ts +5 -4
- package/api/fileManager.js +9 -9
- package/api/fileMapper.d.ts +8 -8
- package/api/fileMapper.js +16 -16
- package/api/fileTransport.d.ts +4 -3
- package/api/fileTransport.js +5 -5
- package/api/functions.d.ts +6 -5
- package/api/functions.js +11 -14
- package/api/github.d.ts +6 -6
- package/api/github.js +5 -5
- package/api/hubdb.d.ts +9 -8
- package/api/hubdb.js +17 -20
- package/api/lighthouseScore.d.ts +4 -3
- package/api/lighthouseScore.js +7 -10
- package/api/localDevAuth.d.ts +5 -4
- package/api/localDevAuth.js +8 -9
- package/api/marketplaceValidation.d.ts +4 -3
- package/api/marketplaceValidation.js +4 -7
- package/api/projects.d.ts +31 -30
- package/api/projects.js +52 -52
- package/api/sandboxHubs.d.ts +5 -4
- package/api/sandboxHubs.js +9 -10
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +5 -14
- package/api/secrets.d.ts +5 -4
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +3 -3
- package/config/CLIConfiguration.js +22 -20
- package/config/configFile.js +7 -14
- package/config/config_DEPRECATED.js +5 -2
- package/config/index.js +45 -48
- package/errors/errors_DEPRECATED.js +2 -2
- package/errors/index.d.ts +18 -0
- package/errors/index.js +63 -0
- package/http/addQueryParams.d.ts +2 -0
- package/http/addQueryParams.js +14 -0
- package/http/getAxiosConfig.d.ts +2 -2
- package/http/getAxiosConfig.js +10 -2
- package/http/index.d.ts +9 -14
- package/http/index.js +28 -53
- package/http/unauthed.d.ts +15 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +2 -2
- package/lang/lang/en.json +2 -2
- package/lib/archive.js +11 -10
- package/lib/cms/functions.js +18 -17
- package/lib/cms/handleFieldsJS.js +8 -7
- package/lib/cms/modules.js +4 -5
- package/lib/cms/processFieldsJs.js +8 -7
- package/lib/cms/templates.js +2 -3
- package/lib/cms/uploadFolder.js +16 -14
- package/lib/cms/validate.js +1 -1
- package/lib/cms/watch.js +16 -9
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.js +22 -21
- package/lib/fileMapper.js +24 -31
- package/lib/fs.js +2 -2
- package/lib/github.js +21 -21
- package/lib/gitignore.js +2 -2
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/lib/notify.js +2 -2
- package/lib/oauth.d.ts +1 -1
- package/lib/oauth.js +8 -17
- package/lib/personalAccessKey.js +16 -21
- package/lib/portManager.js +2 -2
- package/lib/trackUsage.js +12 -6
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +24 -0
- package/models/HubSpotHttpError.js +197 -0
- package/models/OAuth2Manager.d.ts +1 -2
- package/models/OAuth2Manager.js +13 -28
- package/package.json +2 -1
- package/types/Error.d.ts +7 -5
- package/types/Files.d.ts +4 -4
- package/types/Http.d.ts +6 -10
- package/types/Sandbox.d.ts +0 -5
- package/utils/PortManagerServer.d.ts +3 -3
- package/utils/PortManagerServer.js +9 -9
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/errors/apiErrors.d.ts +0 -25
- package/errors/apiErrors.js +0 -176
- package/errors/fileSystemErrors.d.ts +0 -6
- package/errors/fileSystemErrors.js +0 -35
- package/errors/standardErrors.d.ts +0 -20
- package/errors/standardErrors.js +0 -62
- package/lib/developerTestAccounts.d.ts +0 -4
- package/lib/developerTestAccounts.js +0 -35
- package/lib/sandboxes.d.ts +0 -14
- package/lib/sandboxes.js +0 -70
- package/models/HubSpotAuthError.d.ts +0 -12
- package/models/HubSpotAuthError.js +0 -20
|
@@ -9,7 +9,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
9
9
|
const semver_1 = __importDefault(require("semver"));
|
|
10
10
|
const url_1 = require("url");
|
|
11
11
|
const path_2 = require("../path");
|
|
12
|
-
const standardErrors_1 = require("../../errors/standardErrors");
|
|
13
12
|
const lang_1 = require("../../utils/lang");
|
|
14
13
|
const i18nKey = 'lib.cms.processFieldsJs';
|
|
15
14
|
const { dirName, fieldOptions, filePath, writeDir } = process.env;
|
|
@@ -25,21 +24,23 @@ console.info((0, lang_1.i18n)(`${i18nKey}.converting`, {
|
|
|
25
24
|
* This function has optional return type of Promise<Array> | Array. In order to have uniform handling,
|
|
26
25
|
* we wrap the return value of the function in a Promise.resolve(), and then process.
|
|
27
26
|
*/
|
|
28
|
-
const fieldsPromise = dynamicImport(filePath).catch(e =>
|
|
27
|
+
const fieldsPromise = dynamicImport(filePath).catch(e => {
|
|
28
|
+
throw e;
|
|
29
|
+
});
|
|
29
30
|
fieldsPromise.then(fieldsFunc => {
|
|
30
31
|
const fieldsFuncType = typeof fieldsFunc;
|
|
31
32
|
if (fieldsFuncType !== 'function') {
|
|
32
|
-
(0,
|
|
33
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.notFunction`, {
|
|
33
34
|
path: filePath,
|
|
34
35
|
returned: fieldsFuncType,
|
|
35
|
-
});
|
|
36
|
+
}));
|
|
36
37
|
}
|
|
37
38
|
return Promise.resolve(fieldsFunc(fieldOptions)).then(fields => {
|
|
38
39
|
if (!Array.isArray(fields)) {
|
|
39
|
-
(0,
|
|
40
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.notArray`, {
|
|
40
41
|
path: filePath,
|
|
41
42
|
returned: typeof fields,
|
|
42
|
-
});
|
|
43
|
+
}));
|
|
43
44
|
}
|
|
44
45
|
const finalPath = path_1.default.join(writeDir, '/fields.json');
|
|
45
46
|
return fieldsArrayToJson(fields).then(json => {
|
|
@@ -89,7 +90,7 @@ async function dynamicImport(filePath) {
|
|
|
89
90
|
}
|
|
90
91
|
else {
|
|
91
92
|
if ((0, path_2.getExt)(filePath) == 'mjs') {
|
|
92
|
-
(0,
|
|
93
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidMjsFile`));
|
|
93
94
|
}
|
|
94
95
|
return require(filePath);
|
|
95
96
|
}
|
package/lib/cms/templates.js
CHANGED
|
@@ -7,7 +7,6 @@ exports.TEMPLATE_TYPES = exports.createTemplate = exports.isCodedFile = exports.
|
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const github_1 = require("../github");
|
|
10
|
-
const standardErrors_1 = require("../../errors/standardErrors");
|
|
11
10
|
const logger_1 = require("../logger");
|
|
12
11
|
const lang_1 = require("../../utils/lang");
|
|
13
12
|
const i18nKey = 'lib.cms.templates';
|
|
@@ -52,9 +51,9 @@ async function createTemplate(name, dest, type = 'page-template', options = { al
|
|
|
52
51
|
const filename = name.endsWith('.html') ? name : `${name}.html`;
|
|
53
52
|
const filePath = path_1.default.join(dest, filename);
|
|
54
53
|
if (!options.allowExisting && fs_extra_1.default.existsSync(filePath)) {
|
|
55
|
-
(0,
|
|
54
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.createTemplate.errors.pathExists`, {
|
|
56
55
|
path: filePath,
|
|
57
|
-
});
|
|
56
|
+
}));
|
|
58
57
|
}
|
|
59
58
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createTemplate.creatingPath`, { path: dest }));
|
|
60
59
|
fs_extra_1.default.mkdirp(dest);
|
package/lib/cms/uploadFolder.js
CHANGED
|
@@ -12,11 +12,11 @@ const fileMapper_2 = require("../../api/fileMapper");
|
|
|
12
12
|
const modules_1 = require("../../utils/cms/modules");
|
|
13
13
|
const escapeRegExp_1 = require("../escapeRegExp");
|
|
14
14
|
const path_2 = require("../path");
|
|
15
|
-
const
|
|
16
|
-
const apiErrors_1 = require("../../errors/apiErrors");
|
|
15
|
+
const errors_1 = require("../../errors");
|
|
17
16
|
const logger_1 = require("../logger");
|
|
18
17
|
const files_1 = require("../../constants/files");
|
|
19
18
|
const lang_1 = require("../../utils/lang");
|
|
19
|
+
const HubSpotHttpError_1 = require("../../models/HubSpotHttpError");
|
|
20
20
|
const i18nKey = 'lib.cms.uploadFolder';
|
|
21
21
|
const queue = new p_queue_1.default({
|
|
22
22
|
concurrency: 10,
|
|
@@ -86,17 +86,21 @@ const defaultUploadSuccessCallback = (file, destPath) => logger_1.logger.log((0,
|
|
|
86
86
|
}));
|
|
87
87
|
const defaultUploadFirstErrorCallback = (file, destPath, error) => {
|
|
88
88
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.failed`, { file, destPath }));
|
|
89
|
-
if (
|
|
90
|
-
logger_1.logger.debug(error.
|
|
89
|
+
if ((0, errors_1.isHubSpotHttpError)(error)) {
|
|
90
|
+
logger_1.logger.debug(error.data);
|
|
91
91
|
}
|
|
92
|
-
else {
|
|
92
|
+
else if (error instanceof Error) {
|
|
93
93
|
logger_1.logger.debug(error.message);
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
const defaultUploadRetryCallback = (file, destPath) => logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.retry`, { file, destPath }));
|
|
97
97
|
const defaultUploadFinalErrorCallback = (accountId, file, destPath, error) => {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const retryFailed = (0, lang_1.i18n)(`${i18nKey}.uploadFolder.retryFailed`, {
|
|
99
|
+
file,
|
|
100
|
+
destPath,
|
|
101
|
+
});
|
|
102
|
+
logger_1.logger.debug(retryFailed);
|
|
103
|
+
throw new HubSpotHttpError_1.HubSpotHttpError(retryFailed, { cause: error }, {
|
|
100
104
|
accountId,
|
|
101
105
|
request: destPath,
|
|
102
106
|
payload: file,
|
|
@@ -140,11 +144,10 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
140
144
|
_onSuccessCallback(originalFilePath, destPath);
|
|
141
145
|
}
|
|
142
146
|
catch (err) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
throw error;
|
|
147
|
+
if ((0, errors_1.isAuthError)(err)) {
|
|
148
|
+
throw err;
|
|
146
149
|
}
|
|
147
|
-
_onFirstErrorCallback(file, destPath,
|
|
150
|
+
_onFirstErrorCallback(file, destPath, err);
|
|
148
151
|
failures.push({
|
|
149
152
|
file,
|
|
150
153
|
destPath,
|
|
@@ -169,9 +172,8 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
169
172
|
file,
|
|
170
173
|
};
|
|
171
174
|
}
|
|
172
|
-
catch (
|
|
173
|
-
|
|
174
|
-
if ((0, standardErrors_1.isFatalError)(error)) {
|
|
175
|
+
catch (error) {
|
|
176
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
175
177
|
throw error;
|
|
176
178
|
}
|
|
177
179
|
_onFinalErrorCallback(accountId, file, destPath, error);
|
package/lib/cms/validate.js
CHANGED
|
@@ -26,7 +26,7 @@ async function lint(accountId, filepath, callback) {
|
|
|
26
26
|
}
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
|
-
const validation = await (0, validateHubl_1.validateHubl)(accountId, source);
|
|
29
|
+
const { data: validation } = await (0, validateHubl_1.validateHubl)(accountId, source);
|
|
30
30
|
const result = {
|
|
31
31
|
file,
|
|
32
32
|
validation,
|
package/lib/cms/watch.js
CHANGED
|
@@ -8,7 +8,6 @@ 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
10
|
const debounce_1 = __importDefault(require("debounce"));
|
|
11
|
-
const apiErrors_1 = require("../../errors/apiErrors");
|
|
12
11
|
const handleFieldsJS_1 = require("./handleFieldsJS");
|
|
13
12
|
const uploadFolder_1 = require("./uploadFolder");
|
|
14
13
|
const ignoreRules_1 = require("../ignoreRules");
|
|
@@ -20,6 +19,8 @@ const notify_1 = require("../notify");
|
|
|
20
19
|
const themes_1 = require("./themes");
|
|
21
20
|
const logger_1 = require("../logger");
|
|
22
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
25
|
const queue = new p_queue_1.default({
|
|
25
26
|
concurrency: 10,
|
|
@@ -36,11 +37,14 @@ function _notifyOfThemePreview(filePath, accountId) {
|
|
|
36
37
|
}
|
|
37
38
|
const notifyOfThemePreview = (0, debounce_1.default)(_notifyOfThemePreview, 1000);
|
|
38
39
|
const defaultOnUploadFileError = (file, dest, accountId) => (error) => {
|
|
39
|
-
|
|
40
|
+
const uploadFailedMessage = (0, lang_1.i18n)(`${i18nKey}.uploadFailed`, {
|
|
40
41
|
file,
|
|
41
42
|
dest,
|
|
42
|
-
})
|
|
43
|
-
(
|
|
43
|
+
});
|
|
44
|
+
logger_1.logger.debug(uploadFailedMessage);
|
|
45
|
+
throw new HubSpotHttpError_1.HubSpotHttpError(uploadFailedMessage, {
|
|
46
|
+
cause: error,
|
|
47
|
+
}, {
|
|
44
48
|
accountId,
|
|
45
49
|
request: dest,
|
|
46
50
|
payload: file,
|
|
@@ -98,14 +102,17 @@ async function deleteRemoteFile(accountId, filePath, remoteFilePath) {
|
|
|
98
102
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.deleteSuccess`, { remoteFilePath }));
|
|
99
103
|
notifyOfThemePreview(filePath, accountId);
|
|
100
104
|
})
|
|
101
|
-
.catch(
|
|
105
|
+
.catch(error => {
|
|
102
106
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.deleteFailed`, {
|
|
103
107
|
remoteFilePath,
|
|
104
108
|
}));
|
|
105
|
-
(0,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
if ((0, errors_1.isHubSpotHttpError)(error)) {
|
|
110
|
+
error.updateContext({
|
|
111
|
+
accountId,
|
|
112
|
+
request: remoteFilePath,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
throw error;
|
|
109
116
|
});
|
|
110
117
|
});
|
|
111
118
|
}
|
package/lib/customObjects.js
CHANGED
|
@@ -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
|
-
|
|
28
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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
|
}
|
package/lib/fileManager.js
CHANGED
|
@@ -11,13 +11,12 @@ const fileManager_1 = require("../api/fileManager");
|
|
|
11
11
|
const fs_1 = require("./fs");
|
|
12
12
|
const logger_1 = require("./logger");
|
|
13
13
|
const ignoreRules_1 = require("./ignoreRules");
|
|
14
|
-
const http_1 =
|
|
14
|
+
const http_1 = require("../http");
|
|
15
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");
|
|
20
17
|
const lang_1 = require("../utils/lang");
|
|
18
|
+
const errors_1 = require("../errors");
|
|
19
|
+
const FileSystemError_1 = require("../models/FileSystemError");
|
|
21
20
|
const i18nKey = 'lib.fileManager';
|
|
22
21
|
async function uploadFolder(accountId, src, dest) {
|
|
23
22
|
const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
|
|
@@ -38,13 +37,17 @@ async function uploadFolder(accountId, src, dest) {
|
|
|
38
37
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadSuccess`, { file, destPath }));
|
|
39
38
|
}
|
|
40
39
|
catch (err) {
|
|
41
|
-
if ((0,
|
|
42
|
-
|
|
40
|
+
if ((0, errors_1.isHubSpotHttpError)(err)) {
|
|
41
|
+
err.updateContext({
|
|
42
|
+
filepath: file,
|
|
43
|
+
dest: destPath,
|
|
44
|
+
});
|
|
45
|
+
throw err;
|
|
43
46
|
}
|
|
44
|
-
(0,
|
|
47
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.uploadFailed`, {
|
|
45
48
|
file,
|
|
46
49
|
destPath,
|
|
47
|
-
});
|
|
50
|
+
}));
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
}
|
|
@@ -65,7 +68,7 @@ async function downloadFile(accountId, file, dest, overwrite) {
|
|
|
65
68
|
if (await skipExisting(overwrite || false, destPath)) {
|
|
66
69
|
return;
|
|
67
70
|
}
|
|
68
|
-
await http_1.
|
|
71
|
+
await http_1.http.getOctetStream(accountId, {
|
|
69
72
|
baseURL: file.url,
|
|
70
73
|
url: '',
|
|
71
74
|
}, destPath);
|
|
@@ -76,7 +79,7 @@ async function fetchAllPagedFiles(accountId, folderId, includeArchived) {
|
|
|
76
79
|
let count = 0;
|
|
77
80
|
let offset = 0;
|
|
78
81
|
while (totalFiles === null || count < totalFiles) {
|
|
79
|
-
const response = await (0, fileManager_1.fetchFiles)(accountId, folderId, offset, includeArchived);
|
|
82
|
+
const { data: response } = await (0, fileManager_1.fetchFiles)(accountId, folderId, offset, includeArchived);
|
|
80
83
|
if (totalFiles === null) {
|
|
81
84
|
totalFiles = response.total_count;
|
|
82
85
|
}
|
|
@@ -91,10 +94,10 @@ async function fetchFolderContents(accountId, folder, dest, overwrite, includeAr
|
|
|
91
94
|
await fs_extra_1.default.ensureDir(dest);
|
|
92
95
|
}
|
|
93
96
|
catch (err) {
|
|
94
|
-
|
|
97
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
95
98
|
dest,
|
|
96
99
|
accountId,
|
|
97
|
-
|
|
100
|
+
operation: 'write',
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
103
|
const files = await fetchAllPagedFiles(accountId, folder.id, includeArchived);
|
|
@@ -105,7 +108,7 @@ async function fetchFolderContents(accountId, folder, dest, overwrite, includeAr
|
|
|
105
108
|
for (const file of files) {
|
|
106
109
|
await downloadFile(accountId, file, dest, overwrite);
|
|
107
110
|
}
|
|
108
|
-
const { objects: folders } = await (0, fileManager_1.fetchFolders)(accountId, folder.id);
|
|
111
|
+
const { data: { objects: folders }, } = await (0, fileManager_1.fetchFolders)(accountId, folder.id);
|
|
109
112
|
for (const folder of folders) {
|
|
110
113
|
const nestedFolder = path_1.default.join(dest, folder.name);
|
|
111
114
|
await fetchFolderContents(accountId, folder, nestedFolder, overwrite, includeArchived);
|
|
@@ -134,10 +137,10 @@ async function downloadFolder(accountId, src, dest, folder, overwrite, includeAr
|
|
|
134
137
|
// Download a single file and write to local file system.
|
|
135
138
|
async function downloadSingleFile(accountId, src, dest, file, overwrite, includeArchived) {
|
|
136
139
|
if (!includeArchived && file.archived) {
|
|
137
|
-
(0,
|
|
140
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.archivedFile`, { src }));
|
|
138
141
|
}
|
|
139
142
|
if (file.hidden) {
|
|
140
|
-
(0,
|
|
143
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.hiddenFile`, { src }));
|
|
141
144
|
}
|
|
142
145
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.fetchFileStarted`, {
|
|
143
146
|
src,
|
|
@@ -159,7 +162,7 @@ async function downloadFileOrFolder(accountId, src, dest, overwrite, includeArch
|
|
|
159
162
|
await downloadFolder(accountId, src, dest, rootFolder, overwrite, includeArchived);
|
|
160
163
|
}
|
|
161
164
|
else {
|
|
162
|
-
const { file, folder } = await (0, fileManager_1.fetchStat)(accountId, src);
|
|
165
|
+
const { data: { file, folder }, } = await (0, fileManager_1.fetchStat)(accountId, src);
|
|
163
166
|
if (file) {
|
|
164
167
|
await downloadSingleFile(accountId, src, dest, file, overwrite, includeArchived);
|
|
165
168
|
}
|
|
@@ -169,15 +172,13 @@ async function downloadFileOrFolder(accountId, src, dest, overwrite, includeArch
|
|
|
169
172
|
}
|
|
170
173
|
}
|
|
171
174
|
catch (err) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
(0, apiErrors_1.throwApiError)(err, {
|
|
175
|
+
if ((0, errors_1.isAuthError)(err)) {
|
|
176
|
+
err.updateContext({
|
|
175
177
|
request: src,
|
|
176
178
|
accountId,
|
|
177
179
|
});
|
|
178
180
|
}
|
|
179
|
-
|
|
180
|
-
(0, standardErrors_1.throwError)(error);
|
|
181
|
+
throw err;
|
|
181
182
|
}
|
|
182
183
|
}
|
|
183
184
|
exports.downloadFileOrFolder = downloadFileOrFolder;
|
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
|
|
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,
|
|
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
|
-
|
|
127
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
129
128
|
filepath,
|
|
130
129
|
accountId,
|
|
131
|
-
|
|
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,
|
|
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
|
-
|
|
184
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
192
185
|
filepath: localFilepath,
|
|
193
186
|
accountId,
|
|
194
|
-
|
|
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,
|
|
236
|
-
(0,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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,
|
|
298
|
-
(0,
|
|
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,
|
|
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
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
|
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,
|
|
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 {
|
|
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<
|
|
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
|
}>;
|