@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.
Files changed (189) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +17 -0
  3. package/api/appsDev.d.ts +6 -0
  4. package/api/appsDev.js +29 -0
  5. package/api/customObjects.d.ts +8 -7
  6. package/api/customObjects.js +13 -16
  7. package/api/designManager.d.ts +4 -13
  8. package/api/designManager.js +6 -9
  9. package/api/developerTestAccounts.d.ts +7 -0
  10. package/api/developerTestAccounts.js +48 -0
  11. package/api/fileManager.d.ts +5 -4
  12. package/api/fileManager.js +11 -11
  13. package/api/fileMapper.d.ts +8 -7
  14. package/api/fileMapper.js +17 -17
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/functions.d.ts +7 -4
  18. package/api/functions.js +22 -11
  19. package/api/github.d.ts +7 -9
  20. package/api/github.js +31 -13
  21. package/api/hubdb.d.ts +11 -10
  22. package/api/hubdb.js +28 -22
  23. package/api/lighthouseScore.d.ts +4 -4
  24. package/api/lighthouseScore.js +9 -12
  25. package/api/localDevAuth.d.ts +8 -16
  26. package/api/localDevAuth.js +34 -13
  27. package/api/marketplaceValidation.d.ts +4 -4
  28. package/api/marketplaceValidation.js +8 -11
  29. package/api/projects.d.ts +31 -24
  30. package/api/projects.js +164 -44
  31. package/api/sandboxHubs.d.ts +6 -4
  32. package/api/sandboxHubs.js +10 -11
  33. package/api/sandboxSync.d.ts +4 -4
  34. package/api/sandboxSync.js +4 -13
  35. package/api/secrets.d.ts +6 -8
  36. package/api/secrets.js +9 -12
  37. package/api/validateHubl.d.ts +2 -1
  38. package/api/validateHubl.js +3 -6
  39. package/config/CLIConfiguration.d.ts +15 -11
  40. package/config/CLIConfiguration.js +175 -90
  41. package/config/configFile.js +13 -21
  42. package/config/configUtils.d.ts +2 -21
  43. package/config/configUtils.js +5 -4
  44. package/config/config_DEPRECATED.d.ts +6 -8
  45. package/config/config_DEPRECATED.js +79 -25
  46. package/config/environment.js +5 -4
  47. package/config/getAccountIdentifier.d.ts +2 -0
  48. package/config/getAccountIdentifier.js +15 -0
  49. package/config/index.d.ts +13 -8
  50. package/config/index.js +97 -57
  51. package/config/migrate.d.ts +20 -0
  52. package/config/migrate.js +150 -0
  53. package/constants/config.d.ts +25 -1
  54. package/constants/config.js +32 -3
  55. package/constants/environments.d.ts +1 -0
  56. package/constants/environments.js +1 -0
  57. package/constants/extensions.d.ts +2 -0
  58. package/constants/extensions.js +3 -1
  59. package/constants/files.d.ts +2 -2
  60. package/constants/files.js +3 -3
  61. package/errors/errors_DEPRECATED.d.ts +1 -5
  62. package/errors/errors_DEPRECATED.js +2 -2
  63. package/errors/index.d.ts +18 -0
  64. package/errors/index.js +63 -0
  65. package/http/addQueryParams.d.ts +2 -0
  66. package/http/addQueryParams.js +14 -0
  67. package/http/getAxiosConfig.d.ts +6 -3
  68. package/http/getAxiosConfig.js +51 -7
  69. package/http/index.d.ts +11 -12
  70. package/http/index.js +35 -41
  71. package/http/unauthed.d.ts +14 -0
  72. package/http/unauthed.js +38 -0
  73. package/lang/en.json +384 -386
  74. package/lib/archive.d.ts +2 -8
  75. package/lib/archive.js +34 -30
  76. package/lib/cms/functions.d.ts +7 -12
  77. package/lib/cms/functions.js +49 -51
  78. package/lib/cms/handleFieldsJS.js +16 -14
  79. package/lib/cms/modules.d.ts +4 -15
  80. package/lib/cms/modules.js +81 -78
  81. package/lib/cms/processFieldsJs.js +10 -33
  82. package/lib/cms/templates.d.ts +43 -3
  83. package/lib/cms/templates.js +53 -11
  84. package/lib/cms/uploadFolder.d.ts +3 -14
  85. package/lib/cms/uploadFolder.js +58 -42
  86. package/lib/cms/validate.js +1 -1
  87. package/lib/cms/watch.d.ts +2 -18
  88. package/lib/cms/watch.js +63 -68
  89. package/lib/customObjects.js +4 -15
  90. package/lib/fileManager.d.ts +2 -6
  91. package/lib/fileManager.js +54 -65
  92. package/lib/fileMapper.d.ts +4 -15
  93. package/lib/fileMapper.js +67 -88
  94. package/lib/fs.d.ts +1 -1
  95. package/lib/fs.js +10 -6
  96. package/lib/github.d.ts +12 -14
  97. package/lib/github.js +70 -35
  98. package/lib/gitignore.d.ts +2 -0
  99. package/lib/gitignore.js +21 -4
  100. package/lib/hubdb.d.ts +3 -2
  101. package/lib/hubdb.js +11 -9
  102. package/{utils → lib}/notify.js +2 -2
  103. package/lib/oauth.d.ts +2 -5
  104. package/lib/oauth.js +14 -25
  105. package/lib/path.d.ts +3 -0
  106. package/lib/path.js +46 -1
  107. package/lib/personalAccessKey.d.ts +8 -11
  108. package/lib/personalAccessKey.js +76 -38
  109. package/lib/portManager.d.ts +3 -5
  110. package/lib/portManager.js +18 -6
  111. package/lib/trackUsage.js +18 -11
  112. package/lib/urls.js +5 -1
  113. package/models/FileSystemError.d.ts +6 -0
  114. package/models/FileSystemError.js +47 -0
  115. package/models/HubSpotHttpError.d.ts +24 -0
  116. package/models/HubSpotHttpError.js +197 -0
  117. package/models/OAuth2Manager.d.ts +5 -27
  118. package/models/OAuth2Manager.js +41 -64
  119. package/package.json +35 -35
  120. package/types/Accounts.d.ts +103 -3
  121. package/types/Apps.d.ts +77 -0
  122. package/types/Archive.d.ts +9 -0
  123. package/types/Archive.js +2 -0
  124. package/types/Build.d.ts +4 -2
  125. package/types/ComponentStructure.d.ts +30 -10
  126. package/types/Config.d.ts +19 -2
  127. package/types/Deploy.d.ts +3 -2
  128. package/types/DesignManager.d.ts +10 -0
  129. package/types/DesignManager.js +2 -0
  130. package/types/Error.d.ts +9 -5
  131. package/types/FieldsJS.d.ts +1 -0
  132. package/types/FieldsJS.js +2 -0
  133. package/types/FileManager.d.ts +1 -1
  134. package/types/Files.d.ts +43 -4
  135. package/types/Functions.d.ts +52 -0
  136. package/types/Github.d.ts +13 -0
  137. package/types/Http.d.ts +12 -11
  138. package/types/Hubdb.d.ts +9 -0
  139. package/types/MarketplaceValidation.d.ts +7 -3
  140. package/types/Migration.d.ts +28 -0
  141. package/types/Migration.js +10 -0
  142. package/types/Modules.d.ts +11 -0
  143. package/types/PortManager.d.ts +7 -0
  144. package/types/Project.d.ts +30 -0
  145. package/types/ProjectLog.d.ts +9 -0
  146. package/types/ProjectLog.js +2 -0
  147. package/types/Sandbox.d.ts +37 -47
  148. package/types/Schemas.d.ts +56 -0
  149. package/types/Secrets.d.ts +3 -0
  150. package/types/Secrets.js +2 -0
  151. package/types/developerTestAccounts.d.ts +13 -0
  152. package/types/developerTestAccounts.js +2 -0
  153. package/utils/PortManagerServer.d.ts +6 -7
  154. package/utils/PortManagerServer.js +22 -16
  155. package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
  156. package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
  157. package/utils/cms/fieldsJS.d.ts +1 -2
  158. package/utils/cms/modules.js +2 -2
  159. package/utils/detectPort.js +3 -3
  160. package/utils/git.d.ts +1 -7
  161. package/utils/git.js +2 -18
  162. package/errors/apiErrors.d.ts +0 -19
  163. package/errors/apiErrors.js +0 -179
  164. package/errors/fileSystemErrors.d.ts +0 -5
  165. package/errors/fileSystemErrors.js +0 -31
  166. package/errors/standardErrors.d.ts +0 -27
  167. package/errors/standardErrors.js +0 -59
  168. package/lang/lang/en.json +0 -401
  169. package/lib/logging/git.d.ts +0 -2
  170. package/lib/logging/git.js +0 -54
  171. package/lib/logging/logs.d.ts +0 -22
  172. package/lib/logging/logs.js +0 -86
  173. package/lib/logging/table.d.ts +0 -3
  174. package/lib/logging/table.js +0 -47
  175. package/lib/sandboxes.d.ts +0 -14
  176. package/lib/sandboxes.js +0 -71
  177. package/models/HubSpotAuthError.d.ts +0 -12
  178. package/models/HubSpotAuthError.js +0 -20
  179. package/types/LogCallbacks.d.ts +0 -7
  180. package/utils/logger.d.ts +0 -5
  181. package/utils/logger.js +0 -23
  182. package/utils/objectUtils.d.ts +0 -8
  183. package/utils/objectUtils.js +0 -33
  184. /package/{utils → lib}/escapeRegExp.d.ts +0 -0
  185. /package/{utils → lib}/escapeRegExp.js +0 -0
  186. /package/lib/{logging/logger.d.ts → logger.d.ts} +0 -0
  187. /package/lib/{logging/logger.js → logger.js} +0 -0
  188. /package/{utils → lib}/notify.d.ts +0 -0
  189. /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;
@@ -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,2 @@
1
+ import { HttpOptions, QueryParams } from '../types/Http';
2
+ export declare function addQueryParams(configOptions: HttpOptions, queryParams?: QueryParams): HttpOptions;
@@ -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;
@@ -1,6 +1,9 @@
1
- import { AxiosConfigOptions } from '../types/Http';
1
+ import { HttpOptions } from '../types/Http';
2
2
  import { AxiosRequestConfig } from 'axios';
3
- export declare const DEFAULT_USER_AGENT_HEADERS: {
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: AxiosConfigOptions): AxiosRequestConfig;
9
+ export declare function getAxiosConfig(options: HttpOptions): AxiosRequestConfig;
@@ -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.DEFAULT_USER_AGENT_HEADERS = void 0;
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
- exports.DEFAULT_USER_AGENT_HEADERS = {
8
- 'User-Agent': `HubSpot Local Dev Lib/${package_json_1.version}`,
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 { httpTimeout, httpUseLocalhost } = (0, config_1.getAndLoadConfigIfNeeded)();
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
- ...exports.DEFAULT_USER_AGENT_HEADERS,
56
+ ...getDefaultUserAgentHeader(),
57
+ ...(headers || {}),
17
58
  },
18
- timeout: httpTimeout || 15000,
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 { LogCallbacksArg } from '../types/LogCallbacks';
2
- import { HttpOptions } from '../types/Http';
3
- import { AxiosResponse } from 'axios';
4
- declare function getRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
5
- declare function postRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
6
- declare function putRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
7
- declare function patchRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
8
- declare function deleteRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
9
- declare const getRequestStreamCallbackKeys: readonly ["onWrite"];
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, logCallbacks?: LogCallbacksArg<typeof getRequestStreamCallbackKeys>) => Promise<AxiosResponse>;
15
+ getOctetStream: (accountId: number, options: HttpOptions, destPath: string) => AxiosPromise<any>;
17
16
  };
18
- export default http;
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 standardErrors_1 = require("../errors/standardErrors");
14
- const logger_1 = require("../utils/logger");
15
- const axios_1 = __importDefault(require("axios"));
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, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.withOauth`, { accountId });
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, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.withAuth`, { accountId });
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 { query, ...rest } = options;
87
- const axiosConfig = addQueryParams(rest, query);
88
- const configWithAuth = await withAuth(accountId, axiosConfig);
89
- const { data } = await (0, axios_1.default)(configWithAuth);
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 configWithAuth = await withAuth(accountId, options);
94
- const { data } = await (0, axios_1.default)({ ...configWithAuth, method: 'post' });
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 configWithAuth = await withAuth(accountId, options);
99
- const { data } = await (0, axios_1.default)({ ...configWithAuth, method: 'put' });
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 configWithAuth = await withAuth(accountId, options);
104
- const { data } = await (0, axios_1.default)({ ...configWithAuth, method: 'put' });
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 configWithAuth = await withAuth(accountId, options);
109
- const { data } = await (0, axios_1.default)({ ...configWithAuth, method: 'delete' });
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, logCallbacks) => {
115
- const { query, ...rest } = options;
116
- const axiosConfig = addQueryParams(rest, query);
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('onWrite', `${i18nKey}.createGetRequestStream.onWrite`, {
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
- const http = {
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 {};
@@ -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
+ };