@hubspot/local-dev-lib 0.2.1 → 0.2.2-experimental.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -0
- package/README.md +17 -0
- package/api/appsDev.d.ts +6 -0
- package/api/appsDev.js +29 -0
- package/api/customObjects.d.ts +8 -7
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +4 -13
- package/api/designManager.js +6 -9
- package/api/developerTestAccounts.d.ts +7 -0
- package/api/developerTestAccounts.js +48 -0
- package/api/fileManager.d.ts +5 -4
- package/api/fileManager.js +11 -11
- package/api/fileMapper.d.ts +8 -7
- package/api/fileMapper.js +17 -17
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/functions.d.ts +7 -4
- package/api/functions.js +22 -11
- package/api/github.d.ts +7 -9
- package/api/github.js +31 -13
- package/api/hubdb.d.ts +11 -10
- package/api/hubdb.js +28 -22
- package/api/lighthouseScore.d.ts +4 -4
- package/api/lighthouseScore.js +9 -12
- package/api/localDevAuth.d.ts +8 -16
- package/api/localDevAuth.js +34 -13
- package/api/marketplaceValidation.d.ts +4 -4
- package/api/marketplaceValidation.js +8 -11
- package/api/projects.d.ts +31 -24
- package/api/projects.js +164 -44
- package/api/sandboxHubs.d.ts +6 -4
- package/api/sandboxHubs.js +10 -11
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +4 -13
- package/api/secrets.d.ts +6 -8
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +15 -11
- package/config/CLIConfiguration.js +175 -90
- package/config/configFile.js +13 -21
- package/config/configUtils.d.ts +2 -21
- package/config/configUtils.js +5 -4
- package/config/config_DEPRECATED.d.ts +6 -8
- package/config/config_DEPRECATED.js +79 -25
- package/config/environment.js +5 -4
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +13 -8
- package/config/index.js +97 -57
- package/config/migrate.d.ts +20 -0
- package/config/migrate.js +150 -0
- package/constants/config.d.ts +25 -1
- package/constants/config.js +32 -3
- package/constants/environments.d.ts +1 -0
- package/constants/environments.js +1 -0
- package/constants/extensions.d.ts +2 -0
- package/constants/extensions.js +3 -1
- package/constants/files.d.ts +2 -2
- package/constants/files.js +3 -3
- package/errors/errors_DEPRECATED.d.ts +1 -5
- package/errors/errors_DEPRECATED.js +2 -2
- package/errors/index.d.ts +18 -0
- package/errors/index.js +63 -0
- package/http/addQueryParams.d.ts +2 -0
- package/http/addQueryParams.js +14 -0
- package/http/getAxiosConfig.d.ts +6 -3
- package/http/getAxiosConfig.js +51 -7
- package/http/index.d.ts +11 -12
- package/http/index.js +35 -41
- package/http/unauthed.d.ts +14 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +384 -386
- package/lib/archive.d.ts +2 -8
- package/lib/archive.js +34 -30
- package/lib/cms/functions.d.ts +7 -12
- package/lib/cms/functions.js +49 -51
- package/lib/cms/handleFieldsJS.js +16 -14
- package/lib/cms/modules.d.ts +4 -15
- package/lib/cms/modules.js +81 -78
- package/lib/cms/processFieldsJs.js +10 -33
- package/lib/cms/templates.d.ts +43 -3
- package/lib/cms/templates.js +53 -11
- package/lib/cms/uploadFolder.d.ts +3 -14
- package/lib/cms/uploadFolder.js +58 -42
- package/lib/cms/validate.js +1 -1
- package/lib/cms/watch.d.ts +2 -18
- package/lib/cms/watch.js +63 -68
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.d.ts +2 -6
- package/lib/fileManager.js +54 -65
- package/lib/fileMapper.d.ts +4 -15
- package/lib/fileMapper.js +67 -88
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +10 -6
- package/lib/github.d.ts +12 -14
- package/lib/github.js +70 -35
- package/lib/gitignore.d.ts +2 -0
- package/lib/gitignore.js +21 -4
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/{utils → lib}/notify.js +2 -2
- package/lib/oauth.d.ts +2 -5
- package/lib/oauth.js +14 -25
- package/lib/path.d.ts +3 -0
- package/lib/path.js +46 -1
- package/lib/personalAccessKey.d.ts +8 -11
- package/lib/personalAccessKey.js +76 -38
- package/lib/portManager.d.ts +3 -5
- package/lib/portManager.js +18 -6
- package/lib/trackUsage.js +18 -11
- package/lib/urls.js +5 -1
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +24 -0
- package/models/HubSpotHttpError.js +197 -0
- package/models/OAuth2Manager.d.ts +5 -27
- package/models/OAuth2Manager.js +41 -64
- package/package.json +35 -35
- package/types/Accounts.d.ts +103 -3
- package/types/Apps.d.ts +77 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/Build.d.ts +4 -2
- package/types/ComponentStructure.d.ts +30 -10
- package/types/Config.d.ts +19 -2
- package/types/Deploy.d.ts +3 -2
- package/types/DesignManager.d.ts +10 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +9 -5
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +1 -1
- package/types/Files.d.ts +43 -4
- package/types/Functions.d.ts +52 -0
- package/types/Github.d.ts +13 -0
- package/types/Http.d.ts +12 -11
- package/types/Hubdb.d.ts +9 -0
- package/types/MarketplaceValidation.d.ts +7 -3
- package/types/Migration.d.ts +28 -0
- package/types/Migration.js +10 -0
- package/types/Modules.d.ts +11 -0
- package/types/PortManager.d.ts +7 -0
- package/types/Project.d.ts +30 -0
- package/types/ProjectLog.d.ts +9 -0
- package/types/ProjectLog.js +2 -0
- package/types/Sandbox.d.ts +37 -47
- package/types/Schemas.d.ts +56 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/developerTestAccounts.d.ts +13 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +6 -7
- package/utils/PortManagerServer.js +22 -16
- package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
- package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
- package/utils/cms/fieldsJS.d.ts +1 -2
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/utils/git.d.ts +1 -7
- package/utils/git.js +2 -18
- package/errors/apiErrors.d.ts +0 -19
- package/errors/apiErrors.js +0 -179
- package/errors/fileSystemErrors.d.ts +0 -5
- package/errors/fileSystemErrors.js +0 -31
- package/errors/standardErrors.d.ts +0 -27
- package/errors/standardErrors.js +0 -59
- package/lang/lang/en.json +0 -401
- package/lib/logging/git.d.ts +0 -2
- package/lib/logging/git.js +0 -54
- package/lib/logging/logs.d.ts +0 -22
- package/lib/logging/logs.js +0 -86
- package/lib/logging/table.d.ts +0 -3
- package/lib/logging/table.js +0 -47
- package/lib/sandboxes.d.ts +0 -14
- package/lib/sandboxes.js +0 -71
- package/models/HubSpotAuthError.d.ts +0 -12
- package/models/HubSpotAuthError.js +0 -20
- package/types/LogCallbacks.d.ts +0 -7
- package/utils/logger.d.ts +0 -5
- package/utils/logger.js +0 -23
- package/utils/objectUtils.d.ts +0 -8
- package/utils/objectUtils.js +0 -33
- /package/{utils → lib}/escapeRegExp.d.ts +0 -0
- /package/{utils → lib}/escapeRegExp.js +0 -0
- /package/lib/{logging/logger.d.ts → logger.d.ts} +0 -0
- /package/lib/{logging/logger.js → logger.js} +0 -0
- /package/{utils → lib}/notify.d.ts +0 -0
- /package/types/{LogCallbacks.js → Apps.js} +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HubSpotHttpError } from '../models/HubSpotHttpError';
|
|
2
|
+
import { BaseError } from '../types/Error';
|
|
3
|
+
import { FileSystemError } from '../models/FileSystemError';
|
|
4
|
+
export declare function isSpecifiedError(err: unknown, { statusCode, category, subCategory, errorType, code, }: {
|
|
5
|
+
statusCode?: number;
|
|
6
|
+
category?: string;
|
|
7
|
+
subCategory?: string;
|
|
8
|
+
errorType?: string;
|
|
9
|
+
code?: string;
|
|
10
|
+
}): err is HubSpotHttpError;
|
|
11
|
+
export declare function isMissingScopeError(err: unknown): err is HubSpotHttpError;
|
|
12
|
+
export declare function isGatingError(err: unknown): err is HubSpotHttpError;
|
|
13
|
+
export declare function isTimeoutError(err: unknown): err is HubSpotHttpError;
|
|
14
|
+
export declare function isAuthError(err: unknown): err is HubSpotHttpError;
|
|
15
|
+
export declare function isValidationError(err: unknown): boolean;
|
|
16
|
+
export declare function isHubSpotHttpError(error?: unknown): error is HubSpotHttpError;
|
|
17
|
+
export declare function isSystemError(err: unknown): err is BaseError;
|
|
18
|
+
export declare function isFileSystemError(err: unknown): err is FileSystemError;
|
package/errors/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFileSystemError = exports.isSystemError = exports.isHubSpotHttpError = exports.isValidationError = exports.isAuthError = exports.isTimeoutError = exports.isGatingError = exports.isMissingScopeError = exports.isSpecifiedError = void 0;
|
|
4
|
+
const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
|
|
5
|
+
const FileSystemError_1 = require("../models/FileSystemError");
|
|
6
|
+
function isSpecifiedError(err, { statusCode, category, subCategory, errorType, code, }) {
|
|
7
|
+
if (!isHubSpotHttpError(err)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const { data, status, code: actualCode } = err;
|
|
11
|
+
const statusCodeMatchesError = !statusCode || status === statusCode;
|
|
12
|
+
const categoryMatchesError = !category || data?.category === category;
|
|
13
|
+
const subCategoryMatchesError = !subCategory || data?.subCategory === subCategory;
|
|
14
|
+
const errorTypeMatchesError = !errorType || data?.errorType === errorType;
|
|
15
|
+
const codeMatchesError = !code || actualCode === code;
|
|
16
|
+
return (statusCodeMatchesError &&
|
|
17
|
+
categoryMatchesError &&
|
|
18
|
+
subCategoryMatchesError &&
|
|
19
|
+
errorTypeMatchesError &&
|
|
20
|
+
codeMatchesError);
|
|
21
|
+
}
|
|
22
|
+
exports.isSpecifiedError = isSpecifiedError;
|
|
23
|
+
function isMissingScopeError(err) {
|
|
24
|
+
return isSpecifiedError(err, { statusCode: 403, category: 'MISSING_SCOPES' });
|
|
25
|
+
}
|
|
26
|
+
exports.isMissingScopeError = isMissingScopeError;
|
|
27
|
+
function isGatingError(err) {
|
|
28
|
+
return isSpecifiedError(err, { statusCode: 403, category: 'GATED' });
|
|
29
|
+
}
|
|
30
|
+
exports.isGatingError = isGatingError;
|
|
31
|
+
function isTimeoutError(err) {
|
|
32
|
+
return isSpecifiedError(err, { code: 'ETIMEDOUT' });
|
|
33
|
+
}
|
|
34
|
+
exports.isTimeoutError = isTimeoutError;
|
|
35
|
+
function isAuthError(err) {
|
|
36
|
+
return (isSpecifiedError(err, { statusCode: 401 }) ||
|
|
37
|
+
isSpecifiedError(err, { statusCode: 403 }));
|
|
38
|
+
}
|
|
39
|
+
exports.isAuthError = isAuthError;
|
|
40
|
+
function isValidationError(err) {
|
|
41
|
+
return (isHubSpotHttpError(err) &&
|
|
42
|
+
isSpecifiedError(err, { statusCode: 400 }) &&
|
|
43
|
+
!!(err?.data?.message || !!err.data?.errors));
|
|
44
|
+
}
|
|
45
|
+
exports.isValidationError = isValidationError;
|
|
46
|
+
function isHubSpotHttpError(error) {
|
|
47
|
+
return !!error && error instanceof HubSpotHttpError_1.HubSpotHttpError;
|
|
48
|
+
}
|
|
49
|
+
exports.isHubSpotHttpError = isHubSpotHttpError;
|
|
50
|
+
function isSystemError(err) {
|
|
51
|
+
return (err instanceof Error &&
|
|
52
|
+
'errno' in err &&
|
|
53
|
+
err.errno != null &&
|
|
54
|
+
'code' in err &&
|
|
55
|
+
err.code != null &&
|
|
56
|
+
'syscall' in err &&
|
|
57
|
+
err.syscall != null);
|
|
58
|
+
}
|
|
59
|
+
exports.isSystemError = isSystemError;
|
|
60
|
+
function isFileSystemError(err) {
|
|
61
|
+
return err instanceof FileSystemError_1.FileSystemError;
|
|
62
|
+
}
|
|
63
|
+
exports.isFileSystemError = isFileSystemError;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addQueryParams = void 0;
|
|
4
|
+
function addQueryParams(configOptions, queryParams = {}) {
|
|
5
|
+
const { params } = configOptions;
|
|
6
|
+
return {
|
|
7
|
+
...configOptions,
|
|
8
|
+
params: {
|
|
9
|
+
...queryParams,
|
|
10
|
+
...params,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
exports.addQueryParams = addQueryParams;
|
package/http/getAxiosConfig.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpOptions } from '../types/Http';
|
|
2
2
|
import { AxiosRequestConfig } from 'axios';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const USER_AGENTS: {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function getDefaultUserAgentHeader(): {
|
|
4
7
|
'User-Agent': string;
|
|
5
8
|
};
|
|
6
|
-
export declare function getAxiosConfig(options:
|
|
9
|
+
export declare function getAxiosConfig(options: HttpOptions): AxiosRequestConfig;
|
package/http/getAxiosConfig.js
CHANGED
|
@@ -1,21 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAxiosConfig = exports.
|
|
6
|
+
exports.getAxiosConfig = exports.getDefaultUserAgentHeader = exports.USER_AGENTS = void 0;
|
|
4
7
|
const package_json_1 = require("../package.json");
|
|
5
8
|
const config_1 = require("../config");
|
|
6
9
|
const urls_1 = require("../lib/urls");
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
const https_1 = __importDefault(require("https"));
|
|
11
|
+
const http_1 = __importDefault(require("http"));
|
|
12
|
+
// Total number of sockets across all hosts
|
|
13
|
+
const MAX_TOTAL_SOCKETS = 25;
|
|
14
|
+
// Total number of sockets per each host
|
|
15
|
+
const MAX_SOCKETS_PER_HOST = 5;
|
|
16
|
+
const httpAgent = new http_1.default.Agent({
|
|
17
|
+
keepAlive: true,
|
|
18
|
+
maxTotalSockets: MAX_TOTAL_SOCKETS,
|
|
19
|
+
maxSockets: MAX_SOCKETS_PER_HOST,
|
|
20
|
+
});
|
|
21
|
+
const httpsAgent = new https_1.default.Agent({
|
|
22
|
+
keepAlive: true,
|
|
23
|
+
maxTotalSockets: MAX_TOTAL_SOCKETS,
|
|
24
|
+
maxSockets: MAX_SOCKETS_PER_HOST,
|
|
25
|
+
});
|
|
26
|
+
exports.USER_AGENTS = {
|
|
27
|
+
'HubSpot Local Dev Lib': package_json_1.version,
|
|
28
|
+
};
|
|
29
|
+
function getDefaultUserAgentHeader() {
|
|
30
|
+
let userAgentString = '';
|
|
31
|
+
Object.keys(exports.USER_AGENTS).forEach((userAgentKey, i) => {
|
|
32
|
+
userAgentString += `${i > 0 ? ', ' : ''}${userAgentKey}/${exports.USER_AGENTS[userAgentKey]}`;
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
'User-Agent': userAgentString,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.getDefaultUserAgentHeader = getDefaultUserAgentHeader;
|
|
39
|
+
const DEFAULT_TRANSITIONAL = {
|
|
40
|
+
clarifyTimeoutError: true,
|
|
9
41
|
};
|
|
10
42
|
function getAxiosConfig(options) {
|
|
11
|
-
const { env, localHostOverride, ...rest } = options;
|
|
12
|
-
const
|
|
43
|
+
const { env, localHostOverride, headers, ...rest } = options;
|
|
44
|
+
const config = (0, config_1.getAndLoadConfigIfNeeded)();
|
|
45
|
+
let httpTimeout = 15000;
|
|
46
|
+
let httpUseLocalhost = false;
|
|
47
|
+
if (config && config.httpTimeout) {
|
|
48
|
+
httpTimeout = config.httpTimeout;
|
|
49
|
+
}
|
|
50
|
+
if (config && config.httpUseLocalhost) {
|
|
51
|
+
httpUseLocalhost = config.httpUseLocalhost;
|
|
52
|
+
}
|
|
13
53
|
return {
|
|
14
54
|
baseURL: (0, urls_1.getHubSpotApiOrigin)(env, localHostOverride ? false : httpUseLocalhost),
|
|
15
55
|
headers: {
|
|
16
|
-
...
|
|
56
|
+
...getDefaultUserAgentHeader(),
|
|
57
|
+
...(headers || {}),
|
|
17
58
|
},
|
|
18
|
-
timeout: httpTimeout
|
|
59
|
+
timeout: httpTimeout,
|
|
60
|
+
transitional: DEFAULT_TRANSITIONAL,
|
|
61
|
+
httpAgent,
|
|
62
|
+
httpsAgent,
|
|
19
63
|
...rest,
|
|
20
64
|
};
|
|
21
65
|
}
|
package/http/index.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HttpOptions } from '../types/Http';
|
|
3
|
-
|
|
4
|
-
declare function getRequest<T>(accountId: number, options: HttpOptions):
|
|
5
|
-
declare function postRequest<T>(accountId: number, options: HttpOptions):
|
|
6
|
-
declare function putRequest<T>(accountId: number, options: HttpOptions):
|
|
7
|
-
declare function patchRequest<T>(accountId: number, options: HttpOptions):
|
|
8
|
-
declare function deleteRequest<T>(accountId: number, options: HttpOptions):
|
|
9
|
-
declare const
|
|
10
|
-
declare const http: {
|
|
1
|
+
import { AxiosPromise } from 'axios';
|
|
2
|
+
import { HttpOptions, HubSpotPromise } from '../types/Http';
|
|
3
|
+
export declare function addUserAgentHeader(key: string, value: string): void;
|
|
4
|
+
declare function getRequest<T>(accountId: number, options: HttpOptions): HubSpotPromise<T>;
|
|
5
|
+
declare function postRequest<T>(accountId: number, options: HttpOptions): HubSpotPromise<T>;
|
|
6
|
+
declare function putRequest<T>(accountId: number, options: HttpOptions): HubSpotPromise<T>;
|
|
7
|
+
declare function patchRequest<T>(accountId: number, options: HttpOptions): HubSpotPromise<T>;
|
|
8
|
+
declare function deleteRequest<T>(accountId: number, options: HttpOptions): HubSpotPromise<T>;
|
|
9
|
+
export declare const http: {
|
|
11
10
|
get: typeof getRequest;
|
|
12
11
|
post: typeof postRequest;
|
|
13
12
|
put: typeof putRequest;
|
|
14
13
|
patch: typeof patchRequest;
|
|
15
14
|
delete: typeof deleteRequest;
|
|
16
|
-
getOctetStream: (accountId: number, options: HttpOptions, destPath: string
|
|
15
|
+
getOctetStream: (accountId: number, options: HttpOptions, destPath: string) => AxiosPromise<any>;
|
|
17
16
|
};
|
|
18
|
-
export
|
|
17
|
+
export {};
|
package/http/index.js
CHANGED
|
@@ -3,22 +3,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.http = exports.addUserAgentHeader = void 0;
|
|
6
7
|
const path_1 = __importDefault(require("path"));
|
|
7
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
9
|
const content_disposition_1 = __importDefault(require("content-disposition"));
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
11
|
const config_1 = require("../config");
|
|
10
12
|
const getAxiosConfig_1 = require("./getAxiosConfig");
|
|
13
|
+
const addQueryParams_1 = require("./addQueryParams");
|
|
11
14
|
const personalAccessKey_1 = require("../lib/personalAccessKey");
|
|
12
15
|
const oauth_1 = require("../lib/oauth");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
+
const logger_1 = require("../lib/logger");
|
|
17
|
+
const lang_1 = require("../utils/lang");
|
|
18
|
+
const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
|
|
16
19
|
const i18nKey = 'http.index';
|
|
20
|
+
axios_1.default.interceptors.response.use(undefined, error => {
|
|
21
|
+
// Wrap all axios errors in our own Error class. Attach the error
|
|
22
|
+
// as the cause for the new error, so we maintain the stack trace
|
|
23
|
+
return Promise.reject(new HubSpotHttpError_1.HubSpotHttpError(error.message, { cause: error }));
|
|
24
|
+
});
|
|
25
|
+
function addUserAgentHeader(key, value) {
|
|
26
|
+
getAxiosConfig_1.USER_AGENTS[key] = value;
|
|
27
|
+
}
|
|
28
|
+
exports.addUserAgentHeader = addUserAgentHeader;
|
|
17
29
|
async function withOauth(accountId, accountConfig, axiosConfig) {
|
|
18
30
|
const { headers } = axiosConfig;
|
|
19
31
|
const oauth = (0, oauth_1.getOauthManager)(accountId, accountConfig);
|
|
20
32
|
if (!oauth) {
|
|
21
|
-
(0,
|
|
33
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withOauth`, { accountId }));
|
|
22
34
|
}
|
|
23
35
|
const accessToken = await oauth.accessToken();
|
|
24
36
|
return {
|
|
@@ -53,7 +65,7 @@ function withPortalId(portalId, axiosConfig) {
|
|
|
53
65
|
async function withAuth(accountId, options) {
|
|
54
66
|
const accountConfig = (0, config_1.getAccountConfig)(accountId);
|
|
55
67
|
if (!accountConfig) {
|
|
56
|
-
(0,
|
|
68
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withAuth`, { accountId }));
|
|
57
69
|
}
|
|
58
70
|
const { env, authType, apiKey } = accountConfig;
|
|
59
71
|
const axiosConfig = withPortalId(accountId, (0, getAxiosConfig_1.getAxiosConfig)({ env, ...options }));
|
|
@@ -72,49 +84,32 @@ async function withAuth(accountId, options) {
|
|
|
72
84
|
},
|
|
73
85
|
};
|
|
74
86
|
}
|
|
75
|
-
function addQueryParams(configOptions, queryParams = {}) {
|
|
76
|
-
const { params } = configOptions;
|
|
77
|
-
return {
|
|
78
|
-
...configOptions,
|
|
79
|
-
params: {
|
|
80
|
-
...queryParams,
|
|
81
|
-
...params,
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
87
|
async function getRequest(accountId, options) {
|
|
86
|
-
const {
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
return data;
|
|
88
|
+
const { params, ...rest } = options;
|
|
89
|
+
const optionsWithParams = (0, addQueryParams_1.addQueryParams)(rest, params);
|
|
90
|
+
const requestConfig = await withAuth(accountId, optionsWithParams);
|
|
91
|
+
return (0, axios_1.default)(requestConfig);
|
|
91
92
|
}
|
|
92
93
|
async function postRequest(accountId, options) {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
return data;
|
|
94
|
+
const requestConfig = await withAuth(accountId, options);
|
|
95
|
+
return (0, axios_1.default)({ ...requestConfig, method: 'post' });
|
|
96
96
|
}
|
|
97
97
|
async function putRequest(accountId, options) {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
return data;
|
|
98
|
+
const requestConfig = await withAuth(accountId, options);
|
|
99
|
+
return (0, axios_1.default)({ ...requestConfig, method: 'put' });
|
|
101
100
|
}
|
|
102
101
|
async function patchRequest(accountId, options) {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
return data;
|
|
102
|
+
const requestConfig = await withAuth(accountId, options);
|
|
103
|
+
return (0, axios_1.default)({ ...requestConfig, method: 'patch' });
|
|
106
104
|
}
|
|
107
105
|
async function deleteRequest(accountId, options) {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
return data;
|
|
106
|
+
const requestConfig = await withAuth(accountId, options);
|
|
107
|
+
return (0, axios_1.default)({ ...requestConfig, method: 'delete' });
|
|
111
108
|
}
|
|
112
|
-
const getRequestStreamCallbackKeys = ['onWrite'];
|
|
113
109
|
function createGetRequestStream(contentType) {
|
|
114
|
-
return async (accountId, options, destPath
|
|
115
|
-
const {
|
|
116
|
-
const axiosConfig = addQueryParams(rest,
|
|
117
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
110
|
+
return async (accountId, options, destPath) => {
|
|
111
|
+
const { params, ...rest } = options;
|
|
112
|
+
const axiosConfig = (0, addQueryParams_1.addQueryParams)(rest, params);
|
|
118
113
|
// eslint-disable-next-line no-async-promise-executor
|
|
119
114
|
return new Promise(async (resolve, reject) => {
|
|
120
115
|
try {
|
|
@@ -151,9 +146,9 @@ function createGetRequestStream(contentType) {
|
|
|
151
146
|
reject(err);
|
|
152
147
|
});
|
|
153
148
|
writeStream.on('close', async () => {
|
|
154
|
-
logger(
|
|
149
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createGetRequestStream.onWrite`, {
|
|
155
150
|
filepath,
|
|
156
|
-
});
|
|
151
|
+
}));
|
|
157
152
|
resolve(res);
|
|
158
153
|
});
|
|
159
154
|
}
|
|
@@ -168,7 +163,7 @@ function createGetRequestStream(contentType) {
|
|
|
168
163
|
};
|
|
169
164
|
}
|
|
170
165
|
const getOctetStream = createGetRequestStream('application/octet-stream');
|
|
171
|
-
|
|
166
|
+
exports.http = {
|
|
172
167
|
get: getRequest,
|
|
173
168
|
post: postRequest,
|
|
174
169
|
put: putRequest,
|
|
@@ -176,4 +171,3 @@ const http = {
|
|
|
176
171
|
delete: deleteRequest,
|
|
177
172
|
getOctetStream,
|
|
178
173
|
};
|
|
179
|
-
exports.default = http;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HttpOptions, HubSpotPromise } from '../types/Http';
|
|
2
|
+
declare function getRequest<T>(options: HttpOptions): HubSpotPromise<T>;
|
|
3
|
+
declare function postRequest<T>(options: HttpOptions): HubSpotPromise<T>;
|
|
4
|
+
declare function putRequest<T>(options: HttpOptions): HubSpotPromise<T>;
|
|
5
|
+
declare function patchRequest<T>(options: HttpOptions): HubSpotPromise<T>;
|
|
6
|
+
declare function deleteRequest<T>(options: HttpOptions): HubSpotPromise<T>;
|
|
7
|
+
export declare const http: {
|
|
8
|
+
get: typeof getRequest;
|
|
9
|
+
post: typeof postRequest;
|
|
10
|
+
put: typeof putRequest;
|
|
11
|
+
patch: typeof patchRequest;
|
|
12
|
+
delete: typeof deleteRequest;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
package/http/unauthed.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.http = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const getAxiosConfig_1 = require("./getAxiosConfig");
|
|
9
|
+
const addQueryParams_1 = require("./addQueryParams");
|
|
10
|
+
async function getRequest(options) {
|
|
11
|
+
const { params, ...rest } = options;
|
|
12
|
+
const optionsWithParams = (0, addQueryParams_1.addQueryParams)(rest, params);
|
|
13
|
+
const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(optionsWithParams);
|
|
14
|
+
return (0, axios_1.default)(requestConfig);
|
|
15
|
+
}
|
|
16
|
+
async function postRequest(options) {
|
|
17
|
+
const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
|
|
18
|
+
return (0, axios_1.default)({ ...requestConfig, method: 'post' });
|
|
19
|
+
}
|
|
20
|
+
async function putRequest(options) {
|
|
21
|
+
const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
|
|
22
|
+
return (0, axios_1.default)({ ...requestConfig, method: 'put' });
|
|
23
|
+
}
|
|
24
|
+
async function patchRequest(options) {
|
|
25
|
+
const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
|
|
26
|
+
return (0, axios_1.default)({ ...requestConfig, method: 'patch' });
|
|
27
|
+
}
|
|
28
|
+
async function deleteRequest(options) {
|
|
29
|
+
const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
|
|
30
|
+
return (0, axios_1.default)({ ...requestConfig, method: 'delete' });
|
|
31
|
+
}
|
|
32
|
+
exports.http = {
|
|
33
|
+
get: getRequest,
|
|
34
|
+
post: postRequest,
|
|
35
|
+
put: putRequest,
|
|
36
|
+
patch: patchRequest,
|
|
37
|
+
delete: deleteRequest,
|
|
38
|
+
};
|