@hubspot/local-dev-lib 0.0.7 → 0.0.9
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/customObjects.js +3 -3
- package/api/fileMapper.d.ts +2 -0
- package/api/fileMapper.js +3 -2
- package/api/functions.js +1 -1
- package/api/hubdb.js +4 -4
- package/api/lighthouseScore.d.ts +2 -2
- package/api/lighthouseScore.js +2 -2
- package/api/localDevAuth.d.ts +5 -1
- package/api/localDevAuth.js +1 -1
- package/api/marketplaceValidation.d.ts +2 -2
- package/api/marketplaceValidation.js +2 -2
- package/api/projects.js +2 -2
- package/api/sandboxHubs.js +1 -1
- package/api/sandboxSync.js +1 -1
- package/api/secrets.js +2 -2
- package/api/validateHubl.js +1 -1
- package/config/CLIConfiguration.js +20 -18
- package/config/configFile.js +1 -2
- package/config/configUtils.js +2 -1
- package/config/config_DEPRECATED.js +27 -24
- package/config/environment.js +4 -3
- package/constants/ports.d.ts +3 -0
- package/constants/ports.js +6 -0
- package/errors/apiErrors.d.ts +1 -1
- package/errors/apiErrors.js +13 -13
- package/errors/errors_DEPRECATED.js +2 -2
- package/errors/fileSystemErrors.js +1 -1
- package/errors/standardErrors.d.ts +4 -3
- package/errors/standardErrors.js +2 -2
- package/http/index.js +8 -4
- package/lang/en.json +383 -0
- package/lang/lang/en.json +383 -0
- package/lib/archive.js +10 -9
- package/lib/cms/functions.js +13 -13
- package/lib/cms/handleFieldsJS.js +8 -6
- package/lib/cms/modules.js +5 -4
- package/lib/cms/processFieldsJs.js +6 -8
- package/lib/cms/templates.js +10 -5
- package/lib/cms/uploadFolder.js +11 -7
- package/lib/cms/watch.js +33 -21
- package/lib/customObjects.d.ts +4 -4
- package/lib/customObjects.js +21 -4
- package/lib/fileMapper.js +28 -21
- package/lib/github.js +15 -11
- package/lib/gitignore.js +2 -1
- package/lib/hubdb.d.ts +1 -1
- package/lib/hubdb.js +5 -4
- package/lib/logging/git.js +1 -1
- package/lib/logging/logs.js +5 -1
- package/lib/oauth.js +5 -4
- package/lib/personalAccessKey.d.ts +1 -1
- package/lib/personalAccessKey.js +6 -5
- package/lib/portManager.d.ts +13 -0
- package/lib/portManager.js +45 -0
- package/lib/sandboxes.js +7 -7
- package/lib/trackUsage.js +3 -3
- package/models/HubSpotAuthError.d.ts +1 -1
- package/models/HubSpotAuthError.js +2 -2
- package/models/OAuth2Manager.d.ts +1 -1
- package/models/OAuth2Manager.js +5 -5
- package/package.json +7 -2
- package/types/Error.d.ts +3 -3
- package/types/Http.d.ts +8 -11
- package/types/Hubdb.d.ts +27 -17
- package/types/Lang.d.ts +7 -0
- package/types/Lang.js +2 -0
- package/types/PortManager.d.ts +4 -0
- package/types/PortManager.js +2 -0
- package/types/Schemas.d.ts +18 -33
- package/types/Utils.d.ts +5 -0
- package/utils/PortManagerServer.d.ts +29 -0
- package/utils/PortManagerServer.js +158 -0
- package/utils/cms/modules.js +2 -1
- package/utils/detectPort.d.ts +1 -0
- package/utils/detectPort.js +102 -0
- package/utils/lang.d.ts +2 -4
- package/utils/lang.js +12 -14
- package/utils/logger.d.ts +4 -3
- package/utils/logger.js +4 -3
- package/utils/notify.js +2 -1
- package/lang/en.lyaml +0 -247
|
@@ -34,13 +34,9 @@ const url_1 = require("url");
|
|
|
34
34
|
const path_2 = require("../path");
|
|
35
35
|
const standardErrors_1 = require("../../errors/standardErrors");
|
|
36
36
|
const lang_1 = require("../../utils/lang");
|
|
37
|
-
const i18nKey = 'processFieldsJs';
|
|
37
|
+
const i18nKey = 'lib.cms.processFieldsJs';
|
|
38
38
|
const { dirName, fieldOptions, filePath, writeDir } = process.env;
|
|
39
39
|
const baseName = path_1.default.basename(filePath);
|
|
40
|
-
const FieldErrors = {
|
|
41
|
-
IsNotFunction: 'IsNotFunction',
|
|
42
|
-
DoesNotReturnArray: 'DoesNotReturnArray',
|
|
43
|
-
};
|
|
44
40
|
//TODO - Figure out agnostic logging
|
|
45
41
|
console.info((0, lang_1.i18n)(`${i18nKey}.converting`, {
|
|
46
42
|
src: dirName + `/${baseName}`,
|
|
@@ -56,14 +52,16 @@ const fieldsPromise = dynamicImport(filePath).catch(e => (0, standardErrors_1.th
|
|
|
56
52
|
fieldsPromise.then(fieldsFunc => {
|
|
57
53
|
const fieldsFuncType = typeof fieldsFunc;
|
|
58
54
|
if (fieldsFuncType !== 'function') {
|
|
59
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}
|
|
55
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.notFunction`, {
|
|
60
56
|
path: filePath,
|
|
57
|
+
returned: fieldsFuncType,
|
|
61
58
|
});
|
|
62
59
|
}
|
|
63
60
|
return Promise.resolve(fieldsFunc(fieldOptions)).then(fields => {
|
|
64
61
|
if (!Array.isArray(fields)) {
|
|
65
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}
|
|
62
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.notArray`, {
|
|
66
63
|
path: filePath,
|
|
64
|
+
returned: typeof fields,
|
|
67
65
|
});
|
|
68
66
|
}
|
|
69
67
|
const finalPath = path_1.default.join(writeDir, '/fields.json');
|
|
@@ -115,7 +113,7 @@ async function dynamicImport(filePath) {
|
|
|
115
113
|
}
|
|
116
114
|
else {
|
|
117
115
|
if ((0, path_2.getExt)(filePath) == 'mjs') {
|
|
118
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.invalidMjsFile`);
|
|
116
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidMjsFile`);
|
|
119
117
|
}
|
|
120
118
|
return require(filePath);
|
|
121
119
|
}
|
package/lib/cms/templates.js
CHANGED
|
@@ -6,9 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createTemplate = exports.isCodedFile = exports.getAnnotationValue = exports.ANNOTATION_KEYS = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const github_1 = require("
|
|
9
|
+
const github_1 = require("../github");
|
|
10
10
|
const standardErrors_1 = require("../../errors/standardErrors");
|
|
11
11
|
const logger_1 = require("../../utils/logger");
|
|
12
|
+
const i18nKey = 'lib.cms.templates';
|
|
12
13
|
// Matches the .html file extension, excluding module.html
|
|
13
14
|
const TEMPLATE_EXTENSION_REGEX = new RegExp(/(?<!module)\.html$/);
|
|
14
15
|
// Matches an annotation value, ending at space, newline, or end of string
|
|
@@ -51,12 +52,16 @@ async function createTemplate(name, dest, type = 'page-template', options = { al
|
|
|
51
52
|
const filename = name.endsWith('.html') ? name : `${name}.html`;
|
|
52
53
|
const filePath = path_1.default.join(dest, filename);
|
|
53
54
|
if (!options.allowExisting && fs_extra_1.default.existsSync(filePath)) {
|
|
54
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
55
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createTemplate.errors.pathExists`, {
|
|
56
|
+
path: filePath,
|
|
57
|
+
});
|
|
55
58
|
}
|
|
56
|
-
(0, logger_1.debug)(
|
|
59
|
+
(0, logger_1.debug)(`${i18nKey}.createTemplate.creatingPath`, { path: dest });
|
|
57
60
|
fs_extra_1.default.mkdirp(dest);
|
|
58
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks
|
|
59
|
-
logger('creatingFile', {
|
|
61
|
+
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
62
|
+
logger('creatingFile', `${i18nKey}.createTemplate.creatingFile`, {
|
|
63
|
+
path: filePath,
|
|
64
|
+
});
|
|
60
65
|
await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', assetPath, filePath);
|
|
61
66
|
}
|
|
62
67
|
exports.createTemplate = createTemplate;
|
package/lib/cms/uploadFolder.js
CHANGED
|
@@ -17,6 +17,7 @@ const standardErrors_1 = require("../../errors/standardErrors");
|
|
|
17
17
|
const apiErrors_1 = require("../../errors/apiErrors");
|
|
18
18
|
const logger_2 = require("../../utils/logger");
|
|
19
19
|
const files_1 = require("../../constants/files");
|
|
20
|
+
const i18nKey = 'lib.cms.uploadFolder';
|
|
20
21
|
const queue = new p_queue_1.default({
|
|
21
22
|
concurrency: 10,
|
|
22
23
|
});
|
|
@@ -77,7 +78,7 @@ async function getFilesByType(filePaths, projectDir, rootWriteDir, commandOption
|
|
|
77
78
|
exports.getFilesByType = getFilesByType;
|
|
78
79
|
const uploadFolderCallbackKeys = ['success'];
|
|
79
80
|
async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOptions = {}, filePaths = [], mode = null, logCallbacks) {
|
|
80
|
-
const logger = (0, logger_2.makeTypedLogger)(logCallbacks
|
|
81
|
+
const logger = (0, logger_2.makeTypedLogger)(logCallbacks);
|
|
81
82
|
const { saveOutput, convertFields } = commandOptions;
|
|
82
83
|
const tmpDir = convertFields
|
|
83
84
|
? (0, handleFieldsJS_1.createTmpDirSync)('hubspot-temp-fieldsjs-output-')
|
|
@@ -104,13 +105,13 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
104
105
|
const relativePath = file.replace(fieldsJsFileInfo ? tmpDirRegex : regex, '');
|
|
105
106
|
const destPath = (0, path_2.convertToUnixPath)(path_1.default.join(dest, relativePath));
|
|
106
107
|
return async () => {
|
|
107
|
-
(0, logger_1.debug)(
|
|
108
|
+
(0, logger_1.debug)(`${i18nKey}.uploadFolder.attempt`, {
|
|
108
109
|
file: originalFilePath || '',
|
|
109
110
|
destPath,
|
|
110
111
|
});
|
|
111
112
|
try {
|
|
112
113
|
await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
|
|
113
|
-
logger('success', {
|
|
114
|
+
logger('success', `${i18nKey}.uploadFolder.success`, {
|
|
114
115
|
file: originalFilePath || '',
|
|
115
116
|
destPath,
|
|
116
117
|
});
|
|
@@ -120,7 +121,7 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
120
121
|
if ((0, standardErrors_1.isFatalError)(error)) {
|
|
121
122
|
throw error;
|
|
122
123
|
}
|
|
123
|
-
(0, logger_1.debug)(
|
|
124
|
+
(0, logger_1.debug)(`${i18nKey}.uploadFolder.failed`, { file, destPath });
|
|
124
125
|
if (error.response && error.response.body) {
|
|
125
126
|
console.debug(error.response.body);
|
|
126
127
|
}
|
|
@@ -141,10 +142,13 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
141
142
|
const results = await queue
|
|
142
143
|
.addAll(failures.map(({ file, destPath }) => {
|
|
143
144
|
return async () => {
|
|
144
|
-
(0, logger_1.debug)(
|
|
145
|
+
(0, logger_1.debug)(`${i18nKey}.uploadFolder.retry`, { file, destPath });
|
|
145
146
|
try {
|
|
146
147
|
await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
|
|
147
|
-
logger('success', {
|
|
148
|
+
logger('success', `${i18nKey}.uploadFolder.success`, {
|
|
149
|
+
file,
|
|
150
|
+
destPath,
|
|
151
|
+
});
|
|
148
152
|
return {
|
|
149
153
|
resultType: files_1.FILE_UPLOAD_RESULT_TYPES.SUCCESS,
|
|
150
154
|
error: null,
|
|
@@ -152,7 +156,7 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
152
156
|
};
|
|
153
157
|
}
|
|
154
158
|
catch (err) {
|
|
155
|
-
(0, logger_1.debug)(
|
|
159
|
+
(0, logger_1.debug)(`${i18nKey}.uploadFolder.retryFailed`, { file, destPath });
|
|
156
160
|
const error = err;
|
|
157
161
|
if ((0, standardErrors_1.isFatalError)(error)) {
|
|
158
162
|
throw error;
|
package/lib/cms/watch.js
CHANGED
|
@@ -20,6 +20,7 @@ const notify_1 = require("../../utils/notify");
|
|
|
20
20
|
const themes_1 = require("./themes");
|
|
21
21
|
const logger_1 = require("../../utils/logger");
|
|
22
22
|
const logger_2 = require("../../utils/logger");
|
|
23
|
+
const i18nKey = 'lib.cms.watch';
|
|
23
24
|
const watchCallbackKeys = [
|
|
24
25
|
'notifyOfThemePreview',
|
|
25
26
|
'uploadSuccess',
|
|
@@ -33,17 +34,19 @@ const queue = new p_queue_1.default({
|
|
|
33
34
|
concurrency: 10,
|
|
34
35
|
});
|
|
35
36
|
function _notifyOfThemePreview(filePath, accountId, logCallbacks) {
|
|
36
|
-
const logger = makeLogger(logCallbacks
|
|
37
|
+
const logger = makeLogger(logCallbacks);
|
|
37
38
|
if (queue.size > 0)
|
|
38
39
|
return;
|
|
39
40
|
const previewUrl = (0, themes_1.getThemePreviewUrl)(filePath, accountId);
|
|
40
41
|
if (!previewUrl)
|
|
41
42
|
return;
|
|
42
|
-
logger('notifyOfThemePreview', {
|
|
43
|
+
logger('notifyOfThemePreview', `${i18nKey}.notifyOfThemePreview`, {
|
|
44
|
+
previewUrl,
|
|
45
|
+
});
|
|
43
46
|
}
|
|
44
47
|
const notifyOfThemePreview = (0, debounce_1.debounce)(_notifyOfThemePreview, 1000);
|
|
45
48
|
async function uploadFile(accountId, file, dest, options, mode = null, logCallbacks) {
|
|
46
|
-
const logger = makeLogger(logCallbacks
|
|
49
|
+
const logger = makeLogger(logCallbacks);
|
|
47
50
|
const src = options.src;
|
|
48
51
|
const absoluteSrcPath = path_1.default.resolve((0, path_2.getCwd)(), file);
|
|
49
52
|
const themeJsonPath = (0, themes_1.getThemeJSONPath)(absoluteSrcPath);
|
|
@@ -52,11 +55,11 @@ async function uploadFile(accountId, file, dest, options, mode = null, logCallba
|
|
|
52
55
|
: path_1.default.dirname((0, path_2.getCwd)());
|
|
53
56
|
const convertFields = (0, handleFieldsJS_1.isConvertableFieldJs)(src, file, options.commandOptions.convertFields);
|
|
54
57
|
if (!(0, path_2.isAllowedExtension)(file) && !convertFields) {
|
|
55
|
-
(0, logger_2.debug)(
|
|
58
|
+
(0, logger_2.debug)(`${i18nKey}.skipUnsupportedExtension`, { file });
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
61
|
if ((0, ignoreRules_1.shouldIgnoreFile)(file)) {
|
|
59
|
-
(0, logger_2.debug)(
|
|
62
|
+
(0, logger_2.debug)(`${i18nKey}.skipIgnoreRule`, { file });
|
|
60
63
|
return;
|
|
61
64
|
}
|
|
62
65
|
let fieldsJs = undefined;
|
|
@@ -68,19 +71,22 @@ async function uploadFile(accountId, file, dest, options, mode = null, logCallba
|
|
|
68
71
|
dest = (0, path_2.convertToUnixPath)(path_1.default.join(path_1.default.dirname(dest), 'fields.json'));
|
|
69
72
|
}
|
|
70
73
|
const fileToUpload = convertFields && fieldsJs?.outputPath ? fieldsJs.outputPath : file;
|
|
71
|
-
(0, logger_2.debug)(
|
|
74
|
+
(0, logger_2.debug)(`${i18nKey}.uploadAttempt`, { file, dest });
|
|
72
75
|
const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(mode, options);
|
|
73
76
|
queue.add(() => {
|
|
74
77
|
return (0, fileMapper_2.upload)(accountId, fileToUpload, dest, apiOptions)
|
|
75
78
|
.then(() => {
|
|
76
|
-
logger('uploadSuccess', { file, dest });
|
|
79
|
+
logger('uploadSuccess', `${i18nKey}.uploadSuccess`, { file, dest });
|
|
77
80
|
notifyOfThemePreview(file, accountId, logCallbacks);
|
|
78
81
|
})
|
|
79
82
|
.catch(() => {
|
|
80
|
-
(0, logger_2.debug)(
|
|
81
|
-
(0, logger_2.debug)(
|
|
83
|
+
(0, logger_2.debug)(`${i18nKey}.uploadFailed`, { file, dest });
|
|
84
|
+
(0, logger_2.debug)(`${i18nKey}.uploadRetry`, { file, dest });
|
|
82
85
|
return (0, fileMapper_2.upload)(accountId, file, dest, apiOptions).catch((error) => {
|
|
83
|
-
(0, logger_2.debug)(
|
|
86
|
+
(0, logger_2.debug)(`${i18nKey}.uploadFailed`, {
|
|
87
|
+
file,
|
|
88
|
+
dest,
|
|
89
|
+
});
|
|
84
90
|
(0, apiErrors_1.throwApiUploadError)(error, {
|
|
85
91
|
accountId,
|
|
86
92
|
request: dest,
|
|
@@ -91,20 +97,22 @@ async function uploadFile(accountId, file, dest, options, mode = null, logCallba
|
|
|
91
97
|
});
|
|
92
98
|
}
|
|
93
99
|
async function deleteRemoteFile(accountId, filePath, remoteFilePath, logCallbacks) {
|
|
94
|
-
const logger = makeLogger(logCallbacks
|
|
100
|
+
const logger = makeLogger(logCallbacks);
|
|
95
101
|
if ((0, ignoreRules_1.shouldIgnoreFile)(filePath)) {
|
|
96
|
-
(0, logger_2.debug)(
|
|
102
|
+
(0, logger_2.debug)(`${i18nKey}.skipIgnoreRule`, { file: filePath });
|
|
97
103
|
return;
|
|
98
104
|
}
|
|
99
|
-
(0, logger_2.debug)(
|
|
105
|
+
(0, logger_2.debug)(`${i18nKey}.deleteAttempt`, { remoteFilePath });
|
|
100
106
|
return queue.add(() => {
|
|
101
107
|
return (0, fileMapper_2.deleteFile)(accountId, remoteFilePath)
|
|
102
108
|
.then(() => {
|
|
103
|
-
logger('deleteSuccess', { remoteFilePath });
|
|
109
|
+
logger('deleteSuccess', `${i18nKey}.deleteSuccess`, { remoteFilePath });
|
|
104
110
|
notifyOfThemePreview(filePath, accountId, logCallbacks);
|
|
105
111
|
})
|
|
106
112
|
.catch((error) => {
|
|
107
|
-
(0, logger_2.debug)(
|
|
113
|
+
(0, logger_2.debug)(`${i18nKey}.deleteFailed`, {
|
|
114
|
+
remoteFilePath,
|
|
115
|
+
});
|
|
108
116
|
(0, apiErrors_1.throwApiError)(error, {
|
|
109
117
|
accountId,
|
|
110
118
|
request: remoteFilePath,
|
|
@@ -113,7 +121,7 @@ async function deleteRemoteFile(accountId, filePath, remoteFilePath, logCallback
|
|
|
113
121
|
});
|
|
114
122
|
}
|
|
115
123
|
function watch(accountId, src, dest, { mode, remove, disableInitial, notify, commandOptions, filePaths, }, postInitialUploadCallback = null, onUploadFolderError, onQueueAddError, logCallbacks) {
|
|
116
|
-
const logger = makeLogger(logCallbacks
|
|
124
|
+
const logger = makeLogger(logCallbacks);
|
|
117
125
|
const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
|
|
118
126
|
if (notify) {
|
|
119
127
|
(0, ignoreRules_1.ignoreFile)(notify);
|
|
@@ -129,7 +137,11 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
|
|
|
129
137
|
if (!disableInitial) {
|
|
130
138
|
// Use uploadFolder so that failures of initial upload are retried
|
|
131
139
|
const uploadFolderPromise = (0, uploadFolder_1.uploadFolder)(accountId, src, dest, {}, commandOptions, filePaths, mode || null).then(result => {
|
|
132
|
-
logger('folderUploadSuccess', {
|
|
140
|
+
logger('folderUploadSuccess', `${i18nKey}.folderUploadSuccess`, {
|
|
141
|
+
src,
|
|
142
|
+
dest,
|
|
143
|
+
accountId,
|
|
144
|
+
});
|
|
133
145
|
if (postInitialUploadCallback) {
|
|
134
146
|
postInitialUploadCallback(result);
|
|
135
147
|
}
|
|
@@ -139,7 +151,7 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
|
|
|
139
151
|
}
|
|
140
152
|
}
|
|
141
153
|
watcher.on('ready', () => {
|
|
142
|
-
logger('ready', { src });
|
|
154
|
+
logger('ready', `${i18nKey}.ready`, { src });
|
|
143
155
|
});
|
|
144
156
|
watcher.on('add', async (filePath) => {
|
|
145
157
|
const destPath = getDesignManagerPath(filePath);
|
|
@@ -157,16 +169,16 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
|
|
|
157
169
|
}
|
|
158
170
|
const remotePath = getDesignManagerPath(filePath);
|
|
159
171
|
if ((0, ignoreRules_1.shouldIgnoreFile)(filePath)) {
|
|
160
|
-
(0, logger_2.debug)(
|
|
172
|
+
(0, logger_2.debug)(`${i18nKey}.skipIgnoreRule`, { file: filePath });
|
|
161
173
|
return;
|
|
162
174
|
}
|
|
163
|
-
(0, logger_2.debug)(
|
|
175
|
+
(0, logger_2.debug)(`${i18nKey}.deleteAttemptWithType`, {
|
|
164
176
|
type,
|
|
165
177
|
remoteFilePath: remotePath,
|
|
166
178
|
});
|
|
167
179
|
const queueAddPromise = queue.add(() => {
|
|
168
180
|
const deletePromise = deleteRemoteFile(accountId, filePath, remotePath, logCallbacks).then(() => {
|
|
169
|
-
logger('deleteSuccessWithType', {
|
|
181
|
+
logger('deleteSuccessWithType', `${i18nKey}.deleteSuccessWithType`, {
|
|
170
182
|
type,
|
|
171
183
|
remoteFilePath: remotePath,
|
|
172
184
|
});
|
package/lib/customObjects.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from '../types/Schemas';
|
|
2
|
-
export declare function getResolvedPath(dest
|
|
3
|
-
export declare function writeSchemaToDisk(schema: Schema, dest
|
|
4
|
-
export declare function downloadSchemas(accountId: number, dest
|
|
5
|
-
export declare function downloadSchema(accountId: number, schemaObjectType: string, dest
|
|
2
|
+
export declare function getResolvedPath(dest?: string, name?: string): string;
|
|
3
|
+
export declare function writeSchemaToDisk(schema: Schema, dest?: string): Promise<void>;
|
|
4
|
+
export declare function downloadSchemas(accountId: number, dest?: string): Promise<Array<Schema>>;
|
|
5
|
+
export declare function downloadSchema(accountId: number, schemaObjectType: string, dest?: string): Promise<Schema>;
|
package/lib/customObjects.js
CHANGED
|
@@ -9,6 +9,7 @@ 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");
|
|
12
13
|
function getResolvedPath(dest, name) {
|
|
13
14
|
if (name)
|
|
14
15
|
return path_1.default.resolve((0, path_2.getCwd)(), dest || '', `${name}.json`);
|
|
@@ -23,14 +24,30 @@ async function writeSchemaToDisk(schema, dest) {
|
|
|
23
24
|
}
|
|
24
25
|
exports.writeSchemaToDisk = writeSchemaToDisk;
|
|
25
26
|
async function downloadSchemas(accountId, dest) {
|
|
26
|
-
|
|
27
|
+
let response;
|
|
28
|
+
try {
|
|
29
|
+
response = await (0, customObjects_1.fetchObjectSchemas)(accountId);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
(0, apiErrors_1.throwApiError)(err);
|
|
33
|
+
}
|
|
27
34
|
if (response.results.length) {
|
|
28
|
-
response.results
|
|
35
|
+
for (const schema of response.results) {
|
|
36
|
+
await writeSchemaToDisk(schema, dest);
|
|
37
|
+
}
|
|
29
38
|
}
|
|
39
|
+
return response.results;
|
|
30
40
|
}
|
|
31
41
|
exports.downloadSchemas = downloadSchemas;
|
|
32
42
|
async function downloadSchema(accountId, schemaObjectType, dest) {
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
}
|
|
50
|
+
await writeSchemaToDisk(response, dest);
|
|
51
|
+
return response;
|
|
35
52
|
}
|
|
36
53
|
exports.downloadSchema = downloadSchema;
|
package/lib/fileMapper.js
CHANGED
|
@@ -15,6 +15,7 @@ const files_1 = require("../constants/files");
|
|
|
15
15
|
const fileSystemErrors_1 = require("../errors/fileSystemErrors");
|
|
16
16
|
const apiErrors_1 = require("../errors/apiErrors");
|
|
17
17
|
const logger_1 = require("../utils/logger");
|
|
18
|
+
const i18nKey = 'lib.fileMapper';
|
|
18
19
|
const queue = new p_queue_1.default({
|
|
19
20
|
concurrency: 10,
|
|
20
21
|
});
|
|
@@ -74,7 +75,7 @@ function validateFileMapperNode(node) {
|
|
|
74
75
|
catch (err) {
|
|
75
76
|
json = node;
|
|
76
77
|
}
|
|
77
|
-
(0, standardErrors_1.throwTypeErrorWithMessage)(
|
|
78
|
+
(0, standardErrors_1.throwTypeErrorWithMessage)(`${i18nKey}.errors.invalidNode`, {
|
|
78
79
|
json: JSON.stringify(json),
|
|
79
80
|
});
|
|
80
81
|
}
|
|
@@ -141,16 +142,16 @@ async function skipExisting(filepath, overwrite = false) {
|
|
|
141
142
|
}
|
|
142
143
|
const filemapperCallbackKeys = ['skippedExisting', 'wroteFolder'];
|
|
143
144
|
async function fetchAndWriteFileStream(accountId, srcPath, filepath, mode, options = {}, logCallbacks) {
|
|
144
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks
|
|
145
|
+
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
145
146
|
if (typeof srcPath !== 'string' || !srcPath.trim()) {
|
|
146
147
|
return;
|
|
147
148
|
}
|
|
148
149
|
if (await skipExisting(filepath, options.overwrite)) {
|
|
149
|
-
logger('skippedExisting', { filepath });
|
|
150
|
+
logger('skippedExisting', `${i18nKey}.skippedExisting`, { filepath });
|
|
150
151
|
return;
|
|
151
152
|
}
|
|
152
153
|
if (!(0, path_2.isAllowedExtension)(srcPath)) {
|
|
153
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
154
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidFileType`, { srcPath });
|
|
154
155
|
}
|
|
155
156
|
let node;
|
|
156
157
|
try {
|
|
@@ -167,10 +168,12 @@ async function fetchAndWriteFileStream(accountId, srcPath, filepath, mode, optio
|
|
|
167
168
|
// Writes an individual file or folder (not recursive). If file source is missing, the
|
|
168
169
|
//file is fetched.
|
|
169
170
|
async function writeFileMapperNode(accountId, filepath, node, mode, options = {}, logCallbacks) {
|
|
170
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks
|
|
171
|
+
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
171
172
|
const localFilepath = (0, path_2.convertToLocalFileSystemPath)(path_1.default.resolve(filepath));
|
|
172
173
|
if (await skipExisting(localFilepath, options.overwrite)) {
|
|
173
|
-
logger('skippedExisting', {
|
|
174
|
+
logger('skippedExisting', `${i18nKey}.skippedExisting`, {
|
|
175
|
+
filepath: localFilepath,
|
|
176
|
+
});
|
|
174
177
|
return true;
|
|
175
178
|
}
|
|
176
179
|
if (!node.folder) {
|
|
@@ -184,7 +187,9 @@ async function writeFileMapperNode(accountId, filepath, node, mode, options = {}
|
|
|
184
187
|
}
|
|
185
188
|
try {
|
|
186
189
|
await fs_extra_1.default.ensureDir(localFilepath);
|
|
187
|
-
logger('wroteFolder', {
|
|
190
|
+
logger('wroteFolder', `${i18nKey}.wroteFolder`, {
|
|
191
|
+
filepath: localFilepath,
|
|
192
|
+
});
|
|
188
193
|
}
|
|
189
194
|
catch (err) {
|
|
190
195
|
(0, fileSystemErrors_1.throwFileSystemError)(err, {
|
|
@@ -197,14 +202,14 @@ async function writeFileMapperNode(accountId, filepath, node, mode, options = {}
|
|
|
197
202
|
return true;
|
|
198
203
|
}
|
|
199
204
|
function isTimeout(err) {
|
|
200
|
-
return !!err && (err.
|
|
205
|
+
return !!err && (err.status === 408 || err.code === 'ESOCKETTIMEDOUT');
|
|
201
206
|
}
|
|
202
207
|
async function downloadFile(accountId, src, destPath, mode, options = {}, logCallbacks) {
|
|
203
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks
|
|
208
|
+
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
204
209
|
const { isFile, isHubspot } = getTypeDataFromPath(src);
|
|
205
210
|
try {
|
|
206
211
|
if (!isFile) {
|
|
207
|
-
|
|
212
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidRequest`, { src });
|
|
208
213
|
}
|
|
209
214
|
const dest = path_1.default.resolve(destPath);
|
|
210
215
|
const cwd = (0, path_2.getCwd)();
|
|
@@ -227,7 +232,7 @@ async function downloadFile(accountId, src, destPath, mode, options = {}, logCal
|
|
|
227
232
|
const localFsPath = (0, path_2.convertToLocalFileSystemPath)(filepath);
|
|
228
233
|
await fetchAndWriteFileStream(accountId, src, localFsPath, mode, options, logCallbacks);
|
|
229
234
|
await queue.onIdle();
|
|
230
|
-
logger('completedFetch', {
|
|
235
|
+
logger('completedFetch', `${i18nKey}.completedFetch`, {
|
|
231
236
|
src,
|
|
232
237
|
version: getAssetVersionIdentifier(options.assetVersion, src),
|
|
233
238
|
dest,
|
|
@@ -236,18 +241,20 @@ async function downloadFile(accountId, src, destPath, mode, options = {}, logCal
|
|
|
236
241
|
catch (err) {
|
|
237
242
|
const error = err;
|
|
238
243
|
if (isHubspot && isTimeout(err)) {
|
|
239
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
244
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.assetTimeout`, {}, error);
|
|
240
245
|
}
|
|
241
246
|
else {
|
|
242
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
247
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.failedToFetchFile`, { src, dest: destPath }, error);
|
|
243
248
|
}
|
|
244
249
|
}
|
|
245
250
|
}
|
|
246
251
|
async function fetchFolderFromApi(accountId, src, mode, options = {}, logCallbacks) {
|
|
247
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks
|
|
252
|
+
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
248
253
|
const { isRoot, isFolder, isHubspot } = getTypeDataFromPath(src);
|
|
249
254
|
if (!isFolder) {
|
|
250
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
255
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidFetchFolderRequest`, {
|
|
256
|
+
src,
|
|
257
|
+
});
|
|
251
258
|
}
|
|
252
259
|
try {
|
|
253
260
|
const srcPath = isRoot ? '@root' : src;
|
|
@@ -255,13 +262,13 @@ async function fetchFolderFromApi(accountId, src, mode, options = {}, logCallbac
|
|
|
255
262
|
const node = isHubspot
|
|
256
263
|
? await (0, fileMapper_1.downloadDefault)(accountId, srcPath, queryValues)
|
|
257
264
|
: await (0, fileMapper_1.download)(accountId, srcPath, queryValues);
|
|
258
|
-
logger('folderFetch', { src, accountId });
|
|
265
|
+
logger('folderFetch', `${i18nKey}.folderFetch`, { src, accountId });
|
|
259
266
|
return node;
|
|
260
267
|
}
|
|
261
268
|
catch (err) {
|
|
262
269
|
const error = err;
|
|
263
270
|
if (isHubspot && isTimeout(error)) {
|
|
264
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
271
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.assetTimeout`, {}, error);
|
|
265
272
|
}
|
|
266
273
|
else {
|
|
267
274
|
(0, apiErrors_1.throwStatusCodeError)(error, {
|
|
@@ -273,7 +280,7 @@ async function fetchFolderFromApi(accountId, src, mode, options = {}, logCallbac
|
|
|
273
280
|
}
|
|
274
281
|
exports.fetchFolderFromApi = fetchFolderFromApi;
|
|
275
282
|
async function downloadFolder(accountId, src, destPath, mode, options = {}, logCallbacks) {
|
|
276
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks
|
|
283
|
+
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
277
284
|
try {
|
|
278
285
|
const node = await fetchFolderFromApi(accountId, src, mode, options, logCallbacks);
|
|
279
286
|
if (!node) {
|
|
@@ -295,18 +302,18 @@ async function downloadFolder(accountId, src, destPath, mode, options = {}, logC
|
|
|
295
302
|
}, rootPath);
|
|
296
303
|
await queue.onIdle();
|
|
297
304
|
if (success) {
|
|
298
|
-
logger('completedFolderFetch', {
|
|
305
|
+
logger('completedFolderFetch', `${i18nKey}.completedFolderFetch`, {
|
|
299
306
|
src,
|
|
300
307
|
version: getAssetVersionIdentifier(options.assetVersion, src),
|
|
301
308
|
dest,
|
|
302
309
|
});
|
|
303
310
|
}
|
|
304
311
|
else {
|
|
305
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
312
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.incompleteFetch`, { src });
|
|
306
313
|
}
|
|
307
314
|
}
|
|
308
315
|
catch (err) {
|
|
309
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
316
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.failedToFetchFolder`, { src, dest: destPath }, err);
|
|
310
317
|
}
|
|
311
318
|
}
|
|
312
319
|
/**
|
package/lib/github.js
CHANGED
|
@@ -12,20 +12,21 @@ const standardErrors_1 = require("../errors/standardErrors");
|
|
|
12
12
|
const archive_1 = require("./archive");
|
|
13
13
|
const github_1 = require("../constants/github");
|
|
14
14
|
const getAxiosConfig_1 = require("../http/getAxiosConfig");
|
|
15
|
+
const i18nKey = 'lib.github';
|
|
15
16
|
const GITHUB_AUTH_HEADERS = {
|
|
16
17
|
authorization: global && global.githubToken ? `Bearer ${global.githubToken}` : null,
|
|
17
18
|
};
|
|
18
19
|
async function fetchJsonFromRepository(repoPath, filePath, ref) {
|
|
19
20
|
try {
|
|
20
21
|
const URL = `https://raw.githubusercontent.com/${repoPath}/${ref}/${filePath}`;
|
|
21
|
-
(0, logger_1.debug)(
|
|
22
|
+
(0, logger_1.debug)(`${i18nKey}.fetchJsonFromRepository.fetching`, { url: URL });
|
|
22
23
|
const { data } = await axios_1.default.get(URL, {
|
|
23
24
|
headers: { ...getAxiosConfig_1.DEFAULT_USER_AGENT_HEADERS, ...GITHUB_AUTH_HEADERS },
|
|
24
25
|
});
|
|
25
26
|
return data;
|
|
26
27
|
}
|
|
27
28
|
catch (err) {
|
|
28
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
29
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.fetchJsonFromRepository.errors.fetchFail`, {}, err);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
exports.fetchJsonFromRepository = fetchJsonFromRepository;
|
|
@@ -45,7 +46,7 @@ async function fetchReleaseData(repoPath, tag = '') {
|
|
|
45
46
|
}
|
|
46
47
|
catch (err) {
|
|
47
48
|
const error = err;
|
|
48
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
49
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.fetchReleaseData.errors.fetchFail`, { tag: tag || 'latest' }, error);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
exports.fetchReleaseData = fetchReleaseData;
|
|
@@ -53,35 +54,38 @@ async function downloadGithubRepoZip(repoPath, tag = '', releaseType = github_1.
|
|
|
53
54
|
try {
|
|
54
55
|
let zipUrl;
|
|
55
56
|
if (releaseType === github_1.GITHUB_RELEASE_TYPES.REPOSITORY) {
|
|
56
|
-
(0, logger_1.debug)(
|
|
57
|
+
(0, logger_1.debug)(`${i18nKey}.downloadGithubRepoZip.fetching`, {
|
|
58
|
+
releaseType,
|
|
59
|
+
repoPath,
|
|
60
|
+
});
|
|
57
61
|
zipUrl = `https://api.github.com/repos/${repoPath}/zipball${ref ? `/${ref}` : ''}`;
|
|
58
62
|
}
|
|
59
63
|
else {
|
|
60
64
|
const releaseData = await fetchReleaseData(repoPath, tag);
|
|
61
65
|
zipUrl = releaseData.zipball_url;
|
|
62
66
|
const { name } = releaseData;
|
|
63
|
-
(0, logger_1.debug)(
|
|
67
|
+
(0, logger_1.debug)(`${i18nKey}.downloadGithubRepoZip.fetchingName`, { name });
|
|
64
68
|
}
|
|
65
69
|
const { data } = await axios_1.default.get(zipUrl, {
|
|
66
70
|
headers: { ...getAxiosConfig_1.DEFAULT_USER_AGENT_HEADERS, ...GITHUB_AUTH_HEADERS },
|
|
67
71
|
});
|
|
68
|
-
(0, logger_1.debug)(
|
|
72
|
+
(0, logger_1.debug)(`${i18nKey}.downloadGithubRepoZip.completed`);
|
|
69
73
|
return data;
|
|
70
74
|
}
|
|
71
75
|
catch (err) {
|
|
72
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
76
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.downloadGithubRepoZip.errors.fetchFail`, {}, err);
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
const cloneGithubRepoCallbackKeys = ['success'];
|
|
76
80
|
async function cloneGithubRepo(dest, type, repoPath, sourceDir, options = {}, logCallbacks) {
|
|
77
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks
|
|
81
|
+
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
78
82
|
const { themeVersion, projectVersion, releaseType, ref } = options;
|
|
79
83
|
const tag = projectVersion || themeVersion;
|
|
80
84
|
const zip = await downloadGithubRepoZip(repoPath, tag, releaseType, ref);
|
|
81
85
|
const repoName = repoPath.split('/')[1];
|
|
82
86
|
const success = await (0, archive_1.extractZipArchive)(zip, repoName, dest, { sourceDir });
|
|
83
87
|
if (success) {
|
|
84
|
-
logger('success', { type, dest });
|
|
88
|
+
logger('success', `${i18nKey}.cloneGithubRepo.success`, { type, dest });
|
|
85
89
|
}
|
|
86
90
|
return success;
|
|
87
91
|
}
|
|
@@ -111,7 +115,7 @@ async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filt
|
|
|
111
115
|
if (filter && !filter(contentPiecePath, downloadPath)) {
|
|
112
116
|
return Promise.resolve();
|
|
113
117
|
}
|
|
114
|
-
(0, logger_1.debug)(
|
|
118
|
+
(0, logger_1.debug)(`${i18nKey}.downloadGithubRepoContents.downloading`, {
|
|
115
119
|
contentPiecePath,
|
|
116
120
|
downloadUrl: download_url,
|
|
117
121
|
downloadPath,
|
|
@@ -130,7 +134,7 @@ async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filt
|
|
|
130
134
|
catch (e) {
|
|
131
135
|
const error = e;
|
|
132
136
|
if (error?.error?.message) {
|
|
133
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
137
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
|
|
134
138
|
errorMessage: error.error.message,
|
|
135
139
|
}, error);
|
|
136
140
|
}
|
package/lib/gitignore.js
CHANGED
|
@@ -9,6 +9,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const git_1 = require("../utils/git");
|
|
10
10
|
const config_1 = require("../constants/config");
|
|
11
11
|
const standardErrors_1 = require("../errors/standardErrors");
|
|
12
|
+
const i18nKey = 'lib.gitignore';
|
|
12
13
|
const GITIGNORE_FILE = '.gitignore';
|
|
13
14
|
function checkAndAddConfigToGitignore(configPath) {
|
|
14
15
|
try {
|
|
@@ -25,7 +26,7 @@ function checkAndAddConfigToGitignore(configPath) {
|
|
|
25
26
|
(0, fs_extra_1.writeFileSync)(gitignoreFilePath, updatedContents);
|
|
26
27
|
}
|
|
27
28
|
catch (e) {
|
|
28
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
29
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.configIgnore`, {}, e);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
exports.checkAndAddConfigToGitignore = checkAndAddConfigToGitignore;
|
package/lib/hubdb.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Row } from '../types/Hubdb';
|
|
2
|
-
export declare function addRowsToHubDbTable(accountId: number, tableId: string, rows
|
|
2
|
+
export declare function addRowsToHubDbTable(accountId: number, tableId: string, rows?: Array<Row>): Promise<{
|
|
3
3
|
tableId: string;
|
|
4
4
|
rowCount: number;
|
|
5
5
|
}>;
|