@hubspot/local-dev-lib 0.3.0 → 0.3.1-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.
- package/LICENSE +12 -0
- package/README.md +17 -0
- package/api/appsDev.d.ts +6 -0
- package/api/appsDev.js +29 -0
- package/api/customObjects.d.ts +8 -7
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +4 -13
- package/api/designManager.js +6 -9
- package/api/developerTestAccounts.d.ts +7 -0
- package/api/developerTestAccounts.js +48 -0
- package/api/fileManager.d.ts +5 -4
- package/api/fileManager.js +11 -11
- package/api/fileMapper.d.ts +8 -7
- package/api/fileMapper.js +16 -16
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/fireAlarm.d.ts +3 -0
- package/api/fireAlarm.js +11 -0
- package/api/functions.d.ts +7 -7
- package/api/functions.js +13 -16
- package/api/github.d.ts +8 -9
- package/api/github.js +31 -13
- package/api/hubdb.d.ts +11 -10
- package/api/hubdb.js +28 -22
- package/api/lighthouseScore.d.ts +4 -4
- package/api/lighthouseScore.js +9 -12
- package/api/localDevAuth.d.ts +9 -16
- package/api/localDevAuth.js +36 -14
- package/api/marketplaceValidation.d.ts +4 -4
- package/api/marketplaceValidation.js +8 -11
- package/api/projects.d.ts +47 -24
- package/api/projects.js +178 -43
- package/api/sandboxHubs.d.ts +6 -4
- package/api/sandboxHubs.js +10 -11
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +4 -13
- package/api/secrets.d.ts +6 -8
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +12 -8
- package/config/CLIConfiguration.js +140 -64
- package/config/configFile.js +9 -18
- package/config/configUtils.d.ts +2 -21
- package/config/configUtils.js +3 -3
- package/config/config_DEPRECATED.d.ts +5 -8
- package/config/config_DEPRECATED.js +60 -26
- package/config/environment.js +1 -1
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +13 -8
- package/config/index.js +99 -59
- package/config/migrate.d.ts +22 -0
- package/config/migrate.js +178 -0
- package/constants/config.d.ts +22 -3
- package/constants/config.js +29 -5
- package/constants/environments.d.ts +1 -0
- package/constants/environments.js +1 -0
- package/constants/extensions.d.ts +2 -0
- package/constants/extensions.js +3 -1
- package/constants/files.d.ts +2 -2
- package/constants/files.js +3 -3
- package/constants/projects.d.ts +12 -0
- package/constants/projects.js +15 -0
- package/errors/errors_DEPRECATED.d.ts +1 -5
- 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 +6 -3
- package/http/getAxiosConfig.js +49 -6
- package/http/index.d.ts +11 -10
- package/http/index.js +87 -36
- package/http/unauthed.d.ts +14 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +384 -386
- package/lib/archive.d.ts +3 -6
- package/lib/archive.js +27 -21
- package/lib/cms/functions.d.ts +6 -9
- package/lib/cms/functions.js +25 -20
- package/lib/cms/handleFieldsJS.d.ts +2 -2
- package/lib/cms/handleFieldsJS.js +15 -11
- package/lib/cms/modules.d.ts +5 -13
- package/lib/cms/modules.js +71 -73
- package/lib/cms/processFieldsJs.js +10 -33
- package/lib/cms/templates.d.ts +42 -0
- package/lib/cms/templates.js +49 -6
- package/lib/cms/uploadFolder.d.ts +3 -12
- package/lib/cms/uploadFolder.js +57 -39
- package/lib/cms/validate.js +1 -1
- package/lib/cms/watch.d.ts +2 -15
- package/lib/cms/watch.js +36 -28
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.js +24 -24
- package/lib/fileMapper.d.ts +4 -13
- package/lib/fileMapper.js +57 -67
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +10 -6
- package/lib/github.d.ts +11 -11
- package/lib/github.js +45 -31
- package/lib/gitignore.d.ts +2 -0
- package/lib/gitignore.js +21 -4
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/{utils → lib}/notify.js +2 -2
- package/lib/oauth.d.ts +1 -1
- package/lib/oauth.js +10 -19
- package/lib/path.d.ts +3 -0
- package/lib/path.js +46 -1
- package/lib/personalAccessKey.d.ts +8 -11
- package/lib/personalAccessKey.js +72 -52
- package/lib/portManager.d.ts +3 -5
- package/lib/portManager.js +18 -6
- package/lib/text.d.ts +1 -1
- package/lib/text.js +3 -0
- package/lib/trackUsage.js +14 -8
- package/lib/urls.js +5 -1
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +26 -0
- package/models/HubSpotHttpError.js +208 -0
- package/models/OAuth2Manager.d.ts +2 -27
- package/models/OAuth2Manager.js +15 -30
- package/package.json +38 -36
- package/types/Accounts.d.ts +98 -3
- package/types/Apps.d.ts +77 -0
- package/types/Apps.js +2 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/Build.d.ts +4 -2
- package/types/ComponentStructure.d.ts +30 -10
- package/types/Config.d.ts +19 -2
- package/types/Deploy.d.ts +3 -2
- package/types/DesignManager.d.ts +15 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +9 -5
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +1 -1
- package/types/Files.d.ts +43 -4
- package/types/FireAlarm.d.ts +9 -0
- package/types/FireAlarm.js +2 -0
- package/types/Functions.d.ts +52 -0
- package/types/Github.d.ts +13 -0
- package/types/Http.d.ts +13 -12
- package/types/Hubdb.d.ts +9 -0
- package/types/MarketplaceValidation.d.ts +7 -3
- package/types/Migration.d.ts +30 -0
- package/types/Migration.js +12 -0
- package/types/Modules.d.ts +11 -0
- package/types/PortManager.d.ts +7 -0
- package/types/Project.d.ts +30 -0
- package/types/ProjectLog.d.ts +9 -0
- package/types/ProjectLog.js +2 -0
- package/types/Sandbox.d.ts +25 -36
- package/types/Schemas.d.ts +56 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/developerTestAccounts.d.ts +23 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +6 -7
- package/utils/PortManagerServer.js +16 -10
- package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
- package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
- package/utils/cms/fieldsJS.d.ts +1 -2
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/utils/git.d.ts +1 -7
- package/utils/git.js +2 -18
- package/errors/apiErrors.d.ts +0 -21
- package/errors/apiErrors.js +0 -177
- package/errors/fileSystemErrors.d.ts +0 -6
- package/errors/fileSystemErrors.js +0 -35
- package/errors/standardErrors.d.ts +0 -21
- package/errors/standardErrors.js +0 -52
- package/lang/lang/en.json +0 -401
- package/lib/logging/git.d.ts +0 -2
- package/lib/logging/git.js +0 -54
- package/lib/logging/logs.d.ts +0 -22
- package/lib/logging/logs.js +0 -86
- package/lib/logging/table.d.ts +0 -3
- package/lib/logging/table.js +0 -47
- 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
- package/utils/objectUtils.d.ts +0 -8
- package/utils/objectUtils.js +0 -33
- /package/{utils → lib}/escapeRegExp.d.ts +0 -0
- /package/{utils → lib}/escapeRegExp.js +0 -0
- /package/lib/{logging/logger.d.ts → logger.d.ts} +0 -0
- /package/lib/{logging/logger.js → logger.js} +0 -0
- /package/{utils → lib}/notify.d.ts +0 -0
|
@@ -1,28 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
5
|
};
|
|
@@ -32,7 +9,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
32
9
|
const semver_1 = __importDefault(require("semver"));
|
|
33
10
|
const url_1 = require("url");
|
|
34
11
|
const path_2 = require("../path");
|
|
35
|
-
const standardErrors_1 = require("../../errors/standardErrors");
|
|
36
12
|
const lang_1 = require("../../utils/lang");
|
|
37
13
|
const i18nKey = 'lib.cms.processFieldsJs';
|
|
38
14
|
const { dirName, fieldOptions, filePath, writeDir } = process.env;
|
|
@@ -48,21 +24,23 @@ console.info((0, lang_1.i18n)(`${i18nKey}.converting`, {
|
|
|
48
24
|
* This function has optional return type of Promise<Array> | Array. In order to have uniform handling,
|
|
49
25
|
* we wrap the return value of the function in a Promise.resolve(), and then process.
|
|
50
26
|
*/
|
|
51
|
-
const fieldsPromise = dynamicImport(filePath).catch(e =>
|
|
27
|
+
const fieldsPromise = dynamicImport(filePath).catch(e => {
|
|
28
|
+
throw e;
|
|
29
|
+
});
|
|
52
30
|
fieldsPromise.then(fieldsFunc => {
|
|
53
31
|
const fieldsFuncType = typeof fieldsFunc;
|
|
54
32
|
if (fieldsFuncType !== 'function') {
|
|
55
|
-
(0,
|
|
33
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.notFunction`, {
|
|
56
34
|
path: filePath,
|
|
57
35
|
returned: fieldsFuncType,
|
|
58
|
-
});
|
|
36
|
+
}));
|
|
59
37
|
}
|
|
60
38
|
return Promise.resolve(fieldsFunc(fieldOptions)).then(fields => {
|
|
61
39
|
if (!Array.isArray(fields)) {
|
|
62
|
-
(0,
|
|
40
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.notArray`, {
|
|
63
41
|
path: filePath,
|
|
64
42
|
returned: typeof fields,
|
|
65
|
-
});
|
|
43
|
+
}));
|
|
66
44
|
}
|
|
67
45
|
const finalPath = path_1.default.join(writeDir, '/fields.json');
|
|
68
46
|
return fieldsArrayToJson(fields).then(json => {
|
|
@@ -106,14 +84,13 @@ async function fieldsArrayToJson(fields) {
|
|
|
106
84
|
* @returns {Promise | undefined} - Returns _default_ exported content if ESM, or exported module content if CJS, or undefined if node version < 13.2 and file is .mjs.
|
|
107
85
|
*/
|
|
108
86
|
async function dynamicImport(filePath) {
|
|
109
|
-
var _a;
|
|
110
87
|
if (semver_1.default.gte(process.version, '13.2.0')) {
|
|
111
|
-
const exported = await (
|
|
112
|
-
return exported;
|
|
88
|
+
const exported = await new Function(`return import("${(0, url_1.pathToFileURL)(filePath)}")`)();
|
|
89
|
+
return exported.default;
|
|
113
90
|
}
|
|
114
91
|
else {
|
|
115
92
|
if ((0, path_2.getExt)(filePath) == 'mjs') {
|
|
116
|
-
(0,
|
|
93
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidMjsFile`));
|
|
117
94
|
}
|
|
118
95
|
return require(filePath);
|
|
119
96
|
}
|
package/lib/cms/templates.d.ts
CHANGED
|
@@ -20,4 +20,46 @@ declare const ASSET_PATHS: {
|
|
|
20
20
|
export declare function createTemplate(name: string, dest: string, type?: keyof typeof ASSET_PATHS, options?: {
|
|
21
21
|
allowExisting: boolean;
|
|
22
22
|
}): Promise<void>;
|
|
23
|
+
export declare const TEMPLATE_TYPES: {
|
|
24
|
+
unmapped: number;
|
|
25
|
+
email_base_template: number;
|
|
26
|
+
email: number;
|
|
27
|
+
landing_page_base_template: number;
|
|
28
|
+
landing_page: number;
|
|
29
|
+
blog_base: number;
|
|
30
|
+
blog: number;
|
|
31
|
+
blog_listing: number;
|
|
32
|
+
site_page: number;
|
|
33
|
+
blog_listing_context: number;
|
|
34
|
+
blog_post_context: number;
|
|
35
|
+
error_page: number;
|
|
36
|
+
subscription_preferences: number;
|
|
37
|
+
unsubscribe_confirmation: number;
|
|
38
|
+
unsubscribe_simple: number;
|
|
39
|
+
optin_email: number;
|
|
40
|
+
optin_followup_email: number;
|
|
41
|
+
optin_confirmation_page: number;
|
|
42
|
+
global_group: number;
|
|
43
|
+
password_prompt_page: number;
|
|
44
|
+
resubscribe_email: number;
|
|
45
|
+
unsubscribe_confirmation_email: number;
|
|
46
|
+
resubscribe_confirmation_email: number;
|
|
47
|
+
custom_module: number;
|
|
48
|
+
css: number;
|
|
49
|
+
js: number;
|
|
50
|
+
search_results: number;
|
|
51
|
+
membership_login: number;
|
|
52
|
+
membership_register: number;
|
|
53
|
+
membership_reset: number;
|
|
54
|
+
membership_reset_request: number;
|
|
55
|
+
drag_drop_email: number;
|
|
56
|
+
knowledge_article: number;
|
|
57
|
+
membership_email: number;
|
|
58
|
+
section: number;
|
|
59
|
+
global_content_partial: number;
|
|
60
|
+
simple_landing_page_template: number;
|
|
61
|
+
proposal: number;
|
|
62
|
+
blog_post: number;
|
|
63
|
+
quote: number;
|
|
64
|
+
};
|
|
23
65
|
export {};
|
package/lib/cms/templates.js
CHANGED
|
@@ -3,12 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createTemplate = exports.isCodedFile = exports.getAnnotationValue = exports.ANNOTATION_KEYS = void 0;
|
|
6
|
+
exports.TEMPLATE_TYPES = 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
9
|
const github_1 = require("../github");
|
|
10
|
-
const
|
|
11
|
-
const logger_1 = require("../logging/logger");
|
|
10
|
+
const logger_1 = require("../logger");
|
|
12
11
|
const lang_1 = require("../../utils/lang");
|
|
13
12
|
const i18nKey = 'lib.cms.templates';
|
|
14
13
|
// Matches the .html file extension, excluding module.html
|
|
@@ -52,15 +51,59 @@ 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);
|
|
61
60
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createTemplate.creatingFile`, {
|
|
62
61
|
path: filePath,
|
|
63
62
|
}));
|
|
64
|
-
await (0, github_1.
|
|
63
|
+
await (0, github_1.cloneGithubRepo)('HubSpot/cms-sample-assets', filePath, {
|
|
64
|
+
sourceDir: assetPath,
|
|
65
|
+
});
|
|
65
66
|
}
|
|
66
67
|
exports.createTemplate = createTemplate;
|
|
68
|
+
exports.TEMPLATE_TYPES = {
|
|
69
|
+
unmapped: 0,
|
|
70
|
+
email_base_template: 1,
|
|
71
|
+
email: 2,
|
|
72
|
+
landing_page_base_template: 3,
|
|
73
|
+
landing_page: 4,
|
|
74
|
+
blog_base: 5,
|
|
75
|
+
blog: 6,
|
|
76
|
+
blog_listing: 42,
|
|
77
|
+
site_page: 8,
|
|
78
|
+
blog_listing_context: 9,
|
|
79
|
+
blog_post_context: 10,
|
|
80
|
+
error_page: 11,
|
|
81
|
+
subscription_preferences: 12,
|
|
82
|
+
unsubscribe_confirmation: 13,
|
|
83
|
+
unsubscribe_simple: 14,
|
|
84
|
+
optin_email: 15,
|
|
85
|
+
optin_followup_email: 16,
|
|
86
|
+
optin_confirmation_page: 17,
|
|
87
|
+
global_group: 18,
|
|
88
|
+
password_prompt_page: 19,
|
|
89
|
+
resubscribe_email: 20,
|
|
90
|
+
unsubscribe_confirmation_email: 21,
|
|
91
|
+
resubscribe_confirmation_email: 22,
|
|
92
|
+
custom_module: 23,
|
|
93
|
+
css: 24,
|
|
94
|
+
js: 25,
|
|
95
|
+
search_results: 27,
|
|
96
|
+
membership_login: 29,
|
|
97
|
+
membership_register: 30,
|
|
98
|
+
membership_reset: 31,
|
|
99
|
+
membership_reset_request: 32,
|
|
100
|
+
drag_drop_email: 34,
|
|
101
|
+
knowledge_article: 35,
|
|
102
|
+
membership_email: 36,
|
|
103
|
+
section: 37,
|
|
104
|
+
global_content_partial: 38,
|
|
105
|
+
simple_landing_page_template: 39,
|
|
106
|
+
proposal: 40,
|
|
107
|
+
blog_post: 41,
|
|
108
|
+
quote: 43,
|
|
109
|
+
};
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import { FieldsJs } from './handleFieldsJS';
|
|
2
2
|
import { FileMapperInputOptions } from '../../types/Files';
|
|
3
|
-
import { UploadFolderResults } from '../../types/Files';
|
|
4
|
-
import {
|
|
5
|
-
type CommandOptions = {
|
|
6
|
-
convertFields?: boolean;
|
|
7
|
-
fieldOptions?: string;
|
|
8
|
-
saveOutput?: boolean;
|
|
9
|
-
};
|
|
10
|
-
type FilePathsByType = {
|
|
11
|
-
[key: string]: Array<string>;
|
|
12
|
-
};
|
|
3
|
+
import { UploadFolderResults, CommandOptions, FilePathsByType } from '../../types/Files';
|
|
4
|
+
import { CmsPublishMode } from '../../types/Files';
|
|
13
5
|
export declare function getFilesByType(filePaths: Array<string>, projectDir: string, rootWriteDir: string | null, commandOptions: CommandOptions): Promise<[FilePathsByType, Array<FieldsJs>]>;
|
|
14
|
-
export declare function uploadFolder(accountId: number, src: string, dest: string, fileMapperOptions: FileMapperInputOptions, commandOptions?: CommandOptions, filePaths?: Array<string>,
|
|
6
|
+
export declare function uploadFolder(accountId: number, src: string, dest: string, fileMapperOptions: FileMapperInputOptions, commandOptions?: CommandOptions, filePaths?: Array<string>, cmsPublishMode?: CmsPublishMode | null): Promise<Array<UploadFolderResults>>;
|
|
15
7
|
export declare function hasUploadErrors(results: Array<UploadFolderResults>): boolean;
|
|
16
|
-
export {};
|
package/lib/cms/uploadFolder.js
CHANGED
|
@@ -10,13 +10,13 @@ const handleFieldsJS_1 = require("./handleFieldsJS");
|
|
|
10
10
|
const fileMapper_1 = require("../fileMapper");
|
|
11
11
|
const fileMapper_2 = require("../../api/fileMapper");
|
|
12
12
|
const modules_1 = require("../../utils/cms/modules");
|
|
13
|
-
const escapeRegExp_1 = require("
|
|
13
|
+
const escapeRegExp_1 = require("../escapeRegExp");
|
|
14
14
|
const path_2 = require("../path");
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const logger_1 = require("../logging/logger");
|
|
15
|
+
const errors_1 = require("../../errors");
|
|
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,
|
|
@@ -76,13 +76,48 @@ async function getFilesByType(filePaths, projectDir, rootWriteDir, commandOption
|
|
|
76
76
|
return [filePathsByType, fieldsJsObjects];
|
|
77
77
|
}
|
|
78
78
|
exports.getFilesByType = getFilesByType;
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const defaultUploadAttemptCallback = (file, destPath) => logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.attempt`, {
|
|
80
|
+
file: file || '',
|
|
81
|
+
destPath,
|
|
82
|
+
}));
|
|
83
|
+
const defaultUploadSuccessCallback = (file, destPath) => logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadFolder.success`, {
|
|
84
|
+
file: file || '',
|
|
85
|
+
destPath,
|
|
86
|
+
}));
|
|
87
|
+
const defaultUploadFirstErrorCallback = (file, destPath, error) => {
|
|
88
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.failed`, { file, destPath }));
|
|
89
|
+
if ((0, errors_1.isHubSpotHttpError)(error)) {
|
|
90
|
+
logger_1.logger.debug(error.data);
|
|
91
|
+
}
|
|
92
|
+
else if (error instanceof Error) {
|
|
93
|
+
logger_1.logger.debug(error.message);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const defaultUploadRetryCallback = (file, destPath) => logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.retry`, { file, destPath }));
|
|
97
|
+
const defaultUploadFinalErrorCallback = (accountId, file, destPath, error) => {
|
|
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 }, {
|
|
104
|
+
accountId,
|
|
105
|
+
request: destPath,
|
|
106
|
+
payload: file,
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOptions = {}, filePaths = [], cmsPublishMode = null) {
|
|
110
|
+
const { saveOutput, convertFields, onAttemptCallback, onSuccessCallback, onFirstErrorCallback, onRetryCallback, onFinalErrorCallback, } = commandOptions;
|
|
111
|
+
const _onAttemptCallback = onAttemptCallback || defaultUploadAttemptCallback;
|
|
112
|
+
const _onSuccessCallback = onSuccessCallback || defaultUploadSuccessCallback;
|
|
113
|
+
const _onFirstErrorCallback = onFirstErrorCallback || defaultUploadFirstErrorCallback;
|
|
114
|
+
const _onRetryCallback = onRetryCallback || defaultUploadRetryCallback;
|
|
115
|
+
const _onFinalErrorCallback = onFinalErrorCallback || defaultUploadFinalErrorCallback;
|
|
81
116
|
const tmpDir = convertFields
|
|
82
117
|
? (0, handleFieldsJS_1.createTmpDirSync)('hubspot-temp-fieldsjs-output-')
|
|
83
118
|
: null;
|
|
84
119
|
const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
|
|
85
|
-
const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(
|
|
120
|
+
const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(cmsPublishMode, fileMapperOptions);
|
|
86
121
|
const failures = [];
|
|
87
122
|
let fieldsJsPaths = [];
|
|
88
123
|
let tmpDirRegex;
|
|
@@ -103,29 +138,16 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
103
138
|
const relativePath = file.replace(fieldsJsFileInfo ? tmpDirRegex : regex, '');
|
|
104
139
|
const destPath = (0, path_2.convertToUnixPath)(path_1.default.join(dest, relativePath));
|
|
105
140
|
return async () => {
|
|
106
|
-
|
|
107
|
-
file: originalFilePath || '',
|
|
108
|
-
destPath,
|
|
109
|
-
}));
|
|
141
|
+
_onAttemptCallback(originalFilePath, destPath);
|
|
110
142
|
try {
|
|
111
143
|
await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
|
|
112
|
-
|
|
113
|
-
file: originalFilePath || '',
|
|
114
|
-
destPath,
|
|
115
|
-
}));
|
|
144
|
+
_onSuccessCallback(originalFilePath, destPath);
|
|
116
145
|
}
|
|
117
146
|
catch (err) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
throw error;
|
|
121
|
-
}
|
|
122
|
-
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.failed`, { file, destPath }));
|
|
123
|
-
if (error.response && error.response.data) {
|
|
124
|
-
logger_1.logger.debug(error.response.data);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
logger_1.logger.debug(error.message);
|
|
147
|
+
if ((0, errors_1.isAuthError)(err)) {
|
|
148
|
+
throw err;
|
|
128
149
|
}
|
|
150
|
+
_onFirstErrorCallback(file, destPath, err);
|
|
129
151
|
failures.push({
|
|
130
152
|
file,
|
|
131
153
|
destPath,
|
|
@@ -140,30 +162,26 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
140
162
|
const results = await queue
|
|
141
163
|
.addAll(failures.map(({ file, destPath }) => {
|
|
142
164
|
return async () => {
|
|
143
|
-
|
|
165
|
+
_onRetryCallback(file, destPath);
|
|
144
166
|
try {
|
|
145
167
|
await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
|
|
146
|
-
|
|
147
|
-
file,
|
|
148
|
-
destPath,
|
|
149
|
-
}));
|
|
168
|
+
_onSuccessCallback(file, destPath);
|
|
150
169
|
return {
|
|
151
170
|
resultType: files_1.FILE_UPLOAD_RESULT_TYPES.SUCCESS,
|
|
152
171
|
error: null,
|
|
153
172
|
file,
|
|
154
173
|
};
|
|
155
174
|
}
|
|
156
|
-
catch (
|
|
157
|
-
|
|
158
|
-
const error = err;
|
|
159
|
-
if ((0, standardErrors_1.isFatalError)(error)) {
|
|
175
|
+
catch (error) {
|
|
176
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
160
177
|
throw error;
|
|
161
178
|
}
|
|
162
|
-
(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
179
|
+
_onFinalErrorCallback(accountId, file, destPath, error);
|
|
180
|
+
return {
|
|
181
|
+
resultType: files_1.FILE_UPLOAD_RESULT_TYPES.FAILURE,
|
|
182
|
+
error,
|
|
183
|
+
file,
|
|
184
|
+
};
|
|
167
185
|
}
|
|
168
186
|
};
|
|
169
187
|
}))
|
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.d.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
import chokidar from 'chokidar';
|
|
2
|
-
import {
|
|
3
|
-
import { Mode } from '../../types/Files';
|
|
2
|
+
import { WatchOptions, WatchErrorHandler } from '../../types/Files';
|
|
4
3
|
import { UploadFolderResults } from '../../types/Files';
|
|
5
|
-
|
|
6
|
-
mode?: Mode;
|
|
7
|
-
remove?: boolean;
|
|
8
|
-
disableInitial?: boolean;
|
|
9
|
-
notify?: string;
|
|
10
|
-
commandOptions: {
|
|
11
|
-
convertFields?: boolean;
|
|
12
|
-
};
|
|
13
|
-
filePaths?: Array<string>;
|
|
14
|
-
};
|
|
15
|
-
type ErrorHandler = (error: AxiosError) => void;
|
|
16
|
-
export declare function watch(accountId: number, src: string, dest: string, { mode, remove, disableInitial, notify, commandOptions, filePaths, }: WatchOptions, postInitialUploadCallback?: ((result: Array<UploadFolderResults>) => void) | null, onUploadFolderError?: ErrorHandler, onQueueAddError?: ErrorHandler): chokidar.FSWatcher;
|
|
17
|
-
export {};
|
|
4
|
+
export declare function watch(accountId: number, src: string, dest: string, { cmsPublishMode, remove, disableInitial, notify, commandOptions, filePaths, }: WatchOptions, postInitialUploadCallback?: ((result: Array<UploadFolderResults>) => void) | null, onUploadFolderError?: WatchErrorHandler, onQueueAddError?: WatchErrorHandler, onUploadFileError?: (file: string, dest: string, accountId: number) => WatchErrorHandler): chokidar.FSWatcher;
|
package/lib/cms/watch.js
CHANGED
|
@@ -7,19 +7,20 @@ 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("
|
|
16
|
+
const escapeRegExp_1 = require("../escapeRegExp");
|
|
18
17
|
const path_2 = require("../path");
|
|
19
|
-
const notify_1 = require("
|
|
18
|
+
const notify_1 = require("../notify");
|
|
20
19
|
const themes_1 = require("./themes");
|
|
21
|
-
const logger_1 = require("../
|
|
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,
|
|
@@ -34,8 +35,22 @@ function _notifyOfThemePreview(filePath, accountId) {
|
|
|
34
35
|
previewUrl,
|
|
35
36
|
}));
|
|
36
37
|
}
|
|
37
|
-
const notifyOfThemePreview = (0, debounce_1.
|
|
38
|
-
|
|
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) {
|
|
39
54
|
const src = options.src;
|
|
40
55
|
const absoluteSrcPath = path_1.default.resolve((0, path_2.getCwd)(), file);
|
|
41
56
|
const themeJsonPath = (0, themes_1.getThemeJSONPath)(absoluteSrcPath);
|
|
@@ -61,7 +76,7 @@ async function uploadFile(accountId, file, dest, options, mode = null) {
|
|
|
61
76
|
}
|
|
62
77
|
const fileToUpload = convertFields && fieldsJs?.outputPath ? fieldsJs.outputPath : file;
|
|
63
78
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadAttempt`, { file, dest }));
|
|
64
|
-
const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(
|
|
79
|
+
const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(cmsPublishMode, options);
|
|
65
80
|
queue.add(() => {
|
|
66
81
|
return (0, fileMapper_2.upload)(accountId, fileToUpload, dest, apiOptions)
|
|
67
82
|
.then(() => {
|
|
@@ -71,17 +86,7 @@ async function uploadFile(accountId, file, dest, options, mode = null) {
|
|
|
71
86
|
.catch(() => {
|
|
72
87
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFailed`, { file, dest }));
|
|
73
88
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadRetry`, { file, dest }));
|
|
74
|
-
return (0, fileMapper_2.upload)(accountId, file, dest, apiOptions).catch((
|
|
75
|
-
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFailed`, {
|
|
76
|
-
file,
|
|
77
|
-
dest,
|
|
78
|
-
}));
|
|
79
|
-
(0, apiErrors_1.throwApiUploadError)(error, {
|
|
80
|
-
accountId,
|
|
81
|
-
request: dest,
|
|
82
|
-
payload: file,
|
|
83
|
-
});
|
|
84
|
-
});
|
|
89
|
+
return (0, fileMapper_2.upload)(accountId, file, dest, apiOptions).catch(onUploadFileError(file, dest, accountId));
|
|
85
90
|
});
|
|
86
91
|
});
|
|
87
92
|
}
|
|
@@ -97,18 +102,21 @@ async function deleteRemoteFile(accountId, filePath, remoteFilePath) {
|
|
|
97
102
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.deleteSuccess`, { remoteFilePath }));
|
|
98
103
|
notifyOfThemePreview(filePath, accountId);
|
|
99
104
|
})
|
|
100
|
-
.catch(
|
|
105
|
+
.catch(error => {
|
|
101
106
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.deleteFailed`, {
|
|
102
107
|
remoteFilePath,
|
|
103
108
|
}));
|
|
104
|
-
(0,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
if ((0, errors_1.isHubSpotHttpError)(error)) {
|
|
110
|
+
error.updateContext({
|
|
111
|
+
accountId,
|
|
112
|
+
request: remoteFilePath,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
throw error;
|
|
108
116
|
});
|
|
109
117
|
});
|
|
110
118
|
}
|
|
111
|
-
function watch(accountId, src, dest, {
|
|
119
|
+
function watch(accountId, src, dest, { cmsPublishMode, remove, disableInitial, notify, commandOptions, filePaths, }, postInitialUploadCallback = null, onUploadFolderError, onQueueAddError, onUploadFileError) {
|
|
112
120
|
const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
|
|
113
121
|
if (notify) {
|
|
114
122
|
(0, ignoreRules_1.ignoreFile)(notify);
|
|
@@ -123,7 +131,7 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
|
|
|
123
131
|
}
|
|
124
132
|
if (!disableInitial) {
|
|
125
133
|
// Use uploadFolder so that failures of initial upload are retried
|
|
126
|
-
const uploadFolderPromise = (0, uploadFolder_1.uploadFolder)(accountId, src, dest, {}, commandOptions, filePaths,
|
|
134
|
+
const uploadFolderPromise = (0, uploadFolder_1.uploadFolder)(accountId, src, dest, {}, commandOptions, filePaths, cmsPublishMode || null).then(result => {
|
|
127
135
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.folderUploadSuccess`, {
|
|
128
136
|
src,
|
|
129
137
|
dest,
|
|
@@ -145,7 +153,7 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
|
|
|
145
153
|
const uploadPromise = uploadFile(accountId, filePath, destPath, {
|
|
146
154
|
src,
|
|
147
155
|
commandOptions,
|
|
148
|
-
},
|
|
156
|
+
}, cmsPublishMode, onUploadFileError);
|
|
149
157
|
(0, notify_1.triggerNotify)(notify, 'Added', filePath, uploadPromise);
|
|
150
158
|
});
|
|
151
159
|
if (remove) {
|
|
@@ -185,7 +193,7 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
|
|
|
185
193
|
const uploadPromise = uploadFile(accountId, filePath, destPath, {
|
|
186
194
|
src,
|
|
187
195
|
commandOptions,
|
|
188
|
-
},
|
|
196
|
+
}, cmsPublishMode, onUploadFileError);
|
|
189
197
|
(0, notify_1.triggerNotify)(notify, 'Changed', filePath, uploadPromise);
|
|
190
198
|
});
|
|
191
199
|
return watcher;
|
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
|
}
|