@hubspot/local-dev-lib 1.13.1 → 2.0.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 (104) hide show
  1. package/api/appsDev.d.ts +6 -5
  2. package/api/appsDev.js +6 -10
  3. package/api/customObjects.d.ts +7 -6
  4. package/api/customObjects.js +13 -16
  5. package/api/designManager.d.ts +3 -2
  6. package/api/designManager.js +5 -8
  7. package/api/developerTestAccounts.d.ts +5 -4
  8. package/api/developerTestAccounts.js +9 -10
  9. package/api/fileManager.d.ts +5 -4
  10. package/api/fileManager.js +9 -9
  11. package/api/fileMapper.d.ts +8 -8
  12. package/api/fileMapper.js +16 -16
  13. package/api/fileTransport.d.ts +4 -3
  14. package/api/fileTransport.js +5 -5
  15. package/api/functions.d.ts +6 -5
  16. package/api/functions.js +11 -14
  17. package/api/github.d.ts +6 -6
  18. package/api/github.js +5 -5
  19. package/api/hubdb.d.ts +9 -8
  20. package/api/hubdb.js +17 -20
  21. package/api/lighthouseScore.d.ts +4 -3
  22. package/api/lighthouseScore.js +7 -10
  23. package/api/localDevAuth.d.ts +5 -4
  24. package/api/localDevAuth.js +8 -9
  25. package/api/marketplaceValidation.d.ts +4 -3
  26. package/api/marketplaceValidation.js +4 -7
  27. package/api/projects.d.ts +31 -30
  28. package/api/projects.js +52 -52
  29. package/api/sandboxHubs.d.ts +5 -4
  30. package/api/sandboxHubs.js +9 -10
  31. package/api/sandboxSync.d.ts +4 -4
  32. package/api/sandboxSync.js +5 -14
  33. package/api/secrets.d.ts +5 -4
  34. package/api/secrets.js +9 -12
  35. package/api/validateHubl.d.ts +2 -1
  36. package/api/validateHubl.js +3 -6
  37. package/config/CLIConfiguration.d.ts +3 -3
  38. package/config/CLIConfiguration.js +22 -20
  39. package/config/configFile.js +7 -14
  40. package/config/config_DEPRECATED.js +5 -2
  41. package/config/index.js +45 -48
  42. package/errors/errors_DEPRECATED.js +2 -2
  43. package/errors/index.d.ts +18 -0
  44. package/errors/index.js +63 -0
  45. package/http/addQueryParams.d.ts +2 -0
  46. package/http/addQueryParams.js +14 -0
  47. package/http/getAxiosConfig.d.ts +2 -2
  48. package/http/getAxiosConfig.js +10 -2
  49. package/http/index.d.ts +9 -14
  50. package/http/index.js +28 -53
  51. package/http/unauthed.d.ts +15 -0
  52. package/http/unauthed.js +38 -0
  53. package/lang/en.json +1 -2
  54. package/lang/lang/en.json +1 -2
  55. package/lib/archive.js +11 -10
  56. package/lib/cms/functions.js +18 -17
  57. package/lib/cms/handleFieldsJS.js +8 -7
  58. package/lib/cms/modules.js +4 -5
  59. package/lib/cms/processFieldsJs.js +8 -7
  60. package/lib/cms/templates.js +2 -3
  61. package/lib/cms/uploadFolder.js +16 -14
  62. package/lib/cms/validate.js +1 -1
  63. package/lib/cms/watch.js +16 -9
  64. package/lib/customObjects.js +4 -15
  65. package/lib/fileManager.js +22 -21
  66. package/lib/fileMapper.js +24 -31
  67. package/lib/fs.js +2 -2
  68. package/lib/github.js +21 -21
  69. package/lib/gitignore.js +2 -2
  70. package/lib/hubdb.d.ts +3 -2
  71. package/lib/hubdb.js +11 -9
  72. package/lib/notify.js +2 -2
  73. package/lib/oauth.d.ts +1 -1
  74. package/lib/oauth.js +8 -17
  75. package/lib/personalAccessKey.js +16 -21
  76. package/lib/portManager.js +2 -2
  77. package/lib/trackUsage.js +3 -3
  78. package/models/FileSystemError.d.ts +6 -0
  79. package/models/FileSystemError.js +47 -0
  80. package/models/HubSpotHttpError.d.ts +24 -0
  81. package/models/HubSpotHttpError.js +197 -0
  82. package/models/OAuth2Manager.d.ts +1 -2
  83. package/models/OAuth2Manager.js +13 -28
  84. package/package.json +2 -1
  85. package/types/Error.d.ts +7 -5
  86. package/types/Files.d.ts +4 -4
  87. package/types/Http.d.ts +6 -10
  88. package/types/Sandbox.d.ts +0 -5
  89. package/utils/PortManagerServer.d.ts +3 -3
  90. package/utils/PortManagerServer.js +9 -9
  91. package/utils/cms/modules.js +2 -2
  92. package/utils/detectPort.js +3 -3
  93. package/errors/apiErrors.d.ts +0 -25
  94. package/errors/apiErrors.js +0 -176
  95. package/errors/fileSystemErrors.d.ts +0 -6
  96. package/errors/fileSystemErrors.js +0 -35
  97. package/errors/standardErrors.d.ts +0 -20
  98. package/errors/standardErrors.js +0 -62
  99. package/lib/developerTestAccounts.d.ts +0 -4
  100. package/lib/developerTestAccounts.js +0 -35
  101. package/lib/sandboxes.d.ts +0 -14
  102. package/lib/sandboxes.js +0 -70
  103. package/models/HubSpotAuthError.d.ts +0 -12
  104. package/models/HubSpotAuthError.js +0 -20
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFileSystemError = exports.isSystemError = exports.isHubSpotHttpError = exports.isValidationError = exports.isAuthError = exports.isTimeoutError = exports.isGatingError = exports.isMissingScopeError = exports.isSpecifiedError = void 0;
4
+ const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
5
+ const FileSystemError_1 = require("../models/FileSystemError");
6
+ function isSpecifiedError(err, { statusCode, category, subCategory, errorType, code, }) {
7
+ if (!isHubSpotHttpError(err)) {
8
+ return false;
9
+ }
10
+ const { data, status, code: actualCode } = err;
11
+ const statusCodeMatchesError = !statusCode || status === statusCode;
12
+ const categoryMatchesError = !category || data?.category === category;
13
+ const subCategoryMatchesError = !subCategory || data?.subCategory === subCategory;
14
+ const errorTypeMatchesError = !errorType || data?.errorType === errorType;
15
+ const codeMatchesError = !code || actualCode === code;
16
+ return (statusCodeMatchesError &&
17
+ categoryMatchesError &&
18
+ subCategoryMatchesError &&
19
+ errorTypeMatchesError &&
20
+ codeMatchesError);
21
+ }
22
+ exports.isSpecifiedError = isSpecifiedError;
23
+ function isMissingScopeError(err) {
24
+ return isSpecifiedError(err, { statusCode: 403, category: 'MISSING_SCOPES' });
25
+ }
26
+ exports.isMissingScopeError = isMissingScopeError;
27
+ function isGatingError(err) {
28
+ return isSpecifiedError(err, { statusCode: 403, category: 'GATED' });
29
+ }
30
+ exports.isGatingError = isGatingError;
31
+ function isTimeoutError(err) {
32
+ return isSpecifiedError(err, { code: 'ETIMEDOUT' });
33
+ }
34
+ exports.isTimeoutError = isTimeoutError;
35
+ function isAuthError(err) {
36
+ return (isSpecifiedError(err, { statusCode: 401 }) ||
37
+ isSpecifiedError(err, { statusCode: 403 }));
38
+ }
39
+ exports.isAuthError = isAuthError;
40
+ function isValidationError(err) {
41
+ return (isHubSpotHttpError(err) &&
42
+ isSpecifiedError(err, { statusCode: 400 }) &&
43
+ !!(err?.data?.message || !!err.data?.errors));
44
+ }
45
+ exports.isValidationError = isValidationError;
46
+ function isHubSpotHttpError(error) {
47
+ return !!error && error instanceof HubSpotHttpError_1.HubSpotHttpError;
48
+ }
49
+ exports.isHubSpotHttpError = isHubSpotHttpError;
50
+ function isSystemError(err) {
51
+ return (err instanceof Error &&
52
+ 'errno' in err &&
53
+ err.errno != null &&
54
+ 'code' in err &&
55
+ err.code != null &&
56
+ 'syscall' in err &&
57
+ err.syscall != null);
58
+ }
59
+ exports.isSystemError = isSystemError;
60
+ function isFileSystemError(err) {
61
+ return err instanceof FileSystemError_1.FileSystemError;
62
+ }
63
+ exports.isFileSystemError = isFileSystemError;
@@ -0,0 +1,2 @@
1
+ import { HttpOptions, QueryParams } from '../types/Http';
2
+ export declare function addQueryParams(configOptions: HttpOptions, queryParams?: QueryParams): HttpOptions;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addQueryParams = void 0;
4
+ function addQueryParams(configOptions, queryParams = {}) {
5
+ const { params } = configOptions;
6
+ return {
7
+ ...configOptions,
8
+ params: {
9
+ ...queryParams,
10
+ ...params,
11
+ },
12
+ };
13
+ }
14
+ exports.addQueryParams = addQueryParams;
@@ -1,4 +1,4 @@
1
- import { AxiosConfigOptions } from '../types/Http';
1
+ import { HttpOptions } from '../types/Http';
2
2
  import { AxiosRequestConfig } from 'axios';
3
3
  export declare const USER_AGENTS: {
4
4
  [key: string]: string;
@@ -6,4 +6,4 @@ export declare const USER_AGENTS: {
6
6
  export declare function getDefaultUserAgentHeader(): {
7
7
  'User-Agent': string;
8
8
  };
9
- export declare function getAxiosConfig(options: AxiosConfigOptions): AxiosRequestConfig;
9
+ export declare function getAxiosConfig(options: HttpOptions): AxiosRequestConfig;
@@ -41,14 +41,22 @@ const DEFAULT_TRANSITIONAL = {
41
41
  };
42
42
  function getAxiosConfig(options) {
43
43
  const { env, localHostOverride, headers, ...rest } = options;
44
- const { httpTimeout, httpUseLocalhost } = (0, config_1.getAndLoadConfigIfNeeded)();
44
+ const config = (0, config_1.getAndLoadConfigIfNeeded)();
45
+ let httpTimeout = 15000;
46
+ let httpUseLocalhost = false;
47
+ if (config && config.httpTimeout) {
48
+ httpTimeout = config.httpTimeout;
49
+ }
50
+ if (config && config.httpUseLocalhost) {
51
+ httpUseLocalhost = config.httpUseLocalhost;
52
+ }
45
53
  return {
46
54
  baseURL: (0, urls_1.getHubSpotApiOrigin)(env, localHostOverride ? false : httpUseLocalhost),
47
55
  headers: {
48
56
  ...getDefaultUserAgentHeader(),
49
57
  ...(headers || {}),
50
58
  },
51
- timeout: httpTimeout || 15000,
59
+ timeout: httpTimeout,
52
60
  transitional: DEFAULT_TRANSITIONAL,
53
61
  httpAgent,
54
62
  httpsAgent,
package/http/index.d.ts CHANGED
@@ -1,22 +1,17 @@
1
- import { AxiosResponse } from 'axios';
1
+ import { AxiosPromise } from 'axios';
2
2
  import { HttpOptions } from '../types/Http';
3
3
  export declare function addUserAgentHeader(key: string, value: string): void;
4
- declare function getRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
5
- declare function getRequest<T>(accountId: number, options: HttpOptions, withFullResponse: true): Promise<AxiosResponse<T>>;
6
- declare function postRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
7
- declare function postRequest<T>(accountId: number, options: HttpOptions, withFullResponse: true): Promise<AxiosResponse<T>>;
8
- declare function putRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
9
- declare function putRequest<T>(accountId: number, options: HttpOptions, withFullResponse: true): Promise<AxiosResponse<T>>;
10
- declare function patchRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
11
- declare function patchRequest<T>(accountId: number, options: HttpOptions, withFullResponse: true): Promise<AxiosResponse<T>>;
12
- declare function deleteRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
13
- declare function deleteRequest<T>(accountId: number, options: HttpOptions, withFullResponse: true): Promise<AxiosResponse<T>>;
14
- declare const http: {
4
+ declare function getRequest<T>(accountId: number, options: HttpOptions): AxiosPromise<T>;
5
+ declare function postRequest<T>(accountId: number, options: HttpOptions): AxiosPromise<T>;
6
+ declare function putRequest<T>(accountId: number, options: HttpOptions): AxiosPromise<T>;
7
+ declare function patchRequest<T>(accountId: number, options: HttpOptions): AxiosPromise<T>;
8
+ declare function deleteRequest<T>(accountId: number, options: HttpOptions): AxiosPromise<T>;
9
+ export declare const http: {
15
10
  get: typeof getRequest;
16
11
  post: typeof postRequest;
17
12
  put: typeof putRequest;
18
13
  patch: typeof patchRequest;
19
14
  delete: typeof deleteRequest;
20
- getOctetStream: (accountId: number, options: HttpOptions, destPath: string) => Promise<AxiosResponse>;
15
+ getOctetStream: (accountId: number, options: HttpOptions, destPath: string) => AxiosPromise<any>;
21
16
  };
22
- export default http;
17
+ export {};
package/http/index.js CHANGED
@@ -3,19 +3,25 @@ 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.addUserAgentHeader = void 0;
6
+ exports.http = exports.addUserAgentHeader = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const content_disposition_1 = __importDefault(require("content-disposition"));
10
10
  const axios_1 = __importDefault(require("axios"));
11
11
  const config_1 = require("../config");
12
12
  const getAxiosConfig_1 = require("./getAxiosConfig");
13
+ const addQueryParams_1 = require("./addQueryParams");
13
14
  const personalAccessKey_1 = require("../lib/personalAccessKey");
14
15
  const oauth_1 = require("../lib/oauth");
15
- const standardErrors_1 = require("../errors/standardErrors");
16
16
  const logger_1 = require("../lib/logger");
17
17
  const lang_1 = require("../utils/lang");
18
+ const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
18
19
  const i18nKey = 'http.index';
20
+ axios_1.default.interceptors.response.use(undefined, error => {
21
+ // Wrap all axios errors in our own Error class. Attach the error
22
+ // as the cause for the new error, so we maintain the stack trace
23
+ return Promise.reject(new HubSpotHttpError_1.HubSpotHttpError(error.message, { cause: error }));
24
+ });
19
25
  function addUserAgentHeader(key, value) {
20
26
  getAxiosConfig_1.USER_AGENTS[key] = value;
21
27
  }
@@ -24,7 +30,7 @@ async function withOauth(accountId, accountConfig, axiosConfig) {
24
30
  const { headers } = axiosConfig;
25
31
  const oauth = (0, oauth_1.getOauthManager)(accountId, accountConfig);
26
32
  if (!oauth) {
27
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.withOauth`, { accountId });
33
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withOauth`, { accountId }));
28
34
  }
29
35
  const accessToken = await oauth.accessToken();
30
36
  return {
@@ -59,7 +65,7 @@ function withPortalId(portalId, axiosConfig) {
59
65
  async function withAuth(accountId, options) {
60
66
  const accountConfig = (0, config_1.getAccountConfig)(accountId);
61
67
  if (!accountConfig) {
62
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.withAuth`, { accountId });
68
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withAuth`, { accountId }));
63
69
  }
64
70
  const { env, authType, apiKey } = accountConfig;
65
71
  const axiosConfig = withPortalId(accountId, (0, getAxiosConfig_1.getAxiosConfig)({ env, ...options }));
@@ -78,62 +84,32 @@ async function withAuth(accountId, options) {
78
84
  },
79
85
  };
80
86
  }
81
- function addQueryParams(configOptions, queryParams = {}) {
82
- const { params } = configOptions;
83
- return {
84
- ...configOptions,
85
- params: {
86
- ...queryParams,
87
- ...params,
88
- },
89
- };
90
- }
91
- async function getRequest(accountId, options, withFullResponse) {
87
+ async function getRequest(accountId, options) {
92
88
  const { params, ...rest } = options;
93
- const axiosConfig = addQueryParams(rest, params);
94
- const configWithAuth = await withAuth(accountId, axiosConfig);
95
- const response = await (0, axios_1.default)(configWithAuth);
96
- if (withFullResponse) {
97
- return response;
98
- }
99
- return response.data;
89
+ const optionsWithParams = (0, addQueryParams_1.addQueryParams)(rest, params);
90
+ const requestConfig = await withAuth(accountId, optionsWithParams);
91
+ return (0, axios_1.default)(requestConfig);
100
92
  }
101
- async function postRequest(accountId, options, withFullResponse) {
102
- const configWithAuth = await withAuth(accountId, options);
103
- const response = await (0, axios_1.default)({ ...configWithAuth, method: 'post' });
104
- if (withFullResponse) {
105
- return response;
106
- }
107
- return response.data;
93
+ async function postRequest(accountId, options) {
94
+ const requestConfig = await withAuth(accountId, options);
95
+ return (0, axios_1.default)({ ...requestConfig, method: 'post' });
108
96
  }
109
- async function putRequest(accountId, options, withFullResponse) {
110
- const configWithAuth = await withAuth(accountId, options);
111
- const response = await (0, axios_1.default)({ ...configWithAuth, method: 'put' });
112
- if (withFullResponse) {
113
- return response;
114
- }
115
- return response.data;
97
+ async function putRequest(accountId, options) {
98
+ const requestConfig = await withAuth(accountId, options);
99
+ return (0, axios_1.default)({ ...requestConfig, method: 'put' });
116
100
  }
117
- async function patchRequest(accountId, options, withFullResponse) {
118
- const configWithAuth = await withAuth(accountId, options);
119
- const response = await (0, axios_1.default)({ ...configWithAuth, method: 'patch' });
120
- if (withFullResponse) {
121
- return response;
122
- }
123
- return response.data;
101
+ async function patchRequest(accountId, options) {
102
+ const requestConfig = await withAuth(accountId, options);
103
+ return (0, axios_1.default)({ ...requestConfig, method: 'patch' });
124
104
  }
125
- async function deleteRequest(accountId, options, withFullResponse = false) {
126
- const configWithAuth = await withAuth(accountId, options);
127
- const response = await (0, axios_1.default)({ ...configWithAuth, method: 'delete' });
128
- if (withFullResponse) {
129
- return response;
130
- }
131
- return response.data;
105
+ async function deleteRequest(accountId, options) {
106
+ const requestConfig = await withAuth(accountId, options);
107
+ return (0, axios_1.default)({ ...requestConfig, method: 'delete' });
132
108
  }
133
109
  function createGetRequestStream(contentType) {
134
110
  return async (accountId, options, destPath) => {
135
111
  const { params, ...rest } = options;
136
- const axiosConfig = addQueryParams(rest, params);
112
+ const axiosConfig = (0, addQueryParams_1.addQueryParams)(rest, params);
137
113
  // eslint-disable-next-line no-async-promise-executor
138
114
  return new Promise(async (resolve, reject) => {
139
115
  try {
@@ -187,7 +163,7 @@ function createGetRequestStream(contentType) {
187
163
  };
188
164
  }
189
165
  const getOctetStream = createGetRequestStream('application/octet-stream');
190
- const http = {
166
+ exports.http = {
191
167
  get: getRequest,
192
168
  post: postRequest,
193
169
  put: putRequest,
@@ -195,4 +171,3 @@ const http = {
195
171
  delete: deleteRequest,
196
172
  getOctetStream,
197
173
  };
198
- exports.default = http;
@@ -0,0 +1,15 @@
1
+ import { AxiosPromise } from 'axios';
2
+ import { HttpOptions } from '../types/Http';
3
+ declare function getRequest<T>(options: HttpOptions): AxiosPromise<T>;
4
+ declare function postRequest<T>(options: HttpOptions): AxiosPromise<T>;
5
+ declare function putRequest<T>(options: HttpOptions): AxiosPromise<T>;
6
+ declare function patchRequest<T>(options: HttpOptions): AxiosPromise<T>;
7
+ declare function deleteRequest<T>(options: HttpOptions): AxiosPromise<T>;
8
+ export declare const http: {
9
+ get: typeof getRequest;
10
+ post: typeof postRequest;
11
+ put: typeof putRequest;
12
+ patch: typeof patchRequest;
13
+ delete: typeof deleteRequest;
14
+ };
15
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.http = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const getAxiosConfig_1 = require("./getAxiosConfig");
9
+ const addQueryParams_1 = require("./addQueryParams");
10
+ async function getRequest(options) {
11
+ const { params, ...rest } = options;
12
+ const optionsWithParams = (0, addQueryParams_1.addQueryParams)(rest, params);
13
+ const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(optionsWithParams);
14
+ return (0, axios_1.default)(requestConfig);
15
+ }
16
+ async function postRequest(options) {
17
+ const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
18
+ return (0, axios_1.default)({ ...requestConfig, method: 'post' });
19
+ }
20
+ async function putRequest(options) {
21
+ const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
22
+ return (0, axios_1.default)({ ...requestConfig, method: 'put' });
23
+ }
24
+ async function patchRequest(options) {
25
+ const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
26
+ return (0, axios_1.default)({ ...requestConfig, method: 'patch' });
27
+ }
28
+ async function deleteRequest(options) {
29
+ const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
30
+ return (0, axios_1.default)({ ...requestConfig, method: 'delete' });
31
+ }
32
+ exports.http = {
33
+ get: getRequest,
34
+ post: postRequest,
35
+ put: putRequest,
36
+ patch: patchRequest,
37
+ delete: deleteRequest,
38
+ };
package/lang/en.json CHANGED
@@ -384,7 +384,6 @@
384
384
  "400Generic": "The {{ messageDetail }} failed due to a client error.",
385
385
  "generic": "The {{ messageDetail }} failed."
386
386
  }
387
- },
388
- "generic": "{{ name }}:"
387
+ }
389
388
  }
390
389
  }
package/lang/lang/en.json CHANGED
@@ -384,7 +384,6 @@
384
384
  "400Generic": "The {{ messageDetail }} failed due to a client error.",
385
385
  "generic": "The {{ messageDetail }} failed."
386
386
  }
387
- },
388
- "generic": "{{ name }}:"
387
+ }
389
388
  }
390
389
  }
package/lib/archive.js CHANGED
@@ -8,10 +8,9 @@ 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
11
  const logger_1 = require("./logger");
14
12
  const lang_1 = require("../utils/lang");
13
+ const FileSystemError_1 = require("../models/FileSystemError");
15
14
  const i18nKey = 'lib.archive';
16
15
  async function extractZip(name, zip, hideLogs = false) {
17
16
  const result = { extractDir: '', tmpDir: '' };
@@ -31,15 +30,16 @@ async function extractZip(name, zip, hideLogs = false) {
31
30
  }
32
31
  catch (err) {
33
32
  if (tmpZipPath || result.tmpDir) {
34
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
33
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
35
34
  filepath: tmpZipPath || result.tmpDir,
36
- write: true,
35
+ operation: 'write',
37
36
  });
38
37
  }
39
38
  else {
40
- (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
+ });
41
42
  }
42
- return result;
43
43
  }
44
44
  // Extract zip
45
45
  try {
@@ -48,7 +48,9 @@ async function extractZip(name, zip, hideLogs = false) {
48
48
  result.extractDir = tmpExtractPath;
49
49
  }
50
50
  catch (err) {
51
- (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
+ });
52
54
  }
53
55
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.extractZip.success`));
54
56
  return result;
@@ -81,12 +83,11 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true,
81
83
  }
82
84
  catch (err) {
83
85
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.error`, { dest }));
84
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
86
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
85
87
  filepath: dest,
86
- write: true,
88
+ operation: 'write',
87
89
  });
88
90
  }
89
- return false;
90
91
  }
91
92
  async function cleanupTempDir(tmpDir) {
92
93
  if (!tmpDir)
@@ -10,9 +10,8 @@ const findup_sync_1 = __importDefault(require("findup-sync"));
10
10
  const path_2 = require("../path");
11
11
  const github_1 = require("../github");
12
12
  const logger_1 = require("../logger");
13
- const standardErrors_1 = require("../../errors/standardErrors");
14
- const fileSystemErrors_1 = require("../../errors/fileSystemErrors");
15
13
  const lang_1 = require("../../utils/lang");
14
+ const FileSystemError_1 = require("../../models/FileSystemError");
16
15
  const i18nKey = 'lib.cms.functions';
17
16
  function isObjectOrFunction(value) {
18
17
  const type = typeof value;
@@ -48,9 +47,9 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
48
47
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
49
48
  configFilePath,
50
49
  }));
51
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
50
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
52
51
  filepath: configFilePath,
53
- read: true,
52
+ operation: 'read',
54
53
  });
55
54
  }
56
55
  let config;
@@ -61,20 +60,22 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
61
60
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.invalidJSON`, {
62
61
  configFilePath,
63
62
  }));
64
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
63
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
65
64
  filepath: configFilePath,
66
- read: true,
65
+ operation: 'read',
67
66
  });
68
67
  }
69
68
  if (!isObjectOrFunction(config)) {
70
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, { configFilePath });
69
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, {
70
+ configFilePath,
71
+ }));
71
72
  }
72
73
  if (config.endpoints) {
73
74
  if (config.endpoints[endpointPath]) {
74
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
75
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
75
76
  configFilePath,
76
77
  endpointPath,
77
- });
78
+ }));
78
79
  }
79
80
  else {
80
81
  config.endpoints[endpointPath] = createEndpoint(endpointMethod, functionFile);
@@ -92,9 +93,9 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
92
93
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
93
94
  configFilePath,
94
95
  }));
95
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
96
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
96
97
  filepath: configFilePath,
97
- write: true,
98
+ operation: 'read',
98
99
  });
99
100
  }
100
101
  }
@@ -106,9 +107,9 @@ async function createFunction(functionInfo, dest, options = {}) {
106
107
  nocase: true,
107
108
  });
108
109
  if (ancestorFunctionsConfig) {
109
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createFunction.errors.nestedConfigError`, {
110
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.createFunction.errors.nestedConfigError`, {
110
111
  ancestorConfigPath: path_1.default.dirname(ancestorFunctionsConfig),
111
- });
112
+ }));
112
113
  }
113
114
  const folderName = functionsFolder.endsWith('.functions')
114
115
  ? functionsFolder
@@ -129,9 +130,9 @@ async function createFunction(functionInfo, dest, options = {}) {
129
130
  const functionFilePath = path_1.default.join(destPath, functionFile);
130
131
  const configFilePath = path_1.default.join(destPath, 'serverless.json');
131
132
  if (!allowExistingFile && fs_extra_1.default.existsSync(functionFilePath)) {
132
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createFunction.errors.jsFileConflictError`, {
133
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.createFunction.errors.jsFileConflictError`, {
133
134
  functionFilePath,
134
- });
135
+ }));
135
136
  }
136
137
  await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', 'functions/sample-function.js', functionFilePath);
137
138
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
@@ -160,9 +161,9 @@ async function createFunction(functionInfo, dest, options = {}) {
160
161
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createFunction.failedToCreateFile`, {
161
162
  configFilePath,
162
163
  }));
163
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
164
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
164
165
  filepath: configFilePath,
165
- write: true,
166
+ operation: 'write',
166
167
  });
167
168
  }
168
169
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdConfigFile`, {
@@ -11,7 +11,6 @@ const child_process_1 = require("child_process");
11
11
  const escapeRegExp_1 = require("../escapeRegExp");
12
12
  const modules_1 = require("../../utils/cms/modules");
13
13
  const logger_1 = require("../logger");
14
- const standardErrors_1 = require("../../errors/standardErrors");
15
14
  const lang_1 = require("../../utils/lang");
16
15
  const i18nKey = 'lib.cms.handleFieldsJs';
17
16
  class FieldsJs {
@@ -69,7 +68,7 @@ class FieldsJs {
69
68
  }));
70
69
  });
71
70
  }).catch((e) => {
72
- (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 });
73
72
  });
74
73
  }
75
74
  /**
@@ -79,9 +78,9 @@ class FieldsJs {
79
78
  */
80
79
  saveOutput() {
81
80
  if (!this.outputPath || !fs_extra_1.default.existsSync(this.outputPath)) {
82
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.saveOutput.errors.saveFailed`, {
81
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.saveOutput.errors.saveFailed`, {
83
82
  path: this.filePath,
84
- });
83
+ }));
85
84
  }
86
85
  const relativePath = path_1.default.relative(this.rootWriteDir, path_1.default.dirname(this.outputPath));
87
86
  const savePath = path_1.default.join(this.projectDir, relativePath, 'fields.output.json');
@@ -89,7 +88,7 @@ class FieldsJs {
89
88
  fs_extra_1.default.copyFileSync(this.outputPath, savePath);
90
89
  }
91
90
  catch (err) {
92
- (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 });
93
92
  }
94
93
  }
95
94
  /**
@@ -131,7 +130,9 @@ function createTmpDirSync(prefix) {
131
130
  tmpDir = fs_extra_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), prefix));
132
131
  }
133
132
  catch (err) {
134
- (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
+ });
135
136
  }
136
137
  return tmpDir;
137
138
  }
@@ -140,7 +141,7 @@ exports.createTmpDirSync = createTmpDirSync;
140
141
  function cleanupTmpDirSync(tmpDir) {
141
142
  fs_extra_1.default.rm(tmpDir, { recursive: true }, err => {
142
143
  if (err) {
143
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.cleanupTmpDirSync.errors.deleteFailed`, {}, err);
144
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.cleanupTmpDirSync.errors.deleteFailed`), { cause: err });
144
145
  }
145
146
  });
146
147
  }
@@ -9,7 +9,6 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const path_2 = require("../path");
10
10
  const fs_1 = require("../fs");
11
11
  const github_1 = require("../github");
12
- const standardErrors_1 = require("../../errors/standardErrors");
13
12
  const logger_1 = require("../logger");
14
13
  const modules_1 = require("../../utils/cms/modules");
15
14
  const lang_1 = require("../../utils/lang");
@@ -98,10 +97,10 @@ const updateFileContents = async (file, metaData, getInternalVersion) => {
98
97
  }
99
98
  catch (error) {
100
99
  const { message } = error;
101
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createModule.errors.fileUpdateFailure`, {
100
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.createModule.errors.fileUpdateFailure`, {
102
101
  path: file,
103
102
  errorMessage: message,
104
- });
103
+ }));
105
104
  }
106
105
  };
107
106
  async function createModule(moduleDefinition, name, dest, getInternalVersion, options = {
@@ -126,9 +125,9 @@ async function createModule(moduleDefinition, name, dest, getInternalVersion, op
126
125
  ? path_1.default.join(dest, folderName)
127
126
  : path_1.default.join(dest, `${name}`);
128
127
  if (!options.allowExistingDir && fs_extra_1.default.existsSync(destPath)) {
129
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createModule.errors.pathExists`, {
128
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.createModule.errors.pathExists`, {
130
129
  path: destPath,
131
- });
130
+ }));
132
131
  }
133
132
  else {
134
133
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createModule.creatingPath`, {