@hubspot/local-dev-lib 0.0.10 → 0.1.0-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 (192) 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 +5 -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 +6 -5
  12. package/api/fileManager.js +13 -12
  13. package/api/fileMapper.d.ts +8 -8
  14. package/api/fileMapper.js +19 -18
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/functions.d.ts +7 -3
  18. package/api/functions.js +22 -11
  19. package/api/github.d.ts +11 -0
  20. package/api/github.js +71 -0
  21. package/api/hubdb.d.ts +11 -9
  22. package/api/hubdb.js +28 -22
  23. package/api/lighthouseScore.d.ts +4 -3
  24. package/api/lighthouseScore.js +9 -12
  25. package/api/localDevAuth.d.ts +7 -15
  26. package/api/localDevAuth.js +28 -13
  27. package/api/marketplaceValidation.d.ts +4 -3
  28. package/api/marketplaceValidation.js +8 -11
  29. package/api/projects.d.ts +34 -21
  30. package/api/projects.js +135 -45
  31. package/api/sandboxHubs.d.ts +5 -4
  32. package/api/sandboxHubs.js +10 -11
  33. package/api/sandboxSync.d.ts +4 -4
  34. package/api/sandboxSync.js +5 -14
  35. package/api/secrets.d.ts +6 -8
  36. package/api/secrets.js +9 -12
  37. package/api/validateHubl.d.ts +2 -1
  38. package/api/validateHubl.js +3 -6
  39. package/config/CLIConfiguration.d.ts +13 -10
  40. package/config/CLIConfiguration.js +129 -77
  41. package/config/configFile.js +12 -18
  42. package/config/configUtils.d.ts +2 -21
  43. package/config/configUtils.js +5 -4
  44. package/config/config_DEPRECATED.d.ts +6 -8
  45. package/config/config_DEPRECATED.js +73 -24
  46. package/config/environment.js +5 -4
  47. package/config/getAccountIdentifier.d.ts +2 -0
  48. package/config/getAccountIdentifier.js +15 -0
  49. package/config/index.d.ts +10 -7
  50. package/config/index.js +83 -55
  51. package/constants/api.d.ts +10 -12
  52. package/constants/api.js +10 -12
  53. package/constants/config.d.ts +15 -1
  54. package/constants/config.js +17 -3
  55. package/constants/environments.d.ts +1 -0
  56. package/constants/environments.js +1 -0
  57. package/constants/extensions.d.ts +2 -0
  58. package/constants/extensions.js +3 -1
  59. package/constants/files.d.ts +2 -2
  60. package/constants/files.js +3 -3
  61. package/errors/errors_DEPRECATED.d.ts +1 -5
  62. package/errors/errors_DEPRECATED.js +3 -16
  63. package/errors/index.d.ts +18 -0
  64. package/errors/index.js +63 -0
  65. package/http/addQueryParams.d.ts +2 -0
  66. package/http/addQueryParams.js +14 -0
  67. package/http/getAxiosConfig.d.ts +6 -3
  68. package/http/getAxiosConfig.js +51 -7
  69. package/http/index.d.ts +10 -11
  70. package/http/index.js +35 -41
  71. package/http/unauthed.d.ts +15 -0
  72. package/http/unauthed.js +38 -0
  73. package/lang/en.json +374 -368
  74. package/lib/archive.d.ts +2 -6
  75. package/lib/archive.js +34 -29
  76. package/lib/cms/functions.d.ts +7 -12
  77. package/lib/cms/functions.js +47 -50
  78. package/lib/cms/handleFieldsJS.js +16 -14
  79. package/lib/cms/modules.d.ts +5 -15
  80. package/lib/cms/modules.js +100 -39
  81. package/lib/cms/processFieldsJs.js +10 -33
  82. package/lib/cms/templates.d.ts +43 -3
  83. package/lib/cms/templates.js +51 -11
  84. package/lib/cms/uploadFolder.d.ts +3 -14
  85. package/lib/cms/uploadFolder.js +58 -42
  86. package/lib/{validate.d.ts → cms/validate.d.ts} +1 -1
  87. package/lib/{validate.js → cms/validate.js} +5 -5
  88. package/lib/cms/watch.d.ts +2 -18
  89. package/lib/cms/watch.js +63 -68
  90. package/lib/customObjects.js +4 -15
  91. package/lib/fileManager.d.ts +2 -0
  92. package/lib/fileManager.js +184 -0
  93. package/lib/fileMapper.d.ts +4 -15
  94. package/lib/fileMapper.js +68 -89
  95. package/lib/fs.js +2 -2
  96. package/lib/github.d.ts +6 -18
  97. package/lib/github.js +97 -76
  98. package/lib/gitignore.d.ts +2 -0
  99. package/lib/gitignore.js +21 -4
  100. package/lib/hubdb.d.ts +3 -2
  101. package/lib/hubdb.js +11 -9
  102. package/lib/{logging/logger.d.ts → logger.d.ts} +20 -8
  103. package/{utils → lib}/notify.js +2 -2
  104. package/lib/oauth.d.ts +2 -5
  105. package/lib/oauth.js +14 -25
  106. package/lib/path.d.ts +3 -0
  107. package/lib/path.js +46 -1
  108. package/lib/personalAccessKey.d.ts +7 -10
  109. package/lib/personalAccessKey.js +75 -48
  110. package/lib/portManager.d.ts +3 -5
  111. package/lib/portManager.js +18 -6
  112. package/lib/text.d.ts +1 -0
  113. package/lib/text.js +9 -1
  114. package/lib/trackUsage.js +18 -11
  115. package/lib/urls.js +5 -1
  116. package/models/FileSystemError.d.ts +6 -0
  117. package/models/FileSystemError.js +47 -0
  118. package/models/HubSpotHttpError.d.ts +24 -0
  119. package/models/HubSpotHttpError.js +197 -0
  120. package/models/OAuth2Manager.d.ts +5 -27
  121. package/models/OAuth2Manager.js +41 -64
  122. package/package.json +19 -18
  123. package/types/Accounts.d.ts +86 -3
  124. package/types/Apps.d.ts +77 -0
  125. package/types/Archive.d.ts +9 -0
  126. package/types/Archive.js +2 -0
  127. package/types/ComponentStructure.d.ts +30 -10
  128. package/types/Config.d.ts +19 -2
  129. package/types/DesignManager.d.ts +10 -0
  130. package/types/DesignManager.js +2 -0
  131. package/types/Error.d.ts +12 -34
  132. package/types/FieldsJS.d.ts +1 -0
  133. package/types/FieldsJS.js +2 -0
  134. package/types/FileManager.d.ts +12 -7
  135. package/types/Files.d.ts +43 -4
  136. package/types/Functions.d.ts +26 -0
  137. package/types/Github.d.ts +12 -0
  138. package/types/Http.d.ts +11 -12
  139. package/types/Hubdb.d.ts +9 -0
  140. package/types/Lang.d.ts +3 -0
  141. package/types/Migration.d.ts +28 -0
  142. package/types/Migration.js +10 -0
  143. package/types/Modules.d.ts +11 -0
  144. package/types/PortManager.d.ts +7 -0
  145. package/types/Project.d.ts +4 -0
  146. package/types/ProjectLog.d.ts +9 -0
  147. package/types/ProjectLog.js +2 -0
  148. package/types/Sandbox.d.ts +37 -47
  149. package/types/Schemas.d.ts +12 -0
  150. package/types/Secrets.d.ts +3 -0
  151. package/types/Secrets.js +2 -0
  152. package/types/developerTestAccounts.d.ts +12 -0
  153. package/types/developerTestAccounts.js +2 -0
  154. package/utils/PortManagerServer.d.ts +6 -7
  155. package/utils/PortManagerServer.js +24 -18
  156. package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
  157. package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
  158. package/utils/cms/fieldsJS.d.ts +1 -2
  159. package/utils/cms/modules.js +2 -2
  160. package/utils/detectPort.js +3 -3
  161. package/utils/git.d.ts +1 -7
  162. package/utils/git.js +2 -18
  163. package/utils/lang.d.ts +1 -5
  164. package/constants/github.d.ts +0 -4
  165. package/constants/github.js +0 -7
  166. package/errors/apiErrors.d.ts +0 -23
  167. package/errors/apiErrors.js +0 -197
  168. package/errors/fileSystemErrors.d.ts +0 -5
  169. package/errors/fileSystemErrors.js +0 -31
  170. package/errors/standardErrors.d.ts +0 -26
  171. package/errors/standardErrors.js +0 -64
  172. package/lang/lang/en.json +0 -383
  173. package/lib/logging/git.d.ts +0 -2
  174. package/lib/logging/git.js +0 -54
  175. package/lib/logging/logs.d.ts +0 -22
  176. package/lib/logging/logs.js +0 -86
  177. package/lib/logging/table.d.ts +0 -3
  178. package/lib/logging/table.js +0 -47
  179. package/lib/sandboxes.d.ts +0 -14
  180. package/lib/sandboxes.js +0 -71
  181. package/models/HubSpotAuthError.d.ts +0 -9
  182. package/models/HubSpotAuthError.js +0 -20
  183. package/types/LogCallbacks.d.ts +0 -6
  184. package/utils/logger.d.ts +0 -11
  185. package/utils/logger.js +0 -23
  186. package/utils/objectUtils.d.ts +0 -8
  187. package/utils/objectUtils.js +0 -33
  188. /package/{utils → lib}/escapeRegExp.d.ts +0 -0
  189. /package/{utils → lib}/escapeRegExp.js +0 -0
  190. /package/lib/{logging/logger.js → logger.js} +0 -0
  191. /package/{utils → lib}/notify.d.ts +0 -0
  192. /package/types/{LogCallbacks.js → Apps.js} +0 -0
@@ -3,15 +3,15 @@ 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.createModule = exports.validateSrcAndDestPaths = exports.ValidationIds = void 0;
6
+ exports.isModuleHTMLFile = exports.retrieveDefaultModule = exports.createModule = exports.validateSrcAndDestPaths = exports.ValidationIds = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const path_2 = require("../path");
10
10
  const fs_1 = require("../fs");
11
11
  const github_1 = require("../github");
12
- const standardErrors_1 = require("../../errors/standardErrors");
13
- const logger_1 = require("../../utils/logger");
12
+ const logger_1 = require("../logger");
14
13
  const modules_1 = require("../../utils/cms/modules");
14
+ const lang_1 = require("../../utils/lang");
15
15
  const i18nKey = 'lib.cms.modules';
16
16
  // Ids for testing
17
17
  exports.ValidationIds = {
@@ -67,32 +67,83 @@ async function validateSrcAndDestPaths(src, dest) {
67
67
  return results;
68
68
  }
69
69
  exports.validateSrcAndDestPaths = validateSrcAndDestPaths;
70
- const createModuleCallbackKeys = ['creatingPath', 'creatingModule'];
71
- async function createModule(moduleDefinition, name, dest, options = {
70
+ /* createModule() helper
71
+ * Takes a file and uses the constants above to transform the contents
72
+ */
73
+ // Strings to replace in React module files
74
+ const MODULE_STRING_TRANSFORMATIONS = [
75
+ {
76
+ regex: /\/\* import global styles \*\//g,
77
+ string: 'import "./global-sample-react-module.css";',
78
+ fallback: '',
79
+ },
80
+ {
81
+ regex: /\/\* Default config \*\//g,
82
+ string: 'export const defaultModuleConfig = { \n moduleName: "sample_react-module", \n version: 0, \n};',
83
+ fallback: '',
84
+ },
85
+ ];
86
+ const updateFileContents = async (file, metaData, getInternalVersion) => {
87
+ try {
88
+ let fileContents = await fs_extra_1.default.readFile(file, 'utf8'); // returns Promise
89
+ MODULE_STRING_TRANSFORMATIONS.forEach(entry => {
90
+ const replacementString = getInternalVersion
91
+ ? entry.string
92
+ : entry.fallback;
93
+ fileContents = fileContents.replace(entry.regex, replacementString);
94
+ });
95
+ await fs_extra_1.default.writeFile(file, fileContents, 'utf8');
96
+ await fs_extra_1.default.appendFile(file, 'export const meta = ' + JSON.stringify(metaData, null, ' '));
97
+ }
98
+ catch (error) {
99
+ const { message } = error;
100
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.createModule.errors.fileUpdateFailure`, {
101
+ path: file,
102
+ errorMessage: message,
103
+ }));
104
+ }
105
+ };
106
+ async function createModule(moduleDefinition, name, dest, getInternalVersion, options = {
72
107
  allowExistingDir: false,
73
- }, logCallbacks) {
74
- const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
75
- const writeModuleMeta = ({ contentTypes, moduleLabel, global }, dest) => {
76
- const metaData = {
77
- label: moduleLabel,
78
- css_assets: [],
79
- external_js: [],
80
- global: global,
81
- help_text: '',
82
- host_template_types: contentTypes,
83
- js_assets: [],
84
- other_assets: [],
85
- smart_type: 'NOT_SMART',
86
- tags: [],
87
- is_available_for_new_content: false,
88
- };
89
- fs_extra_1.default.writeJSONSync(dest, metaData, { spaces: 2 });
108
+ }) {
109
+ const { moduleLabel, contentTypes, global, reactType: isReactModule, availableForNewContent, } = moduleDefinition;
110
+ const moduleMetaData = {
111
+ label: moduleLabel,
112
+ css_assets: [],
113
+ external_js: [],
114
+ global: global,
115
+ help_text: '',
116
+ content_types: contentTypes,
117
+ js_assets: [],
118
+ other_assets: [],
119
+ smart_type: 'NOT_SMART',
120
+ tags: [],
121
+ is_available_for_new_content: availableForNewContent,
90
122
  };
123
+ const folderName = name.endsWith('.module') ? name : `${name}.module`;
124
+ const destPath = !isReactModule
125
+ ? path_1.default.join(dest, folderName)
126
+ : path_1.default.join(dest, `${name}`);
127
+ if (!options.allowExistingDir && fs_extra_1.default.existsSync(destPath)) {
128
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.createModule.errors.pathExists`, {
129
+ path: destPath,
130
+ }));
131
+ }
132
+ else {
133
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createModule.creatingPath`, {
134
+ path: destPath,
135
+ }));
136
+ fs_extra_1.default.ensureDirSync(destPath);
137
+ }
138
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createModule.creatingModule`, {
139
+ path: destPath,
140
+ }));
141
+ // Filter out certain fetched files from the response
91
142
  const moduleFileFilter = (src, dest) => {
92
143
  const emailEnabled = moduleDefinition.contentTypes.includes('EMAIL');
93
144
  switch (path_1.default.basename(src)) {
94
145
  case 'meta.json':
95
- writeModuleMeta(moduleDefinition, dest);
146
+ fs_extra_1.default.writeJSONSync(dest, moduleMetaData, { spaces: 2 }); // writing a meta.json file to standard HubL modules
96
147
  return false;
97
148
  case 'module.js':
98
149
  case 'module.css':
@@ -100,26 +151,36 @@ async function createModule(moduleDefinition, name, dest, options = {
100
151
  return false;
101
152
  }
102
153
  return true;
154
+ case 'global-sample-react-module.css':
155
+ case 'stories':
156
+ case 'tests':
157
+ if (getInternalVersion) {
158
+ return true;
159
+ }
160
+ return false;
103
161
  default:
104
162
  return true;
105
163
  }
106
164
  };
107
- const folderName = !name || name.endsWith('.module') ? name : `${name}.module`;
108
- const destPath = path_1.default.join(dest, folderName);
109
- if (!options.allowExistingDir && fs_extra_1.default.existsSync(destPath)) {
110
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createModule.errors.writeModuleMeta`, {
111
- path: destPath,
112
- });
165
+ // Download gitHub contents to the dest directory
166
+ const sampleAssetPath = !isReactModule
167
+ ? 'Sample.module'
168
+ : 'SampleReactModule';
169
+ await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', `modules/${sampleAssetPath}`, destPath, '', moduleFileFilter);
170
+ // Updating React module files after fetch
171
+ if (isReactModule) {
172
+ await updateFileContents(`${destPath}/index.tsx`, moduleMetaData, getInternalVersion);
113
173
  }
114
- else {
115
- logger('creatingPath', `${i18nKey}.createModule.creatingPath`, {
116
- path: destPath,
117
- });
118
- fs_extra_1.default.ensureDirSync(destPath);
119
- }
120
- logger('creatingModule', `${i18nKey}.createModule.creatingModule`, {
121
- path: destPath,
122
- });
123
- await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', 'modules/Sample.module', destPath, '', moduleFileFilter);
124
174
  }
125
175
  exports.createModule = createModule;
176
+ async function retrieveDefaultModule(name, dest) {
177
+ if (!name) {
178
+ const defaultReactModules = await (0, github_1.listGithubRepoContents)('HubSpot/cms-react', 'default-react-modules/src/components/modules/', 'dir');
179
+ return defaultReactModules;
180
+ }
181
+ await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-react', `default-react-modules/src/components/modules/${name}`, dest);
182
+ }
183
+ exports.retrieveDefaultModule = retrieveDefaultModule;
184
+ const MODULE_HTML_EXTENSION_REGEX = new RegExp(/\.module(?:\/|\\)module\.html$/);
185
+ const isModuleHTMLFile = (filePath) => MODULE_HTML_EXTENSION_REGEX.test(filePath);
186
+ exports.isModuleHTMLFile = isModuleHTMLFile;
@@ -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
  }
@@ -1,4 +1,3 @@
1
- import { LogCallbacksArg } from '../../types/LogCallbacks';
2
1
  export declare const ANNOTATION_KEYS: {
3
2
  isAvailableForNewContent: string;
4
3
  templateType: string;
@@ -18,8 +17,49 @@ declare const ASSET_PATHS: {
18
17
  readonly 'search-template': "templates/search-template.html";
19
18
  readonly section: "templates/section.html";
20
19
  };
21
- declare const templatesCallbackKeys: string[];
22
20
  export declare function createTemplate(name: string, dest: string, type?: keyof typeof ASSET_PATHS, options?: {
23
21
  allowExisting: boolean;
24
- }, logCallbacks?: LogCallbacksArg<typeof templatesCallbackKeys>): Promise<void>;
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
+ };
25
65
  export {};
@@ -3,12 +3,12 @@ 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("../../utils/logger");
10
+ const logger_1 = require("../logger");
11
+ const lang_1 = require("../../utils/lang");
12
12
  const i18nKey = 'lib.cms.templates';
13
13
  // Matches the .html file extension, excluding module.html
14
14
  const TEMPLATE_EXTENSION_REGEX = new RegExp(/(?<!module)\.html$/);
@@ -46,22 +46,62 @@ const ASSET_PATHS = {
46
46
  'search-template': 'templates/search-template.html',
47
47
  section: 'templates/section.html',
48
48
  };
49
- const templatesCallbackKeys = ['creatingFile'];
50
- async function createTemplate(name, dest, type = 'page-template', options = { allowExisting: false }, logCallbacks) {
49
+ async function createTemplate(name, dest, type = 'page-template', options = { allowExisting: false }) {
51
50
  const assetPath = ASSET_PATHS[type];
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
- (0, logger_1.debug)(`${i18nKey}.createTemplate.creatingPath`, { path: dest });
58
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createTemplate.creatingPath`, { path: dest }));
60
59
  fs_extra_1.default.mkdirp(dest);
61
- const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
62
- logger('creatingFile', `${i18nKey}.createTemplate.creatingFile`, {
60
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createTemplate.creatingFile`, {
63
61
  path: filePath,
64
- });
62
+ }));
65
63
  await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', assetPath, filePath);
66
64
  }
67
65
  exports.createTemplate = createTemplate;
66
+ exports.TEMPLATE_TYPES = {
67
+ unmapped: 0,
68
+ email_base_template: 1,
69
+ email: 2,
70
+ landing_page_base_template: 3,
71
+ landing_page: 4,
72
+ blog_base: 5,
73
+ blog: 6,
74
+ blog_listing: 42,
75
+ site_page: 8,
76
+ blog_listing_context: 9,
77
+ blog_post_context: 10,
78
+ error_page: 11,
79
+ subscription_preferences: 12,
80
+ unsubscribe_confirmation: 13,
81
+ unsubscribe_simple: 14,
82
+ optin_email: 15,
83
+ optin_followup_email: 16,
84
+ optin_confirmation_page: 17,
85
+ global_group: 18,
86
+ password_prompt_page: 19,
87
+ resubscribe_email: 20,
88
+ unsubscribe_confirmation_email: 21,
89
+ resubscribe_confirmation_email: 22,
90
+ custom_module: 23,
91
+ css: 24,
92
+ js: 25,
93
+ search_results: 27,
94
+ membership_login: 29,
95
+ membership_register: 30,
96
+ membership_reset: 31,
97
+ membership_reset_request: 32,
98
+ drag_drop_email: 34,
99
+ knowledge_article: 35,
100
+ membership_email: 36,
101
+ section: 37,
102
+ global_content_partial: 38,
103
+ simple_landing_page_template: 39,
104
+ proposal: 40,
105
+ blog_post: 41,
106
+ quote: 43,
107
+ };
@@ -1,18 +1,7 @@
1
1
  import { FieldsJs } from './handleFieldsJS';
2
2
  import { FileMapperInputOptions } from '../../types/Files';
3
- import { LogCallbacksArg } from '../../types/LogCallbacks';
4
- import { UploadFolderResults } from '../../types/Files';
5
- import { Mode } from '../../types/Files';
6
- type CommandOptions = {
7
- convertFields?: boolean;
8
- fieldOptions?: string;
9
- saveOutput?: boolean;
10
- };
11
- type FilePathsByType = {
12
- [key: string]: Array<string>;
13
- };
3
+ import { UploadFolderResults, CommandOptions, FilePathsByType } from '../../types/Files';
4
+ import { CmsPublishMode } from '../../types/Files';
14
5
  export declare function getFilesByType(filePaths: Array<string>, projectDir: string, rootWriteDir: string | null, commandOptions: CommandOptions): Promise<[FilePathsByType, Array<FieldsJs>]>;
15
- declare const uploadFolderCallbackKeys: string[];
16
- export declare function uploadFolder(accountId: number, src: string, dest: string, fileMapperOptions: FileMapperInputOptions, commandOptions?: CommandOptions, filePaths?: Array<string>, mode?: Mode | null, logCallbacks?: LogCallbacksArg<typeof uploadFolderCallbackKeys>): 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>>;
17
7
  export declare function hasUploadErrors(results: Array<UploadFolderResults>): boolean;
18
- 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");
14
- const logger_1 = require("../../utils/logger");
13
+ const escapeRegExp_1 = require("../escapeRegExp");
15
14
  const path_2 = require("../path");
16
- const standardErrors_1 = require("../../errors/standardErrors");
17
- const apiErrors_1 = require("../../errors/apiErrors");
18
- const logger_2 = require("../../utils/logger");
15
+ const errors_1 = require("../../errors");
16
+ const logger_1 = require("../logger");
19
17
  const files_1 = require("../../constants/files");
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,15 +76,48 @@ async function getFilesByType(filePaths, projectDir, rootWriteDir, commandOption
76
76
  return [filePathsByType, fieldsJsObjects];
77
77
  }
78
78
  exports.getFilesByType = getFilesByType;
79
- const uploadFolderCallbackKeys = ['success'];
80
- async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOptions = {}, filePaths = [], mode = null, logCallbacks) {
81
- const logger = (0, logger_2.makeTypedLogger)(logCallbacks);
82
- 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;
83
116
  const tmpDir = convertFields
84
117
  ? (0, handleFieldsJS_1.createTmpDirSync)('hubspot-temp-fieldsjs-output-')
85
118
  : null;
86
119
  const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
87
- const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(mode, fileMapperOptions);
120
+ const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(cmsPublishMode, fileMapperOptions);
88
121
  const failures = [];
89
122
  let fieldsJsPaths = [];
90
123
  let tmpDirRegex;
@@ -105,29 +138,16 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
105
138
  const relativePath = file.replace(fieldsJsFileInfo ? tmpDirRegex : regex, '');
106
139
  const destPath = (0, path_2.convertToUnixPath)(path_1.default.join(dest, relativePath));
107
140
  return async () => {
108
- (0, logger_1.debug)(`${i18nKey}.uploadFolder.attempt`, {
109
- file: originalFilePath || '',
110
- destPath,
111
- });
141
+ _onAttemptCallback(originalFilePath, destPath);
112
142
  try {
113
143
  await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
114
- logger('success', `${i18nKey}.uploadFolder.success`, {
115
- file: originalFilePath || '',
116
- destPath,
117
- });
144
+ _onSuccessCallback(originalFilePath, destPath);
118
145
  }
119
146
  catch (err) {
120
- const error = err;
121
- if ((0, standardErrors_1.isFatalError)(error)) {
122
- throw error;
123
- }
124
- (0, logger_1.debug)(`${i18nKey}.uploadFolder.failed`, { file, destPath });
125
- if (error.response && error.response.body) {
126
- console.debug(error.response.body);
127
- }
128
- else {
129
- console.debug(error.message);
147
+ if ((0, errors_1.isAuthError)(err)) {
148
+ throw err;
130
149
  }
150
+ _onFirstErrorCallback(file, destPath, err);
131
151
  failures.push({
132
152
  file,
133
153
  destPath,
@@ -142,30 +162,26 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
142
162
  const results = await queue
143
163
  .addAll(failures.map(({ file, destPath }) => {
144
164
  return async () => {
145
- (0, logger_1.debug)(`${i18nKey}.uploadFolder.retry`, { file, destPath });
165
+ _onRetryCallback(file, destPath);
146
166
  try {
147
167
  await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
148
- logger('success', `${i18nKey}.uploadFolder.success`, {
149
- file,
150
- destPath,
151
- });
168
+ _onSuccessCallback(file, destPath);
152
169
  return {
153
170
  resultType: files_1.FILE_UPLOAD_RESULT_TYPES.SUCCESS,
154
171
  error: null,
155
172
  file,
156
173
  };
157
174
  }
158
- catch (err) {
159
- (0, logger_1.debug)(`${i18nKey}.uploadFolder.retryFailed`, { file, destPath });
160
- const error = err;
161
- if ((0, standardErrors_1.isFatalError)(error)) {
175
+ catch (error) {
176
+ if ((0, errors_1.isAuthError)(error)) {
162
177
  throw error;
163
178
  }
164
- (0, apiErrors_1.throwApiUploadError)(error, {
165
- accountId,
166
- request: destPath,
167
- payload: file,
168
- });
179
+ _onFinalErrorCallback(accountId, file, destPath, error);
180
+ return {
181
+ resultType: files_1.FILE_UPLOAD_RESULT_TYPES.FAILURE,
182
+ error,
183
+ file,
184
+ };
169
185
  }
170
186
  };
171
187
  }))
@@ -1,2 +1,2 @@
1
- import { LintResult } from '../types/HublValidation';
1
+ import { LintResult } from '../../types/HublValidation';
2
2
  export declare function lint(accountId: number, filepath: string, callback?: (lintResult: LintResult) => number): Promise<Array<Partial<LintResult>> | void>;
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.lint = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const extensions_1 = require("../constants/extensions");
9
- const validateHubl_1 = require("../api/validateHubl");
10
- const fs_1 = require("./fs");
11
- const path_1 = require("./path");
8
+ const extensions_1 = require("../../constants/extensions");
9
+ const validateHubl_1 = require("../../api/validateHubl");
10
+ const fs_1 = require("../fs");
11
+ const path_1 = require("../path");
12
12
  async function lint(accountId, filepath, callback) {
13
13
  const stats = await fs_extra_1.default.stat(filepath);
14
14
  const files = stats.isDirectory() ? await (0, fs_1.walk)(filepath) : [filepath];
@@ -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,20 +1,4 @@
1
1
  import chokidar from 'chokidar';
2
- import { LogCallbacksArg } from '../../types/LogCallbacks';
3
- import { Mode } from '../../types/Files';
2
+ import { WatchOptions, WatchErrorHandler } from '../../types/Files';
4
3
  import { UploadFolderResults } from '../../types/Files';
5
- import { StatusCodeError } from '../../types/Error';
6
- declare const watchCallbackKeys: readonly ["notifyOfThemePreview", "uploadSuccess", "deleteSuccess", "folderUploadSuccess", "ready", "deleteSuccessWithType"];
7
- type WatchLogCallbacks = LogCallbacksArg<typeof watchCallbackKeys>;
8
- type WatchOptions = {
9
- mode?: Mode;
10
- remove?: boolean;
11
- disableInitial?: boolean;
12
- notify?: string;
13
- commandOptions: {
14
- convertFields?: boolean;
15
- };
16
- filePaths?: Array<string>;
17
- };
18
- type ErrorHandler = (error: StatusCodeError) => void;
19
- 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, logCallbacks?: WatchLogCallbacks): chokidar.FSWatcher;
20
- 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;