@hubspot/local-dev-lib 0.0.10 → 0.1.0-experimental.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +17 -0
  3. package/api/appsDev.d.ts +6 -0
  4. package/api/appsDev.js +29 -0
  5. package/api/customObjects.d.ts +8 -7
  6. package/api/customObjects.js +13 -16
  7. package/api/designManager.d.ts +5 -13
  8. package/api/designManager.js +6 -9
  9. package/api/developerTestAccounts.d.ts +7 -0
  10. package/api/developerTestAccounts.js +48 -0
  11. package/api/fileManager.d.ts +6 -5
  12. package/api/fileManager.js +13 -12
  13. package/api/fileMapper.d.ts +8 -8
  14. package/api/fileMapper.js +19 -18
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/functions.d.ts +7 -3
  18. package/api/functions.js +22 -11
  19. package/api/github.d.ts +11 -0
  20. package/api/github.js +71 -0
  21. package/api/hubdb.d.ts +11 -9
  22. package/api/hubdb.js +28 -22
  23. package/api/lighthouseScore.d.ts +4 -3
  24. package/api/lighthouseScore.js +9 -12
  25. package/api/localDevAuth.d.ts +7 -15
  26. package/api/localDevAuth.js +28 -13
  27. package/api/marketplaceValidation.d.ts +4 -3
  28. package/api/marketplaceValidation.js +8 -11
  29. package/api/projects.d.ts +34 -21
  30. package/api/projects.js +135 -45
  31. package/api/sandboxHubs.d.ts +5 -4
  32. package/api/sandboxHubs.js +10 -11
  33. package/api/sandboxSync.d.ts +4 -4
  34. package/api/sandboxSync.js +5 -14
  35. package/api/secrets.d.ts +6 -8
  36. package/api/secrets.js +9 -12
  37. package/api/validateHubl.d.ts +2 -1
  38. package/api/validateHubl.js +3 -6
  39. package/config/CLIConfiguration.d.ts +13 -10
  40. package/config/CLIConfiguration.js +129 -77
  41. package/config/configFile.js +12 -18
  42. package/config/configUtils.d.ts +2 -21
  43. package/config/configUtils.js +5 -4
  44. package/config/config_DEPRECATED.d.ts +6 -8
  45. package/config/config_DEPRECATED.js +73 -24
  46. package/config/environment.js +5 -4
  47. package/config/getAccountIdentifier.d.ts +2 -0
  48. package/config/getAccountIdentifier.js +15 -0
  49. package/config/index.d.ts +10 -7
  50. package/config/index.js +83 -55
  51. package/constants/api.d.ts +10 -12
  52. package/constants/api.js +10 -12
  53. package/constants/config.d.ts +15 -1
  54. package/constants/config.js +17 -3
  55. package/constants/environments.d.ts +1 -0
  56. package/constants/environments.js +1 -0
  57. package/constants/extensions.d.ts +2 -0
  58. package/constants/extensions.js +3 -1
  59. package/constants/files.d.ts +2 -2
  60. package/constants/files.js +3 -3
  61. package/errors/errors_DEPRECATED.d.ts +1 -5
  62. package/errors/errors_DEPRECATED.js +3 -16
  63. package/errors/index.d.ts +18 -0
  64. package/errors/index.js +63 -0
  65. package/http/addQueryParams.d.ts +2 -0
  66. package/http/addQueryParams.js +14 -0
  67. package/http/getAxiosConfig.d.ts +6 -3
  68. package/http/getAxiosConfig.js +51 -7
  69. package/http/index.d.ts +10 -11
  70. package/http/index.js +35 -41
  71. package/http/unauthed.d.ts +15 -0
  72. package/http/unauthed.js +38 -0
  73. package/lang/en.json +374 -368
  74. package/lib/archive.d.ts +2 -6
  75. package/lib/archive.js +34 -29
  76. package/lib/cms/functions.d.ts +7 -12
  77. package/lib/cms/functions.js +47 -50
  78. package/lib/cms/handleFieldsJS.js +16 -14
  79. package/lib/cms/modules.d.ts +5 -15
  80. package/lib/cms/modules.js +100 -39
  81. package/lib/cms/processFieldsJs.js +10 -33
  82. package/lib/cms/templates.d.ts +43 -3
  83. package/lib/cms/templates.js +51 -11
  84. package/lib/cms/uploadFolder.d.ts +3 -14
  85. package/lib/cms/uploadFolder.js +58 -42
  86. package/lib/{validate.d.ts → cms/validate.d.ts} +1 -1
  87. package/lib/{validate.js → cms/validate.js} +5 -5
  88. package/lib/cms/watch.d.ts +2 -18
  89. package/lib/cms/watch.js +63 -68
  90. package/lib/customObjects.js +4 -15
  91. package/lib/fileManager.d.ts +2 -0
  92. package/lib/fileManager.js +184 -0
  93. package/lib/fileMapper.d.ts +4 -15
  94. package/lib/fileMapper.js +68 -89
  95. package/lib/fs.js +2 -2
  96. package/lib/github.d.ts +6 -18
  97. package/lib/github.js +97 -76
  98. package/lib/gitignore.d.ts +2 -0
  99. package/lib/gitignore.js +21 -4
  100. package/lib/hubdb.d.ts +3 -2
  101. package/lib/hubdb.js +11 -9
  102. package/lib/{logging/logger.d.ts → logger.d.ts} +20 -8
  103. package/{utils → lib}/notify.js +2 -2
  104. package/lib/oauth.d.ts +2 -5
  105. package/lib/oauth.js +14 -25
  106. package/lib/path.d.ts +3 -0
  107. package/lib/path.js +46 -1
  108. package/lib/personalAccessKey.d.ts +7 -10
  109. package/lib/personalAccessKey.js +75 -48
  110. package/lib/portManager.d.ts +3 -5
  111. package/lib/portManager.js +18 -6
  112. package/lib/text.d.ts +1 -0
  113. package/lib/text.js +9 -1
  114. package/lib/trackUsage.js +18 -11
  115. package/lib/urls.js +5 -1
  116. package/models/FileSystemError.d.ts +6 -0
  117. package/models/FileSystemError.js +47 -0
  118. package/models/HubSpotHttpError.d.ts +24 -0
  119. package/models/HubSpotHttpError.js +197 -0
  120. package/models/OAuth2Manager.d.ts +5 -27
  121. package/models/OAuth2Manager.js +41 -64
  122. package/package.json +19 -18
  123. package/types/Accounts.d.ts +86 -3
  124. package/types/Apps.d.ts +77 -0
  125. package/types/Archive.d.ts +9 -0
  126. package/types/Archive.js +2 -0
  127. package/types/ComponentStructure.d.ts +30 -10
  128. package/types/Config.d.ts +19 -2
  129. package/types/DesignManager.d.ts +10 -0
  130. package/types/DesignManager.js +2 -0
  131. package/types/Error.d.ts +12 -34
  132. package/types/FieldsJS.d.ts +1 -0
  133. package/types/FieldsJS.js +2 -0
  134. package/types/FileManager.d.ts +12 -7
  135. package/types/Files.d.ts +43 -4
  136. package/types/Functions.d.ts +26 -0
  137. package/types/Github.d.ts +12 -0
  138. package/types/Http.d.ts +11 -12
  139. package/types/Hubdb.d.ts +9 -0
  140. package/types/Lang.d.ts +3 -0
  141. package/types/Migration.d.ts +28 -0
  142. package/types/Migration.js +10 -0
  143. package/types/Modules.d.ts +11 -0
  144. package/types/PortManager.d.ts +7 -0
  145. package/types/Project.d.ts +4 -0
  146. package/types/ProjectLog.d.ts +9 -0
  147. package/types/ProjectLog.js +2 -0
  148. package/types/Sandbox.d.ts +37 -47
  149. package/types/Schemas.d.ts +12 -0
  150. package/types/Secrets.d.ts +3 -0
  151. package/types/Secrets.js +2 -0
  152. package/types/developerTestAccounts.d.ts +12 -0
  153. package/types/developerTestAccounts.js +2 -0
  154. package/utils/PortManagerServer.d.ts +6 -7
  155. package/utils/PortManagerServer.js +24 -18
  156. package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
  157. package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
  158. package/utils/cms/fieldsJS.d.ts +1 -2
  159. package/utils/cms/modules.js +2 -2
  160. package/utils/detectPort.js +3 -3
  161. package/utils/git.d.ts +1 -7
  162. package/utils/git.js +2 -18
  163. package/utils/lang.d.ts +1 -5
  164. package/constants/github.d.ts +0 -4
  165. package/constants/github.js +0 -7
  166. package/errors/apiErrors.d.ts +0 -23
  167. package/errors/apiErrors.js +0 -197
  168. package/errors/fileSystemErrors.d.ts +0 -5
  169. package/errors/fileSystemErrors.js +0 -31
  170. package/errors/standardErrors.d.ts +0 -26
  171. package/errors/standardErrors.js +0 -64
  172. package/lang/lang/en.json +0 -383
  173. package/lib/logging/git.d.ts +0 -2
  174. package/lib/logging/git.js +0 -54
  175. package/lib/logging/logs.d.ts +0 -22
  176. package/lib/logging/logs.js +0 -86
  177. package/lib/logging/table.d.ts +0 -3
  178. package/lib/logging/table.js +0 -47
  179. package/lib/sandboxes.d.ts +0 -14
  180. package/lib/sandboxes.js +0 -71
  181. package/models/HubSpotAuthError.d.ts +0 -9
  182. package/models/HubSpotAuthError.js +0 -20
  183. package/types/LogCallbacks.d.ts +0 -6
  184. package/utils/logger.d.ts +0 -11
  185. package/utils/logger.js +0 -23
  186. package/utils/objectUtils.d.ts +0 -8
  187. package/utils/objectUtils.js +0 -33
  188. /package/{utils → lib}/escapeRegExp.d.ts +0 -0
  189. /package/{utils → lib}/escapeRegExp.js +0 -0
  190. /package/lib/{logging/logger.js → logger.js} +0 -0
  191. /package/{utils → lib}/notify.d.ts +0 -0
  192. /package/types/{LogCallbacks.js → Apps.js} +0 -0
package/lib/archive.d.ts CHANGED
@@ -1,7 +1,3 @@
1
1
  /// <reference types="node" />
2
- type CopySourceToDestOptions = {
3
- sourceDir?: string;
4
- includesRootDir?: boolean;
5
- };
6
- export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions): Promise<boolean>;
7
- export {};
2
+ import { CopySourceToDestOptions } from '../types/Archive';
3
+ export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir, hideLogs }?: CopySourceToDestOptions): Promise<boolean>;
package/lib/archive.js CHANGED
@@ -7,17 +7,17 @@ exports.extractZipArchive = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = require("path");
9
9
  const os_1 = require("os");
10
- const util_1 = require("util");
11
10
  const extract_zip_1 = __importDefault(require("extract-zip"));
12
- const fileSystemErrors_1 = require("../errors/fileSystemErrors");
13
- const standardErrors_1 = require("../errors/standardErrors");
14
- const logger_1 = require("../utils/logger");
15
- const extract = (0, util_1.promisify)(extract_zip_1.default);
11
+ const logger_1 = require("./logger");
12
+ const lang_1 = require("../utils/lang");
13
+ const FileSystemError_1 = require("../models/FileSystemError");
16
14
  const i18nKey = 'lib.archive';
17
- async function extractZip(name, zip) {
15
+ async function extractZip(name, zip, hideLogs = false) {
18
16
  const result = { extractDir: '', tmpDir: '' };
19
17
  const TMP_FOLDER_PREFIX = `hubspot-temp-${name}-`;
20
- (0, logger_1.debug)(`${i18nKey}.extractZip.init`);
18
+ if (!hideLogs) {
19
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.extractZip.init`));
20
+ }
21
21
  // Write zip to disk
22
22
  let tmpZipPath = '';
23
23
  try {
@@ -30,39 +30,44 @@ async function extractZip(name, zip) {
30
30
  }
31
31
  catch (err) {
32
32
  if (tmpZipPath || result.tmpDir) {
33
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
33
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
34
34
  filepath: tmpZipPath || result.tmpDir,
35
- write: true,
35
+ operation: 'write',
36
36
  });
37
37
  }
38
38
  else {
39
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.extractZip.errors.write`, {}, err);
39
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.extractZip.errors.write`), {
40
+ cause: err,
41
+ });
40
42
  }
41
- return result;
42
43
  }
43
44
  // Extract zip
44
45
  try {
45
46
  const tmpExtractPath = (0, path_1.join)(result.tmpDir, 'extracted');
46
- await extract(tmpZipPath, { dir: tmpExtractPath });
47
+ await (0, extract_zip_1.default)(tmpZipPath, { dir: tmpExtractPath });
47
48
  result.extractDir = tmpExtractPath;
48
49
  }
49
50
  catch (err) {
50
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.extractZip.errors.extract`, {}, err);
51
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.extractZip.errors.extract`), {
52
+ cause: err,
53
+ });
51
54
  }
52
- (0, logger_1.debug)(`${i18nKey}.extractZip.success`);
55
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.extractZip.success`));
53
56
  return result;
54
57
  }
55
- async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true } = {}) {
58
+ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true, hideLogs = false, } = {}) {
56
59
  try {
57
- (0, logger_1.debug)(`${i18nKey}.copySourceToDest.init`);
60
+ if (!hideLogs) {
61
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.init`));
62
+ }
58
63
  const srcDirPath = [src];
59
64
  if (includesRootDir) {
60
65
  const files = await fs_extra_1.default.readdir(src);
61
66
  const rootDir = files[0];
62
67
  if (!rootDir) {
63
- (0, logger_1.debug)(`${i18nKey}.copySourceToDest.sourceEmpty`);
68
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.sourceEmpty`));
64
69
  // Create the dest path if it doesn't already exist
65
- fs_extra_1.default.ensureDir(dest);
70
+ await fs_extra_1.default.ensureDir(dest);
66
71
  // No root found so nothing to copy
67
72
  return true;
68
73
  }
@@ -73,39 +78,39 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true }
73
78
  }
74
79
  const projectSrcDir = (0, path_1.join)(...srcDirPath);
75
80
  await fs_extra_1.default.copy(projectSrcDir, dest);
76
- (0, logger_1.debug)(`${i18nKey}.copySourceToDest.success`);
81
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.success`));
77
82
  return true;
78
83
  }
79
84
  catch (err) {
80
- (0, logger_1.debug)(`${i18nKey}.copySourceToDest.error`, { dest });
81
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
85
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.error`, { dest }));
86
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
82
87
  filepath: dest,
83
- write: true,
88
+ operation: 'write',
84
89
  });
85
90
  }
86
- return false;
87
91
  }
88
- function cleanupTempDir(tmpDir) {
92
+ async function cleanupTempDir(tmpDir) {
89
93
  if (!tmpDir)
90
94
  return;
91
95
  try {
92
- fs_extra_1.default.remove(tmpDir);
96
+ await fs_extra_1.default.remove(tmpDir);
93
97
  }
94
98
  catch (e) {
95
- (0, logger_1.debug)(`${i18nKey}.cleanupTempDir.error`, { tmpDir });
99
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.cleanupTempDir.error`, { tmpDir }));
96
100
  }
97
101
  }
98
- async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}) {
102
+ async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs } = {}) {
99
103
  let success = false;
100
104
  if (zip) {
101
- const { extractDir, tmpDir } = await extractZip(name, zip);
105
+ const { extractDir, tmpDir } = await extractZip(name, zip, hideLogs);
102
106
  if (extractDir !== null) {
103
107
  success = await copySourceToDest(extractDir, dest, {
104
108
  sourceDir,
105
109
  includesRootDir,
110
+ hideLogs,
106
111
  });
107
112
  }
108
- cleanupTempDir(tmpDir);
113
+ await cleanupTempDir(tmpDir);
109
114
  }
110
115
  return success;
111
116
  }
@@ -1,13 +1,8 @@
1
- import { LogCallbacksArg } from '../../types/LogCallbacks';
2
- type FunctionInfo = {
3
- functionsFolder: string;
4
- filename: string;
5
- endpointPath: string;
6
- endpointMethod: string;
1
+ import { FunctionConfig, FunctionConfigInfo, FunctionInfo, FunctionOptions } from '../../types/Functions';
2
+ export declare function isObjectOrFunction(value: object): boolean;
3
+ export declare function createEndpoint(endpointMethod: string, filename: string): {
4
+ method: string;
5
+ file: string;
7
6
  };
8
- type FunctionOptions = {
9
- allowExistingFile?: boolean;
10
- };
11
- declare const createFunctionCallbackKeys: string[];
12
- export declare function createFunction(functionInfo: FunctionInfo, dest: string, options: FunctionOptions, logCallbacks?: LogCallbacksArg<typeof createFunctionCallbackKeys>): Promise<void>;
13
- export {};
7
+ export declare function createConfig({ endpointPath, endpointMethod, functionFile, }: FunctionConfigInfo): FunctionConfig;
8
+ export declare function createFunction(functionInfo: FunctionInfo, dest: string, options?: FunctionOptions): Promise<void>;
@@ -3,26 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createFunction = void 0;
6
+ exports.createFunction = exports.createConfig = exports.createEndpoint = exports.isObjectOrFunction = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const findup_sync_1 = __importDefault(require("findup-sync"));
10
10
  const path_2 = require("../path");
11
11
  const github_1 = require("../github");
12
- const logger_1 = require("../../utils/logger");
13
- const standardErrors_1 = require("../../errors/standardErrors");
14
- const fileSystemErrors_1 = require("../../errors/fileSystemErrors");
12
+ const logger_1 = require("../logger");
13
+ const lang_1 = require("../../utils/lang");
14
+ const FileSystemError_1 = require("../../models/FileSystemError");
15
15
  const i18nKey = 'lib.cms.functions';
16
16
  function isObjectOrFunction(value) {
17
17
  const type = typeof value;
18
18
  return value != null && (type === 'object' || type === 'function');
19
19
  }
20
+ exports.isObjectOrFunction = isObjectOrFunction;
20
21
  function createEndpoint(endpointMethod, filename) {
21
22
  return {
22
23
  method: endpointMethod || 'GET',
23
24
  file: filename,
24
25
  };
25
26
  }
27
+ exports.createEndpoint = createEndpoint;
26
28
  function createConfig({ endpointPath, endpointMethod, functionFile, }) {
27
29
  return {
28
30
  runtime: 'nodejs18.x',
@@ -34,6 +36,7 @@ function createConfig({ endpointPath, endpointMethod, functionFile, }) {
34
36
  },
35
37
  };
36
38
  }
39
+ exports.createConfig = createConfig;
37
40
  function writeConfig(configFilePath, config) {
38
41
  const configJson = JSON.stringify(config, null, ' ');
39
42
  fs_extra_1.default.writeFileSync(configFilePath, configJson);
@@ -44,12 +47,12 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
44
47
  configString = fs_extra_1.default.readFileSync(configFilePath).toString();
45
48
  }
46
49
  catch (err) {
47
- (0, logger_1.debug)(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
50
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
48
51
  configFilePath,
49
- });
50
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
52
+ }));
53
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
51
54
  filepath: configFilePath,
52
- read: true,
55
+ operation: 'read',
53
56
  });
54
57
  }
55
58
  let config;
@@ -57,23 +60,25 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
57
60
  config = JSON.parse(configString);
58
61
  }
59
62
  catch (err) {
60
- (0, logger_1.debug)(`${i18nKey}.updateExistingConfig.invalidJSON`, {
63
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.invalidJSON`, {
61
64
  configFilePath,
62
- });
63
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
65
+ }));
66
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
64
67
  filepath: configFilePath,
65
- read: true,
68
+ operation: 'read',
66
69
  });
67
70
  }
68
71
  if (!isObjectOrFunction(config)) {
69
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, { configFilePath });
72
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, {
73
+ configFilePath,
74
+ }));
70
75
  }
71
76
  if (config.endpoints) {
72
77
  if (config.endpoints[endpointPath]) {
73
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
78
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
74
79
  configFilePath,
75
80
  endpointPath,
76
- });
81
+ }));
77
82
  }
78
83
  else {
79
84
  config.endpoints[endpointPath] = createEndpoint(endpointMethod, functionFile);
@@ -88,24 +93,16 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
88
93
  writeConfig(configFilePath, config);
89
94
  }
90
95
  catch (err) {
91
- (0, logger_1.debug)(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
96
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
92
97
  configFilePath,
93
- });
94
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
98
+ }));
99
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
95
100
  filepath: configFilePath,
96
- write: true,
101
+ operation: 'read',
97
102
  });
98
103
  }
99
104
  }
100
- const createFunctionCallbackKeys = [
101
- 'destPathAlreadyExists',
102
- 'createdDest',
103
- 'createdFunctionFile',
104
- 'createdConfigFile',
105
- 'success',
106
- ];
107
- async function createFunction(functionInfo, dest, options, logCallbacks) {
108
- const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
105
+ async function createFunction(functionInfo, dest, options = {}) {
109
106
  const { functionsFolder, filename, endpointPath, endpointMethod } = functionInfo;
110
107
  const allowExistingFile = options.allowExistingFile || false;
111
108
  const ancestorFunctionsConfig = (0, findup_sync_1.default)('serverless.json', {
@@ -113,9 +110,9 @@ async function createFunction(functionInfo, dest, options, logCallbacks) {
113
110
  nocase: true,
114
111
  });
115
112
  if (ancestorFunctionsConfig) {
116
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createFunction.errors.nestedConfigError`, {
113
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.createFunction.errors.nestedConfigError`, {
117
114
  ancestorConfigPath: path_1.default.dirname(ancestorFunctionsConfig),
118
- });
115
+ }));
119
116
  }
120
117
  const folderName = functionsFolder.endsWith('.functions')
121
118
  ? functionsFolder
@@ -123,40 +120,40 @@ async function createFunction(functionInfo, dest, options, logCallbacks) {
123
120
  const functionFile = filename.endsWith('.js') ? filename : `${filename}.js`;
124
121
  const destPath = path_1.default.join(dest, folderName);
125
122
  if (fs_extra_1.default.existsSync(destPath)) {
126
- logger('destPathAlreadyExists', `${i18nKey}.createFunction.destPathAlreadyExists`, {
123
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.destPathAlreadyExists`, {
127
124
  path: destPath,
128
- });
125
+ }));
129
126
  }
130
127
  else {
131
128
  fs_extra_1.default.mkdirp(destPath);
132
- logger('createdDest', `${i18nKey}.createFunction.createdDest`, {
129
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdDest`, {
133
130
  path: destPath,
134
- });
131
+ }));
135
132
  }
136
133
  const functionFilePath = path_1.default.join(destPath, functionFile);
137
134
  const configFilePath = path_1.default.join(destPath, 'serverless.json');
138
135
  if (!allowExistingFile && fs_extra_1.default.existsSync(functionFilePath)) {
139
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createFunction.errors.jsFileConflictError`, {
136
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.createFunction.errors.jsFileConflictError`, {
140
137
  functionFilePath,
141
- });
138
+ }));
142
139
  }
143
140
  await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', 'functions/sample-function.js', functionFilePath);
144
- logger('createdFunctionFile', `${i18nKey}.createFunction.createdFunctionFile`, {
141
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
145
142
  path: functionFilePath,
146
- });
143
+ }));
147
144
  if (fs_extra_1.default.existsSync(configFilePath)) {
148
145
  updateExistingConfig(configFilePath, {
149
146
  endpointPath,
150
147
  endpointMethod,
151
148
  functionFile,
152
149
  });
153
- logger('createdFunctionFile', `${i18nKey}.createFunction.createdFunctionFile`, {
150
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
154
151
  path: functionFilePath,
155
- });
156
- logger('success', `${i18nKey}.createFunction.success`, {
152
+ }));
153
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
157
154
  endpointPath: endpointPath,
158
155
  folderName,
159
- });
156
+ }));
160
157
  }
161
158
  else {
162
159
  const config = createConfig({ endpointPath, endpointMethod, functionFile });
@@ -164,21 +161,21 @@ async function createFunction(functionInfo, dest, options, logCallbacks) {
164
161
  writeConfig(configFilePath, config);
165
162
  }
166
163
  catch (err) {
167
- (0, logger_1.debug)(`${i18nKey}.createFunction.failedToCreateFile`, {
164
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createFunction.failedToCreateFile`, {
168
165
  configFilePath,
169
- });
170
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
166
+ }));
167
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
171
168
  filepath: configFilePath,
172
- write: true,
169
+ operation: 'write',
173
170
  });
174
171
  }
175
- logger('createdConfigFile', `${i18nKey}.createFunction.createdConfigFile`, {
172
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdConfigFile`, {
176
173
  path: configFilePath,
177
- });
178
- logger('success', `${i18nKey}.createFunction.success`, {
174
+ }));
175
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
179
176
  endpointPath: endpointPath,
180
177
  folderName,
181
- });
178
+ }));
182
179
  }
183
180
  }
184
181
  exports.createFunction = createFunction;
@@ -8,10 +8,10 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const child_process_1 = require("child_process");
11
- const escapeRegExp_1 = require("../../utils/escapeRegExp");
11
+ const escapeRegExp_1 = require("../escapeRegExp");
12
12
  const modules_1 = require("../../utils/cms/modules");
13
- const logger_1 = require("../../utils/logger");
14
- const standardErrors_1 = require("../../errors/standardErrors");
13
+ const logger_1 = require("../logger");
14
+ const lang_1 = require("../../utils/lang");
15
15
  const i18nKey = 'lib.cms.handleFieldsJs';
16
16
  class FieldsJs {
17
17
  projectDir;
@@ -51,9 +51,9 @@ class FieldsJs {
51
51
  writeDir,
52
52
  },
53
53
  });
54
- (0, logger_1.debug)(`${i18nKey}.convertFieldsJs.creating`, {
54
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.creating`, {
55
55
  pid: convertFieldsProcess.pid || '',
56
- });
56
+ }));
57
57
  convertFieldsProcess.on('message', function (message) {
58
58
  if (message.action === 'ERROR') {
59
59
  reject(message.message);
@@ -63,12 +63,12 @@ class FieldsJs {
63
63
  }
64
64
  });
65
65
  convertFieldsProcess.on('close', () => {
66
- (0, logger_1.debug)(`${i18nKey}.convertFieldsJs.terminating`, {
66
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.terminating`, {
67
67
  pid: convertFieldsProcess.pid || '',
68
- });
68
+ }));
69
69
  });
70
70
  }).catch((e) => {
71
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.convertFieldsJs.errors.errorConverting`, { filePath }, e);
71
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.errors.errorConverting`, { filePath }), { cause: e });
72
72
  });
73
73
  }
74
74
  /**
@@ -78,9 +78,9 @@ class FieldsJs {
78
78
  */
79
79
  saveOutput() {
80
80
  if (!this.outputPath || !fs_extra_1.default.existsSync(this.outputPath)) {
81
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.saveOutput.errors.saveFailed`, {
81
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.saveOutput.errors.saveFailed`, {
82
82
  path: this.filePath,
83
- });
83
+ }));
84
84
  }
85
85
  const relativePath = path_1.default.relative(this.rootWriteDir, path_1.default.dirname(this.outputPath));
86
86
  const savePath = path_1.default.join(this.projectDir, relativePath, 'fields.output.json');
@@ -88,7 +88,7 @@ class FieldsJs {
88
88
  fs_extra_1.default.copyFileSync(this.outputPath, savePath);
89
89
  }
90
90
  catch (err) {
91
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.saveOutput.errors.saveFailed`, { path: savePath }, err);
91
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.saveOutput.errors.saveFailed`, { path: savePath }), { cause: err });
92
92
  }
93
93
  }
94
94
  /**
@@ -120,7 +120,7 @@ function isConvertableFieldJs(rootDir, filePath, convertFields = false) {
120
120
  const inModuleFolder = (0, modules_1.isModuleFolderChild)({ path: filePath, isLocal: true });
121
121
  return !!(convertFields &&
122
122
  allowedFieldsNames.includes(baseName) &&
123
- (inModuleFolder || relativePath == '/'));
123
+ (inModuleFolder || relativePath == path_1.default.sep));
124
124
  }
125
125
  exports.isConvertableFieldJs = isConvertableFieldJs;
126
126
  // Try creating tempdir
@@ -130,7 +130,9 @@ function createTmpDirSync(prefix) {
130
130
  tmpDir = fs_extra_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), prefix));
131
131
  }
132
132
  catch (err) {
133
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createTmpDirSync.errors.writeFailed`, {}, err);
133
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.createTmpDirSync.errors.writeFailed`), {
134
+ cause: err,
135
+ });
134
136
  }
135
137
  return tmpDir;
136
138
  }
@@ -139,7 +141,7 @@ exports.createTmpDirSync = createTmpDirSync;
139
141
  function cleanupTmpDirSync(tmpDir) {
140
142
  fs_extra_1.default.rm(tmpDir, { recursive: true }, err => {
141
143
  if (err) {
142
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.cleanupTmpDirSync.errors.deleteFailed`, {}, err);
144
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.cleanupTmpDirSync.errors.deleteFailed`), { cause: err });
143
145
  }
144
146
  });
145
147
  }
@@ -1,5 +1,4 @@
1
- import { LogCallbacksArg } from '../../types/LogCallbacks';
2
- import { PathInput } from '../../types/Modules';
1
+ import { PathInput, ValidationResult, ModuleDefinition } from '../../types/Modules';
3
2
  export declare const ValidationIds: {
4
3
  SRC_REQUIRED: string;
5
4
  DEST_REQUIRED: string;
@@ -7,18 +6,9 @@ export declare const ValidationIds: {
7
6
  MODULE_TO_MODULE_NESTING: string;
8
7
  MODULE_NESTING: string;
9
8
  };
10
- type ValidationResult = {
11
- id: string;
12
- message: string;
13
- };
14
9
  export declare function validateSrcAndDestPaths(src?: PathInput, dest?: PathInput): Promise<Array<ValidationResult>>;
15
- type ModuleDefinition = {
16
- contentTypes: Array<string>;
17
- moduleLabel: string;
18
- global: boolean;
19
- };
20
- declare const createModuleCallbackKeys: readonly ["creatingPath", "creatingModule"];
21
- export declare function createModule(moduleDefinition: ModuleDefinition, name: string, dest: string, options?: {
10
+ export declare function createModule(moduleDefinition: ModuleDefinition, name: string, dest: string, getInternalVersion: boolean, options?: {
22
11
  allowExistingDir: boolean;
23
- }, logCallbacks?: LogCallbacksArg<typeof createModuleCallbackKeys>): Promise<void>;
24
- export {};
12
+ }): Promise<void>;
13
+ export declare function retrieveDefaultModule(name: string | undefined, dest: string): Promise<import("../../types/Github").GithubRepoFile[] | undefined>;
14
+ export declare const isModuleHTMLFile: (filePath: string) => boolean;