@hubspot/local-dev-lib 0.6.1-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 +39 -124
- 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 +21 -17
- 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,109 +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
|
-
function logRequest(response) {
|
|
55
|
-
try {
|
|
56
|
-
if (!process.env.HUBSPOT_NETWORK_LOGGING) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (!process.env.HUBSPOT_DEBUG_LOGGING_VERBOSE &&
|
|
60
|
-
IGNORE_URLS_NETWORK_DEBUG.some(url => response?.config?.url && response.config.url.includes(url))) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
logger_1.logger.debug(util.inspect({
|
|
64
|
-
method: response.config.method,
|
|
65
|
-
baseURL: response.config.baseURL,
|
|
66
|
-
url: response.config.url,
|
|
67
|
-
data: response.data,
|
|
68
|
-
status: response.status,
|
|
69
|
-
}, false, null, true));
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
// Ignore any errors that occur while logging the response
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
axios_1.default.interceptors.response.use((response) => {
|
|
76
|
-
logRequest(response);
|
|
77
|
-
return response;
|
|
78
|
-
}, error => {
|
|
79
|
-
try {
|
|
80
|
-
if ((0, axios_1.isAxiosError)(error) && error.response) {
|
|
81
|
-
logRequest(error.response);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
// Ignore any errors that occur while logging the response
|
|
86
|
-
}
|
|
87
|
-
// Don't re-wrap if already a HubSpotHttpError. This can happen when
|
|
88
|
-
// multiple copies of local-dev-lib are loaded and share the same axios
|
|
89
|
-
// instance, causing multiple interceptors to be registered.
|
|
90
|
-
if (error instanceof HubSpotHttpError_1.HubSpotHttpError ||
|
|
91
|
-
error?.name === HubSpotHttpError_1.HubSpotHttpErrorName) {
|
|
92
|
-
return Promise.reject(error);
|
|
93
|
-
}
|
|
94
|
-
// Wrap all axios errors in our own Error class. Attach the error
|
|
95
|
-
// as the cause for the new error, so we maintain the stack trace
|
|
96
|
-
return Promise.reject(new HubSpotHttpError_1.HubSpotHttpError(error.message, { cause: error }));
|
|
97
|
-
});
|
|
98
|
-
function addUserAgentHeader(key, value) {
|
|
99
|
-
getAxiosConfig_1.USER_AGENTS[key] = value;
|
|
14
|
+
export function addUserAgentHeader(key, value) {
|
|
15
|
+
USER_AGENTS[key] = value;
|
|
100
16
|
}
|
|
101
|
-
exports.addUserAgentHeader = addUserAgentHeader;
|
|
102
17
|
async function withOauth(account, axiosConfig) {
|
|
103
18
|
const { headers } = axiosConfig;
|
|
104
|
-
const oauth =
|
|
19
|
+
const oauth = getOauthManager(account);
|
|
105
20
|
if (!oauth) {
|
|
106
|
-
throw new Error(
|
|
21
|
+
throw new Error(i18n(`${i18nKey}.errors.withOauth`, { accountId: account.accountId }));
|
|
107
22
|
}
|
|
108
23
|
const accessToken = await oauth.accessToken();
|
|
109
24
|
return {
|
|
@@ -116,7 +31,7 @@ async function withOauth(account, axiosConfig) {
|
|
|
116
31
|
}
|
|
117
32
|
async function withPersonalAccessKey(accountId, axiosConfig) {
|
|
118
33
|
const { headers } = axiosConfig;
|
|
119
|
-
const accessToken = await
|
|
34
|
+
const accessToken = await accessTokenForPersonalAccessKey(accountId);
|
|
120
35
|
return {
|
|
121
36
|
...axiosConfig,
|
|
122
37
|
headers: {
|
|
@@ -136,16 +51,16 @@ function withPortalId(portalId, axiosConfig) {
|
|
|
136
51
|
};
|
|
137
52
|
}
|
|
138
53
|
async function withAuth(accountId, options) {
|
|
139
|
-
const account =
|
|
54
|
+
const account = getConfigAccountById(accountId);
|
|
140
55
|
const { env, authType } = account;
|
|
141
|
-
const axiosConfig = withPortalId(accountId,
|
|
142
|
-
if (authType ===
|
|
56
|
+
const axiosConfig = withPortalId(accountId, getAxiosConfig({ env, ...options }));
|
|
57
|
+
if (authType === PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
143
58
|
return withPersonalAccessKey(accountId, axiosConfig);
|
|
144
59
|
}
|
|
145
|
-
if (authType ===
|
|
60
|
+
if (authType === OAUTH_AUTH_METHOD.value) {
|
|
146
61
|
return withOauth(account, axiosConfig);
|
|
147
62
|
}
|
|
148
|
-
if (authType ===
|
|
63
|
+
if (authType === API_KEY_AUTH_METHOD.value) {
|
|
149
64
|
const { params } = axiosConfig;
|
|
150
65
|
return {
|
|
151
66
|
...axiosConfig,
|
|
@@ -155,42 +70,42 @@ async function withAuth(accountId, options) {
|
|
|
155
70
|
},
|
|
156
71
|
};
|
|
157
72
|
}
|
|
158
|
-
throw new Error(
|
|
73
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidAuthType`, {
|
|
159
74
|
accountId,
|
|
160
75
|
authType,
|
|
161
76
|
}));
|
|
162
77
|
}
|
|
163
78
|
async function getRequest(accountId, options) {
|
|
164
79
|
const { params, ...rest } = options;
|
|
165
|
-
const optionsWithParams =
|
|
80
|
+
const optionsWithParams = addQueryParams(rest, params);
|
|
166
81
|
const requestConfig = await withAuth(accountId, optionsWithParams);
|
|
167
|
-
return (
|
|
82
|
+
return httpClient(requestConfig);
|
|
168
83
|
}
|
|
169
84
|
async function postRequest(accountId, options) {
|
|
170
85
|
const requestConfig = await withAuth(accountId, options);
|
|
171
|
-
return (
|
|
86
|
+
return httpClient({ ...requestConfig, method: 'post' });
|
|
172
87
|
}
|
|
173
88
|
async function putRequest(accountId, options) {
|
|
174
89
|
const requestConfig = await withAuth(accountId, options);
|
|
175
|
-
return (
|
|
90
|
+
return httpClient({ ...requestConfig, method: 'put' });
|
|
176
91
|
}
|
|
177
92
|
async function patchRequest(accountId, options) {
|
|
178
93
|
const requestConfig = await withAuth(accountId, options);
|
|
179
|
-
return (
|
|
94
|
+
return httpClient({ ...requestConfig, method: 'patch' });
|
|
180
95
|
}
|
|
181
96
|
async function deleteRequest(accountId, options) {
|
|
182
97
|
const requestConfig = await withAuth(accountId, options);
|
|
183
|
-
return (
|
|
98
|
+
return httpClient({ ...requestConfig, method: 'delete' });
|
|
184
99
|
}
|
|
185
100
|
function createGetRequestStream(contentType) {
|
|
186
101
|
return async (accountId, options, destPath) => {
|
|
187
102
|
const { params, ...rest } = options;
|
|
188
|
-
const axiosConfig =
|
|
103
|
+
const axiosConfig = addQueryParams(rest, params);
|
|
189
104
|
// eslint-disable-next-line no-async-promise-executor
|
|
190
105
|
return new Promise(async (resolve, reject) => {
|
|
191
106
|
try {
|
|
192
107
|
const { headers, ...opts } = await withAuth(accountId, axiosConfig);
|
|
193
|
-
const res = await (
|
|
108
|
+
const res = await httpClient({
|
|
194
109
|
method: 'get',
|
|
195
110
|
...opts,
|
|
196
111
|
headers: {
|
|
@@ -201,20 +116,20 @@ function createGetRequestStream(contentType) {
|
|
|
201
116
|
});
|
|
202
117
|
if (res.status >= 200 && res.status < 300) {
|
|
203
118
|
let filepath = destPath;
|
|
204
|
-
if (
|
|
205
|
-
const stat =
|
|
119
|
+
if (fs.existsSync(destPath)) {
|
|
120
|
+
const stat = fs.statSync(destPath);
|
|
206
121
|
if (stat.isDirectory()) {
|
|
207
|
-
const { parameters } =
|
|
208
|
-
filepath =
|
|
122
|
+
const { parameters } = contentDisposition.parse(res.headers['content-disposition'] || '');
|
|
123
|
+
filepath = path.join(destPath, parameters.filename);
|
|
209
124
|
}
|
|
210
125
|
}
|
|
211
126
|
try {
|
|
212
|
-
|
|
127
|
+
fs.ensureFileSync(filepath);
|
|
213
128
|
}
|
|
214
129
|
catch (err) {
|
|
215
130
|
reject(err);
|
|
216
131
|
}
|
|
217
|
-
const writeStream =
|
|
132
|
+
const writeStream = fs.createWriteStream(filepath, {
|
|
218
133
|
encoding: 'binary',
|
|
219
134
|
});
|
|
220
135
|
res.data.pipe(writeStream);
|
|
@@ -222,7 +137,7 @@ function createGetRequestStream(contentType) {
|
|
|
222
137
|
reject(err);
|
|
223
138
|
});
|
|
224
139
|
writeStream.on('close', async () => {
|
|
225
|
-
|
|
140
|
+
logger.log(i18n(`${i18nKey}.createGetRequestStream.onWrite`, {
|
|
226
141
|
filepath,
|
|
227
142
|
}));
|
|
228
143
|
resolve(res);
|
|
@@ -239,7 +154,7 @@ function createGetRequestStream(contentType) {
|
|
|
239
154
|
};
|
|
240
155
|
}
|
|
241
156
|
const getOctetStream = createGetRequestStream('application/octet-stream');
|
|
242
|
-
|
|
157
|
+
export const http = {
|
|
243
158
|
get: getRequest,
|
|
244
159
|
post: postRequest,
|
|
245
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>;
|