@hubspot/local-dev-lib 4.0.4 → 5.0.0-beta.1

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 (205) hide show
  1. package/api/appsDev.d.ts +2 -2
  2. package/api/appsDev.js +13 -22
  3. package/api/crm.d.ts +2 -2
  4. package/api/crm.js +9 -16
  5. package/api/customObjects.d.ts +2 -2
  6. package/api/customObjects.js +13 -22
  7. package/api/designManager.d.ts +2 -2
  8. package/api/designManager.js +5 -10
  9. package/api/devSecrets.d.ts +2 -2
  10. package/api/devSecrets.js +9 -16
  11. package/api/developerTestAccounts.d.ts +2 -4
  12. package/api/developerTestAccounts.js +23 -52
  13. package/api/fileManager.d.ts +2 -2
  14. package/api/fileManager.js +14 -24
  15. package/api/fileMapper.d.ts +2 -3
  16. package/api/fileMapper.js +34 -49
  17. package/api/fileTransport.d.ts +1 -1
  18. package/api/fileTransport.js +12 -21
  19. package/api/fireAlarm.d.ts +2 -3
  20. package/api/fireAlarm.js +5 -9
  21. package/api/functions.d.ts +2 -2
  22. package/api/functions.js +11 -19
  23. package/api/github.d.ts +2 -4
  24. package/api/github.js +16 -27
  25. package/api/hubdb.d.ts +2 -2
  26. package/api/hubdb.js +19 -31
  27. package/api/lighthouseScore.d.ts +2 -2
  28. package/api/lighthouseScore.js +7 -13
  29. package/api/localDevAuth.d.ts +3 -6
  30. package/api/localDevAuth.js +10 -37
  31. package/api/marketplaceValidation.d.ts +2 -2
  32. package/api/marketplaceValidation.js +7 -13
  33. package/api/projects.d.ts +6 -8
  34. package/api/projects.js +65 -100
  35. package/api/sandboxHubs.d.ts +2 -5
  36. package/api/sandboxHubs.js +15 -42
  37. package/api/sandboxSync.d.ts +2 -2
  38. package/api/sandboxSync.js +7 -12
  39. package/api/secrets.d.ts +2 -2
  40. package/api/secrets.js +9 -16
  41. package/api/validateHubl.d.ts +2 -2
  42. package/api/validateHubl.js +3 -7
  43. package/config/defaultAccountOverride.d.ts +2 -1
  44. package/config/defaultAccountOverride.js +16 -26
  45. package/config/index.d.ts +4 -4
  46. package/config/index.js +141 -177
  47. package/config/migrate.d.ts +2 -2
  48. package/config/migrate.js +26 -37
  49. package/config/state.d.ts +1 -1
  50. package/config/state.js +17 -45
  51. package/config/utils.d.ts +4 -4
  52. package/config/utils.js +85 -108
  53. package/constants/api.js +3 -6
  54. package/constants/auth.js +9 -12
  55. package/constants/config.js +37 -43
  56. package/constants/endpoints.d.ts +6 -0
  57. package/constants/endpoints.js +6 -0
  58. package/constants/environments.js +1 -4
  59. package/constants/extensions.js +6 -9
  60. package/constants/files.js +5 -8
  61. package/constants/ports.js +3 -6
  62. package/constants/projects.js +2 -5
  63. package/enums/build.d.ts +1 -0
  64. package/enums/build.js +6 -8
  65. package/enums/deploy.js +2 -5
  66. package/enums/project.js +1 -4
  67. package/errors/index.d.ts +4 -5
  68. package/errors/index.js +17 -39
  69. package/errors/isSystemError.d.ts +2 -0
  70. package/errors/isSystemError.js +9 -0
  71. package/http/addQueryParams.d.ts +1 -1
  72. package/http/addQueryParams.js +1 -5
  73. package/http/client.js +14 -42
  74. package/http/getAxiosConfig.d.ts +1 -1
  75. package/http/getAxiosConfig.js +21 -31
  76. package/http/index.d.ts +2 -2
  77. package/http/index.js +39 -46
  78. package/http/unauthed.d.ts +1 -1
  79. package/http/unauthed.js +15 -18
  80. package/lang/en.json +1 -1
  81. package/lib/archive.d.ts +1 -3
  82. package/lib/archive.js +37 -67
  83. package/lib/cms/functions.d.ts +1 -1
  84. package/lib/cms/functions.js +45 -55
  85. package/lib/cms/handleFieldsJS.js +36 -44
  86. package/lib/cms/modules.d.ts +2 -2
  87. package/lib/cms/modules.js +49 -59
  88. package/lib/cms/processFieldsJs.js +17 -32
  89. package/lib/cms/templates.js +17 -26
  90. package/lib/cms/themes.js +10 -18
  91. package/lib/cms/uploadFolder.d.ts +4 -4
  92. package/lib/cms/uploadFolder.js +55 -64
  93. package/lib/cms/validate.d.ts +1 -1
  94. package/lib/cms/validate.js +11 -18
  95. package/lib/cms/watch.d.ts +2 -2
  96. package/lib/cms/watch.js +66 -73
  97. package/lib/crm.d.ts +1 -1
  98. package/lib/crm.js +15 -23
  99. package/lib/customObjects.d.ts +1 -1
  100. package/lib/customObjects.js +15 -25
  101. package/lib/environment.d.ts +1 -1
  102. package/lib/environment.js +5 -11
  103. package/lib/escapeRegExp.js +1 -5
  104. package/lib/fileManager.js +43 -51
  105. package/lib/fileMapper.d.ts +1 -1
  106. package/lib/fileMapper.js +68 -84
  107. package/lib/fs.d.ts +1 -1
  108. package/lib/fs.js +18 -27
  109. package/lib/github.d.ts +1 -3
  110. package/lib/github.js +39 -51
  111. package/lib/gitignore.d.ts +1 -1
  112. package/lib/gitignore.js +16 -24
  113. package/lib/hubdb.d.ts +1 -1
  114. package/lib/hubdb.js +29 -40
  115. package/lib/ignoreRules.js +25 -34
  116. package/lib/isDeepEqual.js +1 -5
  117. package/lib/logger.d.ts +8 -20
  118. package/lib/logger.js +47 -59
  119. package/lib/notify.js +9 -16
  120. package/lib/oauth.d.ts +2 -2
  121. package/lib/oauth.js +12 -17
  122. package/lib/path.d.ts +0 -1
  123. package/lib/path.js +30 -48
  124. package/lib/personalAccessKey.d.ts +2 -4
  125. package/lib/personalAccessKey.js +43 -60
  126. package/lib/portManager.d.ts +2 -2
  127. package/lib/portManager.js +26 -41
  128. package/lib/text.js +2 -7
  129. package/lib/trackUsage.d.ts +0 -2
  130. package/lib/trackUsage.js +23 -29
  131. package/lib/urls.js +4 -9
  132. package/models/FileSystemError.d.ts +1 -1
  133. package/models/FileSystemError.js +12 -16
  134. package/models/HubSpotConfigError.d.ts +1 -1
  135. package/models/HubSpotConfigError.js +8 -12
  136. package/models/HubSpotHttpError.d.ts +1 -1
  137. package/models/HubSpotHttpError.js +22 -26
  138. package/models/OAuth2Manager.d.ts +1 -1
  139. package/models/OAuth2Manager.js +17 -24
  140. package/package.json +20 -16
  141. package/types/Accounts.d.ts +6 -5
  142. package/types/Accounts.js +1 -2
  143. package/types/Activity.d.ts +3 -3
  144. package/types/Activity.js +1 -2
  145. package/types/Api.d.ts +1 -1
  146. package/types/Api.js +1 -2
  147. package/types/Apps.js +1 -2
  148. package/types/Archive.js +1 -2
  149. package/types/Build.d.ts +4 -5
  150. package/types/Build.js +1 -2
  151. package/types/CLIOptions.js +1 -2
  152. package/types/ComponentStructure.d.ts +2 -2
  153. package/types/ComponentStructure.js +1 -2
  154. package/types/Config.d.ts +4 -6
  155. package/types/Config.js +1 -2
  156. package/types/Crm.js +1 -2
  157. package/types/Deploy.d.ts +5 -11
  158. package/types/Deploy.js +1 -2
  159. package/types/DesignManager.js +1 -2
  160. package/types/DevSecrets.js +1 -2
  161. package/types/Error.js +1 -2
  162. package/types/FieldsJS.js +1 -2
  163. package/types/FileManager.js +1 -2
  164. package/types/Files.d.ts +4 -4
  165. package/types/Files.js +1 -2
  166. package/types/FireAlarm.js +1 -2
  167. package/types/Functions.js +1 -2
  168. package/types/Github.d.ts +1 -1
  169. package/types/Github.js +1 -2
  170. package/types/Http.d.ts +0 -4
  171. package/types/Http.js +1 -2
  172. package/types/Hubdb.js +1 -2
  173. package/types/HublValidation.js +1 -2
  174. package/types/Lang.d.ts +1 -1
  175. package/types/Lang.js +1 -2
  176. package/types/Lighthouse.js +1 -2
  177. package/types/MarketplaceValidation.js +1 -2
  178. package/types/Migration.d.ts +2 -2
  179. package/types/Migration.js +1 -4
  180. package/types/Modules.js +1 -2
  181. package/types/PortManager.js +1 -2
  182. package/types/Project.d.ts +3 -21
  183. package/types/Project.js +1 -2
  184. package/types/ProjectComponents.d.ts +24 -0
  185. package/types/ProjectComponents.js +1 -0
  186. package/types/ProjectLog.js +1 -2
  187. package/types/Sandbox.js +2 -5
  188. package/types/Schemas.js +1 -2
  189. package/types/Secrets.js +1 -2
  190. package/types/Utils.js +1 -2
  191. package/types/developerTestAccounts.js +1 -2
  192. package/utils/PortManagerServer.d.ts +1 -2
  193. package/utils/PortManagerServer.js +32 -38
  194. package/utils/cms/fieldsJS.d.ts +1 -1
  195. package/utils/cms/fieldsJS.js +1 -5
  196. package/utils/cms/modules.d.ts +1 -1
  197. package/utils/cms/modules.js +13 -22
  198. package/utils/detectPort.js +12 -19
  199. package/utils/git.js +17 -26
  200. package/utils/lang.d.ts +1 -1
  201. package/utils/lang.js +5 -14
  202. package/utils/personalAccessKey.d.ts +8 -0
  203. package/utils/personalAccessKey.js +51 -0
  204. package/errors/errors_DEPRECATED.d.ts +0 -3
  205. package/errors/errors_DEPRECATED.js +0 -60
package/lib/fs.js CHANGED
@@ -1,51 +1,43 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.walk = exports.flattenAndRemoveSymlinks = exports.getFileInfoAsync = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const files_1 = require("../constants/files");
10
- const FileSystemError_1 = require("../models/FileSystemError");
11
- function getFileInfoAsync(dir, file) {
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { STAT_TYPES } from '../constants/files.js';
4
+ import { FileSystemError } from '../models/FileSystemError.js';
5
+ export function getFileInfoAsync(dir, file) {
12
6
  return new Promise((resolve, reject) => {
13
- const filepath = path_1.default.join(dir, file);
14
- fs_1.default.lstat(filepath, (error, stats) => {
7
+ const filepath = path.join(dir, file);
8
+ fs.lstat(filepath, (error, stats) => {
15
9
  if (error) {
16
10
  reject(error);
17
11
  }
18
- let type = files_1.STAT_TYPES.FILE;
12
+ let type = STAT_TYPES.FILE;
19
13
  if (stats.isSymbolicLink()) {
20
- type = files_1.STAT_TYPES.SYMBOLIC_LINK;
14
+ type = STAT_TYPES.SYMBOLIC_LINK;
21
15
  }
22
16
  else if (stats.isDirectory()) {
23
- type = files_1.STAT_TYPES.DIRECTORY;
17
+ type = STAT_TYPES.DIRECTORY;
24
18
  }
25
19
  resolve({ filepath, type });
26
20
  });
27
21
  });
28
22
  }
29
- exports.getFileInfoAsync = getFileInfoAsync;
30
- function flattenAndRemoveSymlinks(filesData) {
23
+ export function flattenAndRemoveSymlinks(filesData) {
31
24
  return filesData.reduce((acc, fileData) => {
32
25
  switch (fileData.type) {
33
- case files_1.STAT_TYPES.FILE:
26
+ case STAT_TYPES.FILE:
34
27
  return acc.concat(fileData.filepath);
35
- case files_1.STAT_TYPES.DIRECTORY:
28
+ case STAT_TYPES.DIRECTORY:
36
29
  return acc.concat(fileData.files || []);
37
- case files_1.STAT_TYPES.SYMBOLIC_LINK:
30
+ case STAT_TYPES.SYMBOLIC_LINK:
38
31
  return acc;
39
32
  default:
40
33
  return acc;
41
34
  }
42
35
  }, []);
43
36
  }
44
- exports.flattenAndRemoveSymlinks = flattenAndRemoveSymlinks;
45
37
  const generateRecursiveFilePromise = async (dir, file, ignoreDirs) => {
46
38
  return getFileInfoAsync(dir, file).then(fileData => {
47
39
  return new Promise(resolve => {
48
- if (fileData.type === files_1.STAT_TYPES.DIRECTORY) {
40
+ if (fileData.type === STAT_TYPES.DIRECTORY) {
49
41
  walk(fileData.filepath, ignoreDirs).then(files => {
50
42
  resolve({ ...fileData, files });
51
43
  });
@@ -56,7 +48,7 @@ const generateRecursiveFilePromise = async (dir, file, ignoreDirs) => {
56
48
  });
57
49
  });
58
50
  };
59
- async function walk(dir, ignoreDirs) {
51
+ export async function walk(dir, ignoreDirs) {
60
52
  function processFiles(files) {
61
53
  // If the directory is in the ignore list, return an empty array to skip the directory contents
62
54
  if (ignoreDirs?.some(ignored => dir.includes(ignored))) {
@@ -64,12 +56,11 @@ async function walk(dir, ignoreDirs) {
64
56
  }
65
57
  return Promise.all(files.map(file => generateRecursiveFilePromise(dir, file, ignoreDirs)));
66
58
  }
67
- return fs_1.default.promises
59
+ return fs.promises
68
60
  .readdir(dir)
69
61
  .then(processFiles)
70
62
  .then(flattenAndRemoveSymlinks)
71
63
  .catch(err => {
72
- throw new FileSystemError_1.FileSystemError({ cause: err });
64
+ throw new FileSystemError({ cause: err });
73
65
  });
74
66
  }
75
- exports.walk = walk;
package/lib/github.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { GithubReleaseData, GithubRepoFile, RepoPath, CloneGithubRepoOptions } from '../types/Github';
1
+ import { GithubReleaseData, GithubRepoFile, RepoPath, CloneGithubRepoOptions } from '../types/Github.js';
4
2
  /**
5
3
  * @deprecated Use `fetchRepoFile` instead - this util is a thin wrapper around it
6
4
  */
package/lib/github.js CHANGED
@@ -1,38 +1,31 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.listGithubRepoContents = exports.downloadGithubRepoContents = exports.fetchGitHubRepoContentFromDownloadUrl = exports.cloneGithubRepo = exports.fetchReleaseData = exports.fetchFileFromRepository = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const archive_1 = require("./archive");
10
- const logger_1 = require("./logger");
11
- const github_1 = require("../api/github");
12
- const lang_1 = require("../utils/lang");
13
- const errors_1 = require("../errors");
1
+ import path from 'path';
2
+ import fs from 'fs-extra';
3
+ import { extractZipArchive } from './archive.js';
4
+ import { logger } from './logger.js';
5
+ import { fetchRepoFile, fetchRepoFileByDownloadUrl, fetchRepoAsZip, fetchRepoReleaseData, fetchRepoContents, } from '../api/github.js';
6
+ import { i18n } from '../utils/lang.js';
7
+ import { isGithubRateLimitError, isHubSpotHttpError, isSystemError, } from '../errors/index.js';
14
8
  const i18nKey = 'lib.github';
15
9
  /**
16
10
  * @deprecated Use `fetchRepoFile` instead - this util is a thin wrapper around it
17
11
  */
18
- async function fetchFileFromRepository(repoPath, filePath, ref) {
12
+ export async function fetchFileFromRepository(repoPath, filePath, ref) {
19
13
  try {
20
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.fetchFileFromRepository.fetching`, {
14
+ logger.debug(i18n(`${i18nKey}.fetchFileFromRepository.fetching`, {
21
15
  path: `${repoPath}/${ref}/${filePath}`,
22
16
  }));
23
- const { data } = await (0, github_1.fetchRepoFile)(repoPath, filePath, ref);
17
+ const { data } = await fetchRepoFile(repoPath, filePath, ref);
24
18
  return data;
25
19
  }
26
20
  catch (err) {
27
21
  checkGithubRateLimit(err);
28
- throw new Error((0, lang_1.i18n)(`${i18nKey}.fetchFileFromRepository.errors.fetchFail`), {
22
+ throw new Error(i18n(`${i18nKey}.fetchFileFromRepository.errors.fetchFail`), {
29
23
  cause: err,
30
24
  });
31
25
  }
32
26
  }
33
- exports.fetchFileFromRepository = fetchFileFromRepository;
34
27
  // Fetches information about a specific release (Defaults to latest)
35
- async function fetchReleaseData(repoPath, tag) {
28
+ export async function fetchReleaseData(repoPath, tag) {
36
29
  if (tag) {
37
30
  tag = tag.trim().toLowerCase();
38
31
  if (tag.length && tag[0] !== 'v') {
@@ -40,17 +33,16 @@ async function fetchReleaseData(repoPath, tag) {
40
33
  }
41
34
  }
42
35
  try {
43
- const { data } = await (0, github_1.fetchRepoReleaseData)(repoPath, tag);
36
+ const { data } = await fetchRepoReleaseData(repoPath, tag);
44
37
  return data;
45
38
  }
46
39
  catch (err) {
47
40
  checkGithubRateLimit(err);
48
- throw new Error((0, lang_1.i18n)(`${i18nKey}.fetchReleaseData.errors.fetchFail`, {
41
+ throw new Error(i18n(`${i18nKey}.fetchReleaseData.errors.fetchFail`, {
49
42
  tag: tag || 'latest',
50
43
  }), { cause: err });
51
44
  }
52
45
  }
53
- exports.fetchReleaseData = fetchReleaseData;
54
46
  async function downloadGithubRepoZip(repoPath, isRelease = false, options = {}) {
55
47
  const { branch, tag } = options;
56
48
  try {
@@ -61,48 +53,47 @@ async function downloadGithubRepoZip(repoPath, isRelease = false, options = {})
61
53
  const releaseData = await fetchReleaseData(repoPath, tag);
62
54
  zipUrl = releaseData.zipball_url;
63
55
  const { name } = releaseData;
64
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoZip.fetchingName`, { name }));
56
+ logger.debug(i18n(`${i18nKey}.downloadGithubRepoZip.fetchingName`, { name }));
65
57
  }
66
58
  else {
67
59
  // If downloading a repository, manually construct the zip url. This url supports both branches and tags as refs
68
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoZip.fetching`, { repoPath }));
60
+ logger.debug(i18n(`${i18nKey}.downloadGithubRepoZip.fetching`, { repoPath }));
69
61
  const ref = branch || tag;
70
62
  zipUrl = `https://api.github.com/repos/${repoPath}/zipball${ref ? `/${ref}` : ''}`;
71
63
  }
72
- const { data } = await (0, github_1.fetchRepoAsZip)(zipUrl);
73
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoZip.completed`));
64
+ const { data } = await fetchRepoAsZip(zipUrl);
65
+ logger.debug(i18n(`${i18nKey}.downloadGithubRepoZip.completed`));
74
66
  return data;
75
67
  }
76
68
  catch (err) {
77
69
  checkGithubRateLimit(err);
78
- throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoZip.errors.fetchFail`), {
70
+ throw new Error(i18n(`${i18nKey}.downloadGithubRepoZip.errors.fetchFail`), {
79
71
  cause: err,
80
72
  });
81
73
  }
82
74
  }
83
- async function cloneGithubRepo(repoPath, dest, options = {}) {
75
+ export async function cloneGithubRepo(repoPath, dest, options = {}) {
84
76
  const { tag, isRelease, branch, sourceDir, type, hideLogs, handleCollision } = options;
85
77
  const zip = await downloadGithubRepoZip(repoPath, isRelease, {
86
78
  tag,
87
79
  branch,
88
80
  });
89
81
  const repoName = repoPath.split('/')[1];
90
- const success = await (0, archive_1.extractZipArchive)(zip, repoName, dest, {
82
+ const success = await extractZipArchive(zip, repoName, dest, {
91
83
  sourceDir,
92
84
  hideLogs,
93
85
  handleCollision,
94
86
  });
95
87
  if (success && !hideLogs) {
96
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.cloneGithubRepo.success`, {
88
+ logger.log(i18n(`${i18nKey}.cloneGithubRepo.success`, {
97
89
  type: type || '',
98
90
  dest,
99
91
  }));
100
92
  }
101
93
  return success;
102
94
  }
103
- exports.cloneGithubRepo = cloneGithubRepo;
104
- async function fetchGitHubRepoContentFromDownloadUrl(dest, downloadUrl) {
105
- const resp = await (0, github_1.fetchRepoFileByDownloadUrl)(downloadUrl);
95
+ export async function fetchGitHubRepoContentFromDownloadUrl(dest, downloadUrl) {
96
+ const resp = await fetchRepoFileByDownloadUrl(downloadUrl);
106
97
  const contentType = resp.headers['content-type'];
107
98
  let fileContents;
108
99
  if (contentType.startsWith('text')) {
@@ -111,30 +102,29 @@ async function fetchGitHubRepoContentFromDownloadUrl(dest, downloadUrl) {
111
102
  else {
112
103
  fileContents = resp.data;
113
104
  }
114
- fs_extra_1.default.outputFileSync(dest, fileContents);
105
+ fs.outputFileSync(dest, fileContents);
115
106
  }
116
- exports.fetchGitHubRepoContentFromDownloadUrl = fetchGitHubRepoContentFromDownloadUrl;
117
107
  /**
118
108
  * Writes files from a public repository to the destination folder
119
109
  @deprecated - This method fetches all the files individually, which can hit rate limits for unauthorized requests. Use `cloneGithubRepo` instead.
120
110
  */
121
- async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filter) {
122
- fs_extra_1.default.ensureDirSync(path_1.default.dirname(dest));
111
+ export async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filter) {
112
+ fs.ensureDirSync(path.dirname(dest));
123
113
  try {
124
- const { data: contentsResp } = await (0, github_1.fetchRepoContents)(repoPath, contentPath, ref);
114
+ const { data: contentsResp } = await fetchRepoContents(repoPath, contentPath, ref);
125
115
  const downloadContent = async (contentPiece) => {
126
116
  const { path: contentPiecePath, download_url, type: contentPieceType, } = contentPiece;
127
- const downloadPath = path_1.default.join(dest, contentPiecePath.replace(contentPath, ''));
117
+ const downloadPath = path.join(dest, contentPiecePath.replace(contentPath, ''));
128
118
  if (filter && !filter(contentPiecePath, downloadPath)) {
129
119
  return Promise.resolve();
130
120
  }
131
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoContents.downloading`, {
121
+ logger.debug(i18n(`${i18nKey}.downloadGithubRepoContents.downloading`, {
132
122
  contentPiecePath,
133
123
  downloadUrl: download_url,
134
124
  downloadPath,
135
125
  }));
136
126
  if (contentPieceType === 'dir') {
137
- const { data: innerDirContent } = await (0, github_1.fetchRepoContents)(repoPath, contentPiecePath, ref);
127
+ const { data: innerDirContent } = await fetchRepoContents(repoPath, contentPiecePath, ref);
138
128
  await Promise.all(innerDirContent.map(downloadContent));
139
129
  return Promise.resolve();
140
130
  }
@@ -151,19 +141,18 @@ async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filt
151
141
  }
152
142
  catch (e) {
153
143
  checkGithubRateLimit(e);
154
- if ((0, errors_1.isSystemError)(e) && e?.error?.message) {
155
- throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
144
+ if (isSystemError(e) && e?.error?.message) {
145
+ throw new Error(i18n(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
156
146
  errorMessage: e.error.message,
157
147
  }), { cause: e });
158
148
  }
159
149
  throw e;
160
150
  }
161
151
  }
162
- exports.downloadGithubRepoContents = downloadGithubRepoContents;
163
152
  // Lists content from a public repository at the specified path
164
- async function listGithubRepoContents(repoPath, contentPath, fileFilter) {
153
+ export async function listGithubRepoContents(repoPath, contentPath, fileFilter) {
165
154
  try {
166
- const { data: contentsResp } = await (0, github_1.fetchRepoContents)(repoPath, contentPath);
155
+ const { data: contentsResp } = await fetchRepoContents(repoPath, contentPath);
167
156
  const filteredFiles = fileFilter && fileFilter != undefined
168
157
  ? contentsResp.filter(item => item.type === fileFilter)
169
158
  : contentsResp;
@@ -171,18 +160,17 @@ async function listGithubRepoContents(repoPath, contentPath, fileFilter) {
171
160
  }
172
161
  catch (e) {
173
162
  checkGithubRateLimit(e);
174
- if ((0, errors_1.isHubSpotHttpError)(e) && e.data.message) {
175
- throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
163
+ if (isHubSpotHttpError(e) && e.data.message) {
164
+ throw new Error(i18n(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
176
165
  errorMessage: e.data.message,
177
166
  }));
178
167
  }
179
168
  throw e;
180
169
  }
181
170
  }
182
- exports.listGithubRepoContents = listGithubRepoContents;
183
171
  function checkGithubRateLimit(err) {
184
- if ((0, errors_1.isGithubRateLimitError)(err)) {
185
- throw new Error((0, lang_1.i18n)(`${i18nKey}.rateLimitError`), {
172
+ if (isGithubRateLimitError(err)) {
173
+ throw new Error(i18n(`${i18nKey}.rateLimitError`), {
186
174
  cause: err,
187
175
  });
188
176
  }
@@ -1,3 +1,3 @@
1
- import { GitInclusionResult } from '../types/Config';
1
+ import { GitInclusionResult } from '../types/Config.js';
2
2
  export declare function checkAndAddConfigToGitignore(configPath: string): void;
3
3
  export declare function checkGitInclusion(configPath: string): GitInclusionResult;
package/lib/gitignore.js CHANGED
@@ -1,49 +1,41 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.checkGitInclusion = exports.checkAndAddConfigToGitignore = void 0;
7
- const fs_extra_1 = require("fs-extra");
8
- const path_1 = __importDefault(require("path"));
9
- const git_1 = require("../utils/git");
10
- const config_1 = require("../constants/config");
11
- const lang_1 = require("../utils/lang");
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import { isConfigPathInGitRepo, getGitignoreFiles, configFilenameIsIgnoredByGitignore, } from '../utils/git.js';
4
+ import { DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME } from '../constants/config.js';
5
+ import { i18n } from '../utils/lang.js';
12
6
  const i18nKey = 'lib.gitignore';
13
7
  const GITIGNORE_FILE = '.gitignore';
14
- function checkAndAddConfigToGitignore(configPath) {
8
+ export function checkAndAddConfigToGitignore(configPath) {
15
9
  try {
16
10
  const { configIgnored, gitignoreFiles } = checkGitInclusion(configPath);
17
11
  if (configIgnored)
18
12
  return;
19
13
  let gitignoreFilePath = gitignoreFiles && gitignoreFiles.length ? gitignoreFiles[0] : null;
20
14
  if (!gitignoreFilePath) {
21
- gitignoreFilePath = path_1.default.join(path_1.default.dirname(configPath), GITIGNORE_FILE);
22
- (0, fs_extra_1.writeFileSync)(gitignoreFilePath, '');
15
+ gitignoreFilePath = path.join(path.dirname(configPath), GITIGNORE_FILE);
16
+ fs.writeFileSync(gitignoreFilePath, '');
23
17
  }
24
- const gitignoreContents = (0, fs_extra_1.readFileSync)(gitignoreFilePath).toString();
25
- const updatedContents = `${gitignoreContents.trim()}\n\n# HubSpot config file\n${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}\n`;
26
- (0, fs_extra_1.writeFileSync)(gitignoreFilePath, updatedContents);
18
+ const gitignoreContents = fs.readFileSync(gitignoreFilePath).toString();
19
+ const updatedContents = `${gitignoreContents.trim()}\n\n# HubSpot config file\n${DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}\n`;
20
+ fs.writeFileSync(gitignoreFilePath, updatedContents);
27
21
  }
28
22
  catch (e) {
29
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.configIgnore`), { cause: e });
23
+ throw new Error(i18n(`${i18nKey}.errors.configIgnore`), { cause: e });
30
24
  }
31
25
  }
32
- exports.checkAndAddConfigToGitignore = checkAndAddConfigToGitignore;
33
- function checkGitInclusion(configPath) {
26
+ export function checkGitInclusion(configPath) {
34
27
  const result = {
35
28
  inGit: false,
36
29
  configIgnored: false,
37
30
  gitignoreFiles: [],
38
31
  };
39
- if ((0, git_1.isConfigPathInGitRepo)(configPath)) {
32
+ if (isConfigPathInGitRepo(configPath)) {
40
33
  result.inGit = true;
41
- result.gitignoreFiles = (0, git_1.getGitignoreFiles)(configPath);
42
- if ((0, git_1.configFilenameIsIgnoredByGitignore)(result.gitignoreFiles, configPath)) {
34
+ result.gitignoreFiles = getGitignoreFiles(configPath);
35
+ if (configFilenameIsIgnoredByGitignore(result.gitignoreFiles, configPath)) {
43
36
  // Found ignore statement in .gitignore that matches config filename
44
37
  result.configIgnored = true;
45
38
  }
46
39
  }
47
40
  return result;
48
41
  }
49
- exports.checkGitInclusion = checkGitInclusion;
package/lib/hubdb.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { Row, Table } from '../types/Hubdb';
2
+ import { Row, Table } from '../types/Hubdb.js';
3
3
  export declare function addRowsToHubDbTable(accountId: number, tableId: string, rows?: Array<Row>): Promise<{
4
4
  tableId: string;
5
5
  rowCount: number;
package/lib/hubdb.js CHANGED
@@ -1,37 +1,31 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.clearHubDbTableRows = exports.downloadHubDbTable = exports.updateHubDbTable = exports.createHubDbTable = exports.addRowsToHubDbTable = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const prettier_1 = __importDefault(require("prettier"));
10
- const hubdb_1 = require("../api/hubdb");
11
- const path_2 = require("./path");
12
- const lang_1 = require("../utils/lang");
1
+ import path from 'path';
2
+ import fs from 'fs-extra';
3
+ import { format } from 'prettier';
4
+ import { createTable, updateTable, createRows, fetchTable, fetchRows, publishTable, deleteRows, } from '../api/hubdb.js';
5
+ import { getCwd } from './path.js';
6
+ import { i18n } from '../utils/lang.js';
13
7
  const i18nKey = 'lib.hubdb';
14
8
  function validateJsonPath(src) {
15
- if (path_1.default.extname(src) !== '.json') {
16
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidJsonPath`));
9
+ if (path.extname(src) !== '.json') {
10
+ throw new Error(i18n(`${i18nKey}.errors.invalidJsonPath`));
17
11
  }
18
12
  }
19
13
  function validateJsonFile(src) {
20
14
  let stats;
21
15
  try {
22
- stats = fs_extra_1.default.statSync(src);
16
+ stats = fs.statSync(src);
23
17
  }
24
18
  catch (err) {
25
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidJsonFile`, { src }), {
19
+ throw new Error(i18n(`${i18nKey}.errors.invalidJsonFile`, { src }), {
26
20
  cause: err,
27
21
  });
28
22
  }
29
23
  if (!stats.isFile()) {
30
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidJsonFile`, { src }));
24
+ throw new Error(i18n(`${i18nKey}.errors.invalidJsonFile`, { src }));
31
25
  }
32
26
  validateJsonPath(src);
33
27
  }
34
- async function addRowsToHubDbTable(accountId, tableId, rows = []) {
28
+ export async function addRowsToHubDbTable(accountId, tableId, rows = []) {
35
29
  const rowsToUpdate = rows.map(row => {
36
30
  const values = row.values;
37
31
  return {
@@ -42,30 +36,27 @@ async function addRowsToHubDbTable(accountId, tableId, rows = []) {
42
36
  };
43
37
  });
44
38
  if (rowsToUpdate.length > 0) {
45
- await (0, hubdb_1.createRows)(accountId, tableId, rowsToUpdate);
39
+ await createRows(accountId, tableId, rowsToUpdate);
46
40
  }
47
- const { data: { rowCount }, } = await (0, hubdb_1.publishTable)(accountId, tableId);
41
+ const { data: { rowCount }, } = await publishTable(accountId, tableId);
48
42
  return {
49
43
  tableId,
50
44
  rowCount,
51
45
  };
52
46
  }
53
- exports.addRowsToHubDbTable = addRowsToHubDbTable;
54
- async function createHubDbTable(accountId, src) {
47
+ export async function createHubDbTable(accountId, src) {
55
48
  validateJsonFile(src);
56
- const table = fs_extra_1.default.readJsonSync(src);
49
+ const table = fs.readJsonSync(src);
57
50
  const { rows, ...schema } = table;
58
- const { data: { id }, } = await (0, hubdb_1.createTable)(accountId, schema);
51
+ const { data: { id }, } = await createTable(accountId, schema);
59
52
  return addRowsToHubDbTable(accountId, id, rows);
60
53
  }
61
- exports.createHubDbTable = createHubDbTable;
62
- async function updateHubDbTable(accountId, tableId, src) {
54
+ export async function updateHubDbTable(accountId, tableId, src) {
63
55
  validateJsonFile(src);
64
- const table = fs_extra_1.default.readJsonSync(src);
56
+ const table = fs.readJsonSync(src);
65
57
  const { ...schema } = table;
66
- return (0, hubdb_1.updateTable)(accountId, tableId, schema);
58
+ return updateTable(accountId, tableId, schema);
67
59
  }
68
- exports.updateHubDbTable = updateHubDbTable;
69
60
  function convertToJSON(table, rows) {
70
61
  const { allowChildTables, allowPublicApiAccess, columns, dynamicMetaTags, enableChildTablePages, label, name, useForPages, } = table;
71
62
  const cleanedColumns = columns
@@ -98,17 +89,17 @@ async function fetchAllRows(accountId, tableId) {
98
89
  let rows = [];
99
90
  let after = null;
100
91
  do {
101
- const axiosResponse = await (0, hubdb_1.fetchRows)(accountId, tableId, after ? { after } : undefined);
92
+ const axiosResponse = await fetchRows(accountId, tableId, after ? { after } : undefined);
102
93
  const { paging, results } = axiosResponse.data;
103
94
  rows = rows.concat(results);
104
95
  after = paging && paging.next ? paging.next.after : null;
105
96
  } while (after !== null);
106
97
  return rows;
107
98
  }
108
- async function downloadHubDbTable(accountId, tableId, dest) {
109
- const { data: table } = await (0, hubdb_1.fetchTable)(accountId, tableId);
110
- dest = path_1.default.resolve((0, path_2.getCwd)(), dest || `${table.name}.hubdb.json`);
111
- if (fs_extra_1.default.pathExistsSync(dest)) {
99
+ export async function downloadHubDbTable(accountId, tableId, dest) {
100
+ const { data: table } = await fetchTable(accountId, tableId);
101
+ dest = path.resolve(getCwd(), dest || `${table.name}.hubdb.json`);
102
+ if (fs.pathExistsSync(dest)) {
112
103
  validateJsonFile(dest);
113
104
  }
114
105
  else {
@@ -116,18 +107,16 @@ async function downloadHubDbTable(accountId, tableId, dest) {
116
107
  }
117
108
  const rows = await fetchAllRows(accountId, tableId);
118
109
  const tableToWrite = JSON.stringify(convertToJSON(table, rows));
119
- const tableJson = await prettier_1.default.format(tableToWrite, {
110
+ const tableJson = await format(tableToWrite, {
120
111
  parser: 'json',
121
112
  });
122
- await fs_extra_1.default.outputFile(dest, tableJson);
113
+ await fs.outputFile(dest, tableJson);
123
114
  return { filePath: dest };
124
115
  }
125
- exports.downloadHubDbTable = downloadHubDbTable;
126
- async function clearHubDbTableRows(accountId, tableId) {
116
+ export async function clearHubDbTableRows(accountId, tableId) {
127
117
  const rows = await fetchAllRows(accountId, tableId);
128
- await (0, hubdb_1.deleteRows)(accountId, tableId, rows.map(row => row.id));
118
+ await deleteRows(accountId, tableId, rows.map(row => row.id));
129
119
  return {
130
120
  deletedRowCount: rows.length,
131
121
  };
132
122
  }
133
- exports.clearHubDbTableRows = clearHubDbTableRows;
@@ -1,36 +1,30 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ignoreFile = exports.createIgnoreFilter = exports.shouldIgnoreFile = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const ignore_1 = __importDefault(require("ignore"));
10
- const findup_sync_1 = __importDefault(require("findup-sync"));
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import ignore from 'ignore';
4
+ import findup from 'findup-sync';
11
5
  const ignoreList = [
12
6
  'fields.output.json',
13
7
  'hubspot.config.yml',
14
8
  'hubspot.config.yaml',
15
- 'node_modules',
16
- '.*',
17
- '*.log',
18
- '*.swp',
19
- '.env',
9
+ 'node_modules', // dependencies
10
+ '.*', // hidden files/folders
11
+ '*.log', // Error log for npm
12
+ '*.swp', // Swap file for vim state
13
+ '.env', // Dotenv file
20
14
  // # macOS
21
- 'Icon\\r',
22
- '__MACOSX',
15
+ 'Icon\\r', // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop
16
+ '__MACOSX', // Resource fork
23
17
  // # Linux
24
- '~',
18
+ '~', // Backup file
25
19
  // # Emacs
26
- '*~',
20
+ '*~', // Backup file
27
21
  // # Windows
28
- 'Thumbs.db',
29
- 'ehthumbs.db',
30
- 'Desktop.ini',
22
+ 'Thumbs.db', // Image file cache
23
+ 'ehthumbs.db', // Folder config file
24
+ 'Desktop.ini', // Stores custom folder attributes
31
25
  '@eaDir', // Synology Diskstation "hidden" folder where the server stores thumbnails
32
26
  ];
33
- const ignoreRules = (0, ignore_1.default)().add(ignoreList);
27
+ const ignoreRules = ignore().add(ignoreList);
34
28
  let searchDomain = null;
35
29
  let loaded = false;
36
30
  function loadIgnoreConfig(isInProject = false) {
@@ -42,28 +36,25 @@ function loadIgnoreConfig(isInProject = false) {
42
36
  if (!isInProject) {
43
37
  ignoreRules.add('package-lock.json');
44
38
  }
45
- const file = (0, findup_sync_1.default)('.hsignore');
39
+ const file = findup('.hsignore');
46
40
  if (file) {
47
- if (fs_1.default.existsSync(file)) {
48
- ignoreRules.add(fs_1.default.readFileSync(file).toString());
49
- searchDomain = path_1.default.dirname(file);
41
+ if (fs.existsSync(file)) {
42
+ ignoreRules.add(fs.readFileSync(file).toString());
43
+ searchDomain = path.dirname(file);
50
44
  }
51
45
  }
52
46
  loaded = true;
53
47
  }
54
- function shouldIgnoreFile(file, isInProject = false) {
48
+ export function shouldIgnoreFile(file, isInProject = false) {
55
49
  loadIgnoreConfig(isInProject);
56
50
  const relativeTo = searchDomain || '/';
57
- const relativePath = path_1.default.relative(relativeTo, file);
51
+ const relativePath = path.relative(relativeTo, file);
58
52
  return !!relativePath && ignoreRules.ignores(relativePath);
59
53
  }
60
- exports.shouldIgnoreFile = shouldIgnoreFile;
61
- function createIgnoreFilter(isInProject) {
54
+ export function createIgnoreFilter(isInProject) {
62
55
  loadIgnoreConfig(isInProject);
63
56
  return (file) => !shouldIgnoreFile(file);
64
57
  }
65
- exports.createIgnoreFilter = createIgnoreFilter;
66
- function ignoreFile(filePath) {
58
+ export function ignoreFile(filePath) {
67
59
  ignoreRules.add(filePath);
68
60
  }
69
- exports.ignoreFile = ignoreFile;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDeepEqual = void 0;
4
- function isDeepEqual(object1, object2, ignoreKeys) {
1
+ export function isDeepEqual(object1, object2, ignoreKeys) {
5
2
  if (object1 === object2) {
6
3
  return true;
7
4
  }
@@ -32,4 +29,3 @@ function isDeepEqual(object1, object2, ignoreKeys) {
32
29
  }
33
30
  return true;
34
31
  }
35
- exports.isDeepEqual = isDeepEqual;