@hubspot/local-dev-lib 0.6.2-experimental.0 → 0.6.3-experimental.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 -55
- 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 -40
- 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 -45
- 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 +144 -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.d.ts +30 -1
- package/constants/config.js +65 -42
- 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.d.ts +1 -0
- package/http/client.js +54 -0
- package/http/getAxiosConfig.d.ts +1 -1
- package/http/getAxiosConfig.js +21 -31
- package/http/index.d.ts +2 -2
- package/http/index.js +33 -116
- package/http/unauthed.d.ts +1 -1
- package/http/unauthed.js +15 -21
- package/lang/en.json +3 -2
- 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 +27 -31
- 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,107 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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.http = exports.addUserAgentHeader = void 0;
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
32
|
-
const content_disposition_1 = __importDefault(require("content-disposition"));
|
|
33
|
-
const axios_1 = __importStar(require("axios"));
|
|
34
|
-
const config_1 = require("../config");
|
|
35
|
-
const getAxiosConfig_1 = require("./getAxiosConfig");
|
|
36
|
-
const addQueryParams_1 = require("./addQueryParams");
|
|
37
|
-
const personalAccessKey_1 = require("../lib/personalAccessKey");
|
|
38
|
-
const oauth_1 = require("../lib/oauth");
|
|
39
|
-
const logger_1 = require("../lib/logger");
|
|
40
|
-
const lang_1 = require("../utils/lang");
|
|
41
|
-
const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
|
|
42
|
-
const auth_1 = require("../constants/auth");
|
|
43
|
-
const localDevAuth_1 = require("../api/localDevAuth");
|
|
44
|
-
const fireAlarm_1 = require("../api/fireAlarm");
|
|
45
|
-
const util = __importStar(require("util"));
|
|
46
|
-
const trackUsage_1 = require("../lib/trackUsage");
|
|
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';
|
|
47
13
|
const i18nKey = 'http.index';
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
trackUsage_1.CMS_CLI_USAGE_PATH,
|
|
51
|
-
trackUsage_1.VSCODE_USAGE_PATH,
|
|
52
|
-
fireAlarm_1.FIREALARM_API_AUTH_PATH,
|
|
53
|
-
];
|
|
54
|
-
// Create an isolated axios instance for this copy of local-dev-lib.
|
|
55
|
-
// This prevents issues when multiple copies are loaded and share the global
|
|
56
|
-
// register interceptors on the shared instance causing errors to be wrapped multiple times.
|
|
57
|
-
const httpClient = axios_1.default.create();
|
|
58
|
-
function logRequest(response) {
|
|
59
|
-
try {
|
|
60
|
-
if (!process.env.HUBSPOT_NETWORK_LOGGING) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (!process.env.HUBSPOT_DEBUG_LOGGING_VERBOSE &&
|
|
64
|
-
IGNORE_URLS_NETWORK_DEBUG.some(url => response?.config?.url && response.config.url.includes(url))) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
logger_1.logger.debug(util.inspect({
|
|
68
|
-
method: response.config.method,
|
|
69
|
-
baseURL: response.config.baseURL,
|
|
70
|
-
url: response.config.url,
|
|
71
|
-
data: response.data,
|
|
72
|
-
status: response.status,
|
|
73
|
-
}, false, null, true));
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
// Ignore any errors that occur while logging the response
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Register interceptor on our isolated instance
|
|
80
|
-
httpClient.interceptors.response.use((response) => {
|
|
81
|
-
logRequest(response);
|
|
82
|
-
return response;
|
|
83
|
-
}, error => {
|
|
84
|
-
try {
|
|
85
|
-
if ((0, axios_1.isAxiosError)(error) && error.response) {
|
|
86
|
-
logRequest(error.response);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
// Ignore any errors that occur while logging the response
|
|
91
|
-
}
|
|
92
|
-
// Wrap all axios errors in our own Error class. Attach the error
|
|
93
|
-
// as the cause for the new error, so we maintain the stack trace
|
|
94
|
-
return Promise.reject(new HubSpotHttpError_1.HubSpotHttpError(error.message, { cause: error }));
|
|
95
|
-
});
|
|
96
|
-
function addUserAgentHeader(key, value) {
|
|
97
|
-
getAxiosConfig_1.USER_AGENTS[key] = value;
|
|
14
|
+
export function addUserAgentHeader(key, value) {
|
|
15
|
+
USER_AGENTS[key] = value;
|
|
98
16
|
}
|
|
99
|
-
exports.addUserAgentHeader = addUserAgentHeader;
|
|
100
17
|
async function withOauth(account, axiosConfig) {
|
|
101
18
|
const { headers } = axiosConfig;
|
|
102
|
-
const oauth =
|
|
19
|
+
const oauth = getOauthManager(account);
|
|
103
20
|
if (!oauth) {
|
|
104
|
-
throw new Error(
|
|
21
|
+
throw new Error(i18n(`${i18nKey}.errors.withOauth`, { accountId: account.accountId }));
|
|
105
22
|
}
|
|
106
23
|
const accessToken = await oauth.accessToken();
|
|
107
24
|
return {
|
|
@@ -114,7 +31,7 @@ async function withOauth(account, axiosConfig) {
|
|
|
114
31
|
}
|
|
115
32
|
async function withPersonalAccessKey(accountId, axiosConfig) {
|
|
116
33
|
const { headers } = axiosConfig;
|
|
117
|
-
const accessToken = await
|
|
34
|
+
const accessToken = await accessTokenForPersonalAccessKey(accountId);
|
|
118
35
|
return {
|
|
119
36
|
...axiosConfig,
|
|
120
37
|
headers: {
|
|
@@ -134,16 +51,16 @@ function withPortalId(portalId, axiosConfig) {
|
|
|
134
51
|
};
|
|
135
52
|
}
|
|
136
53
|
async function withAuth(accountId, options) {
|
|
137
|
-
const account =
|
|
54
|
+
const account = getConfigAccountById(accountId);
|
|
138
55
|
const { env, authType } = account;
|
|
139
|
-
const axiosConfig = withPortalId(accountId,
|
|
140
|
-
if (authType ===
|
|
56
|
+
const axiosConfig = withPortalId(accountId, getAxiosConfig({ env, ...options }));
|
|
57
|
+
if (authType === PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
141
58
|
return withPersonalAccessKey(accountId, axiosConfig);
|
|
142
59
|
}
|
|
143
|
-
if (authType ===
|
|
60
|
+
if (authType === OAUTH_AUTH_METHOD.value) {
|
|
144
61
|
return withOauth(account, axiosConfig);
|
|
145
62
|
}
|
|
146
|
-
if (authType ===
|
|
63
|
+
if (authType === API_KEY_AUTH_METHOD.value) {
|
|
147
64
|
const { params } = axiosConfig;
|
|
148
65
|
return {
|
|
149
66
|
...axiosConfig,
|
|
@@ -153,14 +70,14 @@ async function withAuth(accountId, options) {
|
|
|
153
70
|
},
|
|
154
71
|
};
|
|
155
72
|
}
|
|
156
|
-
throw new Error(
|
|
73
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidAuthType`, {
|
|
157
74
|
accountId,
|
|
158
75
|
authType,
|
|
159
76
|
}));
|
|
160
77
|
}
|
|
161
78
|
async function getRequest(accountId, options) {
|
|
162
79
|
const { params, ...rest } = options;
|
|
163
|
-
const optionsWithParams =
|
|
80
|
+
const optionsWithParams = addQueryParams(rest, params);
|
|
164
81
|
const requestConfig = await withAuth(accountId, optionsWithParams);
|
|
165
82
|
return httpClient(requestConfig);
|
|
166
83
|
}
|
|
@@ -183,7 +100,7 @@ async function deleteRequest(accountId, options) {
|
|
|
183
100
|
function createGetRequestStream(contentType) {
|
|
184
101
|
return async (accountId, options, destPath) => {
|
|
185
102
|
const { params, ...rest } = options;
|
|
186
|
-
const axiosConfig =
|
|
103
|
+
const axiosConfig = addQueryParams(rest, params);
|
|
187
104
|
// eslint-disable-next-line no-async-promise-executor
|
|
188
105
|
return new Promise(async (resolve, reject) => {
|
|
189
106
|
try {
|
|
@@ -199,20 +116,20 @@ function createGetRequestStream(contentType) {
|
|
|
199
116
|
});
|
|
200
117
|
if (res.status >= 200 && res.status < 300) {
|
|
201
118
|
let filepath = destPath;
|
|
202
|
-
if (
|
|
203
|
-
const stat =
|
|
119
|
+
if (fs.existsSync(destPath)) {
|
|
120
|
+
const stat = fs.statSync(destPath);
|
|
204
121
|
if (stat.isDirectory()) {
|
|
205
|
-
const { parameters } =
|
|
206
|
-
filepath =
|
|
122
|
+
const { parameters } = contentDisposition.parse(res.headers['content-disposition'] || '');
|
|
123
|
+
filepath = path.join(destPath, parameters.filename);
|
|
207
124
|
}
|
|
208
125
|
}
|
|
209
126
|
try {
|
|
210
|
-
|
|
127
|
+
fs.ensureFileSync(filepath);
|
|
211
128
|
}
|
|
212
129
|
catch (err) {
|
|
213
130
|
reject(err);
|
|
214
131
|
}
|
|
215
|
-
const writeStream =
|
|
132
|
+
const writeStream = fs.createWriteStream(filepath, {
|
|
216
133
|
encoding: 'binary',
|
|
217
134
|
});
|
|
218
135
|
res.data.pipe(writeStream);
|
|
@@ -220,7 +137,7 @@ function createGetRequestStream(contentType) {
|
|
|
220
137
|
reject(err);
|
|
221
138
|
});
|
|
222
139
|
writeStream.on('close', async () => {
|
|
223
|
-
|
|
140
|
+
logger.log(i18n(`${i18nKey}.createGetRequestStream.onWrite`, {
|
|
224
141
|
filepath,
|
|
225
142
|
}));
|
|
226
143
|
resolve(res);
|
|
@@ -237,7 +154,7 @@ function createGetRequestStream(contentType) {
|
|
|
237
154
|
};
|
|
238
155
|
}
|
|
239
156
|
const getOctetStream = createGetRequestStream('application/octet-stream');
|
|
240
|
-
|
|
157
|
+
export const http = {
|
|
241
158
|
get: getRequest,
|
|
242
159
|
post: postRequest,
|
|
243
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,35 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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");
|
|
1
|
+
import { httpClient } from './client.js';
|
|
2
|
+
import { getAxiosConfig } from './getAxiosConfig.js';
|
|
3
|
+
import { addQueryParams } from './addQueryParams.js';
|
|
10
4
|
async function getRequest(options) {
|
|
11
5
|
const { params, ...rest } = options;
|
|
12
|
-
const optionsWithParams =
|
|
13
|
-
const requestConfig = await
|
|
14
|
-
return (
|
|
6
|
+
const optionsWithParams = addQueryParams(rest, params);
|
|
7
|
+
const requestConfig = await getAxiosConfig(optionsWithParams);
|
|
8
|
+
return httpClient(requestConfig);
|
|
15
9
|
}
|
|
16
10
|
async function postRequest(options) {
|
|
17
|
-
const requestConfig = await
|
|
18
|
-
return (
|
|
11
|
+
const requestConfig = await getAxiosConfig(options);
|
|
12
|
+
return httpClient({ ...requestConfig, method: 'post' });
|
|
19
13
|
}
|
|
20
14
|
async function putRequest(options) {
|
|
21
|
-
const requestConfig = await
|
|
22
|
-
return (
|
|
15
|
+
const requestConfig = await getAxiosConfig(options);
|
|
16
|
+
return httpClient({ ...requestConfig, method: 'put' });
|
|
23
17
|
}
|
|
24
18
|
async function patchRequest(options) {
|
|
25
|
-
const requestConfig = await
|
|
26
|
-
return (
|
|
19
|
+
const requestConfig = await getAxiosConfig(options);
|
|
20
|
+
return httpClient({ ...requestConfig, method: 'patch' });
|
|
27
21
|
}
|
|
28
22
|
async function deleteRequest(options) {
|
|
29
|
-
const requestConfig = await
|
|
30
|
-
return (
|
|
23
|
+
const requestConfig = await getAxiosConfig(options);
|
|
24
|
+
return httpClient({ ...requestConfig, method: 'delete' });
|
|
31
25
|
}
|
|
32
|
-
|
|
26
|
+
export const http = {
|
|
33
27
|
get: getRequest,
|
|
34
28
|
post: postRequest,
|
|
35
29
|
put: putRequest,
|
package/lang/en.json
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
"invalidEvent": "Usage tracking event {{ eventName }} is not a valid event type.",
|
|
5
5
|
"sendingEventAuthenticated": "Sending usage event to authenticated endpoint",
|
|
6
6
|
"retryingEventUnauthenticated": "Failed to send the usage event as authenticated. Trying again as unauthenticated.",
|
|
7
|
-
"sendingEventUnauthenticated": "Sending usage event to unauthenticated endpoint"
|
|
7
|
+
"sendingEventUnauthenticated": "Sending usage event to unauthenticated endpoint",
|
|
8
|
+
"unauthenticatedSendFailed": "Failed to send usage event to unauthenticated endpoint"
|
|
8
9
|
},
|
|
9
10
|
"archive": {
|
|
10
11
|
"extractZip": {
|
|
@@ -315,7 +316,7 @@
|
|
|
315
316
|
},
|
|
316
317
|
"buildConfigFromEnvironment": {
|
|
317
318
|
"missingAccountId": "HUBSPOT_ACCOUNT_ID is required, but not currently set",
|
|
318
|
-
"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."
|
|
319
320
|
}
|
|
320
321
|
},
|
|
321
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;
|