@hubspot/local-dev-lib 0.2.2 → 0.2.3-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 (187) 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 +4 -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 +5 -4
  12. package/api/fileManager.js +11 -11
  13. package/api/fileMapper.d.ts +8 -7
  14. package/api/fileMapper.js +17 -17
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/functions.d.ts +7 -4
  18. package/api/functions.js +22 -11
  19. package/api/github.d.ts +7 -9
  20. package/api/github.js +31 -13
  21. package/api/hubdb.d.ts +11 -10
  22. package/api/hubdb.js +28 -22
  23. package/api/lighthouseScore.d.ts +4 -4
  24. package/api/lighthouseScore.js +9 -12
  25. package/api/localDevAuth.d.ts +8 -16
  26. package/api/localDevAuth.js +34 -13
  27. package/api/marketplaceValidation.d.ts +4 -4
  28. package/api/marketplaceValidation.js +8 -11
  29. package/api/projects.d.ts +31 -24
  30. package/api/projects.js +164 -44
  31. package/api/sandboxHubs.d.ts +6 -4
  32. package/api/sandboxHubs.js +10 -11
  33. package/api/sandboxSync.d.ts +4 -4
  34. package/api/sandboxSync.js +4 -13
  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 +15 -11
  40. package/config/CLIConfiguration.js +175 -90
  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 +79 -25
  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 +14 -8
  50. package/config/index.js +108 -57
  51. package/constants/config.d.ts +18 -1
  52. package/constants/config.js +20 -3
  53. package/constants/environments.d.ts +1 -0
  54. package/constants/environments.js +1 -0
  55. package/constants/extensions.d.ts +2 -0
  56. package/constants/extensions.js +3 -1
  57. package/constants/files.d.ts +2 -2
  58. package/constants/files.js +3 -3
  59. package/errors/errors_DEPRECATED.d.ts +1 -5
  60. package/errors/errors_DEPRECATED.js +2 -2
  61. package/errors/index.d.ts +18 -0
  62. package/errors/index.js +63 -0
  63. package/http/addQueryParams.d.ts +2 -0
  64. package/http/addQueryParams.js +14 -0
  65. package/http/getAxiosConfig.d.ts +6 -3
  66. package/http/getAxiosConfig.js +51 -7
  67. package/http/index.d.ts +11 -12
  68. package/http/index.js +35 -41
  69. package/http/unauthed.d.ts +14 -0
  70. package/http/unauthed.js +38 -0
  71. package/lang/en.json +378 -386
  72. package/lib/archive.d.ts +2 -8
  73. package/lib/archive.js +34 -30
  74. package/lib/cms/functions.d.ts +7 -12
  75. package/lib/cms/functions.js +49 -51
  76. package/lib/cms/handleFieldsJS.js +16 -14
  77. package/lib/cms/modules.d.ts +4 -15
  78. package/lib/cms/modules.js +81 -78
  79. package/lib/cms/processFieldsJs.js +10 -33
  80. package/lib/cms/templates.d.ts +43 -3
  81. package/lib/cms/templates.js +53 -11
  82. package/lib/cms/uploadFolder.d.ts +3 -14
  83. package/lib/cms/uploadFolder.js +58 -42
  84. package/lib/cms/validate.js +1 -1
  85. package/lib/cms/watch.d.ts +2 -18
  86. package/lib/cms/watch.js +63 -68
  87. package/lib/customObjects.js +4 -15
  88. package/lib/fileManager.d.ts +2 -6
  89. package/lib/fileManager.js +54 -65
  90. package/lib/fileMapper.d.ts +4 -15
  91. package/lib/fileMapper.js +67 -88
  92. package/lib/fs.d.ts +1 -1
  93. package/lib/fs.js +10 -6
  94. package/lib/github.d.ts +12 -14
  95. package/lib/github.js +70 -35
  96. package/lib/gitignore.d.ts +2 -0
  97. package/lib/gitignore.js +21 -4
  98. package/lib/hubdb.d.ts +3 -2
  99. package/lib/hubdb.js +11 -9
  100. package/{utils → lib}/notify.js +2 -2
  101. package/lib/oauth.d.ts +2 -5
  102. package/lib/oauth.js +14 -25
  103. package/lib/path.d.ts +3 -0
  104. package/lib/path.js +46 -1
  105. package/lib/personalAccessKey.d.ts +8 -11
  106. package/lib/personalAccessKey.js +75 -38
  107. package/lib/portManager.d.ts +3 -5
  108. package/lib/portManager.js +18 -6
  109. package/lib/trackUsage.js +18 -11
  110. package/lib/urls.js +5 -1
  111. package/models/FileSystemError.d.ts +6 -0
  112. package/models/FileSystemError.js +47 -0
  113. package/models/HubSpotHttpError.d.ts +24 -0
  114. package/models/HubSpotHttpError.js +197 -0
  115. package/models/OAuth2Manager.d.ts +5 -27
  116. package/models/OAuth2Manager.js +41 -64
  117. package/package.json +34 -35
  118. package/types/Accounts.d.ts +103 -3
  119. package/types/Apps.d.ts +77 -0
  120. package/types/Archive.d.ts +9 -0
  121. package/types/Archive.js +2 -0
  122. package/types/Build.d.ts +4 -2
  123. package/types/ComponentStructure.d.ts +30 -10
  124. package/types/Config.d.ts +19 -2
  125. package/types/Deploy.d.ts +3 -2
  126. package/types/DesignManager.d.ts +10 -0
  127. package/types/DesignManager.js +2 -0
  128. package/types/Error.d.ts +9 -5
  129. package/types/FieldsJS.d.ts +1 -0
  130. package/types/FieldsJS.js +2 -0
  131. package/types/FileManager.d.ts +1 -1
  132. package/types/Files.d.ts +43 -4
  133. package/types/Functions.d.ts +52 -0
  134. package/types/Github.d.ts +13 -0
  135. package/types/Http.d.ts +12 -11
  136. package/types/Hubdb.d.ts +9 -0
  137. package/types/MarketplaceValidation.d.ts +7 -3
  138. package/types/Migration.d.ts +28 -0
  139. package/types/Migration.js +10 -0
  140. package/types/Modules.d.ts +11 -0
  141. package/types/PortManager.d.ts +7 -0
  142. package/types/Project.d.ts +30 -0
  143. package/types/ProjectLog.d.ts +9 -0
  144. package/types/ProjectLog.js +2 -0
  145. package/types/Sandbox.d.ts +37 -47
  146. package/types/Schemas.d.ts +56 -0
  147. package/types/Secrets.d.ts +3 -0
  148. package/types/Secrets.js +2 -0
  149. package/types/developerTestAccounts.d.ts +13 -0
  150. package/types/developerTestAccounts.js +2 -0
  151. package/utils/PortManagerServer.d.ts +6 -7
  152. package/utils/PortManagerServer.js +22 -16
  153. package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
  154. package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
  155. package/utils/cms/fieldsJS.d.ts +1 -2
  156. package/utils/cms/modules.js +2 -2
  157. package/utils/detectPort.js +3 -3
  158. package/utils/git.d.ts +1 -7
  159. package/utils/git.js +2 -18
  160. package/errors/apiErrors.d.ts +0 -19
  161. package/errors/apiErrors.js +0 -179
  162. package/errors/fileSystemErrors.d.ts +0 -5
  163. package/errors/fileSystemErrors.js +0 -31
  164. package/errors/standardErrors.d.ts +0 -27
  165. package/errors/standardErrors.js +0 -59
  166. package/lang/lang/en.json +0 -401
  167. package/lib/logging/git.d.ts +0 -2
  168. package/lib/logging/git.js +0 -54
  169. package/lib/logging/logs.d.ts +0 -22
  170. package/lib/logging/logs.js +0 -86
  171. package/lib/logging/table.d.ts +0 -3
  172. package/lib/logging/table.js +0 -47
  173. package/lib/sandboxes.d.ts +0 -14
  174. package/lib/sandboxes.js +0 -71
  175. package/models/HubSpotAuthError.d.ts +0 -12
  176. package/models/HubSpotAuthError.js +0 -20
  177. package/types/LogCallbacks.d.ts +0 -7
  178. package/utils/logger.d.ts +0 -5
  179. package/utils/logger.js +0 -23
  180. package/utils/objectUtils.d.ts +0 -8
  181. package/utils/objectUtils.js +0 -33
  182. /package/{utils → lib}/escapeRegExp.d.ts +0 -0
  183. /package/{utils → lib}/escapeRegExp.js +0 -0
  184. /package/lib/{logging/logger.d.ts → logger.d.ts} +0 -0
  185. /package/lib/{logging/logger.js → logger.js} +0 -0
  186. /package/{utils → lib}/notify.d.ts +0 -0
  187. /package/types/{LogCallbacks.js → Apps.js} +0 -0
package/lib/archive.d.ts CHANGED
@@ -1,9 +1,3 @@
1
1
  /// <reference types="node" />
2
- import { LogCallbacksArg } from '../types/LogCallbacks';
3
- declare const archiveCallbackKeys: readonly ["init", "copy"];
4
- type CopySourceToDestOptions = {
5
- sourceDir?: string;
6
- includesRootDir?: boolean;
7
- };
8
- export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions, logCallbacks?: LogCallbacksArg<typeof archiveCallbackKeys>): Promise<boolean>;
9
- 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
@@ -8,16 +8,16 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = require("path");
9
9
  const os_1 = require("os");
10
10
  const extract_zip_1 = __importDefault(require("extract-zip"));
11
- const fileSystemErrors_1 = require("../errors/fileSystemErrors");
12
- const standardErrors_1 = require("../errors/standardErrors");
13
- const logger_1 = require("../utils/logger");
11
+ const logger_1 = require("./logger");
12
+ const lang_1 = require("../utils/lang");
13
+ const FileSystemError_1 = require("../models/FileSystemError");
14
14
  const i18nKey = 'lib.archive';
15
- const archiveCallbackKeys = ['init', 'copy'];
16
- async function extractZip(name, zip, logCallbacks) {
17
- const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
15
+ async function extractZip(name, zip, hideLogs = false) {
18
16
  const result = { extractDir: '', tmpDir: '' };
19
17
  const TMP_FOLDER_PREFIX = `hubspot-temp-${name}-`;
20
- logger('init', `${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,15 +30,16 @@ async function extractZip(name, zip, logCallbacks) {
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 {
@@ -47,23 +48,26 @@ async function extractZip(name, zip, logCallbacks) {
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 } = {}, logCallbacks) {
58
+ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true, hideLogs = false, } = {}) {
56
59
  try {
57
- const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
58
- logger('copy', `${i18nKey}.copySourceToDest.init`);
60
+ if (!hideLogs) {
61
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.init`));
62
+ }
59
63
  const srcDirPath = [src];
60
64
  if (includesRootDir) {
61
65
  const files = await fs_extra_1.default.readdir(src);
62
66
  const rootDir = files[0];
63
67
  if (!rootDir) {
64
- (0, logger_1.debug)(`${i18nKey}.copySourceToDest.sourceEmpty`);
68
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.sourceEmpty`));
65
69
  // Create the dest path if it doesn't already exist
66
- fs_extra_1.default.ensureDir(dest);
70
+ await fs_extra_1.default.ensureDir(dest);
67
71
  // No root found so nothing to copy
68
72
  return true;
69
73
  }
@@ -74,39 +78,39 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true }
74
78
  }
75
79
  const projectSrcDir = (0, path_1.join)(...srcDirPath);
76
80
  await fs_extra_1.default.copy(projectSrcDir, dest);
77
- (0, logger_1.debug)(`${i18nKey}.copySourceToDest.success`);
81
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.success`));
78
82
  return true;
79
83
  }
80
84
  catch (err) {
81
- (0, logger_1.debug)(`${i18nKey}.copySourceToDest.error`, { dest });
82
- (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 }, {
83
87
  filepath: dest,
84
- write: true,
88
+ operation: 'write',
85
89
  });
86
90
  }
87
- return false;
88
91
  }
89
- function cleanupTempDir(tmpDir) {
92
+ async function cleanupTempDir(tmpDir) {
90
93
  if (!tmpDir)
91
94
  return;
92
95
  try {
93
- fs_extra_1.default.remove(tmpDir);
96
+ await fs_extra_1.default.remove(tmpDir);
94
97
  }
95
98
  catch (e) {
96
- (0, logger_1.debug)(`${i18nKey}.cleanupTempDir.error`, { tmpDir });
99
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.cleanupTempDir.error`, { tmpDir }));
97
100
  }
98
101
  }
99
- async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}, logCallbacks) {
102
+ async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs } = {}) {
100
103
  let success = false;
101
104
  if (zip) {
102
- const { extractDir, tmpDir } = await extractZip(name, zip, logCallbacks);
105
+ const { extractDir, tmpDir } = await extractZip(name, zip, hideLogs);
103
106
  if (extractDir !== null) {
104
107
  success = await copySourceToDest(extractDir, dest, {
105
108
  sourceDir,
106
109
  includesRootDir,
107
- }, logCallbacks);
110
+ hideLogs,
111
+ });
108
112
  }
109
- cleanupTempDir(tmpDir);
113
+ await cleanupTempDir(tmpDir);
110
114
  }
111
115
  return success;
112
116
  }
@@ -1,13 +1,8 @@
1
- import { LogCallbacksArg } from '../../types/LogCallbacks';
2
- declare const createFunctionCallbackKeys: readonly ["destPathAlreadyExists", "createdDest", "createdFunctionFile", "createdConfigFile", "success"];
3
- type FunctionInfo = {
4
- functionsFolder: string;
5
- filename: string;
6
- endpointPath: string;
7
- 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;
8
6
  };
9
- type FunctionOptions = {
10
- allowExistingFile?: boolean;
11
- };
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,33 +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
- const createFunctionCallbackKeys = [
17
- 'destPathAlreadyExists',
18
- 'createdDest',
19
- 'createdFunctionFile',
20
- 'createdConfigFile',
21
- 'success',
22
- ];
23
16
  function isObjectOrFunction(value) {
24
17
  const type = typeof value;
25
18
  return value != null && (type === 'object' || type === 'function');
26
19
  }
20
+ exports.isObjectOrFunction = isObjectOrFunction;
27
21
  function createEndpoint(endpointMethod, filename) {
28
22
  return {
29
23
  method: endpointMethod || 'GET',
30
24
  file: filename,
31
25
  };
32
26
  }
27
+ exports.createEndpoint = createEndpoint;
33
28
  function createConfig({ endpointPath, endpointMethod, functionFile, }) {
34
29
  return {
35
30
  runtime: 'nodejs18.x',
@@ -41,6 +36,7 @@ function createConfig({ endpointPath, endpointMethod, functionFile, }) {
41
36
  },
42
37
  };
43
38
  }
39
+ exports.createConfig = createConfig;
44
40
  function writeConfig(configFilePath, config) {
45
41
  const configJson = JSON.stringify(config, null, ' ');
46
42
  fs_extra_1.default.writeFileSync(configFilePath, configJson);
@@ -51,12 +47,12 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
51
47
  configString = fs_extra_1.default.readFileSync(configFilePath).toString();
52
48
  }
53
49
  catch (err) {
54
- (0, logger_1.debug)(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
50
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
55
51
  configFilePath,
56
- });
57
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
52
+ }));
53
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
58
54
  filepath: configFilePath,
59
- read: true,
55
+ operation: 'read',
60
56
  });
61
57
  }
62
58
  let config;
@@ -64,23 +60,25 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
64
60
  config = JSON.parse(configString);
65
61
  }
66
62
  catch (err) {
67
- (0, logger_1.debug)(`${i18nKey}.updateExistingConfig.invalidJSON`, {
63
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.invalidJSON`, {
68
64
  configFilePath,
69
- });
70
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
65
+ }));
66
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
71
67
  filepath: configFilePath,
72
- read: true,
68
+ operation: 'read',
73
69
  });
74
70
  }
75
71
  if (!isObjectOrFunction(config)) {
76
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, { configFilePath });
72
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, {
73
+ configFilePath,
74
+ }));
77
75
  }
78
76
  if (config.endpoints) {
79
77
  if (config.endpoints[endpointPath]) {
80
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
78
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
81
79
  configFilePath,
82
80
  endpointPath,
83
- });
81
+ }));
84
82
  }
85
83
  else {
86
84
  config.endpoints[endpointPath] = createEndpoint(endpointMethod, functionFile);
@@ -95,17 +93,16 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
95
93
  writeConfig(configFilePath, config);
96
94
  }
97
95
  catch (err) {
98
- (0, logger_1.debug)(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
96
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
99
97
  configFilePath,
100
- });
101
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
98
+ }));
99
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
102
100
  filepath: configFilePath,
103
- write: true,
101
+ operation: 'read',
104
102
  });
105
103
  }
106
104
  }
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,41 @@ 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
- await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', 'functions/sample-function.js', functionFilePath);
144
- logger('createdFunctionFile', `${i18nKey}.createFunction.createdFunctionFile`, {
140
+ const result = await (0, github_1.fetchFileFromRepository)('HubSpot/cms-sample-assets', 'functions/sample-function.js', 'main');
141
+ fs_extra_1.default.writeFileSync(functionFilePath, result);
142
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
145
143
  path: functionFilePath,
146
- });
144
+ }));
147
145
  if (fs_extra_1.default.existsSync(configFilePath)) {
148
146
  updateExistingConfig(configFilePath, {
149
147
  endpointPath,
150
148
  endpointMethod,
151
149
  functionFile,
152
150
  });
153
- logger('createdFunctionFile', `${i18nKey}.createFunction.createdFunctionFile`, {
151
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
154
152
  path: functionFilePath,
155
- });
156
- logger('success', `${i18nKey}.createFunction.success`, {
153
+ }));
154
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
157
155
  endpointPath: endpointPath,
158
156
  folderName,
159
- });
157
+ }));
160
158
  }
161
159
  else {
162
160
  const config = createConfig({ endpointPath, endpointMethod, functionFile });
@@ -164,21 +162,21 @@ async function createFunction(functionInfo, dest, options = {}, logCallbacks) {
164
162
  writeConfig(configFilePath, config);
165
163
  }
166
164
  catch (err) {
167
- (0, logger_1.debug)(`${i18nKey}.createFunction.failedToCreateFile`, {
165
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createFunction.failedToCreateFile`, {
168
166
  configFilePath,
169
- });
170
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
167
+ }));
168
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
171
169
  filepath: configFilePath,
172
- write: true,
170
+ operation: 'write',
173
171
  });
174
172
  }
175
- logger('createdConfigFile', `${i18nKey}.createFunction.createdConfigFile`, {
173
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdConfigFile`, {
176
174
  path: configFilePath,
177
- });
178
- logger('success', `${i18nKey}.createFunction.success`, {
175
+ }));
176
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
179
177
  endpointPath: endpointPath,
180
178
  folderName,
181
- });
179
+ }));
182
180
  }
183
181
  }
184
182
  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,6 +1,4 @@
1
- import { LogCallbacksArg } from '../../types/LogCallbacks';
2
- import { PathInput } from '../../types/Modules';
3
- declare const createModuleCallbackKeys: readonly ["creatingPath", "creatingModule"];
1
+ import { PathInput, ValidationResult, ModuleDefinition } from '../../types/Modules';
4
2
  export declare const ValidationIds: {
5
3
  SRC_REQUIRED: string;
6
4
  DEST_REQUIRED: string;
@@ -8,18 +6,9 @@ export declare const ValidationIds: {
8
6
  MODULE_TO_MODULE_NESTING: string;
9
7
  MODULE_NESTING: string;
10
8
  };
11
- type ValidationResult = {
12
- id: string;
13
- message: string;
14
- };
15
9
  export declare function validateSrcAndDestPaths(src?: PathInput, dest?: PathInput): Promise<Array<ValidationResult>>;
16
- type ModuleDefinition = {
17
- contentTypes: Array<string>;
18
- moduleLabel: string;
19
- reactType: boolean;
20
- global: boolean;
21
- };
22
10
  export declare function createModule(moduleDefinition: ModuleDefinition, name: string, dest: string, getInternalVersion: boolean, options?: {
23
11
  allowExistingDir: boolean;
24
- }, logCallbacks?: LogCallbacksArg<typeof createModuleCallbackKeys>): Promise<void>;
25
- 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;