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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/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 +3 -3
  12. package/api/developerTestAccounts.js +29 -40
  13. package/api/fileManager.d.ts +2 -2
  14. package/api/fileManager.js +14 -24
  15. package/api/fileMapper.d.ts +2 -2
  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 -2
  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 +5 -5
  30. package/api/localDevAuth.js +17 -25
  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 +3 -3
  36. package/api/sandboxHubs.js +21 -30
  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.js +18 -26
  44. package/config/index.d.ts +4 -4
  45. package/config/index.js +141 -177
  46. package/config/migrate.d.ts +2 -2
  47. package/config/migrate.js +26 -37
  48. package/config/state.d.ts +1 -1
  49. package/config/state.js +17 -45
  50. package/config/utils.d.ts +4 -4
  51. package/config/utils.js +85 -108
  52. package/constants/api.js +3 -6
  53. package/constants/auth.js +9 -12
  54. package/constants/config.js +37 -43
  55. package/constants/environments.js +1 -4
  56. package/constants/extensions.js +6 -9
  57. package/constants/files.js +5 -8
  58. package/constants/ports.js +3 -6
  59. package/constants/projects.js +2 -5
  60. package/enums/build.js +5 -8
  61. package/enums/deploy.js +2 -5
  62. package/enums/project.js +1 -4
  63. package/errors/errors_DEPRECATED.d.ts +1 -1
  64. package/errors/errors_DEPRECATED.js +2 -7
  65. package/errors/index.d.ts +4 -4
  66. package/errors/index.js +17 -31
  67. package/http/addQueryParams.d.ts +1 -1
  68. package/http/addQueryParams.js +1 -5
  69. package/http/client.js +16 -42
  70. package/http/getAxiosConfig.d.ts +1 -1
  71. package/http/getAxiosConfig.js +21 -31
  72. package/http/index.d.ts +2 -2
  73. package/http/index.js +39 -46
  74. package/http/unauthed.d.ts +1 -1
  75. package/http/unauthed.js +15 -18
  76. package/lib/archive.d.ts +1 -3
  77. package/lib/archive.js +38 -67
  78. package/lib/cms/functions.d.ts +1 -1
  79. package/lib/cms/functions.js +45 -55
  80. package/lib/cms/handleFieldsJS.js +36 -44
  81. package/lib/cms/modules.d.ts +2 -2
  82. package/lib/cms/modules.js +49 -59
  83. package/lib/cms/processFieldsJs.js +17 -32
  84. package/lib/cms/templates.js +17 -26
  85. package/lib/cms/themes.js +10 -18
  86. package/lib/cms/uploadFolder.d.ts +4 -4
  87. package/lib/cms/uploadFolder.js +55 -64
  88. package/lib/cms/validate.d.ts +1 -1
  89. package/lib/cms/validate.js +11 -18
  90. package/lib/cms/watch.d.ts +2 -2
  91. package/lib/cms/watch.js +66 -73
  92. package/lib/crm.d.ts +1 -1
  93. package/lib/crm.js +16 -23
  94. package/lib/customObjects.d.ts +1 -1
  95. package/lib/customObjects.js +15 -25
  96. package/lib/environment.d.ts +1 -1
  97. package/lib/environment.js +5 -11
  98. package/lib/escapeRegExp.js +1 -5
  99. package/lib/fileManager.js +43 -51
  100. package/lib/fileMapper.d.ts +1 -1
  101. package/lib/fileMapper.js +70 -84
  102. package/lib/fs.d.ts +1 -1
  103. package/lib/fs.js +18 -27
  104. package/lib/github.d.ts +1 -3
  105. package/lib/github.js +39 -51
  106. package/lib/gitignore.d.ts +1 -1
  107. package/lib/gitignore.js +16 -24
  108. package/lib/hubdb.d.ts +1 -1
  109. package/lib/hubdb.js +29 -40
  110. package/lib/ignoreRules.js +25 -34
  111. package/lib/isDeepEqual.js +1 -5
  112. package/lib/logger.d.ts +8 -20
  113. package/lib/logger.js +47 -59
  114. package/lib/notify.js +9 -16
  115. package/lib/oauth.d.ts +2 -2
  116. package/lib/oauth.js +12 -17
  117. package/lib/path.d.ts +0 -1
  118. package/lib/path.js +30 -48
  119. package/lib/personalAccessKey.d.ts +3 -3
  120. package/lib/personalAccessKey.js +47 -59
  121. package/lib/portManager.d.ts +2 -2
  122. package/lib/portManager.js +26 -41
  123. package/lib/text.js +2 -7
  124. package/lib/trackUsage.d.ts +2 -2
  125. package/lib/trackUsage.js +26 -29
  126. package/lib/urls.js +4 -9
  127. package/models/FileSystemError.d.ts +1 -1
  128. package/models/FileSystemError.js +12 -16
  129. package/models/HubSpotConfigError.d.ts +1 -1
  130. package/models/HubSpotConfigError.js +8 -12
  131. package/models/HubSpotHttpError.d.ts +1 -1
  132. package/models/HubSpotHttpError.js +22 -26
  133. package/models/OAuth2Manager.d.ts +1 -1
  134. package/models/OAuth2Manager.js +17 -24
  135. package/package.json +17 -16
  136. package/types/Accounts.d.ts +5 -5
  137. package/types/Accounts.js +1 -2
  138. package/types/Activity.d.ts +3 -3
  139. package/types/Activity.js +1 -2
  140. package/types/Api.d.ts +1 -1
  141. package/types/Api.js +1 -2
  142. package/types/Apps.js +1 -2
  143. package/types/Archive.js +1 -2
  144. package/types/Build.d.ts +5 -5
  145. package/types/Build.js +1 -2
  146. package/types/CLIOptions.js +1 -2
  147. package/types/ComponentStructure.d.ts +2 -2
  148. package/types/ComponentStructure.js +1 -2
  149. package/types/Config.d.ts +5 -5
  150. package/types/Config.js +1 -2
  151. package/types/Crm.js +1 -2
  152. package/types/Deploy.d.ts +5 -5
  153. package/types/Deploy.js +1 -2
  154. package/types/DesignManager.js +1 -2
  155. package/types/DevSecrets.js +1 -2
  156. package/types/Error.js +1 -2
  157. package/types/FieldsJS.js +1 -2
  158. package/types/FileManager.js +1 -2
  159. package/types/Files.d.ts +4 -4
  160. package/types/Files.js +1 -2
  161. package/types/FireAlarm.js +1 -2
  162. package/types/Functions.js +1 -2
  163. package/types/Github.d.ts +1 -1
  164. package/types/Github.js +1 -2
  165. package/types/Http.d.ts +0 -4
  166. package/types/Http.js +1 -2
  167. package/types/Hubdb.js +1 -2
  168. package/types/HublValidation.js +1 -2
  169. package/types/Lang.d.ts +1 -1
  170. package/types/Lang.js +1 -2
  171. package/types/Lighthouse.js +1 -2
  172. package/types/MarketplaceValidation.js +1 -2
  173. package/types/Migration.d.ts +2 -2
  174. package/types/Migration.js +1 -4
  175. package/types/Modules.js +1 -2
  176. package/types/PortManager.js +1 -2
  177. package/types/Project.d.ts +3 -3
  178. package/types/Project.js +1 -2
  179. package/types/ProjectLog.js +1 -2
  180. package/types/Sandbox.js +2 -5
  181. package/types/Schemas.js +1 -2
  182. package/types/Secrets.js +1 -2
  183. package/types/Utils.js +1 -2
  184. package/types/developerTestAccounts.js +1 -2
  185. package/utils/PortManagerServer.d.ts +1 -2
  186. package/utils/PortManagerServer.js +32 -38
  187. package/utils/cms/fieldsJS.d.ts +1 -1
  188. package/utils/cms/fieldsJS.js +1 -5
  189. package/utils/cms/modules.d.ts +1 -1
  190. package/utils/cms/modules.js +13 -22
  191. package/utils/detectPort.js +12 -19
  192. package/utils/git.js +17 -26
  193. package/utils/lang.d.ts +1 -1
  194. package/utils/lang.js +5 -14
@@ -1,74 +1,67 @@
1
- "use strict";
2
1
  // FILE MANAGER - not to be confused with fileMapper.ts
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.downloadFileOrFolder = exports.uploadFolder = void 0;
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const path_1 = __importDefault(require("path"));
10
- const fileManager_1 = require("../api/fileManager");
11
- const fs_1 = require("./fs");
12
- const logger_1 = require("./logger");
13
- const ignoreRules_1 = require("./ignoreRules");
14
- const http_1 = require("../http");
15
- const escapeRegExp_1 = require("./escapeRegExp");
16
- const path_2 = require("./path");
17
- const lang_1 = require("../utils/lang");
18
- const errors_1 = require("../errors");
19
- const FileSystemError_1 = require("../models/FileSystemError");
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { uploadFile, fetchStat, fetchFiles, fetchFolders, } from '../api/fileManager.js';
5
+ import { walk } from './fs.js';
6
+ import { logger } from './logger.js';
7
+ import { createIgnoreFilter } from './ignoreRules.js';
8
+ import { http } from '../http/index.js';
9
+ import { escapeRegExp } from './escapeRegExp.js';
10
+ import { getCwd, convertToUnixPath, convertToLocalFileSystemPath, } from './path.js';
11
+ import { i18n } from '../utils/lang.js';
12
+ import { isAuthError, isHubSpotHttpError } from '../errors/index.js';
13
+ import { FileSystemError } from '../models/FileSystemError.js';
20
14
  const i18nKey = 'lib.fileManager';
21
- async function uploadFolder(accountId, src, dest) {
22
- const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
23
- const files = await (0, fs_1.walk)(src);
24
- const filesToUpload = files.filter((0, ignoreRules_1.createIgnoreFilter)(false));
15
+ export async function uploadFolder(accountId, src, dest) {
16
+ const regex = new RegExp(`^${escapeRegExp(src)}`);
17
+ const files = await walk(src);
18
+ const filesToUpload = files.filter(createIgnoreFilter(false));
25
19
  const len = filesToUpload.length;
26
20
  for (let index = 0; index < len; index++) {
27
21
  const file = filesToUpload[index];
28
22
  const relativePath = file.replace(regex, '');
29
- const destPath = (0, path_2.convertToUnixPath)(path_1.default.join(dest, relativePath));
30
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadStarted`, {
23
+ const destPath = convertToUnixPath(path.join(dest, relativePath));
24
+ logger.debug(i18n(`${i18nKey}.uploadStarted`, {
31
25
  file,
32
26
  destPath,
33
27
  accountId,
34
28
  }));
35
29
  try {
36
- await (0, fileManager_1.uploadFile)(accountId, file, destPath);
37
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadSuccess`, { file, destPath }));
30
+ await uploadFile(accountId, file, destPath);
31
+ logger.log(i18n(`${i18nKey}.uploadSuccess`, { file, destPath }));
38
32
  }
39
33
  catch (err) {
40
- if ((0, errors_1.isHubSpotHttpError)(err)) {
34
+ if (isHubSpotHttpError(err)) {
41
35
  err.updateContext({
42
36
  filepath: file,
43
37
  dest: destPath,
44
38
  });
45
39
  throw err;
46
40
  }
47
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.uploadFailed`, {
41
+ throw new Error(i18n(`${i18nKey}.errors.uploadFailed`, {
48
42
  file,
49
43
  destPath,
50
44
  }));
51
45
  }
52
46
  }
53
47
  }
54
- exports.uploadFolder = uploadFolder;
55
48
  async function skipExisting(overwrite, filepath) {
56
49
  if (overwrite) {
57
50
  return false;
58
51
  }
59
- if (await fs_extra_1.default.pathExists(filepath)) {
60
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.skippedExisting`, { filepath }));
52
+ if (await fs.pathExists(filepath)) {
53
+ logger.log(i18n(`${i18nKey}.skippedExisting`, { filepath }));
61
54
  return true;
62
55
  }
63
56
  return false;
64
57
  }
65
58
  async function downloadFile(accountId, file, dest, overwrite) {
66
59
  const fileName = `${file.name}.${file.extension}`;
67
- const destPath = (0, path_2.convertToLocalFileSystemPath)(path_1.default.join(dest, fileName));
60
+ const destPath = convertToLocalFileSystemPath(path.join(dest, fileName));
68
61
  if (await skipExisting(overwrite || false, destPath)) {
69
62
  return;
70
63
  }
71
- await http_1.http.getOctetStream(accountId, {
64
+ await http.getOctetStream(accountId, {
72
65
  baseURL: file.url,
73
66
  url: '',
74
67
  }, destPath);
@@ -79,7 +72,7 @@ async function fetchAllPagedFiles(accountId, folderId, includeArchived) {
79
72
  let count = 0;
80
73
  let offset = 0;
81
74
  while (totalFiles === null || count < totalFiles) {
82
- const { data: response } = await (0, fileManager_1.fetchFiles)(accountId, folderId, offset, includeArchived);
75
+ const { data: response } = await fetchFiles(accountId, folderId, offset, includeArchived);
83
76
  if (totalFiles === null) {
84
77
  totalFiles = response.total_count;
85
78
  }
@@ -91,26 +84,26 @@ async function fetchAllPagedFiles(accountId, folderId, includeArchived) {
91
84
  }
92
85
  async function fetchFolderContents(accountId, folder, dest, overwrite, includeArchived) {
93
86
  try {
94
- await fs_extra_1.default.ensureDir(dest);
87
+ await fs.ensureDir(dest);
95
88
  }
96
89
  catch (err) {
97
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
90
+ throw new FileSystemError({ cause: err }, {
98
91
  dest,
99
92
  accountId,
100
93
  operation: 'write',
101
94
  });
102
95
  }
103
96
  const files = await fetchAllPagedFiles(accountId, folder.id, includeArchived);
104
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.fetchingFiles`, {
97
+ logger.debug(i18n(`${i18nKey}.fetchingFiles`, {
105
98
  fileCount: files.length,
106
99
  folderName: folder.name || '',
107
100
  }));
108
101
  for (const file of files) {
109
102
  await downloadFile(accountId, file, dest, overwrite);
110
103
  }
111
- const { data: { objects: folders }, } = await (0, fileManager_1.fetchFolders)(accountId, folder.id);
104
+ const { data: { objects: folders }, } = await fetchFolders(accountId, folder.id);
112
105
  for (const folder of folders) {
113
- const nestedFolder = path_1.default.join(dest, folder.name);
106
+ const nestedFolder = path.join(dest, folder.name);
114
107
  await fetchFolderContents(accountId, folder, nestedFolder, overwrite, includeArchived);
115
108
  }
116
109
  }
@@ -118,18 +111,18 @@ async function fetchFolderContents(accountId, folder, dest, overwrite, includeAr
118
111
  async function downloadFolder(accountId, src, dest, folder, overwrite, includeArchived) {
119
112
  let absolutePath;
120
113
  if (folder.name) {
121
- absolutePath = (0, path_2.convertToLocalFileSystemPath)(path_1.default.resolve((0, path_2.getCwd)(), dest, folder.name));
114
+ absolutePath = convertToLocalFileSystemPath(path.resolve(getCwd(), dest, folder.name));
122
115
  }
123
116
  else {
124
- absolutePath = (0, path_2.convertToLocalFileSystemPath)(path_1.default.resolve((0, path_2.getCwd)(), dest));
117
+ absolutePath = convertToLocalFileSystemPath(path.resolve(getCwd(), dest));
125
118
  }
126
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.fetchFolderStarted`, {
119
+ logger.log(i18n(`${i18nKey}.fetchFolderStarted`, {
127
120
  src,
128
121
  path: absolutePath,
129
122
  accountId,
130
123
  }));
131
124
  await fetchFolderContents(accountId, folder, absolutePath, overwrite, includeArchived);
132
- logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.fetchFolderSuccess`, {
125
+ logger.success(i18n(`${i18nKey}.fetchFolderSuccess`, {
133
126
  src,
134
127
  dest,
135
128
  }));
@@ -137,24 +130,24 @@ async function downloadFolder(accountId, src, dest, folder, overwrite, includeAr
137
130
  // Download a single file and write to local file system.
138
131
  async function downloadSingleFile(accountId, src, dest, file, overwrite, includeArchived) {
139
132
  if (!includeArchived && file.archived) {
140
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.archivedFile`, { src }));
133
+ throw new Error(i18n(`${i18nKey}.errors.archivedFile`, { src }));
141
134
  }
142
135
  if (file.hidden) {
143
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.hiddenFile`, { src }));
136
+ throw new Error(i18n(`${i18nKey}.errors.hiddenFile`, { src }));
144
137
  }
145
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.fetchFileStarted`, {
138
+ logger.log(i18n(`${i18nKey}.fetchFileStarted`, {
146
139
  src,
147
140
  dest,
148
141
  accountId,
149
142
  }));
150
143
  await downloadFile(accountId, file, dest, overwrite);
151
- logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.fetchFileSuccess`, {
144
+ logger.success(i18n(`${i18nKey}.fetchFileSuccess`, {
152
145
  src,
153
146
  dest,
154
147
  }));
155
148
  }
156
149
  // Lookup path in file manager and initiate download
157
- async function downloadFileOrFolder(accountId, src, dest, overwrite, includeArchived) {
150
+ export async function downloadFileOrFolder(accountId, src, dest, overwrite, includeArchived) {
158
151
  try {
159
152
  if (src == '/') {
160
153
  // Filemanager API treats 'None' as the root
@@ -162,7 +155,7 @@ async function downloadFileOrFolder(accountId, src, dest, overwrite, includeArch
162
155
  await downloadFolder(accountId, src, dest, rootFolder, overwrite, includeArchived);
163
156
  }
164
157
  else {
165
- const { data: { file, folder }, } = await (0, fileManager_1.fetchStat)(accountId, src);
158
+ const { data: { file, folder }, } = await fetchStat(accountId, src);
166
159
  if (file) {
167
160
  await downloadSingleFile(accountId, src, dest, file, overwrite, includeArchived);
168
161
  }
@@ -172,7 +165,7 @@ async function downloadFileOrFolder(accountId, src, dest, overwrite, includeArch
172
165
  }
173
166
  }
174
167
  catch (err) {
175
- if ((0, errors_1.isAuthError)(err)) {
168
+ if (isAuthError(err)) {
176
169
  err.updateContext({
177
170
  request: src,
178
171
  accountId,
@@ -181,4 +174,3 @@ async function downloadFileOrFolder(accountId, src, dest, overwrite, includeArch
181
174
  throw err;
182
175
  }
183
176
  }
184
- exports.downloadFileOrFolder = downloadFileOrFolder;
@@ -1,4 +1,4 @@
1
- import { FileMapperNode, CmsPublishMode, FileMapperOptions, FileMapperInputOptions, PathTypeData, RecursiveFileMapperCallback } from '../types/Files';
1
+ import { FileMapperNode, CmsPublishMode, FileMapperOptions, FileMapperInputOptions, PathTypeData, RecursiveFileMapperCallback } from '../types/Files.js';
2
2
  export declare function isPathToFile(filepath: string): boolean;
3
3
  export declare function isPathToModule(filepath: string): boolean;
4
4
  export declare function isPathToRoot(filepath: string): boolean;
package/lib/fileMapper.js CHANGED
@@ -1,53 +1,43 @@
1
- "use strict";
2
1
  // FILE MAPPER - not to be confused with fileManager.ts
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.downloadFileOrFolder = exports.fetchFolderFromApi = exports.writeUtimes = exports.recurseFolder = exports.getTypeDataFromPath = exports.getFileMapperQueryValues = exports.isPathToHubspot = exports.isPathToRoot = exports.isPathToModule = exports.isPathToFile = void 0;
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const path_1 = __importDefault(require("path"));
10
- const p_queue_1 = __importDefault(require("p-queue"));
11
- const path_2 = require("./path");
12
- const logger_1 = require("./logger");
13
- const fileMapper_1 = require("../api/fileMapper");
14
- const extensions_1 = require("../constants/extensions");
15
- const files_1 = require("../constants/files");
16
- const errors_1 = require("../errors");
17
- const lang_1 = require("../utils/lang");
18
- const FileSystemError_1 = require("../models/FileSystemError");
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import PQueue from 'p-queue';
5
+ import { getCwd, getExt, convertToLocalFileSystemPath, isAllowedExtension, } from './path.js';
6
+ import { logger } from './logger.js';
7
+ import { fetchFileStream, download, downloadDefault, } from '../api/fileMapper.js';
8
+ import { MODULE_EXTENSION, FUNCTIONS_EXTENSION, JSR_ALLOWED_EXTENSIONS, } from '../constants/extensions.js';
9
+ import { CMS_PUBLISH_MODE } from '../constants/files.js';
10
+ import { isTimeoutError } from '../errors/index.js';
11
+ import { i18n } from '../utils/lang.js';
12
+ import { FileSystemError } from '../models/FileSystemError.js';
19
13
  const i18nKey = 'lib.fileMapper';
20
- const queue = new p_queue_1.default({
14
+ const queue = new PQueue({
21
15
  concurrency: 10,
22
16
  });
23
- function isPathToFile(filepath) {
24
- const ext = (0, path_2.getExt)(filepath);
25
- return !!ext && ext !== extensions_1.MODULE_EXTENSION && ext !== extensions_1.FUNCTIONS_EXTENSION;
17
+ export function isPathToFile(filepath) {
18
+ const ext = getExt(filepath);
19
+ return !!ext && ext !== MODULE_EXTENSION && ext !== FUNCTIONS_EXTENSION;
26
20
  }
27
- exports.isPathToFile = isPathToFile;
28
- function isPathToModule(filepath) {
29
- const ext = (0, path_2.getExt)(filepath);
30
- return ext === extensions_1.MODULE_EXTENSION;
21
+ export function isPathToModule(filepath) {
22
+ const ext = getExt(filepath);
23
+ return ext === MODULE_EXTENSION;
31
24
  }
32
- exports.isPathToModule = isPathToModule;
33
- function isPathToRoot(filepath) {
25
+ export function isPathToRoot(filepath) {
34
26
  if (typeof filepath !== 'string')
35
27
  return false;
36
28
  // Root pattern matches empty strings and: / \
37
29
  return /^(\/|\\)?$/.test(filepath.trim());
38
30
  }
39
- exports.isPathToRoot = isPathToRoot;
40
- function isPathToHubspot(filepath) {
31
+ export function isPathToHubspot(filepath) {
41
32
  if (typeof filepath !== 'string')
42
33
  return false;
43
34
  return /^(\/|\\)?@hubspot/i.test(filepath.trim());
44
35
  }
45
- exports.isPathToHubspot = isPathToHubspot;
46
36
  function useApiBuffer(cmsPublishMode) {
47
- return cmsPublishMode === files_1.CMS_PUBLISH_MODE.draft;
37
+ return cmsPublishMode === CMS_PUBLISH_MODE.draft;
48
38
  }
49
39
  // Determines API param based on publish mode and options
50
- function getFileMapperQueryValues(cmsPublishMode, { staging, assetVersion } = {}) {
40
+ export function getFileMapperQueryValues(cmsPublishMode, { staging, assetVersion } = {}) {
51
41
  return {
52
42
  params: {
53
43
  buffer: useApiBuffer(cmsPublishMode),
@@ -56,7 +46,6 @@ function getFileMapperQueryValues(cmsPublishMode, { staging, assetVersion } = {}
56
46
  },
57
47
  };
58
48
  }
59
- exports.getFileMapperQueryValues = getFileMapperQueryValues;
60
49
  // Determines version number to log based on input.options
61
50
  function getAssetVersionIdentifier(assetVersion, src) {
62
51
  if (typeof assetVersion !== 'undefined' &&
@@ -72,15 +61,16 @@ function validateFileMapperNode(node) {
72
61
  let json;
73
62
  try {
74
63
  json = JSON.stringify(node, null, 2);
64
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
75
65
  }
76
66
  catch (err) {
77
67
  json = node;
78
68
  }
79
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidNode`, {
69
+ throw new Error(i18n(`${i18nKey}.errors.invalidNode`, {
80
70
  json: JSON.stringify(json),
81
71
  }));
82
72
  }
83
- function getTypeDataFromPath(src) {
73
+ export function getTypeDataFromPath(src) {
84
74
  const isModule = isPathToModule(src);
85
75
  const isHubspot = isPathToHubspot(src);
86
76
  const isFile = !isModule && isPathToFile(src);
@@ -94,8 +84,7 @@ function getTypeDataFromPath(src) {
94
84
  isFolder,
95
85
  };
96
86
  }
97
- exports.getTypeDataFromPath = getTypeDataFromPath;
98
- function recurseFolder(node, callback, filepath = '', depth = 0) {
87
+ export function recurseFolder(node, callback, filepath = '', depth = 0) {
99
88
  validateFileMapperNode(node);
100
89
  const isRootFolder = node.folder && depth === 0;
101
90
  if (isRootFolder) {
@@ -104,7 +93,7 @@ function recurseFolder(node, callback, filepath = '', depth = 0) {
104
93
  }
105
94
  }
106
95
  else {
107
- filepath = path_1.default.join(filepath, node.name);
96
+ filepath = path.join(filepath, node.name);
108
97
  }
109
98
  let __break = callback(node, filepath, depth);
110
99
  if (__break === false)
@@ -115,28 +104,26 @@ function recurseFolder(node, callback, filepath = '', depth = 0) {
115
104
  });
116
105
  return depth === 0 ? false : __break;
117
106
  }
118
- exports.recurseFolder = recurseFolder;
119
- async function writeUtimes(accountId, filepath, node) {
107
+ export async function writeUtimes(accountId, filepath, node) {
120
108
  try {
121
109
  const now = new Date();
122
110
  const atime = node.createdAt ? new Date(node.createdAt) : now;
123
111
  const mtime = node.updatedAt ? new Date(node.updatedAt) : now;
124
- await fs_extra_1.default.utimes(filepath, atime, mtime);
112
+ await fs.utimes(filepath, atime, mtime);
125
113
  }
126
114
  catch (err) {
127
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
115
+ throw new FileSystemError({ cause: err }, {
128
116
  filepath,
129
117
  accountId,
130
118
  operation: 'write',
131
119
  });
132
120
  }
133
121
  }
134
- exports.writeUtimes = writeUtimes;
135
122
  async function skipExisting(filepath, overwrite = false) {
136
123
  if (overwrite) {
137
124
  return false;
138
125
  }
139
- if (await fs_extra_1.default.pathExists(filepath)) {
126
+ if (await fs.pathExists(filepath)) {
140
127
  return true;
141
128
  }
142
129
  return false;
@@ -146,21 +133,21 @@ async function fetchAndWriteFileStream(accountId, srcPath, filepath, cmsPublishM
146
133
  return;
147
134
  }
148
135
  if (await skipExisting(filepath, options.overwrite)) {
149
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.skippedExisting`, { filepath }));
136
+ logger.log(i18n(`${i18nKey}.skippedExisting`, { filepath }));
150
137
  return;
151
138
  }
152
- if (!(0, path_2.isAllowedExtension)(srcPath, Array.from(extensions_1.JSR_ALLOWED_EXTENSIONS))) {
153
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidFileType`, { srcPath }));
139
+ if (!isAllowedExtension(srcPath, Array.from(JSR_ALLOWED_EXTENSIONS))) {
140
+ throw new Error(i18n(`${i18nKey}.errors.invalidFileType`, { srcPath }));
154
141
  }
155
- const node = await (0, fileMapper_1.fetchFileStream)(accountId, srcPath, filepath, getFileMapperQueryValues(cmsPublishMode, options));
142
+ const node = await fetchFileStream(accountId, srcPath, filepath, getFileMapperQueryValues(cmsPublishMode, options));
156
143
  await writeUtimes(accountId, filepath, node);
157
144
  }
158
145
  // Writes an individual file or folder (not recursive). If file source is missing, the
159
146
  //file is fetched.
160
147
  async function writeFileMapperNode(accountId, filepath, node, cmsPublishMode, options = {}) {
161
- const localFilepath = (0, path_2.convertToLocalFileSystemPath)(path_1.default.resolve(filepath));
148
+ const localFilepath = convertToLocalFileSystemPath(path.resolve(filepath));
162
149
  if (await skipExisting(localFilepath, options.overwrite)) {
163
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.skippedExisting`, {
150
+ logger.log(i18n(`${i18nKey}.skippedExisting`, {
164
151
  filepath: localFilepath,
165
152
  }));
166
153
  return true;
@@ -169,19 +156,20 @@ async function writeFileMapperNode(accountId, filepath, node, cmsPublishMode, op
169
156
  try {
170
157
  await fetchAndWriteFileStream(accountId, node.path, localFilepath, cmsPublishMode, options);
171
158
  return true;
159
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
172
160
  }
173
161
  catch (err) {
174
162
  return false;
175
163
  }
176
164
  }
177
165
  try {
178
- await fs_extra_1.default.ensureDir(localFilepath);
179
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.wroteFolder`, {
166
+ await fs.ensureDir(localFilepath);
167
+ logger.log(i18n(`${i18nKey}.wroteFolder`, {
180
168
  filepath: localFilepath,
181
169
  }));
182
170
  }
183
171
  catch (err) {
184
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
172
+ throw new FileSystemError({ cause: err }, {
185
173
  filepath: localFilepath,
186
174
  accountId,
187
175
  operation: 'write',
@@ -192,31 +180,31 @@ async function writeFileMapperNode(accountId, filepath, node, cmsPublishMode, op
192
180
  async function downloadFile(accountId, src, destPath, cmsPublishMode, options = {}) {
193
181
  const { isFile, isHubspot } = getTypeDataFromPath(src);
194
182
  if (!isFile) {
195
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidRequest`, { src }));
183
+ throw new Error(i18n(`${i18nKey}.errors.invalidRequest`, { src }));
196
184
  }
197
185
  try {
198
- const dest = path_1.default.resolve(destPath);
199
- const cwd = (0, path_2.getCwd)();
186
+ const dest = path.resolve(destPath);
187
+ const cwd = getCwd();
200
188
  let filepath;
201
189
  if (dest === cwd) {
202
190
  // Dest: CWD
203
- filepath = path_1.default.resolve(cwd, path_1.default.basename(src));
191
+ filepath = path.resolve(cwd, path.basename(src));
204
192
  }
205
193
  else if (isPathToFile(dest)) {
206
194
  // Dest: file path
207
- filepath = path_1.default.isAbsolute(dest) ? dest : path_1.default.resolve(cwd, dest);
195
+ filepath = path.isAbsolute(dest) ? dest : path.resolve(cwd, dest);
208
196
  }
209
197
  else {
210
198
  // Dest: folder path
211
- const name = path_1.default.basename(src);
212
- filepath = path_1.default.isAbsolute(dest)
213
- ? path_1.default.resolve(dest, name)
214
- : path_1.default.resolve(cwd, dest, name);
199
+ const name = path.basename(src);
200
+ filepath = path.isAbsolute(dest)
201
+ ? path.resolve(dest, name)
202
+ : path.resolve(cwd, dest, name);
215
203
  }
216
- const localFsPath = (0, path_2.convertToLocalFileSystemPath)(filepath);
204
+ const localFsPath = convertToLocalFileSystemPath(filepath);
217
205
  await fetchAndWriteFileStream(accountId, src, localFsPath, cmsPublishMode, options);
218
206
  await queue.onIdle();
219
- logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.completedFetch`, {
207
+ logger.success(i18n(`${i18nKey}.completedFetch`, {
220
208
  src,
221
209
  version: getAssetVersionIdentifier(options.assetVersion, src),
222
210
  dest,
@@ -224,39 +212,38 @@ async function downloadFile(accountId, src, destPath, cmsPublishMode, options =
224
212
  }
225
213
  catch (err) {
226
214
  const error = err;
227
- if (isHubspot && (0, errors_1.isTimeoutError)(error)) {
228
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.assetTimeout`), { cause: error });
215
+ if (isHubspot && isTimeoutError(error)) {
216
+ throw new Error(i18n(`${i18nKey}.errors.assetTimeout`), { cause: error });
229
217
  }
230
218
  else {
231
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.failedToFetchFile`, { src, dest: destPath }), { cause: error });
219
+ throw new Error(i18n(`${i18nKey}.errors.failedToFetchFile`, { src, dest: destPath }), { cause: error });
232
220
  }
233
221
  }
234
222
  }
235
- async function fetchFolderFromApi(accountId, src, cmsPublishMode, options = {}) {
223
+ export async function fetchFolderFromApi(accountId, src, cmsPublishMode, options = {}) {
236
224
  const { isRoot, isFolder, isHubspot } = getTypeDataFromPath(src);
237
225
  if (!isFolder) {
238
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidFetchFolderRequest`, {
226
+ throw new Error(i18n(`${i18nKey}.errors.invalidFetchFolderRequest`, {
239
227
  src,
240
228
  }));
241
229
  }
242
230
  const srcPath = isRoot ? '@root' : src;
243
231
  const queryValues = getFileMapperQueryValues(cmsPublishMode, options);
244
232
  const { data: node } = isHubspot
245
- ? await (0, fileMapper_1.downloadDefault)(accountId, srcPath, queryValues)
246
- : await (0, fileMapper_1.download)(accountId, srcPath, queryValues);
247
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.folderFetch`, { src, accountId }));
233
+ ? await downloadDefault(accountId, srcPath, queryValues)
234
+ : await download(accountId, srcPath, queryValues);
235
+ logger.log(i18n(`${i18nKey}.folderFetch`, { src, accountId }));
248
236
  return node;
249
237
  }
250
- exports.fetchFolderFromApi = fetchFolderFromApi;
251
238
  async function downloadFolder(accountId, src, destPath, cmsPublishMode, options = {}) {
252
239
  try {
253
240
  const node = await fetchFolderFromApi(accountId, src, cmsPublishMode, options);
254
241
  if (!node) {
255
242
  return;
256
243
  }
257
- const dest = path_1.default.resolve(destPath);
258
- const rootPath = dest === (0, path_2.getCwd)()
259
- ? (0, path_2.convertToLocalFileSystemPath)(path_1.default.resolve(dest, node.name))
244
+ const dest = path.resolve(destPath);
245
+ const rootPath = dest === getCwd()
246
+ ? convertToLocalFileSystemPath(path.resolve(dest, node.name))
260
247
  : dest;
261
248
  let success = true;
262
249
  recurseFolder(node, (childNode, filepath) => {
@@ -264,7 +251,7 @@ async function downloadFolder(accountId, src, destPath, cmsPublishMode, options
264
251
  const succeeded = await writeFileMapperNode(accountId, filepath || '', childNode, cmsPublishMode, options);
265
252
  if (succeeded === false) {
266
253
  success = false;
267
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errors.failedToFetchFile`, {
254
+ logger.debug(i18n(`${i18nKey}.errors.failedToFetchFile`, {
268
255
  src: childNode.path,
269
256
  dest: filepath || '',
270
257
  }));
@@ -274,7 +261,7 @@ async function downloadFolder(accountId, src, destPath, cmsPublishMode, options
274
261
  }, rootPath);
275
262
  await queue.onIdle();
276
263
  if (success) {
277
- logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.completedFolderFetch`, {
264
+ logger.success(i18n(`${i18nKey}.completedFolderFetch`, {
278
265
  src,
279
266
  version: getAssetVersionIdentifier(options.assetVersion, src),
280
267
  dest,
@@ -282,16 +269,16 @@ async function downloadFolder(accountId, src, destPath, cmsPublishMode, options
282
269
  }
283
270
  else {
284
271
  // TODO: Fix this exception. It is triggering the catch block so this error is being rewritten
285
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.incompleteFetch`, { src }));
272
+ throw new Error(i18n(`${i18nKey}.errors.incompleteFetch`, { src }));
286
273
  }
287
274
  }
288
275
  catch (err) {
289
276
  const error = err;
290
- if ((0, errors_1.isTimeoutError)(error)) {
291
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.assetTimeout`), { cause: error });
277
+ if (isTimeoutError(error)) {
278
+ throw new Error(i18n(`${i18nKey}.errors.assetTimeout`), { cause: error });
292
279
  }
293
280
  else {
294
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.failedToFetchFolder`, { src, dest: destPath }), { cause: err });
281
+ throw new Error(i18n(`${i18nKey}.errors.failedToFetchFolder`, { src, dest: destPath }), { cause: err });
295
282
  }
296
283
  }
297
284
  }
@@ -302,7 +289,7 @@ async function downloadFolder(accountId, src, destPath, cmsPublishMode, options
302
289
  * @param {FileMapperInputArguments} input
303
290
  * @returns {Promise}
304
291
  */
305
- async function downloadFileOrFolder(accountId, src, dest, cmsPublishMode, options = {}) {
292
+ export async function downloadFileOrFolder(accountId, src, dest, cmsPublishMode, options = {}) {
306
293
  if (!src) {
307
294
  return;
308
295
  }
@@ -314,4 +301,3 @@ async function downloadFileOrFolder(accountId, src, dest, cmsPublishMode, option
314
301
  await downloadFolder(accountId, src, dest, cmsPublishMode, options);
315
302
  }
316
303
  }
317
- exports.downloadFileOrFolder = downloadFileOrFolder;
package/lib/fs.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FileData } from '../types/Files';
1
+ import { FileData } from '../types/Files.js';
2
2
  export declare function getFileInfoAsync(dir: string, file: string): Promise<FileData>;
3
3
  export declare function flattenAndRemoveSymlinks(filesData: Array<FileData>): Array<string>;
4
4
  export declare function walk(dir: string, ignoreDirs?: string[]): Promise<Array<string>>;