@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.
- package/api/appsDev.d.ts +6 -5
- package/api/appsDev.js +6 -10
- package/api/customObjects.d.ts +7 -6
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +3 -2
- package/api/designManager.js +5 -8
- package/api/developerTestAccounts.d.ts +5 -4
- package/api/developerTestAccounts.js +9 -10
- package/api/fileManager.d.ts +5 -4
- package/api/fileManager.js +9 -9
- package/api/fileMapper.d.ts +8 -8
- package/api/fileMapper.js +16 -16
- package/api/fileTransport.d.ts +4 -3
- package/api/fileTransport.js +5 -5
- package/api/functions.d.ts +6 -5
- package/api/functions.js +11 -14
- package/api/github.d.ts +6 -6
- package/api/github.js +5 -5
- package/api/hubdb.d.ts +9 -8
- package/api/hubdb.js +17 -20
- package/api/lighthouseScore.d.ts +4 -3
- package/api/lighthouseScore.js +7 -10
- package/api/localDevAuth.d.ts +5 -4
- package/api/localDevAuth.js +8 -9
- package/api/marketplaceValidation.d.ts +4 -3
- package/api/marketplaceValidation.js +4 -7
- package/api/projects.d.ts +31 -30
- package/api/projects.js +52 -52
- package/api/sandboxHubs.d.ts +5 -4
- package/api/sandboxHubs.js +9 -10
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +5 -14
- package/api/secrets.d.ts +5 -4
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +3 -3
- package/config/CLIConfiguration.js +22 -20
- package/config/configFile.js +7 -14
- package/config/config_DEPRECATED.js +5 -2
- package/config/index.js +45 -48
- 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 +10 -2
- package/http/index.d.ts +9 -14
- package/http/index.js +28 -53
- package/http/unauthed.d.ts +15 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +1 -2
- package/lang/lang/en.json +1 -2
- package/lib/archive.js +11 -10
- package/lib/cms/functions.js +18 -17
- package/lib/cms/handleFieldsJS.js +8 -7
- package/lib/cms/modules.js +4 -5
- package/lib/cms/processFieldsJs.js +8 -7
- package/lib/cms/templates.js +2 -3
- package/lib/cms/uploadFolder.js +16 -14
- package/lib/cms/validate.js +1 -1
- package/lib/cms/watch.js +16 -9
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.js +22 -21
- package/lib/fileMapper.js +24 -31
- package/lib/fs.js +2 -2
- package/lib/github.js +21 -21
- 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 +8 -17
- package/lib/personalAccessKey.js +16 -21
- package/lib/portManager.js +2 -2
- package/lib/trackUsage.js +3 -3
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +24 -0
- package/models/HubSpotHttpError.js +197 -0
- package/models/OAuth2Manager.d.ts +1 -2
- package/models/OAuth2Manager.js +13 -28
- package/package.json +2 -1
- package/types/Error.d.ts +7 -5
- package/types/Files.d.ts +4 -4
- package/types/Http.d.ts +6 -10
- package/types/Sandbox.d.ts +0 -5
- package/utils/PortManagerServer.d.ts +3 -3
- package/utils/PortManagerServer.js +9 -9
- 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 -176
- package/errors/fileSystemErrors.d.ts +0 -6
- package/errors/fileSystemErrors.js +0 -35
- package/errors/standardErrors.d.ts +0 -20
- package/errors/standardErrors.js +0 -62
- 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
package/errors/index.js
ADDED
|
@@ -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,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;
|
package/http/getAxiosConfig.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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:
|
|
9
|
+
export declare function getAxiosConfig(options: HttpOptions): AxiosRequestConfig;
|
package/http/getAxiosConfig.js
CHANGED
|
@@ -41,14 +41,22 @@ const DEFAULT_TRANSITIONAL = {
|
|
|
41
41
|
};
|
|
42
42
|
function getAxiosConfig(options) {
|
|
43
43
|
const { env, localHostOverride, headers, ...rest } = options;
|
|
44
|
-
const
|
|
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
|
|
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 {
|
|
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):
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
declare function
|
|
8
|
-
declare function
|
|
9
|
-
declare
|
|
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) =>
|
|
15
|
+
getOctetStream: (accountId: number, options: HttpOptions, destPath: string) => AxiosPromise<any>;
|
|
21
16
|
};
|
|
22
|
-
export
|
|
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,
|
|
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,
|
|
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
|
|
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
|
|
94
|
-
const
|
|
95
|
-
|
|
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
|
|
102
|
-
const
|
|
103
|
-
|
|
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
|
|
110
|
-
const
|
|
111
|
-
|
|
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
|
|
118
|
-
const
|
|
119
|
-
|
|
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
|
|
126
|
-
const
|
|
127
|
-
|
|
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
|
-
|
|
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 {};
|
package/http/unauthed.js
ADDED
|
@@ -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
package/lang/lang/en.json
CHANGED
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
|
-
|
|
33
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
35
34
|
filepath: tmpZipPath || result.tmpDir,
|
|
36
|
-
|
|
35
|
+
operation: 'write',
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
else {
|
|
40
|
-
(0,
|
|
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,
|
|
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
|
-
|
|
86
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
85
87
|
filepath: dest,
|
|
86
|
-
|
|
88
|
+
operation: 'write',
|
|
87
89
|
});
|
|
88
90
|
}
|
|
89
|
-
return false;
|
|
90
91
|
}
|
|
91
92
|
async function cleanupTempDir(tmpDir) {
|
|
92
93
|
if (!tmpDir)
|
package/lib/cms/functions.js
CHANGED
|
@@ -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
|
-
|
|
50
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
52
51
|
filepath: configFilePath,
|
|
53
|
-
|
|
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
|
-
|
|
63
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
65
64
|
filepath: configFilePath,
|
|
66
|
-
|
|
65
|
+
operation: 'read',
|
|
67
66
|
});
|
|
68
67
|
}
|
|
69
68
|
if (!isObjectOrFunction(config)) {
|
|
70
|
-
(0,
|
|
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,
|
|
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
|
-
|
|
96
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
96
97
|
filepath: configFilePath,
|
|
97
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
164
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
164
165
|
filepath: configFilePath,
|
|
165
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
144
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.cleanupTmpDirSync.errors.deleteFailed`), { cause: err });
|
|
144
145
|
}
|
|
145
146
|
});
|
|
146
147
|
}
|
package/lib/cms/modules.js
CHANGED
|
@@ -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,
|
|
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,
|
|
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`, {
|