@hubspot/local-dev-lib 0.3.15 → 0.4.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.
- package/LICENSE +12 -0
- package/README.md +17 -0
- package/api/appsDev.d.ts +6 -0
- package/api/appsDev.js +29 -0
- package/api/customObjects.d.ts +8 -20
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +4 -14
- package/api/designManager.js +5 -8
- package/api/devSecrets.d.ts +6 -0
- package/api/devSecrets.js +40 -0
- package/api/developerTestAccounts.d.ts +12 -5
- package/api/developerTestAccounts.js +17 -10
- package/api/fileManager.d.ts +5 -4
- package/api/fileManager.js +9 -9
- package/api/fileMapper.d.ts +8 -7
- package/api/fileMapper.js +16 -16
- package/api/fileTransport.d.ts +4 -3
- package/api/fileTransport.js +5 -5
- package/api/fireAlarm.d.ts +3 -0
- package/api/fireAlarm.js +11 -0
- package/api/functions.d.ts +7 -7
- package/api/functions.js +11 -14
- package/api/github.d.ts +8 -9
- package/api/github.js +30 -13
- package/api/hubdb.d.ts +11 -10
- package/api/hubdb.js +24 -21
- package/api/lighthouseScore.d.ts +4 -4
- package/api/lighthouseScore.js +7 -10
- package/api/localDevAuth.d.ts +9 -19
- package/api/localDevAuth.js +34 -9
- package/api/marketplaceValidation.d.ts +4 -4
- package/api/marketplaceValidation.js +4 -7
- package/api/projects.d.ts +47 -35
- package/api/projects.js +145 -57
- package/api/sandboxHubs.d.ts +6 -4
- package/api/sandboxHubs.js +9 -10
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +4 -13
- package/api/secrets.d.ts +6 -8
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +16 -9
- package/config/CLIConfiguration.js +148 -74
- package/config/configFile.js +8 -17
- package/config/configUtils.d.ts +2 -21
- package/config/configUtils.js +2 -2
- package/config/config_DEPRECATED.d.ts +10 -8
- package/config/config_DEPRECATED.js +62 -32
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +14 -8
- package/config/index.js +108 -59
- package/config/migrate.d.ts +22 -0
- package/config/migrate.js +178 -0
- package/constants/config.d.ts +13 -1
- package/constants/config.js +19 -2
- package/constants/extensions.d.ts +1 -0
- package/constants/extensions.js +2 -1
- package/constants/files.d.ts +2 -2
- package/constants/files.js +3 -3
- package/constants/projects.d.ts +12 -0
- package/constants/projects.js +15 -0
- package/errors/errors_DEPRECATED.d.ts +1 -5
- package/errors/errors_DEPRECATED.js +2 -2
- package/errors/index.d.ts +18 -0
- package/errors/index.js +63 -0
- package/http/addQueryParams.d.ts +2 -0
- package/http/addQueryParams.js +14 -0
- package/http/getAxiosConfig.d.ts +2 -2
- package/http/getAxiosConfig.js +31 -2
- package/http/index.d.ts +10 -10
- package/http/index.js +80 -34
- package/http/unauthed.d.ts +14 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +384 -376
- package/lib/archive.d.ts +3 -6
- package/lib/archive.js +26 -20
- package/lib/cms/functions.d.ts +6 -9
- package/lib/cms/functions.js +24 -19
- package/lib/cms/handleFieldsJS.d.ts +2 -2
- package/lib/cms/handleFieldsJS.js +13 -9
- package/lib/cms/modules.d.ts +5 -13
- package/lib/cms/modules.js +40 -23
- package/lib/cms/processFieldsJs.js +8 -7
- package/lib/cms/templates.d.ts +42 -0
- package/lib/cms/templates.js +48 -5
- package/lib/cms/uploadFolder.d.ts +3 -18
- package/lib/cms/uploadFolder.js +19 -17
- package/lib/cms/validate.js +1 -1
- package/lib/cms/watch.d.ts +2 -15
- package/lib/cms/watch.js +31 -23
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.js +22 -22
- package/lib/fileMapper.d.ts +4 -13
- package/lib/fileMapper.js +47 -50
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +10 -6
- package/lib/github.d.ts +11 -11
- package/lib/github.js +44 -30
- package/lib/gitignore.d.ts +1 -6
- package/lib/gitignore.js +2 -2
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/lib/notify.js +2 -2
- package/lib/oauth.d.ts +1 -1
- package/lib/oauth.js +9 -18
- package/lib/path.d.ts +3 -0
- package/lib/path.js +46 -1
- package/lib/personalAccessKey.d.ts +5 -17
- package/lib/personalAccessKey.js +42 -32
- package/lib/portManager.d.ts +3 -5
- package/lib/portManager.js +18 -6
- package/lib/text.d.ts +1 -1
- package/lib/text.js +3 -0
- package/lib/trackUsage.js +13 -7
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +26 -0
- package/models/HubSpotHttpError.js +208 -0
- package/models/OAuth2Manager.d.ts +2 -27
- package/models/OAuth2Manager.js +14 -29
- package/package.json +38 -35
- package/types/Accounts.d.ts +98 -3
- package/types/Apps.d.ts +77 -0
- package/types/Apps.js +2 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/Build.d.ts +4 -2
- package/types/ComponentStructure.d.ts +30 -10
- package/types/Config.d.ts +21 -2
- package/types/Deploy.d.ts +3 -2
- package/types/DesignManager.d.ts +15 -0
- package/types/DesignManager.js +2 -0
- package/types/DevSecrets.d.ts +5 -0
- package/types/DevSecrets.js +2 -0
- package/types/Error.d.ts +9 -5
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +1 -1
- package/types/Files.d.ts +43 -4
- package/types/FireAlarm.d.ts +9 -0
- package/types/FireAlarm.js +2 -0
- package/types/Functions.d.ts +52 -0
- package/types/Github.d.ts +13 -0
- package/types/Http.d.ts +12 -11
- package/types/Hubdb.d.ts +9 -0
- package/types/MarketplaceValidation.d.ts +7 -3
- package/types/Migration.d.ts +30 -0
- package/types/Migration.js +12 -0
- package/types/Modules.d.ts +11 -0
- package/types/PortManager.d.ts +7 -0
- package/types/Project.d.ts +30 -0
- package/types/Sandbox.d.ts +25 -36
- package/types/Schemas.d.ts +56 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/developerTestAccounts.d.ts +11 -0
- package/utils/PortManagerServer.d.ts +6 -7
- package/utils/PortManagerServer.js +15 -9
- package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
- package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
- package/utils/cms/fieldsJS.d.ts +1 -2
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/errors/apiErrors.d.ts +0 -25
- package/errors/apiErrors.js +0 -186
- package/errors/fileSystemErrors.d.ts +0 -6
- package/errors/fileSystemErrors.js +0 -35
- package/errors/standardErrors.d.ts +0 -21
- package/errors/standardErrors.js +0 -52
- package/lang/lang/en.json +0 -391
- package/lib/developerTestAccounts.d.ts +0 -4
- package/lib/developerTestAccounts.js +0 -35
- package/lib/sandboxes.d.ts +0 -14
- package/lib/sandboxes.js +0 -70
- package/models/HubSpotAuthError.d.ts +0 -12
- package/models/HubSpotAuthError.js +0 -20
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefaultAccount = exports.getAccounts =
|
|
4
|
-
function getAccountIdentifier(account) {
|
|
5
|
-
if (!account) {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
else if (Object.hasOwn(account, 'portalId')) {
|
|
9
|
-
return account.portalId;
|
|
10
|
-
}
|
|
11
|
-
else if (Object.hasOwn(account, 'accountId')) {
|
|
12
|
-
return account.accountId;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.getAccountIdentifier = getAccountIdentifier;
|
|
3
|
+
exports.getDefaultAccount = exports.getAccounts = void 0;
|
|
16
4
|
function getAccounts(config) {
|
|
17
5
|
if (!config) {
|
|
18
6
|
return [];
|
package/utils/cms/fieldsJS.d.ts
CHANGED
package/utils/cms/modules.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.isModuleFolderChild = exports.isModuleFolder = exports.isPathInput = voi
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const path_2 = require("../../lib/path");
|
|
9
9
|
const extensions_1 = require("../../constants/extensions");
|
|
10
|
-
const
|
|
10
|
+
const lang_1 = require("../lang");
|
|
11
11
|
const i18nKey = 'utils.cms.modules';
|
|
12
12
|
const isBool = (x) => !!x === x;
|
|
13
13
|
function isPathInput(pathInput) {
|
|
@@ -19,7 +19,7 @@ exports.isPathInput = isPathInput;
|
|
|
19
19
|
function throwInvalidPathInput(pathInput) {
|
|
20
20
|
if (isPathInput(pathInput))
|
|
21
21
|
return;
|
|
22
|
-
(0,
|
|
22
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.throwInvalidPathInput`));
|
|
23
23
|
}
|
|
24
24
|
function isModuleFolder(pathInput) {
|
|
25
25
|
throwInvalidPathInput(pathInput);
|
package/utils/detectPort.js
CHANGED
|
@@ -30,15 +30,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
30
30
|
exports.detectPort = void 0;
|
|
31
31
|
const net_1 = __importDefault(require("net"));
|
|
32
32
|
const address_1 = require("address");
|
|
33
|
-
const standardErrors_1 = require("../errors/standardErrors");
|
|
34
33
|
const ports_1 = require("../constants/ports");
|
|
34
|
+
const lang_1 = require("./lang");
|
|
35
35
|
const i18nKey = 'utils.detectPort';
|
|
36
36
|
function detectPort(port, exclude = []) {
|
|
37
37
|
if (port && (port < ports_1.MIN_PORT_NUMBER || port > ports_1.MAX_PORT_NUMBER)) {
|
|
38
|
-
(0,
|
|
38
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidPort`, {
|
|
39
39
|
minPort: ports_1.MIN_PORT_NUMBER,
|
|
40
40
|
maxPort: ports_1.MAX_PORT_NUMBER,
|
|
41
|
-
});
|
|
41
|
+
}));
|
|
42
42
|
}
|
|
43
43
|
const portToUse = port || 0;
|
|
44
44
|
const maxPort = Math.min(portToUse + 10, ports_1.MAX_PORT_NUMBER);
|
package/errors/apiErrors.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { AxiosError } from 'axios';
|
|
2
|
-
import { GenericError, AxiosErrorContext, ValidationError } from '../types/Error';
|
|
3
|
-
import { HubSpotAuthError } from '../models/HubSpotAuthError';
|
|
4
|
-
export declare function isSpecifiedError(err: Error | AxiosError, { statusCode, category, subCategory, errorType, code, }: {
|
|
5
|
-
statusCode?: number;
|
|
6
|
-
category?: string;
|
|
7
|
-
subCategory?: string;
|
|
8
|
-
errorType?: string;
|
|
9
|
-
code?: string;
|
|
10
|
-
}): boolean;
|
|
11
|
-
export declare function isMissingScopeError(err: Error | AxiosError): boolean;
|
|
12
|
-
export declare function isGatingError(err: Error | AxiosError): boolean;
|
|
13
|
-
export declare function isTimeoutError(err: Error | AxiosError): boolean;
|
|
14
|
-
export declare function isApiUploadValidationError(err: AxiosError<any>): boolean;
|
|
15
|
-
export declare function isSpecifiedHubSpotAuthError(err: GenericError, { status, category, subCategory }: Partial<HubSpotAuthError>): boolean;
|
|
16
|
-
export declare function parseValidationErrors(responseData?: {
|
|
17
|
-
errors?: Array<ValidationError>;
|
|
18
|
-
message?: string;
|
|
19
|
-
}): Array<string>;
|
|
20
|
-
export declare function getAxiosErrorWithContext(error: AxiosError<any>, context?: AxiosErrorContext): Error;
|
|
21
|
-
/**
|
|
22
|
-
* @throws
|
|
23
|
-
*/
|
|
24
|
-
export declare function throwApiError(error: AxiosError, context?: AxiosErrorContext): never;
|
|
25
|
-
export declare function throwApiUploadError(error: AxiosError, context?: AxiosErrorContext): never;
|
package/errors/apiErrors.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwApiUploadError = exports.throwApiError = exports.getAxiosErrorWithContext = exports.parseValidationErrors = exports.isSpecifiedHubSpotAuthError = exports.isApiUploadValidationError = exports.isTimeoutError = exports.isGatingError = exports.isMissingScopeError = exports.isSpecifiedError = void 0;
|
|
4
|
-
const api_1 = require("../constants/api");
|
|
5
|
-
const lang_1 = require("../utils/lang");
|
|
6
|
-
const standardErrors_1 = require("./standardErrors");
|
|
7
|
-
const i18nKey = 'errors.apiErrors';
|
|
8
|
-
function isSpecifiedError(err, { statusCode, category, subCategory, errorType, code, }) {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
const error = (err && err.cause) || err;
|
|
11
|
-
const statusCodeErr = !statusCode || error.response?.status === statusCode;
|
|
12
|
-
const categoryErr = !category || error.response?.data?.category === category;
|
|
13
|
-
const subCategoryErr = !subCategory || error.response?.data?.subCategory === subCategory;
|
|
14
|
-
const errorTypeErr = !errorType || error.response?.data?.errorType === errorType;
|
|
15
|
-
const codeError = !code || error.code === code;
|
|
16
|
-
return (error.isAxiosError &&
|
|
17
|
-
statusCodeErr &&
|
|
18
|
-
categoryErr &&
|
|
19
|
-
subCategoryErr &&
|
|
20
|
-
errorTypeErr &&
|
|
21
|
-
codeError);
|
|
22
|
-
}
|
|
23
|
-
exports.isSpecifiedError = isSpecifiedError;
|
|
24
|
-
function isMissingScopeError(err) {
|
|
25
|
-
return isSpecifiedError(err, { statusCode: 403, category: 'MISSING_SCOPES' });
|
|
26
|
-
}
|
|
27
|
-
exports.isMissingScopeError = isMissingScopeError;
|
|
28
|
-
function isGatingError(err) {
|
|
29
|
-
return isSpecifiedError(err, { statusCode: 403, category: 'GATED' });
|
|
30
|
-
}
|
|
31
|
-
exports.isGatingError = isGatingError;
|
|
32
|
-
function isTimeoutError(err) {
|
|
33
|
-
return isSpecifiedError(err, { code: 'ETIMEDOUT' });
|
|
34
|
-
}
|
|
35
|
-
exports.isTimeoutError = isTimeoutError;
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
function isApiUploadValidationError(err) {
|
|
38
|
-
return (err.isAxiosError &&
|
|
39
|
-
(err.status === 400 || err.response?.status === 400) &&
|
|
40
|
-
!!err.response &&
|
|
41
|
-
!!(err.response?.data?.message || !!err.response?.data?.errors));
|
|
42
|
-
}
|
|
43
|
-
exports.isApiUploadValidationError = isApiUploadValidationError;
|
|
44
|
-
function isSpecifiedHubSpotAuthError(err, { status, category, subCategory }) {
|
|
45
|
-
const statusCodeErr = !status || err.status === status;
|
|
46
|
-
const categoryErr = !category || err.category === category;
|
|
47
|
-
const subCategoryErr = !subCategory || err.subCategory === subCategory;
|
|
48
|
-
return Boolean(err.name === 'HubSpotAuthError' &&
|
|
49
|
-
statusCodeErr &&
|
|
50
|
-
categoryErr &&
|
|
51
|
-
subCategoryErr);
|
|
52
|
-
}
|
|
53
|
-
exports.isSpecifiedHubSpotAuthError = isSpecifiedHubSpotAuthError;
|
|
54
|
-
function parseValidationErrors(responseData = { errors: [], message: '' }) {
|
|
55
|
-
const errorMessages = [];
|
|
56
|
-
const { errors, message } = responseData;
|
|
57
|
-
if (message) {
|
|
58
|
-
errorMessages.push(message);
|
|
59
|
-
}
|
|
60
|
-
if (errors) {
|
|
61
|
-
const specificErrors = errors.map(error => {
|
|
62
|
-
let errorMessage = error.message;
|
|
63
|
-
if (error.errorTokens && error.errorTokens.line) {
|
|
64
|
-
errorMessage = `line ${error.errorTokens.line}: ${errorMessage}`;
|
|
65
|
-
}
|
|
66
|
-
return errorMessage;
|
|
67
|
-
});
|
|
68
|
-
errorMessages.push(...specificErrors);
|
|
69
|
-
}
|
|
70
|
-
return errorMessages;
|
|
71
|
-
}
|
|
72
|
-
exports.parseValidationErrors = parseValidationErrors;
|
|
73
|
-
/**
|
|
74
|
-
* @throws
|
|
75
|
-
*/
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
-
function throwValidationError(error) {
|
|
78
|
-
const validationErrorMessages = parseValidationErrors(error?.response?.data);
|
|
79
|
-
if (validationErrorMessages.length) {
|
|
80
|
-
return new Error(validationErrorMessages.join(' '), { cause: error });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function getAxiosErrorWithContext(
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
-
error, context = {}) {
|
|
86
|
-
const { status } = error;
|
|
87
|
-
const method = error.config?.method;
|
|
88
|
-
const { projectName } = context;
|
|
89
|
-
let messageDetail;
|
|
90
|
-
if (context.accountId) {
|
|
91
|
-
const action = (method && api_1.HTTP_METHOD_VERBS[method]) || api_1.HTTP_METHOD_VERBS.get;
|
|
92
|
-
const preposition = (method && api_1.HTTP_METHOD_PREPOSITIONS[method]) ||
|
|
93
|
-
api_1.HTTP_METHOD_PREPOSITIONS.get;
|
|
94
|
-
const requestName = context.request
|
|
95
|
-
? `${action} ${preposition} '${context.request}'`
|
|
96
|
-
: action;
|
|
97
|
-
messageDetail = (0, lang_1.i18n)(`${i18nKey}.messageDetail`, {
|
|
98
|
-
accountId: context.accountId,
|
|
99
|
-
requestName,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
messageDetail = (0, lang_1.i18n)(`${i18nKey}.genericMessageDetail`);
|
|
104
|
-
}
|
|
105
|
-
const errorMessage = [];
|
|
106
|
-
if ((method === 'put' || method === 'post') && context.payload) {
|
|
107
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.unableToUpload`, { payload: context.payload }));
|
|
108
|
-
}
|
|
109
|
-
const isProjectMissingScopeError = isMissingScopeError(error) && projectName;
|
|
110
|
-
const isProjectGatingError = isGatingError(error) && projectName;
|
|
111
|
-
switch (status) {
|
|
112
|
-
case 400:
|
|
113
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400`, { messageDetail }));
|
|
114
|
-
break;
|
|
115
|
-
case 401:
|
|
116
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.401`, { messageDetail }));
|
|
117
|
-
break;
|
|
118
|
-
case 403:
|
|
119
|
-
if (isProjectMissingScopeError) {
|
|
120
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.403ProjectMissingScope`, {
|
|
121
|
-
accountId: context.accountId || '',
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
124
|
-
else if (isProjectGatingError) {
|
|
125
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.403ProjectGating`, {
|
|
126
|
-
accountId: context.accountId || '',
|
|
127
|
-
}));
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.403`, { messageDetail }));
|
|
131
|
-
}
|
|
132
|
-
break;
|
|
133
|
-
case 404:
|
|
134
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.404`, { messageDetail }));
|
|
135
|
-
break;
|
|
136
|
-
case 429:
|
|
137
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.429`, { messageDetail }));
|
|
138
|
-
break;
|
|
139
|
-
case 503:
|
|
140
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.503`, { messageDetail }));
|
|
141
|
-
break;
|
|
142
|
-
default:
|
|
143
|
-
if (status && status >= 500 && status < 600) {
|
|
144
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.500Generic`, { messageDetail }));
|
|
145
|
-
}
|
|
146
|
-
else if (status && status >= 400 && status < 500) {
|
|
147
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400Generic`, { messageDetail }));
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.generic`, { messageDetail }));
|
|
151
|
-
}
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
if (error?.response?.data) {
|
|
155
|
-
const { message, errors } = error.response.data;
|
|
156
|
-
if (message && !isProjectMissingScopeError && !isProjectGatingError) {
|
|
157
|
-
errorMessage.push(message);
|
|
158
|
-
}
|
|
159
|
-
if (errors) {
|
|
160
|
-
errors.forEach((err) => {
|
|
161
|
-
if (err.message) {
|
|
162
|
-
errorMessage.push('\n- ' + err.message);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return new Error(errorMessage.join(' '), { cause: error });
|
|
168
|
-
}
|
|
169
|
-
exports.getAxiosErrorWithContext = getAxiosErrorWithContext;
|
|
170
|
-
/**
|
|
171
|
-
* @throws
|
|
172
|
-
*/
|
|
173
|
-
function throwApiError(error, context = {}) {
|
|
174
|
-
if (error.isAxiosError) {
|
|
175
|
-
throw getAxiosErrorWithContext(error, context);
|
|
176
|
-
}
|
|
177
|
-
(0, standardErrors_1.throwError)(error);
|
|
178
|
-
}
|
|
179
|
-
exports.throwApiError = throwApiError;
|
|
180
|
-
function throwApiUploadError(error, context = {}) {
|
|
181
|
-
if (isApiUploadValidationError(error)) {
|
|
182
|
-
throwValidationError(error);
|
|
183
|
-
}
|
|
184
|
-
throwApiError(error, context);
|
|
185
|
-
}
|
|
186
|
-
exports.throwApiUploadError = throwApiUploadError;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { BaseError, FileSystemErrorContext } from '../types/Error';
|
|
2
|
-
export declare function getFileSystemError(error: BaseError, context: FileSystemErrorContext): Error;
|
|
3
|
-
/**
|
|
4
|
-
* @throws
|
|
5
|
-
*/
|
|
6
|
-
export declare function throwFileSystemError(error: BaseError, context: FileSystemErrorContext): void;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwFileSystemError = exports.getFileSystemError = void 0;
|
|
4
|
-
const lang_1 = require("../utils/lang");
|
|
5
|
-
const standardErrors_1 = require("./standardErrors");
|
|
6
|
-
const i18nKey = 'errors.fileSystemErrors';
|
|
7
|
-
function getFileSystemError(error, context) {
|
|
8
|
-
let fileAction = '';
|
|
9
|
-
if (context.read) {
|
|
10
|
-
fileAction = (0, lang_1.i18n)(`${i18nKey}.readAction`);
|
|
11
|
-
}
|
|
12
|
-
else if (context.write) {
|
|
13
|
-
fileAction = (0, lang_1.i18n)(`${i18nKey}.writeAction`);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
fileAction = (0, lang_1.i18n)(`${i18nKey}.otherAction`);
|
|
17
|
-
}
|
|
18
|
-
const filepath = context.filepath
|
|
19
|
-
? `"${context.filepath}"`
|
|
20
|
-
: (0, lang_1.i18n)(`${i18nKey}.unknownFilepath`);
|
|
21
|
-
const message = [(0, lang_1.i18n)(`${i18nKey}.baseMessage`, { fileAction, filepath })];
|
|
22
|
-
// Many `fs` errors will be `SystemError`s
|
|
23
|
-
if ((0, standardErrors_1.isSystemError)(error)) {
|
|
24
|
-
message.push((0, lang_1.i18n)(`${i18nKey}.baseMessage`, { errorMessage: error.message }));
|
|
25
|
-
}
|
|
26
|
-
return new Error(message.join(' '), { cause: error });
|
|
27
|
-
}
|
|
28
|
-
exports.getFileSystemError = getFileSystemError;
|
|
29
|
-
/**
|
|
30
|
-
* @throws
|
|
31
|
-
*/
|
|
32
|
-
function throwFileSystemError(error, context) {
|
|
33
|
-
throw getFileSystemError(error, context);
|
|
34
|
-
}
|
|
35
|
-
exports.throwFileSystemError = throwFileSystemError;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BaseError } from '../types/Error';
|
|
2
|
-
import { LangKey } from '../types/Lang';
|
|
3
|
-
import { AxiosError } from 'axios';
|
|
4
|
-
export declare function isSystemError(err: BaseError): boolean;
|
|
5
|
-
export declare function isFatalError(err: BaseError): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* @throws
|
|
8
|
-
*/
|
|
9
|
-
export declare function throwErrorWithMessage(identifier: LangKey, interpolation?: {
|
|
10
|
-
[key: string]: string | number;
|
|
11
|
-
}, cause?: BaseError | AxiosError): never;
|
|
12
|
-
/**
|
|
13
|
-
* @throws
|
|
14
|
-
*/
|
|
15
|
-
export declare function throwAuthErrorWithMessage(identifier: LangKey, interpolation?: {
|
|
16
|
-
[key: string]: string | number;
|
|
17
|
-
}, cause?: AxiosError): never;
|
|
18
|
-
/**
|
|
19
|
-
* @throws
|
|
20
|
-
*/
|
|
21
|
-
export declare function throwError(error: BaseError): never;
|
package/errors/standardErrors.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwError = exports.throwAuthErrorWithMessage = exports.throwErrorWithMessage = exports.isFatalError = exports.isSystemError = void 0;
|
|
4
|
-
const HubSpotAuthError_1 = require("../models/HubSpotAuthError");
|
|
5
|
-
const lang_1 = require("../utils/lang");
|
|
6
|
-
function isSystemError(err) {
|
|
7
|
-
return err.errno != null && err.code != null && err.syscall != null;
|
|
8
|
-
}
|
|
9
|
-
exports.isSystemError = isSystemError;
|
|
10
|
-
function isFatalError(err) {
|
|
11
|
-
return err instanceof HubSpotAuthError_1.HubSpotAuthError;
|
|
12
|
-
}
|
|
13
|
-
exports.isFatalError = isFatalError;
|
|
14
|
-
function genericThrowErrorWithMessage(ErrorType, identifier, interpolation, cause) {
|
|
15
|
-
const message = (0, lang_1.i18n)(identifier, interpolation);
|
|
16
|
-
if (cause) {
|
|
17
|
-
throw new ErrorType(message, { cause });
|
|
18
|
-
}
|
|
19
|
-
throw new ErrorType(message);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @throws
|
|
23
|
-
*/
|
|
24
|
-
function throwErrorWithMessage(identifier, interpolation, cause) {
|
|
25
|
-
genericThrowErrorWithMessage(Error, identifier, interpolation, cause);
|
|
26
|
-
}
|
|
27
|
-
exports.throwErrorWithMessage = throwErrorWithMessage;
|
|
28
|
-
/**
|
|
29
|
-
* @throws
|
|
30
|
-
*/
|
|
31
|
-
function throwAuthErrorWithMessage(identifier, interpolation, cause) {
|
|
32
|
-
genericThrowErrorWithMessage(
|
|
33
|
-
// @ts-expect-error HubSpotAuthError is not callable
|
|
34
|
-
HubSpotAuthError_1.HubSpotAuthError, identifier, interpolation, cause);
|
|
35
|
-
}
|
|
36
|
-
exports.throwAuthErrorWithMessage = throwAuthErrorWithMessage;
|
|
37
|
-
/**
|
|
38
|
-
* @throws
|
|
39
|
-
*/
|
|
40
|
-
function throwError(error) {
|
|
41
|
-
// Error or Error subclass
|
|
42
|
-
const message = error.name && error.name !== 'Error'
|
|
43
|
-
? [(0, lang_1.i18n)('errors.generic', { name: error.name })]
|
|
44
|
-
: [];
|
|
45
|
-
[error.message, error.reason].forEach(msg => {
|
|
46
|
-
if (msg) {
|
|
47
|
-
message.push(msg);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
throw new Error(message.join(' '), { cause: error });
|
|
51
|
-
}
|
|
52
|
-
exports.throwError = throwError;
|