@hubspot/local-dev-lib 4.0.4 → 5.0.0-beta.1
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 +2 -2
- package/api/appsDev.js +13 -22
- package/api/crm.d.ts +2 -2
- package/api/crm.js +9 -16
- package/api/customObjects.d.ts +2 -2
- package/api/customObjects.js +13 -22
- package/api/designManager.d.ts +2 -2
- package/api/designManager.js +5 -10
- package/api/devSecrets.d.ts +2 -2
- package/api/devSecrets.js +9 -16
- package/api/developerTestAccounts.d.ts +2 -4
- package/api/developerTestAccounts.js +23 -52
- package/api/fileManager.d.ts +2 -2
- package/api/fileManager.js +14 -24
- package/api/fileMapper.d.ts +2 -3
- package/api/fileMapper.js +34 -49
- package/api/fileTransport.d.ts +1 -1
- package/api/fileTransport.js +12 -21
- package/api/fireAlarm.d.ts +2 -3
- package/api/fireAlarm.js +5 -9
- package/api/functions.d.ts +2 -2
- package/api/functions.js +11 -19
- package/api/github.d.ts +2 -4
- package/api/github.js +16 -27
- package/api/hubdb.d.ts +2 -2
- package/api/hubdb.js +19 -31
- package/api/lighthouseScore.d.ts +2 -2
- package/api/lighthouseScore.js +7 -13
- package/api/localDevAuth.d.ts +3 -6
- package/api/localDevAuth.js +10 -37
- package/api/marketplaceValidation.d.ts +2 -2
- package/api/marketplaceValidation.js +7 -13
- package/api/projects.d.ts +6 -8
- package/api/projects.js +65 -100
- package/api/sandboxHubs.d.ts +2 -5
- package/api/sandboxHubs.js +15 -42
- package/api/sandboxSync.d.ts +2 -2
- package/api/sandboxSync.js +7 -12
- package/api/secrets.d.ts +2 -2
- package/api/secrets.js +9 -16
- package/api/validateHubl.d.ts +2 -2
- package/api/validateHubl.js +3 -7
- package/config/defaultAccountOverride.d.ts +2 -1
- package/config/defaultAccountOverride.js +16 -26
- package/config/index.d.ts +4 -4
- package/config/index.js +141 -177
- package/config/migrate.d.ts +2 -2
- package/config/migrate.js +26 -37
- package/config/state.d.ts +1 -1
- package/config/state.js +17 -45
- package/config/utils.d.ts +4 -4
- package/config/utils.js +85 -108
- package/constants/api.js +3 -6
- package/constants/auth.js +9 -12
- package/constants/config.js +37 -43
- package/constants/endpoints.d.ts +6 -0
- package/constants/endpoints.js +6 -0
- package/constants/environments.js +1 -4
- package/constants/extensions.js +6 -9
- package/constants/files.js +5 -8
- package/constants/ports.js +3 -6
- package/constants/projects.js +2 -5
- package/enums/build.d.ts +1 -0
- package/enums/build.js +6 -8
- package/enums/deploy.js +2 -5
- package/enums/project.js +1 -4
- package/errors/index.d.ts +4 -5
- package/errors/index.js +17 -39
- package/errors/isSystemError.d.ts +2 -0
- package/errors/isSystemError.js +9 -0
- package/http/addQueryParams.d.ts +1 -1
- package/http/addQueryParams.js +1 -5
- package/http/client.js +14 -42
- package/http/getAxiosConfig.d.ts +1 -1
- package/http/getAxiosConfig.js +21 -31
- package/http/index.d.ts +2 -2
- package/http/index.js +39 -46
- package/http/unauthed.d.ts +1 -1
- package/http/unauthed.js +15 -18
- package/lang/en.json +1 -1
- package/lib/archive.d.ts +1 -3
- package/lib/archive.js +37 -67
- package/lib/cms/functions.d.ts +1 -1
- package/lib/cms/functions.js +45 -55
- package/lib/cms/handleFieldsJS.js +36 -44
- package/lib/cms/modules.d.ts +2 -2
- package/lib/cms/modules.js +49 -59
- package/lib/cms/processFieldsJs.js +17 -32
- package/lib/cms/templates.js +17 -26
- package/lib/cms/themes.js +10 -18
- package/lib/cms/uploadFolder.d.ts +4 -4
- package/lib/cms/uploadFolder.js +55 -64
- package/lib/cms/validate.d.ts +1 -1
- package/lib/cms/validate.js +11 -18
- package/lib/cms/watch.d.ts +2 -2
- package/lib/cms/watch.js +66 -73
- package/lib/crm.d.ts +1 -1
- package/lib/crm.js +15 -23
- package/lib/customObjects.d.ts +1 -1
- package/lib/customObjects.js +15 -25
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +5 -11
- package/lib/escapeRegExp.js +1 -5
- package/lib/fileManager.js +43 -51
- package/lib/fileMapper.d.ts +1 -1
- package/lib/fileMapper.js +68 -84
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +18 -27
- package/lib/github.d.ts +1 -3
- package/lib/github.js +39 -51
- package/lib/gitignore.d.ts +1 -1
- package/lib/gitignore.js +16 -24
- package/lib/hubdb.d.ts +1 -1
- package/lib/hubdb.js +29 -40
- package/lib/ignoreRules.js +25 -34
- package/lib/isDeepEqual.js +1 -5
- package/lib/logger.d.ts +8 -20
- package/lib/logger.js +47 -59
- package/lib/notify.js +9 -16
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +12 -17
- package/lib/path.d.ts +0 -1
- package/lib/path.js +30 -48
- package/lib/personalAccessKey.d.ts +2 -4
- package/lib/personalAccessKey.js +43 -60
- package/lib/portManager.d.ts +2 -2
- package/lib/portManager.js +26 -41
- package/lib/text.js +2 -7
- package/lib/trackUsage.d.ts +0 -2
- package/lib/trackUsage.js +23 -29
- package/lib/urls.js +4 -9
- package/models/FileSystemError.d.ts +1 -1
- package/models/FileSystemError.js +12 -16
- package/models/HubSpotConfigError.d.ts +1 -1
- package/models/HubSpotConfigError.js +8 -12
- package/models/HubSpotHttpError.d.ts +1 -1
- package/models/HubSpotHttpError.js +22 -26
- package/models/OAuth2Manager.d.ts +1 -1
- package/models/OAuth2Manager.js +17 -24
- package/package.json +20 -16
- package/types/Accounts.d.ts +6 -5
- package/types/Accounts.js +1 -2
- package/types/Activity.d.ts +3 -3
- package/types/Activity.js +1 -2
- package/types/Api.d.ts +1 -1
- package/types/Api.js +1 -2
- package/types/Apps.js +1 -2
- package/types/Archive.js +1 -2
- package/types/Build.d.ts +4 -5
- package/types/Build.js +1 -2
- package/types/CLIOptions.js +1 -2
- package/types/ComponentStructure.d.ts +2 -2
- package/types/ComponentStructure.js +1 -2
- package/types/Config.d.ts +4 -6
- package/types/Config.js +1 -2
- package/types/Crm.js +1 -2
- package/types/Deploy.d.ts +5 -11
- package/types/Deploy.js +1 -2
- package/types/DesignManager.js +1 -2
- package/types/DevSecrets.js +1 -2
- package/types/Error.js +1 -2
- package/types/FieldsJS.js +1 -2
- package/types/FileManager.js +1 -2
- package/types/Files.d.ts +4 -4
- package/types/Files.js +1 -2
- package/types/FireAlarm.js +1 -2
- package/types/Functions.js +1 -2
- package/types/Github.d.ts +1 -1
- package/types/Github.js +1 -2
- package/types/Http.d.ts +0 -4
- package/types/Http.js +1 -2
- package/types/Hubdb.js +1 -2
- package/types/HublValidation.js +1 -2
- package/types/Lang.d.ts +1 -1
- package/types/Lang.js +1 -2
- package/types/Lighthouse.js +1 -2
- package/types/MarketplaceValidation.js +1 -2
- package/types/Migration.d.ts +2 -2
- package/types/Migration.js +1 -4
- package/types/Modules.js +1 -2
- package/types/PortManager.js +1 -2
- package/types/Project.d.ts +3 -21
- package/types/Project.js +1 -2
- package/types/ProjectComponents.d.ts +24 -0
- package/types/ProjectComponents.js +1 -0
- package/types/ProjectLog.js +1 -2
- package/types/Sandbox.js +2 -5
- package/types/Schemas.js +1 -2
- package/types/Secrets.js +1 -2
- package/types/Utils.js +1 -2
- package/types/developerTestAccounts.js +1 -2
- package/utils/PortManagerServer.d.ts +1 -2
- package/utils/PortManagerServer.js +32 -38
- package/utils/cms/fieldsJS.d.ts +1 -1
- package/utils/cms/fieldsJS.js +1 -5
- package/utils/cms/modules.d.ts +1 -1
- package/utils/cms/modules.js +13 -22
- package/utils/detectPort.js +12 -19
- package/utils/git.js +17 -26
- package/utils/lang.d.ts +1 -1
- package/utils/lang.js +5 -14
- package/utils/personalAccessKey.d.ts +8 -0
- package/utils/personalAccessKey.js +51 -0
- package/errors/errors_DEPRECATED.d.ts +0 -3
- package/errors/errors_DEPRECATED.js +0 -60
package/http/getAxiosConfig.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const config_1 = require("../config");
|
|
9
|
-
const urls_1 = require("../lib/urls");
|
|
10
|
-
const http_1 = __importDefault(require("http"));
|
|
11
|
-
const https_1 = __importDefault(require("https"));
|
|
12
|
-
const http_proxy_agent_1 = require("http-proxy-agent");
|
|
13
|
-
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
1
|
+
import pkg from '../package.json' with { type: 'json' };
|
|
2
|
+
import { getConfig } from '../config/index.js';
|
|
3
|
+
import { getHubSpotApiOrigin } from '../lib/urls.js';
|
|
4
|
+
import http from 'http';
|
|
5
|
+
import https from 'https';
|
|
6
|
+
import { HttpProxyAgent } from 'http-proxy-agent';
|
|
7
|
+
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
14
8
|
// Total number of sockets across all hosts
|
|
15
9
|
const MAX_TOTAL_SOCKETS = 25;
|
|
16
10
|
// Total number of sockets per each host
|
|
17
11
|
const MAX_SOCKETS_PER_HOST = 5;
|
|
18
|
-
const httpAgent = new
|
|
12
|
+
const httpAgent = new http.Agent({
|
|
19
13
|
keepAlive: true,
|
|
20
14
|
maxTotalSockets: MAX_TOTAL_SOCKETS,
|
|
21
15
|
maxSockets: MAX_SOCKETS_PER_HOST,
|
|
22
16
|
});
|
|
23
|
-
const httpsAgent = new
|
|
17
|
+
const httpsAgent = new https.Agent({
|
|
24
18
|
keepAlive: true,
|
|
25
19
|
maxTotalSockets: MAX_TOTAL_SOCKETS,
|
|
26
20
|
maxSockets: MAX_SOCKETS_PER_HOST,
|
|
@@ -39,7 +33,7 @@ function getHttpProxyAgent() {
|
|
|
39
33
|
if (!proxyUrl) {
|
|
40
34
|
return httpAgent;
|
|
41
35
|
}
|
|
42
|
-
return new
|
|
36
|
+
return new HttpProxyAgent(proxyUrl, {
|
|
43
37
|
keepAlive: true,
|
|
44
38
|
maxTotalSockets: MAX_TOTAL_SOCKETS,
|
|
45
39
|
maxSockets: MAX_SOCKETS_PER_HOST,
|
|
@@ -52,29 +46,28 @@ function getHttpsProxyAgent() {
|
|
|
52
46
|
if (!proxyUrl) {
|
|
53
47
|
return httpsAgent;
|
|
54
48
|
}
|
|
55
|
-
return new
|
|
49
|
+
return new HttpsProxyAgent(proxyUrl, {
|
|
56
50
|
keepAlive: true,
|
|
57
51
|
maxTotalSockets: MAX_TOTAL_SOCKETS,
|
|
58
52
|
maxSockets: MAX_SOCKETS_PER_HOST,
|
|
59
53
|
});
|
|
60
54
|
}
|
|
61
|
-
|
|
62
|
-
'HubSpot Local Dev Lib':
|
|
55
|
+
export const USER_AGENTS = {
|
|
56
|
+
'HubSpot Local Dev Lib': pkg.version,
|
|
63
57
|
};
|
|
64
|
-
function getDefaultUserAgentHeader() {
|
|
58
|
+
export function getDefaultUserAgentHeader() {
|
|
65
59
|
let userAgentString = '';
|
|
66
|
-
Object.keys(
|
|
67
|
-
userAgentString += `${i > 0 ? ', ' : ''}${userAgentKey}/${
|
|
60
|
+
Object.keys(USER_AGENTS).forEach((userAgentKey, i) => {
|
|
61
|
+
userAgentString += `${i > 0 ? ', ' : ''}${userAgentKey}/${USER_AGENTS[userAgentKey]}`;
|
|
68
62
|
});
|
|
69
63
|
return {
|
|
70
64
|
'User-Agent': userAgentString,
|
|
71
65
|
};
|
|
72
66
|
}
|
|
73
|
-
exports.getDefaultUserAgentHeader = getDefaultUserAgentHeader;
|
|
74
67
|
const DEFAULT_TRANSITIONAL = {
|
|
75
68
|
clarifyTimeoutError: true,
|
|
76
69
|
};
|
|
77
|
-
function hostnameMatchesNoProxyPattern(hostname, pattern) {
|
|
70
|
+
export function hostnameMatchesNoProxyPattern(hostname, pattern) {
|
|
78
71
|
const hostnameNormalized = hostname.toLowerCase();
|
|
79
72
|
const patternNormalized = pattern.trim().toLowerCase();
|
|
80
73
|
if (patternNormalized === '*') {
|
|
@@ -87,8 +80,7 @@ function hostnameMatchesNoProxyPattern(hostname, pattern) {
|
|
|
87
80
|
hostnameNormalized.endsWith(`.${patternNormalized}`) // domain suffix match (e.g. "api.hubapi.com" matches ".hubapi.com")
|
|
88
81
|
);
|
|
89
82
|
}
|
|
90
|
-
|
|
91
|
-
function shouldUseProxy(baseURL) {
|
|
83
|
+
export function shouldUseProxy(baseURL) {
|
|
92
84
|
if (!getHttpProxyEnvVariable() &&
|
|
93
85
|
!getHttpsProxyEnvVariable() &&
|
|
94
86
|
!getAllProxyEnvVariable()) {
|
|
@@ -104,12 +96,11 @@ function shouldUseProxy(baseURL) {
|
|
|
104
96
|
}
|
|
105
97
|
return true;
|
|
106
98
|
}
|
|
107
|
-
|
|
108
|
-
function getAxiosConfig(options) {
|
|
99
|
+
export function getAxiosConfig(options) {
|
|
109
100
|
const { env, localHostOverride, headers, ...rest } = options;
|
|
110
101
|
let config;
|
|
111
102
|
try {
|
|
112
|
-
config =
|
|
103
|
+
config = getConfig();
|
|
113
104
|
}
|
|
114
105
|
catch (e) {
|
|
115
106
|
config = null;
|
|
@@ -122,7 +113,7 @@ function getAxiosConfig(options) {
|
|
|
122
113
|
if (config && config.httpUseLocalhost) {
|
|
123
114
|
httpUseLocalhost = config.httpUseLocalhost;
|
|
124
115
|
}
|
|
125
|
-
const baseURL =
|
|
116
|
+
const baseURL = getHubSpotApiOrigin(env, localHostOverride ? false : httpUseLocalhost);
|
|
126
117
|
return {
|
|
127
118
|
baseURL,
|
|
128
119
|
headers: {
|
|
@@ -138,4 +129,3 @@ function getAxiosConfig(options) {
|
|
|
138
129
|
...rest,
|
|
139
130
|
};
|
|
140
131
|
}
|
|
141
|
-
exports.getAxiosConfig = getAxiosConfig;
|
package/http/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosPromise } from 'axios';
|
|
2
|
-
import { HttpOptions, HubSpotPromise } from '../types/Http';
|
|
2
|
+
import { HttpOptions, HubSpotPromise } from '../types/Http.js';
|
|
3
3
|
export declare function addUserAgentHeader(key: string, value: string): void;
|
|
4
4
|
declare function getRequest<T>(accountId: number, options: HttpOptions): HubSpotPromise<T>;
|
|
5
5
|
declare function postRequest<T>(accountId: number, options: HttpOptions): HubSpotPromise<T>;
|
|
@@ -12,6 +12,6 @@ export declare const http: {
|
|
|
12
12
|
put: typeof putRequest;
|
|
13
13
|
patch: typeof patchRequest;
|
|
14
14
|
delete: typeof deleteRequest;
|
|
15
|
-
getOctetStream: (accountId: number, options: HttpOptions, destPath: string) => AxiosPromise
|
|
15
|
+
getOctetStream: (accountId: number, options: HttpOptions, destPath: string) => AxiosPromise;
|
|
16
16
|
};
|
|
17
17
|
export {};
|
package/http/index.js
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const personalAccessKey_1 = require("../lib/personalAccessKey");
|
|
14
|
-
const oauth_1 = require("../lib/oauth");
|
|
15
|
-
const logger_1 = require("../lib/logger");
|
|
16
|
-
const lang_1 = require("../utils/lang");
|
|
17
|
-
const auth_1 = require("../constants/auth");
|
|
18
|
-
const client_1 = require("./client");
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import contentDisposition from 'content-disposition';
|
|
4
|
+
import { getConfigAccountById } from '../config/index.js';
|
|
5
|
+
import { USER_AGENTS, getAxiosConfig } from './getAxiosConfig.js';
|
|
6
|
+
import { addQueryParams } from './addQueryParams.js';
|
|
7
|
+
import { accessTokenForPersonalAccessKey } from '../lib/personalAccessKey.js';
|
|
8
|
+
import { getOauthManager } from '../lib/oauth.js';
|
|
9
|
+
import { logger } from '../lib/logger.js';
|
|
10
|
+
import { i18n } from '../utils/lang.js';
|
|
11
|
+
import { PERSONAL_ACCESS_KEY_AUTH_METHOD, OAUTH_AUTH_METHOD, API_KEY_AUTH_METHOD, } from '../constants/auth.js';
|
|
12
|
+
import { httpClient } from './client.js';
|
|
19
13
|
const i18nKey = 'http.index';
|
|
20
|
-
function addUserAgentHeader(key, value) {
|
|
21
|
-
|
|
14
|
+
export function addUserAgentHeader(key, value) {
|
|
15
|
+
USER_AGENTS[key] = value;
|
|
22
16
|
}
|
|
23
|
-
exports.addUserAgentHeader = addUserAgentHeader;
|
|
24
17
|
async function withOauth(account, axiosConfig) {
|
|
25
18
|
const { headers } = axiosConfig;
|
|
26
|
-
const oauth =
|
|
19
|
+
const oauth = getOauthManager(account);
|
|
27
20
|
if (!oauth) {
|
|
28
|
-
throw new Error(
|
|
21
|
+
throw new Error(i18n(`${i18nKey}.errors.withOauth`, { accountId: account.accountId }));
|
|
29
22
|
}
|
|
30
23
|
const accessToken = await oauth.accessToken();
|
|
31
24
|
return {
|
|
@@ -38,7 +31,7 @@ async function withOauth(account, axiosConfig) {
|
|
|
38
31
|
}
|
|
39
32
|
async function withPersonalAccessKey(accountId, axiosConfig) {
|
|
40
33
|
const { headers } = axiosConfig;
|
|
41
|
-
const accessToken = await
|
|
34
|
+
const accessToken = await accessTokenForPersonalAccessKey(accountId);
|
|
42
35
|
return {
|
|
43
36
|
...axiosConfig,
|
|
44
37
|
headers: {
|
|
@@ -58,16 +51,16 @@ function withPortalId(portalId, axiosConfig) {
|
|
|
58
51
|
};
|
|
59
52
|
}
|
|
60
53
|
async function withAuth(accountId, options) {
|
|
61
|
-
const account =
|
|
54
|
+
const account = getConfigAccountById(accountId);
|
|
62
55
|
const { env, authType } = account;
|
|
63
|
-
const axiosConfig = withPortalId(accountId,
|
|
64
|
-
if (authType ===
|
|
56
|
+
const axiosConfig = withPortalId(accountId, getAxiosConfig({ env, ...options }));
|
|
57
|
+
if (authType === PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
65
58
|
return withPersonalAccessKey(accountId, axiosConfig);
|
|
66
59
|
}
|
|
67
|
-
if (authType ===
|
|
60
|
+
if (authType === OAUTH_AUTH_METHOD.value) {
|
|
68
61
|
return withOauth(account, axiosConfig);
|
|
69
62
|
}
|
|
70
|
-
if (authType ===
|
|
63
|
+
if (authType === API_KEY_AUTH_METHOD.value) {
|
|
71
64
|
const { params } = axiosConfig;
|
|
72
65
|
return {
|
|
73
66
|
...axiosConfig,
|
|
@@ -77,42 +70,42 @@ async function withAuth(accountId, options) {
|
|
|
77
70
|
},
|
|
78
71
|
};
|
|
79
72
|
}
|
|
80
|
-
throw new Error(
|
|
73
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidAuthType`, {
|
|
81
74
|
accountId,
|
|
82
75
|
authType,
|
|
83
76
|
}));
|
|
84
77
|
}
|
|
85
78
|
async function getRequest(accountId, options) {
|
|
86
79
|
const { params, ...rest } = options;
|
|
87
|
-
const optionsWithParams =
|
|
80
|
+
const optionsWithParams = addQueryParams(rest, params);
|
|
88
81
|
const requestConfig = await withAuth(accountId, optionsWithParams);
|
|
89
|
-
return
|
|
82
|
+
return httpClient(requestConfig);
|
|
90
83
|
}
|
|
91
84
|
async function postRequest(accountId, options) {
|
|
92
85
|
const requestConfig = await withAuth(accountId, options);
|
|
93
|
-
return
|
|
86
|
+
return httpClient({ ...requestConfig, method: 'post' });
|
|
94
87
|
}
|
|
95
88
|
async function putRequest(accountId, options) {
|
|
96
89
|
const requestConfig = await withAuth(accountId, options);
|
|
97
|
-
return
|
|
90
|
+
return httpClient({ ...requestConfig, method: 'put' });
|
|
98
91
|
}
|
|
99
92
|
async function patchRequest(accountId, options) {
|
|
100
93
|
const requestConfig = await withAuth(accountId, options);
|
|
101
|
-
return
|
|
94
|
+
return httpClient({ ...requestConfig, method: 'patch' });
|
|
102
95
|
}
|
|
103
96
|
async function deleteRequest(accountId, options) {
|
|
104
97
|
const requestConfig = await withAuth(accountId, options);
|
|
105
|
-
return
|
|
98
|
+
return httpClient({ ...requestConfig, method: 'delete' });
|
|
106
99
|
}
|
|
107
100
|
function createGetRequestStream(contentType) {
|
|
108
101
|
return async (accountId, options, destPath) => {
|
|
109
102
|
const { params, ...rest } = options;
|
|
110
|
-
const axiosConfig =
|
|
103
|
+
const axiosConfig = addQueryParams(rest, params);
|
|
111
104
|
// eslint-disable-next-line no-async-promise-executor
|
|
112
105
|
return new Promise(async (resolve, reject) => {
|
|
113
106
|
try {
|
|
114
107
|
const { headers, ...opts } = await withAuth(accountId, axiosConfig);
|
|
115
|
-
const res = await
|
|
108
|
+
const res = await httpClient({
|
|
116
109
|
method: 'get',
|
|
117
110
|
...opts,
|
|
118
111
|
headers: {
|
|
@@ -123,20 +116,20 @@ function createGetRequestStream(contentType) {
|
|
|
123
116
|
});
|
|
124
117
|
if (res.status >= 200 && res.status < 300) {
|
|
125
118
|
let filepath = destPath;
|
|
126
|
-
if (
|
|
127
|
-
const stat =
|
|
119
|
+
if (fs.existsSync(destPath)) {
|
|
120
|
+
const stat = fs.statSync(destPath);
|
|
128
121
|
if (stat.isDirectory()) {
|
|
129
|
-
const { parameters } =
|
|
130
|
-
filepath =
|
|
122
|
+
const { parameters } = contentDisposition.parse(res.headers['content-disposition'] || '');
|
|
123
|
+
filepath = path.join(destPath, parameters.filename);
|
|
131
124
|
}
|
|
132
125
|
}
|
|
133
126
|
try {
|
|
134
|
-
|
|
127
|
+
fs.ensureFileSync(filepath);
|
|
135
128
|
}
|
|
136
129
|
catch (err) {
|
|
137
130
|
reject(err);
|
|
138
131
|
}
|
|
139
|
-
const writeStream =
|
|
132
|
+
const writeStream = fs.createWriteStream(filepath, {
|
|
140
133
|
encoding: 'binary',
|
|
141
134
|
});
|
|
142
135
|
res.data.pipe(writeStream);
|
|
@@ -144,7 +137,7 @@ function createGetRequestStream(contentType) {
|
|
|
144
137
|
reject(err);
|
|
145
138
|
});
|
|
146
139
|
writeStream.on('close', async () => {
|
|
147
|
-
|
|
140
|
+
logger.log(i18n(`${i18nKey}.createGetRequestStream.onWrite`, {
|
|
148
141
|
filepath,
|
|
149
142
|
}));
|
|
150
143
|
resolve(res);
|
|
@@ -161,7 +154,7 @@ function createGetRequestStream(contentType) {
|
|
|
161
154
|
};
|
|
162
155
|
}
|
|
163
156
|
const getOctetStream = createGetRequestStream('application/octet-stream');
|
|
164
|
-
|
|
157
|
+
export const http = {
|
|
165
158
|
get: getRequest,
|
|
166
159
|
post: postRequest,
|
|
167
160
|
put: putRequest,
|
package/http/unauthed.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpOptions, HubSpotPromise } from '../types/Http';
|
|
1
|
+
import { HttpOptions, HubSpotPromise } from '../types/Http.js';
|
|
2
2
|
declare function getRequest<T>(options: HttpOptions): HubSpotPromise<T>;
|
|
3
3
|
declare function postRequest<T>(options: HttpOptions): HubSpotPromise<T>;
|
|
4
4
|
declare function putRequest<T>(options: HttpOptions): HubSpotPromise<T>;
|
package/http/unauthed.js
CHANGED
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const client_1 = require("./client");
|
|
5
|
-
const getAxiosConfig_1 = require("./getAxiosConfig");
|
|
6
|
-
const addQueryParams_1 = require("./addQueryParams");
|
|
1
|
+
import { httpClient } from './client.js';
|
|
2
|
+
import { getAxiosConfig } from './getAxiosConfig.js';
|
|
3
|
+
import { addQueryParams } from './addQueryParams.js';
|
|
7
4
|
async function getRequest(options) {
|
|
8
5
|
const { params, ...rest } = options;
|
|
9
|
-
const optionsWithParams =
|
|
10
|
-
const requestConfig = await
|
|
11
|
-
return
|
|
6
|
+
const optionsWithParams = addQueryParams(rest, params);
|
|
7
|
+
const requestConfig = await getAxiosConfig(optionsWithParams);
|
|
8
|
+
return httpClient(requestConfig);
|
|
12
9
|
}
|
|
13
10
|
async function postRequest(options) {
|
|
14
|
-
const requestConfig = await
|
|
15
|
-
return
|
|
11
|
+
const requestConfig = await getAxiosConfig(options);
|
|
12
|
+
return httpClient({ ...requestConfig, method: 'post' });
|
|
16
13
|
}
|
|
17
14
|
async function putRequest(options) {
|
|
18
|
-
const requestConfig = await
|
|
19
|
-
return
|
|
15
|
+
const requestConfig = await getAxiosConfig(options);
|
|
16
|
+
return httpClient({ ...requestConfig, method: 'put' });
|
|
20
17
|
}
|
|
21
18
|
async function patchRequest(options) {
|
|
22
|
-
const requestConfig = await
|
|
23
|
-
return
|
|
19
|
+
const requestConfig = await getAxiosConfig(options);
|
|
20
|
+
return httpClient({ ...requestConfig, method: 'patch' });
|
|
24
21
|
}
|
|
25
22
|
async function deleteRequest(options) {
|
|
26
|
-
const requestConfig = await
|
|
27
|
-
return
|
|
23
|
+
const requestConfig = await getAxiosConfig(options);
|
|
24
|
+
return httpClient({ ...requestConfig, method: 'delete' });
|
|
28
25
|
}
|
|
29
|
-
|
|
26
|
+
export const http = {
|
|
30
27
|
get: getRequest,
|
|
31
28
|
post: postRequest,
|
|
32
29
|
put: putRequest,
|
package/lang/en.json
CHANGED
|
@@ -316,7 +316,7 @@
|
|
|
316
316
|
},
|
|
317
317
|
"buildConfigFromEnvironment": {
|
|
318
318
|
"missingAccountId": "HUBSPOT_ACCOUNT_ID is required, but not currently set",
|
|
319
|
-
"invalidAuthType": "Auth type is invalid. Use HUBSPOT_CLIENT_ID, HUBSPOT_CLIENT_SECRET, and HUBSPOT_REFRESH_TOKEN to authenticate with Oauth2,
|
|
319
|
+
"invalidAuthType": "Auth type is invalid. Use HUBSPOT_CLIENT_ID, HUBSPOT_CLIENT_SECRET, and HUBSPOT_REFRESH_TOKEN to authenticate with Oauth2, HUBSPOT_PERSONAL_ACCESS_KEY to authenticate with Personal Access Key, or API_KEY to authenticate with API Key."
|
|
320
320
|
}
|
|
321
321
|
},
|
|
322
322
|
"defaultAccountOverride": {
|
package/lib/archive.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { CopySourceToDestOptions } from '../types/Archive';
|
|
1
|
+
import { CopySourceToDestOptions } from '../types/Archive.js';
|
|
4
2
|
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir, hideLogs, handleCollision, }?: CopySourceToDestOptions): Promise<boolean>;
|
package/lib/archive.js
CHANGED
|
@@ -1,97 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.extractZipArchive = void 0;
|
|
30
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
31
|
-
const path_1 = __importStar(require("path"));
|
|
32
|
-
const os_1 = require("os");
|
|
33
|
-
const extract_zip_1 = __importDefault(require("extract-zip"));
|
|
34
|
-
const logger_1 = require("./logger");
|
|
35
|
-
const lang_1 = require("../utils/lang");
|
|
36
|
-
const FileSystemError_1 = require("../models/FileSystemError");
|
|
37
|
-
const fs_1 = require("./fs");
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path, { join } from 'path';
|
|
3
|
+
import { tmpdir } from 'os';
|
|
4
|
+
import extract from 'extract-zip';
|
|
5
|
+
import { logger } from './logger.js';
|
|
6
|
+
import { i18n } from '../utils/lang.js';
|
|
7
|
+
import { FileSystemError } from '../models/FileSystemError.js';
|
|
8
|
+
import { walk } from './fs.js';
|
|
38
9
|
const i18nKey = 'lib.archive';
|
|
39
10
|
async function extractZip(name, zip, hideLogs = false) {
|
|
40
11
|
const result = { extractDir: '', tmpDir: '' };
|
|
41
12
|
const TMP_FOLDER_PREFIX = `hubspot-temp-${name}-`;
|
|
42
13
|
if (!hideLogs) {
|
|
43
|
-
|
|
14
|
+
logger.log(i18n(`${i18nKey}.extractZip.init`));
|
|
44
15
|
}
|
|
45
16
|
// Write zip to disk
|
|
46
17
|
let tmpZipPath = '';
|
|
47
18
|
try {
|
|
48
|
-
result.tmpDir = await
|
|
49
|
-
tmpZipPath =
|
|
50
|
-
await
|
|
51
|
-
await
|
|
19
|
+
result.tmpDir = await fs.mkdtemp(join(tmpdir(), TMP_FOLDER_PREFIX));
|
|
20
|
+
tmpZipPath = join(result.tmpDir, 'hubspot-temp.zip');
|
|
21
|
+
await fs.ensureFile(tmpZipPath);
|
|
22
|
+
await fs.writeFile(tmpZipPath, zip, {
|
|
52
23
|
mode: 0o777,
|
|
53
24
|
});
|
|
54
25
|
}
|
|
55
26
|
catch (err) {
|
|
56
27
|
if (tmpZipPath || result.tmpDir) {
|
|
57
|
-
throw new
|
|
28
|
+
throw new FileSystemError({ cause: err }, {
|
|
58
29
|
filepath: tmpZipPath || result.tmpDir,
|
|
59
30
|
operation: 'write',
|
|
60
31
|
});
|
|
61
32
|
}
|
|
62
33
|
else {
|
|
63
|
-
throw new Error(
|
|
34
|
+
throw new Error(i18n(`${i18nKey}.extractZip.errors.write`), {
|
|
64
35
|
cause: err,
|
|
65
36
|
});
|
|
66
37
|
}
|
|
67
38
|
}
|
|
68
39
|
// Extract zip
|
|
69
40
|
try {
|
|
70
|
-
const tmpExtractPath =
|
|
71
|
-
await (
|
|
41
|
+
const tmpExtractPath = join(result.tmpDir, 'extracted');
|
|
42
|
+
await extract(tmpZipPath, { dir: tmpExtractPath });
|
|
72
43
|
result.extractDir = tmpExtractPath;
|
|
73
44
|
}
|
|
74
45
|
catch (err) {
|
|
75
|
-
throw new Error(
|
|
46
|
+
throw new Error(i18n(`${i18nKey}.extractZip.errors.extract`), {
|
|
76
47
|
cause: err,
|
|
77
48
|
});
|
|
78
49
|
}
|
|
79
|
-
|
|
50
|
+
logger.debug(i18n(`${i18nKey}.extractZip.success`));
|
|
80
51
|
return result;
|
|
81
52
|
}
|
|
82
53
|
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true, hideLogs = false, handleCollision, } = {}) {
|
|
83
54
|
try {
|
|
84
55
|
if (!hideLogs) {
|
|
85
|
-
|
|
56
|
+
logger.log(i18n(`${i18nKey}.copySourceToDest.init`));
|
|
86
57
|
}
|
|
87
58
|
const srcDirPath = [src];
|
|
88
59
|
if (includesRootDir) {
|
|
89
|
-
const files = await
|
|
60
|
+
const files = await fs.readdir(src);
|
|
90
61
|
const rootDir = files[0];
|
|
91
62
|
if (!rootDir) {
|
|
92
|
-
|
|
63
|
+
logger.debug(i18n(`${i18nKey}.copySourceToDest.sourceEmpty`));
|
|
93
64
|
// Create the dest path if it doesn't already exist
|
|
94
|
-
await
|
|
65
|
+
await fs.ensureDir(dest);
|
|
95
66
|
// No root found so nothing to copy
|
|
96
67
|
return true;
|
|
97
68
|
}
|
|
@@ -102,19 +73,19 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true,
|
|
|
102
73
|
sourceDirs.push(...(Array.isArray(sourceDir) ? new Set(sourceDir) : [sourceDir]));
|
|
103
74
|
}
|
|
104
75
|
if (sourceDirs.length === 0) {
|
|
105
|
-
const projectSrcDir =
|
|
106
|
-
await
|
|
76
|
+
const projectSrcDir = join(...srcDirPath);
|
|
77
|
+
await fs.copy(projectSrcDir, dest);
|
|
107
78
|
}
|
|
108
79
|
else {
|
|
109
80
|
for (let i = 0; i < sourceDirs.length; i++) {
|
|
110
|
-
const projectSrcDir =
|
|
81
|
+
const projectSrcDir = join(...srcDirPath, sourceDirs[i]);
|
|
111
82
|
let collisions = [];
|
|
112
83
|
let filesWithoutCollisions = [];
|
|
113
|
-
if (
|
|
84
|
+
if (fs.existsSync(dest) &&
|
|
114
85
|
handleCollision &&
|
|
115
86
|
typeof handleCollision === 'function') {
|
|
116
|
-
const existingFiles = (await
|
|
117
|
-
const newFiles = (await
|
|
87
|
+
const existingFiles = (await walk(dest, ['node_modules'])).map(file => path.normalize(path.relative(dest, file)));
|
|
88
|
+
const newFiles = (await walk(projectSrcDir, ['node_modules'])).map(file => path.relative(projectSrcDir, file));
|
|
118
89
|
// Find files that exist in the same positions in both directories
|
|
119
90
|
collisions = existingFiles.filter(currentFile => newFiles.includes(currentFile));
|
|
120
91
|
filesWithoutCollisions = newFiles.filter(currentFile => !collisions.includes(currentFile));
|
|
@@ -127,19 +98,19 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true,
|
|
|
127
98
|
src: projectSrcDir,
|
|
128
99
|
collisions,
|
|
129
100
|
});
|
|
130
|
-
await Promise.all(filesWithoutCollisions.map(currentFile =>
|
|
101
|
+
await Promise.all(filesWithoutCollisions.map(currentFile => fs.copy(path.join(projectSrcDir, currentFile), path.join(dest, currentFile))));
|
|
131
102
|
}
|
|
132
103
|
else {
|
|
133
|
-
await
|
|
104
|
+
await fs.copy(projectSrcDir, dest);
|
|
134
105
|
}
|
|
135
106
|
}
|
|
136
107
|
}
|
|
137
|
-
|
|
108
|
+
logger.debug(i18n(`${i18nKey}.copySourceToDest.success`));
|
|
138
109
|
return true;
|
|
139
110
|
}
|
|
140
111
|
catch (err) {
|
|
141
|
-
|
|
142
|
-
throw new
|
|
112
|
+
logger.debug(i18n(`${i18nKey}.copySourceToDest.error`, { dest }));
|
|
113
|
+
throw new FileSystemError({ cause: err }, {
|
|
143
114
|
filepath: dest,
|
|
144
115
|
operation: 'write',
|
|
145
116
|
});
|
|
@@ -149,13 +120,13 @@ async function cleanupTempDir(tmpDir) {
|
|
|
149
120
|
if (!tmpDir)
|
|
150
121
|
return;
|
|
151
122
|
try {
|
|
152
|
-
await
|
|
123
|
+
await fs.remove(tmpDir);
|
|
153
124
|
}
|
|
154
125
|
catch (e) {
|
|
155
|
-
|
|
126
|
+
logger.debug(i18n(`${i18nKey}.cleanupTempDir.error`, { tmpDir }));
|
|
156
127
|
}
|
|
157
128
|
}
|
|
158
|
-
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs, handleCollision, } = {}) {
|
|
129
|
+
export async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs, handleCollision, } = {}) {
|
|
159
130
|
let success = false;
|
|
160
131
|
if (zip) {
|
|
161
132
|
const { extractDir, tmpDir } = await extractZip(name, zip, hideLogs);
|
|
@@ -171,4 +142,3 @@ async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir,
|
|
|
171
142
|
}
|
|
172
143
|
return success;
|
|
173
144
|
}
|
|
174
|
-
exports.extractZipArchive = extractZipArchive;
|
package/lib/cms/functions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FunctionConfig, FunctionConfigInfo, FunctionInfo, FunctionOptions } from '../../types/Functions';
|
|
1
|
+
import { FunctionConfig, FunctionConfigInfo, FunctionInfo, FunctionOptions } from '../../types/Functions.js';
|
|
2
2
|
export declare function isObjectOrFunction(value: object): boolean;
|
|
3
3
|
export declare function createEndpoint(endpointMethod: string, filename: string): {
|
|
4
4
|
method: string;
|