@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/cms/watch.js CHANGED
@@ -1,48 +1,42 @@
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.watch = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const chokidar_1 = __importDefault(require("chokidar"));
9
- const p_queue_1 = __importDefault(require("p-queue"));
10
- const debounce_1 = __importDefault(require("debounce"));
11
- const handleFieldsJS_1 = require("./handleFieldsJS");
12
- const uploadFolder_1 = require("./uploadFolder");
13
- const ignoreRules_1 = require("../ignoreRules");
14
- const fileMapper_1 = require("../fileMapper");
15
- const fileMapper_2 = require("../../api/fileMapper");
16
- const escapeRegExp_1 = require("../escapeRegExp");
17
- const path_2 = require("../path");
18
- const notify_1 = require("../notify");
19
- const themes_1 = require("./themes");
20
- const logger_1 = require("../logger");
21
- const lang_1 = require("../../utils/lang");
22
- const HubSpotHttpError_1 = require("../../models/HubSpotHttpError");
23
- const errors_1 = require("../../errors");
1
+ import path from 'path';
2
+ import chokidar from 'chokidar';
3
+ import PQueue from 'p-queue';
4
+ import debounce from 'debounce';
5
+ import { isConvertableFieldJs, FieldsJs } from './handleFieldsJS.js';
6
+ import { uploadFolder } from './uploadFolder.js';
7
+ import { shouldIgnoreFile, ignoreFile } from '../ignoreRules.js';
8
+ import { getFileMapperQueryValues } from '../fileMapper.js';
9
+ import { upload, deleteFile } from '../../api/fileMapper.js';
10
+ import { escapeRegExp } from '../escapeRegExp.js';
11
+ import { convertToUnixPath, isAllowedExtension, getCwd } from '../path.js';
12
+ import { triggerNotify } from '../notify.js';
13
+ import { getThemePreviewUrl, getThemeJSONPath } from './themes.js';
14
+ import { logger } from '../logger.js';
15
+ import { i18n } from '../../utils/lang.js';
16
+ import { HubSpotHttpError } from '../../models/HubSpotHttpError.js';
17
+ import { isHubSpotHttpError } from '../../errors/index.js';
24
18
  const i18nKey = 'lib.cms.watch';
25
- const queue = new p_queue_1.default({
19
+ const queue = new PQueue({
26
20
  concurrency: 10,
27
21
  });
28
22
  function _notifyOfThemePreview(filePath, accountId) {
29
23
  if (queue.size > 0)
30
24
  return;
31
- const previewUrl = (0, themes_1.getThemePreviewUrl)(filePath, accountId);
25
+ const previewUrl = getThemePreviewUrl(filePath, accountId);
32
26
  if (!previewUrl)
33
27
  return;
34
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.notifyOfThemePreview`, {
28
+ logger.log(i18n(`${i18nKey}.notifyOfThemePreview`, {
35
29
  previewUrl,
36
30
  }));
37
31
  }
38
- const notifyOfThemePreview = (0, debounce_1.default)(_notifyOfThemePreview, 1000);
32
+ const notifyOfThemePreview = debounce(_notifyOfThemePreview, 1000);
39
33
  const defaultOnUploadFileError = (file, dest, accountId) => (error) => {
40
- const uploadFailedMessage = (0, lang_1.i18n)(`${i18nKey}.uploadFailed`, {
34
+ const uploadFailedMessage = i18n(`${i18nKey}.uploadFailed`, {
41
35
  file,
42
36
  dest,
43
37
  });
44
- logger_1.logger.debug(uploadFailedMessage);
45
- throw new HubSpotHttpError_1.HubSpotHttpError(uploadFailedMessage, {
38
+ logger.debug(uploadFailedMessage);
39
+ throw new HubSpotHttpError(uploadFailedMessage, {
46
40
  cause: error,
47
41
  }, {
48
42
  accountId,
@@ -52,61 +46,61 @@ const defaultOnUploadFileError = (file, dest, accountId) => (error) => {
52
46
  };
53
47
  async function uploadFile(accountId, file, dest, options, cmsPublishMode = null, onUploadFileError = defaultOnUploadFileError) {
54
48
  const src = options.src;
55
- const absoluteSrcPath = path_1.default.resolve((0, path_2.getCwd)(), file);
56
- const themeJsonPath = (0, themes_1.getThemeJSONPath)(absoluteSrcPath);
49
+ const absoluteSrcPath = path.resolve(getCwd(), file);
50
+ const themeJsonPath = getThemeJSONPath(absoluteSrcPath);
57
51
  const projectRoot = themeJsonPath
58
- ? path_1.default.dirname(themeJsonPath)
59
- : path_1.default.dirname((0, path_2.getCwd)());
60
- const convertFields = (0, handleFieldsJS_1.isConvertableFieldJs)(src, file, options.commandOptions.convertFields);
61
- if (!(0, path_2.isAllowedExtension)(file) && !convertFields) {
62
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.skipUnsupportedExtension`, { file }));
52
+ ? path.dirname(themeJsonPath)
53
+ : path.dirname(getCwd());
54
+ const convertFields = isConvertableFieldJs(src, file, options.commandOptions.convertFields);
55
+ if (!isAllowedExtension(file) && !convertFields) {
56
+ logger.debug(i18n(`${i18nKey}.skipUnsupportedExtension`, { file }));
63
57
  return;
64
58
  }
65
- if ((0, ignoreRules_1.shouldIgnoreFile)(file)) {
66
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.skipIgnoreRule`, { file }));
59
+ if (shouldIgnoreFile(file)) {
60
+ logger.debug(i18n(`${i18nKey}.skipIgnoreRule`, { file }));
67
61
  return;
68
62
  }
69
63
  let fieldsJs = undefined;
70
64
  if (convertFields) {
71
- fieldsJs = await new handleFieldsJS_1.FieldsJs(projectRoot, absoluteSrcPath, undefined, options.fieldOptions).init();
65
+ fieldsJs = await new FieldsJs(projectRoot, absoluteSrcPath, undefined, options.fieldOptions).init();
72
66
  if (fieldsJs.rejected)
73
67
  return;
74
68
  // Ensures that the dest path is a .json. The user might pass '.js' accidentally - this ensures it just works.
75
- dest = (0, path_2.convertToUnixPath)(path_1.default.join(path_1.default.dirname(dest), 'fields.json'));
69
+ dest = convertToUnixPath(path.join(path.dirname(dest), 'fields.json'));
76
70
  }
77
71
  const fileToUpload = convertFields && fieldsJs?.outputPath ? fieldsJs.outputPath : file;
78
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadAttempt`, { file, dest }));
79
- const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(cmsPublishMode, options);
72
+ logger.debug(i18n(`${i18nKey}.uploadAttempt`, { file, dest }));
73
+ const apiOptions = getFileMapperQueryValues(cmsPublishMode, options);
80
74
  queue.add(() => {
81
- return (0, fileMapper_2.upload)(accountId, fileToUpload, dest, apiOptions)
75
+ return upload(accountId, fileToUpload, dest, apiOptions)
82
76
  .then(() => {
83
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadSuccess`, { file, dest }));
77
+ logger.log(i18n(`${i18nKey}.uploadSuccess`, { file, dest }));
84
78
  notifyOfThemePreview(file, accountId);
85
79
  })
86
80
  .catch(() => {
87
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFailed`, { file, dest }));
88
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadRetry`, { file, dest }));
89
- return (0, fileMapper_2.upload)(accountId, file, dest, apiOptions).catch(onUploadFileError(file, dest, accountId));
81
+ logger.debug(i18n(`${i18nKey}.uploadFailed`, { file, dest }));
82
+ logger.debug(i18n(`${i18nKey}.uploadRetry`, { file, dest }));
83
+ return upload(accountId, file, dest, apiOptions).catch(onUploadFileError(file, dest, accountId));
90
84
  });
91
85
  });
92
86
  }
93
87
  async function deleteRemoteFile(accountId, filePath, remoteFilePath) {
94
- if ((0, ignoreRules_1.shouldIgnoreFile)(filePath)) {
95
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.skipIgnoreRule`, { file: filePath }));
88
+ if (shouldIgnoreFile(filePath)) {
89
+ logger.debug(i18n(`${i18nKey}.skipIgnoreRule`, { file: filePath }));
96
90
  return;
97
91
  }
98
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.deleteAttempt`, { remoteFilePath }));
92
+ logger.debug(i18n(`${i18nKey}.deleteAttempt`, { remoteFilePath }));
99
93
  return queue.add(() => {
100
- return (0, fileMapper_2.deleteFile)(accountId, remoteFilePath)
94
+ return deleteFile(accountId, remoteFilePath)
101
95
  .then(() => {
102
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.deleteSuccess`, { remoteFilePath }));
96
+ logger.log(i18n(`${i18nKey}.deleteSuccess`, { remoteFilePath }));
103
97
  notifyOfThemePreview(filePath, accountId);
104
98
  })
105
99
  .catch(error => {
106
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.deleteFailed`, {
100
+ logger.debug(i18n(`${i18nKey}.deleteFailed`, {
107
101
  remoteFilePath,
108
102
  }));
109
- if ((0, errors_1.isHubSpotHttpError)(error)) {
103
+ if (isHubSpotHttpError(error)) {
110
104
  error.updateContext({
111
105
  accountId,
112
106
  request: remoteFilePath,
@@ -116,23 +110,23 @@ async function deleteRemoteFile(accountId, filePath, remoteFilePath) {
116
110
  });
117
111
  });
118
112
  }
119
- function watch(accountId, src, dest, { cmsPublishMode, remove, disableInitial, notify, commandOptions, filePaths, }, postInitialUploadCallback = null, onUploadFolderError, onQueueAddError, onUploadFileError) {
120
- const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
113
+ export function watch(accountId, src, dest, { cmsPublishMode, remove, disableInitial, notify, commandOptions, filePaths, }, postInitialUploadCallback = null, onUploadFolderError, onQueueAddError, onUploadFileError) {
114
+ const regex = new RegExp(`^${escapeRegExp(src)}`);
121
115
  if (notify) {
122
- (0, ignoreRules_1.ignoreFile)(notify);
116
+ ignoreFile(notify);
123
117
  }
124
- const watcher = chokidar_1.default.watch(src, {
118
+ const watcher = chokidar.watch(src, {
125
119
  ignoreInitial: true,
126
- ignored: (file) => (0, ignoreRules_1.shouldIgnoreFile)(file),
120
+ ignored: (file) => shouldIgnoreFile(file),
127
121
  });
128
122
  function getDesignManagerPath(file) {
129
123
  const relativePath = file.replace(regex, '');
130
- return (0, path_2.convertToUnixPath)(path_1.default.join(dest, relativePath));
124
+ return convertToUnixPath(path.join(dest, relativePath));
131
125
  }
132
126
  if (!disableInitial) {
133
127
  // Use uploadFolder so that failures of initial upload are retried
134
- const uploadFolderPromise = (0, uploadFolder_1.uploadFolder)(accountId, src, dest, {}, commandOptions, filePaths, cmsPublishMode || null).then(result => {
135
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.folderUploadSuccess`, {
128
+ const uploadFolderPromise = uploadFolder(accountId, src, dest, {}, commandOptions, filePaths, cmsPublishMode || null).then(result => {
129
+ logger.log(i18n(`${i18nKey}.folderUploadSuccess`, {
136
130
  src,
137
131
  dest,
138
132
  accountId,
@@ -146,7 +140,7 @@ function watch(accountId, src, dest, { cmsPublishMode, remove, disableInitial, n
146
140
  }
147
141
  }
148
142
  watcher.on('ready', () => {
149
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.ready`, { src }));
143
+ logger.log(i18n(`${i18nKey}.ready`, { src }));
150
144
  });
151
145
  watcher.on('add', async (filePath) => {
152
146
  const destPath = getDesignManagerPath(filePath);
@@ -154,26 +148,26 @@ function watch(accountId, src, dest, { cmsPublishMode, remove, disableInitial, n
154
148
  src,
155
149
  commandOptions,
156
150
  }, cmsPublishMode, onUploadFileError);
157
- (0, notify_1.triggerNotify)(notify, 'Added', filePath, uploadPromise);
151
+ triggerNotify(notify, 'Added', filePath, uploadPromise);
158
152
  });
159
153
  if (remove) {
160
154
  const deleteFileOrFolder = (type) => (filePath) => {
161
155
  // If it's a fields.js file that is in a module folder or the root, then ignore because it will not exist on the server.
162
- if ((0, handleFieldsJS_1.isConvertableFieldJs)(src, filePath, commandOptions.convertFields)) {
156
+ if (isConvertableFieldJs(src, filePath, commandOptions.convertFields)) {
163
157
  return;
164
158
  }
165
159
  const remotePath = getDesignManagerPath(filePath);
166
- if ((0, ignoreRules_1.shouldIgnoreFile)(filePath)) {
167
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.skipIgnoreRule`, { file: filePath }));
160
+ if (shouldIgnoreFile(filePath)) {
161
+ logger.debug(i18n(`${i18nKey}.skipIgnoreRule`, { file: filePath }));
168
162
  return;
169
163
  }
170
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.deleteAttemptWithType`, {
164
+ logger.debug(i18n(`${i18nKey}.deleteAttemptWithType`, {
171
165
  type,
172
166
  remoteFilePath: remotePath,
173
167
  }));
174
168
  const queueAddPromise = queue.add(() => {
175
169
  const deletePromise = deleteRemoteFile(accountId, filePath, remotePath).then(() => {
176
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.deleteSuccessWithType`, {
170
+ logger.log(i18n(`${i18nKey}.deleteSuccessWithType`, {
177
171
  type,
178
172
  remoteFilePath: remotePath,
179
173
  }));
@@ -181,7 +175,7 @@ function watch(accountId, src, dest, { cmsPublishMode, remove, disableInitial, n
181
175
  if (onQueueAddError) {
182
176
  queueAddPromise.catch(onQueueAddError);
183
177
  }
184
- (0, notify_1.triggerNotify)(notify, 'Removed', filePath, deletePromise);
178
+ triggerNotify(notify, 'Removed', filePath, deletePromise);
185
179
  return deletePromise;
186
180
  });
187
181
  };
@@ -194,8 +188,7 @@ function watch(accountId, src, dest, { cmsPublishMode, remove, disableInitial, n
194
188
  src,
195
189
  commandOptions,
196
190
  }, cmsPublishMode, onUploadFileError);
197
- (0, notify_1.triggerNotify)(notify, 'Changed', filePath, uploadPromise);
191
+ triggerNotify(notify, 'Changed', filePath, uploadPromise);
198
192
  });
199
193
  return watcher;
200
194
  }
201
- exports.watch = watch;
package/lib/crm.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ImportRequest } from '../types/Crm';
1
+ import { ImportRequest } from '../types/Crm.js';
2
2
  export declare function getImportDataRequest(fileName: string): {
3
3
  importRequest: ImportRequest;
4
4
  dataFileNames: string[];
package/lib/crm.js CHANGED
@@ -1,48 +1,40 @@
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.validateImportRequestFile = exports.getImportDataRequest = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const path_2 = require("./path");
9
- const fs_extra_1 = __importDefault(require("fs-extra"));
10
- const lang_1 = require("../utils/lang");
11
- function getImportDataRequest(fileName) {
1
+ import path from 'path';
2
+ import { getCwd } from './path.js';
3
+ import fs from 'fs-extra';
4
+ import { i18n } from '../utils/lang.js';
5
+ export function getImportDataRequest(fileName) {
12
6
  validateImportRequestFile(fileName);
13
- const importRequest = fs_extra_1.default.readJsonSync(path_1.default.resolve((0, path_2.getCwd)(), fileName));
7
+ const importRequest = fs.readJsonSync(path.resolve(getCwd(), fileName));
14
8
  const dataFileNames = importRequest.files.map(file => file.fileName);
15
9
  // allow relative paths in the provided import request
16
10
  importRequest.files = importRequest.files.map(file => ({
17
11
  ...file,
18
- fileName: path_1.default.basename(file.fileName),
12
+ fileName: path.basename(file.fileName),
19
13
  }));
20
14
  if (dataFileNames.length === 0) {
21
- throw new Error((0, lang_1.i18n)('lib.crm.importData.errors.noFiles'));
15
+ throw new Error(i18n('lib.crm.importData.errors.noFiles'));
22
16
  }
23
17
  dataFileNames.forEach(fileName => {
24
18
  if (!fileExists(fileName)) {
25
- throw new Error((0, lang_1.i18n)('lib.crm.importData.errors.fileNotFound', { fileName }));
19
+ throw new Error(i18n('lib.crm.importData.errors.fileNotFound', { fileName }));
26
20
  }
27
21
  });
28
22
  return { importRequest, dataFileNames };
29
23
  }
30
- exports.getImportDataRequest = getImportDataRequest;
31
- function validateImportRequestFile(fileName) {
24
+ export function validateImportRequestFile(fileName) {
32
25
  if (!fileExists(fileName)) {
33
- throw new Error((0, lang_1.i18n)('lib.crm.importData.errors.fileNotFound', { fileName }));
26
+ throw new Error(i18n('lib.crm.importData.errors.fileNotFound', { fileName }));
34
27
  }
35
- if (path_1.default.extname(fileName) !== '.json') {
36
- throw new Error((0, lang_1.i18n)('lib.crm.importData.errors.notJson'));
28
+ if (path.extname(fileName) !== '.json') {
29
+ throw new Error(i18n('lib.crm.importData.errors.notJson'));
37
30
  }
38
31
  }
39
- exports.validateImportRequestFile = validateImportRequestFile;
40
32
  function fileExists(_path) {
41
33
  try {
42
- const absoluteSrcPath = path_1.default.resolve((0, path_2.getCwd)(), _path);
34
+ const absoluteSrcPath = path.resolve(getCwd(), _path);
43
35
  if (!absoluteSrcPath)
44
36
  return false;
45
- const stats = fs_extra_1.default.statSync(absoluteSrcPath);
37
+ const stats = fs.statSync(absoluteSrcPath);
46
38
  const isFile = stats.isFile();
47
39
  if (!isFile) {
48
40
  return false;
@@ -1,4 +1,4 @@
1
- import { Schema } from '../types/Schemas';
1
+ import { Schema } from '../types/Schemas.js';
2
2
  export declare function getResolvedPath(dest?: string, name?: string): string;
3
3
  export declare function writeSchemaToDisk(schema: Schema, dest?: string): Promise<void>;
4
4
  export declare function downloadSchemas(accountId: number, dest?: string): Promise<Array<Schema>>;
@@ -1,29 +1,21 @@
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.downloadSchema = exports.downloadSchemas = exports.writeSchemaToDisk = exports.getResolvedPath = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const path_1 = __importDefault(require("path"));
9
- const prettier_1 = __importDefault(require("prettier"));
10
- const path_2 = require("../lib/path");
11
- const customObjects_1 = require("../api/customObjects");
12
- function getResolvedPath(dest, name) {
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import { getCwd } from '../lib/path.js';
4
+ import { fetchObjectSchemas, fetchObjectSchema } from '../api/customObjects.js';
5
+ import { format } from 'prettier';
6
+ export function getResolvedPath(dest, name) {
13
7
  if (name)
14
- return path_1.default.resolve((0, path_2.getCwd)(), dest || '', `${name}.json`);
15
- return path_1.default.resolve((0, path_2.getCwd)(), dest || '');
8
+ return path.resolve(getCwd(), dest || '', `${name}.json`);
9
+ return path.resolve(getCwd(), dest || '');
16
10
  }
17
- exports.getResolvedPath = getResolvedPath;
18
- async function writeSchemaToDisk(schema, dest) {
19
- const formattedSchema = await prettier_1.default.format(JSON.stringify(schema), {
11
+ export async function writeSchemaToDisk(schema, dest) {
12
+ const formattedSchema = await format(JSON.stringify(schema), {
20
13
  parser: 'json',
21
14
  });
22
- fs_extra_1.default.outputFileSync(getResolvedPath(dest, schema.name), formattedSchema);
15
+ fs.outputFileSync(getResolvedPath(dest, schema.name), formattedSchema);
23
16
  }
24
- exports.writeSchemaToDisk = writeSchemaToDisk;
25
- async function downloadSchemas(accountId, dest) {
26
- const axiosResponse = await (0, customObjects_1.fetchObjectSchemas)(accountId);
17
+ export async function downloadSchemas(accountId, dest) {
18
+ const axiosResponse = await fetchObjectSchemas(accountId);
27
19
  const response = axiosResponse.data;
28
20
  if (response.results.length) {
29
21
  for (const schema of response.results) {
@@ -32,11 +24,9 @@ async function downloadSchemas(accountId, dest) {
32
24
  }
33
25
  return response.results;
34
26
  }
35
- exports.downloadSchemas = downloadSchemas;
36
- async function downloadSchema(accountId, schemaObjectType, dest) {
37
- const axiosResponse = await (0, customObjects_1.fetchObjectSchema)(accountId, schemaObjectType);
27
+ export async function downloadSchema(accountId, schemaObjectType, dest) {
28
+ const axiosResponse = await fetchObjectSchema(accountId, schemaObjectType);
38
29
  const response = axiosResponse.data;
39
30
  await writeSchemaToDisk(response, dest);
40
31
  return response;
41
32
  }
42
- exports.downloadSchema = downloadSchema;
@@ -1,2 +1,2 @@
1
- import { Environment } from '../types/Config';
1
+ import { Environment } from '../types/Accounts.js';
2
2
  export declare function getValidEnv(env?: string | null, maskedProductionValue?: Environment): Environment;
@@ -1,16 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValidEnv = void 0;
4
- const environments_1 = require("../constants/environments");
5
- function getValidEnv(env, maskedProductionValue) {
1
+ import { ENVIRONMENTS } from '../constants/environments.js';
2
+ export function getValidEnv(env, maskedProductionValue) {
6
3
  const prodValue = typeof maskedProductionValue === 'string'
7
4
  ? maskedProductionValue
8
- : environments_1.ENVIRONMENTS.PROD;
9
- const returnVal = typeof env &&
10
- typeof env === 'string' &&
11
- env.toLowerCase() === environments_1.ENVIRONMENTS.QA
12
- ? environments_1.ENVIRONMENTS.QA
5
+ : ENVIRONMENTS.PROD;
6
+ const returnVal = env && typeof env === 'string' && env.toLowerCase() === ENVIRONMENTS.QA
7
+ ? ENVIRONMENTS.QA
13
8
  : prodValue;
14
9
  return returnVal;
15
10
  }
16
- exports.getValidEnv = getValidEnv;
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.escapeRegExp = void 0;
4
- function escapeRegExp(string) {
1
+ export function escapeRegExp(string) {
5
2
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
6
3
  }
7
- exports.escapeRegExp = escapeRegExp;