@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.
Files changed (194) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +17 -0
  3. package/api/appsDev.d.ts +6 -0
  4. package/api/appsDev.js +29 -0
  5. package/api/customObjects.d.ts +8 -7
  6. package/api/customObjects.js +13 -16
  7. package/api/designManager.d.ts +4 -13
  8. package/api/designManager.js +6 -9
  9. package/api/developerTestAccounts.d.ts +7 -0
  10. package/api/developerTestAccounts.js +48 -0
  11. package/api/fileManager.d.ts +5 -4
  12. package/api/fileManager.js +11 -11
  13. package/api/fileMapper.d.ts +8 -7
  14. package/api/fileMapper.js +16 -16
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/fireAlarm.d.ts +3 -0
  18. package/api/fireAlarm.js +11 -0
  19. package/api/functions.d.ts +7 -7
  20. package/api/functions.js +13 -16
  21. package/api/github.d.ts +8 -9
  22. package/api/github.js +31 -13
  23. package/api/hubdb.d.ts +11 -10
  24. package/api/hubdb.js +28 -22
  25. package/api/lighthouseScore.d.ts +4 -4
  26. package/api/lighthouseScore.js +9 -12
  27. package/api/localDevAuth.d.ts +9 -16
  28. package/api/localDevAuth.js +36 -14
  29. package/api/marketplaceValidation.d.ts +4 -4
  30. package/api/marketplaceValidation.js +8 -11
  31. package/api/projects.d.ts +47 -24
  32. package/api/projects.js +178 -43
  33. package/api/sandboxHubs.d.ts +6 -4
  34. package/api/sandboxHubs.js +10 -11
  35. package/api/sandboxSync.d.ts +4 -4
  36. package/api/sandboxSync.js +4 -13
  37. package/api/secrets.d.ts +6 -8
  38. package/api/secrets.js +9 -12
  39. package/api/validateHubl.d.ts +2 -1
  40. package/api/validateHubl.js +3 -6
  41. package/config/CLIConfiguration.d.ts +12 -8
  42. package/config/CLIConfiguration.js +140 -64
  43. package/config/configFile.js +9 -18
  44. package/config/configUtils.d.ts +2 -21
  45. package/config/configUtils.js +3 -3
  46. package/config/config_DEPRECATED.d.ts +5 -8
  47. package/config/config_DEPRECATED.js +60 -26
  48. package/config/environment.js +1 -1
  49. package/config/getAccountIdentifier.d.ts +2 -0
  50. package/config/getAccountIdentifier.js +15 -0
  51. package/config/index.d.ts +13 -8
  52. package/config/index.js +99 -59
  53. package/config/migrate.d.ts +22 -0
  54. package/config/migrate.js +178 -0
  55. package/constants/config.d.ts +22 -3
  56. package/constants/config.js +29 -5
  57. package/constants/environments.d.ts +1 -0
  58. package/constants/environments.js +1 -0
  59. package/constants/extensions.d.ts +2 -0
  60. package/constants/extensions.js +3 -1
  61. package/constants/files.d.ts +2 -2
  62. package/constants/files.js +3 -3
  63. package/constants/projects.d.ts +12 -0
  64. package/constants/projects.js +15 -0
  65. package/errors/errors_DEPRECATED.d.ts +1 -5
  66. package/errors/errors_DEPRECATED.js +2 -2
  67. package/errors/index.d.ts +18 -0
  68. package/errors/index.js +63 -0
  69. package/http/addQueryParams.d.ts +2 -0
  70. package/http/addQueryParams.js +14 -0
  71. package/http/getAxiosConfig.d.ts +6 -3
  72. package/http/getAxiosConfig.js +49 -6
  73. package/http/index.d.ts +11 -10
  74. package/http/index.js +87 -36
  75. package/http/unauthed.d.ts +14 -0
  76. package/http/unauthed.js +38 -0
  77. package/lang/en.json +384 -386
  78. package/lib/archive.d.ts +3 -6
  79. package/lib/archive.js +27 -21
  80. package/lib/cms/functions.d.ts +6 -9
  81. package/lib/cms/functions.js +25 -20
  82. package/lib/cms/handleFieldsJS.d.ts +2 -2
  83. package/lib/cms/handleFieldsJS.js +15 -11
  84. package/lib/cms/modules.d.ts +5 -13
  85. package/lib/cms/modules.js +71 -73
  86. package/lib/cms/processFieldsJs.js +10 -33
  87. package/lib/cms/templates.d.ts +42 -0
  88. package/lib/cms/templates.js +49 -6
  89. package/lib/cms/uploadFolder.d.ts +3 -12
  90. package/lib/cms/uploadFolder.js +57 -39
  91. package/lib/cms/validate.js +1 -1
  92. package/lib/cms/watch.d.ts +2 -15
  93. package/lib/cms/watch.js +36 -28
  94. package/lib/customObjects.js +4 -15
  95. package/lib/fileManager.js +24 -24
  96. package/lib/fileMapper.d.ts +4 -13
  97. package/lib/fileMapper.js +57 -67
  98. package/lib/fs.d.ts +1 -1
  99. package/lib/fs.js +10 -6
  100. package/lib/github.d.ts +11 -11
  101. package/lib/github.js +45 -31
  102. package/lib/gitignore.d.ts +2 -0
  103. package/lib/gitignore.js +21 -4
  104. package/lib/hubdb.d.ts +3 -2
  105. package/lib/hubdb.js +11 -9
  106. package/{utils → lib}/notify.js +2 -2
  107. package/lib/oauth.d.ts +1 -1
  108. package/lib/oauth.js +10 -19
  109. package/lib/path.d.ts +3 -0
  110. package/lib/path.js +46 -1
  111. package/lib/personalAccessKey.d.ts +8 -11
  112. package/lib/personalAccessKey.js +72 -52
  113. package/lib/portManager.d.ts +3 -5
  114. package/lib/portManager.js +18 -6
  115. package/lib/text.d.ts +1 -1
  116. package/lib/text.js +3 -0
  117. package/lib/trackUsage.js +14 -8
  118. package/lib/urls.js +5 -1
  119. package/models/FileSystemError.d.ts +6 -0
  120. package/models/FileSystemError.js +47 -0
  121. package/models/HubSpotHttpError.d.ts +26 -0
  122. package/models/HubSpotHttpError.js +208 -0
  123. package/models/OAuth2Manager.d.ts +2 -27
  124. package/models/OAuth2Manager.js +15 -30
  125. package/package.json +38 -36
  126. package/types/Accounts.d.ts +98 -3
  127. package/types/Apps.d.ts +77 -0
  128. package/types/Apps.js +2 -0
  129. package/types/Archive.d.ts +9 -0
  130. package/types/Archive.js +2 -0
  131. package/types/Build.d.ts +4 -2
  132. package/types/ComponentStructure.d.ts +30 -10
  133. package/types/Config.d.ts +19 -2
  134. package/types/Deploy.d.ts +3 -2
  135. package/types/DesignManager.d.ts +15 -0
  136. package/types/DesignManager.js +2 -0
  137. package/types/Error.d.ts +9 -5
  138. package/types/FieldsJS.d.ts +1 -0
  139. package/types/FieldsJS.js +2 -0
  140. package/types/FileManager.d.ts +1 -1
  141. package/types/Files.d.ts +43 -4
  142. package/types/FireAlarm.d.ts +9 -0
  143. package/types/FireAlarm.js +2 -0
  144. package/types/Functions.d.ts +52 -0
  145. package/types/Github.d.ts +13 -0
  146. package/types/Http.d.ts +13 -12
  147. package/types/Hubdb.d.ts +9 -0
  148. package/types/MarketplaceValidation.d.ts +7 -3
  149. package/types/Migration.d.ts +30 -0
  150. package/types/Migration.js +12 -0
  151. package/types/Modules.d.ts +11 -0
  152. package/types/PortManager.d.ts +7 -0
  153. package/types/Project.d.ts +30 -0
  154. package/types/ProjectLog.d.ts +9 -0
  155. package/types/ProjectLog.js +2 -0
  156. package/types/Sandbox.d.ts +25 -36
  157. package/types/Schemas.d.ts +56 -0
  158. package/types/Secrets.d.ts +3 -0
  159. package/types/Secrets.js +2 -0
  160. package/types/developerTestAccounts.d.ts +23 -0
  161. package/types/developerTestAccounts.js +2 -0
  162. package/utils/PortManagerServer.d.ts +6 -7
  163. package/utils/PortManagerServer.js +16 -10
  164. package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
  165. package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
  166. package/utils/cms/fieldsJS.d.ts +1 -2
  167. package/utils/cms/modules.js +2 -2
  168. package/utils/detectPort.js +3 -3
  169. package/utils/git.d.ts +1 -7
  170. package/utils/git.js +2 -18
  171. package/errors/apiErrors.d.ts +0 -21
  172. package/errors/apiErrors.js +0 -177
  173. package/errors/fileSystemErrors.d.ts +0 -6
  174. package/errors/fileSystemErrors.js +0 -35
  175. package/errors/standardErrors.d.ts +0 -21
  176. package/errors/standardErrors.js +0 -52
  177. package/lang/lang/en.json +0 -401
  178. package/lib/logging/git.d.ts +0 -2
  179. package/lib/logging/git.js +0 -54
  180. package/lib/logging/logs.d.ts +0 -22
  181. package/lib/logging/logs.js +0 -86
  182. package/lib/logging/table.d.ts +0 -3
  183. package/lib/logging/table.js +0 -47
  184. package/lib/sandboxes.d.ts +0 -14
  185. package/lib/sandboxes.js +0 -70
  186. package/models/HubSpotAuthError.d.ts +0 -12
  187. package/models/HubSpotAuthError.js +0 -20
  188. package/utils/objectUtils.d.ts +0 -8
  189. package/utils/objectUtils.js +0 -33
  190. /package/{utils → lib}/escapeRegExp.d.ts +0 -0
  191. /package/{utils → lib}/escapeRegExp.js +0 -0
  192. /package/lib/{logging/logger.d.ts → logger.d.ts} +0 -0
  193. /package/lib/{logging/logger.js → logger.js} +0 -0
  194. /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 => (0, standardErrors_1.throwError)(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, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.notFunction`, {
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, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.notArray`, {
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 (_a = (0, url_1.pathToFileURL)(filePath).toString(), Promise.resolve().then(() => __importStar(require(_a)))).then(content => content.default);
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, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidMjsFile`);
93
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidMjsFile`));
117
94
  }
118
95
  return require(filePath);
119
96
  }
@@ -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 {};
@@ -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 standardErrors_1 = require("../../errors/standardErrors");
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, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createTemplate.errors.pathExists`, {
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.downloadGithubRepoContents)('HubSpot/cms-sample-assets', assetPath, filePath);
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 { Mode } from '../../types/Files';
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>, mode?: Mode | null): Promise<Array<UploadFolderResults>>;
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 {};
@@ -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("../../utils/escapeRegExp");
13
+ const escapeRegExp_1 = require("../escapeRegExp");
14
14
  const path_2 = require("../path");
15
- const standardErrors_1 = require("../../errors/standardErrors");
16
- const apiErrors_1 = require("../../errors/apiErrors");
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
- async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOptions = {}, filePaths = [], mode = null) {
80
- const { saveOutput, convertFields } = commandOptions;
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)(mode, fileMapperOptions);
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
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.attempt`, {
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
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadFolder.success`, {
113
- file: originalFilePath || '',
114
- destPath,
115
- }));
144
+ _onSuccessCallback(originalFilePath, destPath);
116
145
  }
117
146
  catch (err) {
118
- const error = err;
119
- if ((0, standardErrors_1.isFatalError)(error)) {
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
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.retry`, { file, destPath }));
165
+ _onRetryCallback(file, destPath);
144
166
  try {
145
167
  await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
146
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadFolder.success`, {
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 (err) {
157
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.retryFailed`, { file, destPath }));
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
- (0, apiErrors_1.throwApiUploadError)(error, {
163
- accountId,
164
- request: destPath,
165
- payload: file,
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
  }))
@@ -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,
@@ -1,17 +1,4 @@
1
1
  import chokidar from 'chokidar';
2
- import { AxiosError } from 'axios';
3
- import { Mode } from '../../types/Files';
2
+ import { WatchOptions, WatchErrorHandler } from '../../types/Files';
4
3
  import { UploadFolderResults } from '../../types/Files';
5
- type WatchOptions = {
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("../../utils/escapeRegExp");
16
+ const escapeRegExp_1 = require("../escapeRegExp");
18
17
  const path_2 = require("../path");
19
- const notify_1 = require("../../utils/notify");
18
+ const notify_1 = require("../notify");
20
19
  const themes_1 = require("./themes");
21
- const logger_1 = require("../logging/logger");
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.debounce)(_notifyOfThemePreview, 1000);
38
- async function uploadFile(accountId, file, dest, options, mode = null) {
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)(mode, options);
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((error) => {
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((error) => {
105
+ .catch(error => {
101
106
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.deleteFailed`, {
102
107
  remoteFilePath,
103
108
  }));
104
- (0, apiErrors_1.throwApiError)(error, {
105
- accountId,
106
- request: remoteFilePath,
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, { mode, remove, disableInitial, notify, commandOptions, filePaths, }, postInitialUploadCallback = null, onUploadFolderError, onQueueAddError) {
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, mode || null).then(result => {
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
- }, mode);
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
- }, mode);
196
+ }, cmsPublishMode, onUploadFileError);
189
197
  (0, notify_1.triggerNotify)(notify, 'Changed', filePath, uploadPromise);
190
198
  });
191
199
  return watcher;
@@ -9,7 +9,6 @@ const path_1 = __importDefault(require("path"));
9
9
  const prettier_1 = __importDefault(require("prettier"));
10
10
  const path_2 = require("../lib/path");
11
11
  const customObjects_1 = require("../api/customObjects");
12
- const apiErrors_1 = require("../errors/apiErrors");
13
12
  function getResolvedPath(dest, name) {
14
13
  if (name)
15
14
  return path_1.default.resolve((0, path_2.getCwd)(), dest || '', `${name}.json`);
@@ -24,13 +23,8 @@ async function writeSchemaToDisk(schema, dest) {
24
23
  }
25
24
  exports.writeSchemaToDisk = writeSchemaToDisk;
26
25
  async function downloadSchemas(accountId, dest) {
27
- let response;
28
- try {
29
- response = await (0, customObjects_1.fetchObjectSchemas)(accountId);
30
- }
31
- catch (err) {
32
- (0, apiErrors_1.throwApiError)(err);
33
- }
26
+ const axiosResponse = await (0, customObjects_1.fetchObjectSchemas)(accountId);
27
+ const response = axiosResponse.data;
34
28
  if (response.results.length) {
35
29
  for (const schema of response.results) {
36
30
  await writeSchemaToDisk(schema, dest);
@@ -40,13 +34,8 @@ async function downloadSchemas(accountId, dest) {
40
34
  }
41
35
  exports.downloadSchemas = downloadSchemas;
42
36
  async function downloadSchema(accountId, schemaObjectType, dest) {
43
- let response;
44
- try {
45
- response = await (0, customObjects_1.fetchObjectSchema)(accountId, schemaObjectType);
46
- }
47
- catch (err) {
48
- (0, apiErrors_1.throwApiError)(err);
49
- }
37
+ const axiosResponse = await (0, customObjects_1.fetchObjectSchema)(accountId, schemaObjectType);
38
+ const response = axiosResponse.data;
50
39
  await writeSchemaToDisk(response, dest);
51
40
  return response;
52
41
  }