@hubspot/local-dev-lib 0.0.1-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 (230) 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 -0
  6. package/api/customObjects.js +45 -0
  7. package/api/designManager.d.ts +5 -0
  8. package/api/designManager.js +18 -0
  9. package/api/developerTestAccounts.d.ts +7 -0
  10. package/api/developerTestAccounts.js +48 -0
  11. package/api/fileManager.d.ts +6 -0
  12. package/api/fileManager.js +63 -0
  13. package/api/fileMapper.d.ts +12 -0
  14. package/api/fileMapper.js +106 -0
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/functions.d.ts +8 -0
  18. package/api/functions.js +43 -0
  19. package/api/github.d.ts +11 -0
  20. package/api/github.js +71 -0
  21. package/api/hubdb.d.ts +12 -0
  22. package/api/hubdb.js +67 -0
  23. package/api/lighthouseScore.d.ts +6 -0
  24. package/api/lighthouseScore.js +26 -0
  25. package/api/localDevAuth.d.ts +8 -0
  26. package/api/localDevAuth.js +53 -0
  27. package/api/marketplaceValidation.d.ts +6 -0
  28. package/api/marketplaceValidation.js +26 -0
  29. package/api/projects.d.ts +40 -0
  30. package/api/projects.js +216 -0
  31. package/api/sandboxHubs.d.ts +7 -0
  32. package/api/sandboxHubs.js +49 -0
  33. package/api/sandboxSync.d.ts +4 -0
  34. package/api/sandboxSync.js +26 -0
  35. package/api/secrets.d.ts +6 -0
  36. package/api/secrets.js +37 -0
  37. package/api/validateHubl.d.ts +3 -0
  38. package/api/validateHubl.js +15 -0
  39. package/config/CLIConfiguration.d.ts +62 -0
  40. package/config/CLIConfiguration.js +467 -0
  41. package/config/configFile.d.ts +21 -0
  42. package/config/configFile.js +102 -0
  43. package/config/configUtils.d.ts +5 -0
  44. package/config/configUtils.js +87 -0
  45. package/config/config_DEPRECATED.d.ts +75 -0
  46. package/config/config_DEPRECATED.js +678 -0
  47. package/config/environment.d.ts +2 -0
  48. package/config/environment.js +60 -0
  49. package/config/getAccountIdentifier.d.ts +2 -0
  50. package/config/getAccountIdentifier.js +15 -0
  51. package/config/index.d.ts +41 -0
  52. package/config/index.js +260 -0
  53. package/constants/api.d.ts +15 -0
  54. package/constants/api.js +18 -0
  55. package/constants/auth.d.ts +37 -0
  56. package/constants/auth.js +38 -0
  57. package/constants/config.d.ts +18 -0
  58. package/constants/config.js +22 -0
  59. package/constants/environments.d.ts +15 -0
  60. package/constants/environments.js +18 -0
  61. package/constants/extensions.d.ts +6 -0
  62. package/constants/extensions.js +28 -0
  63. package/constants/files.d.ts +21 -0
  64. package/constants/files.js +24 -0
  65. package/constants/ports.d.ts +3 -0
  66. package/constants/ports.js +6 -0
  67. package/enums/build.d.ts +36 -0
  68. package/enums/build.js +39 -0
  69. package/enums/deploy.d.ts +11 -0
  70. package/enums/deploy.js +14 -0
  71. package/enums/project.d.ts +6 -0
  72. package/enums/project.js +9 -0
  73. package/errors/errors_DEPRECATED.d.ts +3 -0
  74. package/errors/errors_DEPRECATED.js +60 -0
  75. package/errors/index.d.ts +18 -0
  76. package/errors/index.js +63 -0
  77. package/http/addQueryParams.d.ts +2 -0
  78. package/http/addQueryParams.js +14 -0
  79. package/http/getAxiosConfig.d.ts +9 -0
  80. package/http/getAxiosConfig.js +66 -0
  81. package/http/index.d.ts +17 -0
  82. package/http/index.js +173 -0
  83. package/http/unauthed.d.ts +15 -0
  84. package/http/unauthed.js +38 -0
  85. package/lang/en.json +389 -0
  86. package/lib/archive.d.ts +3 -0
  87. package/lib/archive.js +117 -0
  88. package/lib/cms/functions.d.ts +8 -0
  89. package/lib/cms/functions.js +181 -0
  90. package/lib/cms/handleFieldsJS.d.ts +33 -0
  91. package/lib/cms/handleFieldsJS.js +148 -0
  92. package/lib/cms/modules.d.ts +14 -0
  93. package/lib/cms/modules.js +186 -0
  94. package/lib/cms/processFieldsJs.d.ts +1 -0
  95. package/lib/cms/processFieldsJs.js +97 -0
  96. package/lib/cms/templates.d.ts +65 -0
  97. package/lib/cms/templates.js +107 -0
  98. package/lib/cms/themes.d.ts +2 -0
  99. package/lib/cms/themes.js +34 -0
  100. package/lib/cms/uploadFolder.d.ts +7 -0
  101. package/lib/cms/uploadFolder.js +202 -0
  102. package/lib/cms/validate.d.ts +2 -0
  103. package/lib/cms/validate.js +40 -0
  104. package/lib/cms/watch.d.ts +4 -0
  105. package/lib/cms/watch.js +201 -0
  106. package/lib/customObjects.d.ts +5 -0
  107. package/lib/customObjects.js +42 -0
  108. package/lib/environment.d.ts +2 -0
  109. package/lib/environment.js +16 -0
  110. package/lib/escapeRegExp.d.ts +1 -0
  111. package/lib/escapeRegExp.js +7 -0
  112. package/lib/fileManager.d.ts +2 -0
  113. package/lib/fileManager.js +184 -0
  114. package/lib/fileMapper.d.ts +18 -0
  115. package/lib/fileMapper.js +317 -0
  116. package/lib/fs.d.ts +4 -0
  117. package/lib/fs.js +71 -0
  118. package/lib/github.d.ts +8 -0
  119. package/lib/github.js +167 -0
  120. package/lib/gitignore.d.ts +3 -0
  121. package/lib/gitignore.js +49 -0
  122. package/lib/hubdb.d.ts +17 -0
  123. package/lib/hubdb.js +133 -0
  124. package/lib/ignoreRules.d.ts +3 -0
  125. package/lib/ignoreRules.js +69 -0
  126. package/lib/logger.d.ts +56 -0
  127. package/lib/logger.js +146 -0
  128. package/lib/notify.d.ts +1 -0
  129. package/lib/notify.js +43 -0
  130. package/lib/oauth.d.ts +4 -0
  131. package/lib/oauth.js +34 -0
  132. package/lib/path.d.ts +14 -0
  133. package/lib/path.js +134 -0
  134. package/lib/personalAccessKey.d.ts +10 -0
  135. package/lib/personalAccessKey.js +163 -0
  136. package/lib/portManager.d.ts +10 -0
  137. package/lib/portManager.js +46 -0
  138. package/lib/text.d.ts +2 -0
  139. package/lib/text.js +24 -0
  140. package/lib/trackUsage.d.ts +1 -0
  141. package/lib/trackUsage.js +63 -0
  142. package/lib/urls.d.ts +2 -0
  143. package/lib/urls.js +24 -0
  144. package/models/FileSystemError.d.ts +6 -0
  145. package/models/FileSystemError.js +47 -0
  146. package/models/HubSpotHttpError.d.ts +24 -0
  147. package/models/HubSpotHttpError.js +197 -0
  148. package/models/OAuth2Manager.d.ts +12 -0
  149. package/models/OAuth2Manager.js +105 -0
  150. package/package.json +81 -0
  151. package/types/Accounts.d.ts +178 -0
  152. package/types/Accounts.js +2 -0
  153. package/types/Activity.d.ts +20 -0
  154. package/types/Activity.js +2 -0
  155. package/types/Api.d.ts +2 -0
  156. package/types/Api.js +2 -0
  157. package/types/Apps.d.ts +77 -0
  158. package/types/Apps.js +2 -0
  159. package/types/Archive.d.ts +9 -0
  160. package/types/Archive.js +2 -0
  161. package/types/Build.d.ts +41 -0
  162. package/types/Build.js +2 -0
  163. package/types/CLIOptions.d.ts +8 -0
  164. package/types/CLIOptions.js +2 -0
  165. package/types/ComponentStructure.d.ts +40 -0
  166. package/types/ComponentStructure.js +2 -0
  167. package/types/Config.d.ts +37 -0
  168. package/types/Config.js +2 -0
  169. package/types/Deploy.d.ts +42 -0
  170. package/types/Deploy.js +2 -0
  171. package/types/DesignManager.d.ts +10 -0
  172. package/types/DesignManager.js +2 -0
  173. package/types/Error.d.ts +37 -0
  174. package/types/Error.js +2 -0
  175. package/types/FieldsJS.d.ts +1 -0
  176. package/types/FieldsJS.js +2 -0
  177. package/types/FileManager.d.ts +71 -0
  178. package/types/FileManager.js +2 -0
  179. package/types/Files.d.ts +79 -0
  180. package/types/Files.js +2 -0
  181. package/types/Functions.d.ts +66 -0
  182. package/types/Functions.js +2 -0
  183. package/types/Github.d.ts +76 -0
  184. package/types/Github.js +2 -0
  185. package/types/Http.d.ts +29 -0
  186. package/types/Http.js +2 -0
  187. package/types/Hubdb.d.ts +109 -0
  188. package/types/Hubdb.js +2 -0
  189. package/types/HublValidation.d.ts +59 -0
  190. package/types/HublValidation.js +2 -0
  191. package/types/Lang.d.ts +10 -0
  192. package/types/Lang.js +2 -0
  193. package/types/Lighthouse.d.ts +25 -0
  194. package/types/Lighthouse.js +2 -0
  195. package/types/MarketplaceValidation.d.ts +28 -0
  196. package/types/MarketplaceValidation.js +2 -0
  197. package/types/Migration.d.ts +28 -0
  198. package/types/Migration.js +10 -0
  199. package/types/Modules.d.ts +16 -0
  200. package/types/Modules.js +2 -0
  201. package/types/PortManager.d.ts +11 -0
  202. package/types/PortManager.js +2 -0
  203. package/types/Project.d.ts +42 -0
  204. package/types/Project.js +2 -0
  205. package/types/ProjectLog.d.ts +9 -0
  206. package/types/ProjectLog.js +2 -0
  207. package/types/Sandbox.d.ts +155 -0
  208. package/types/Sandbox.js +2 -0
  209. package/types/Schemas.d.ts +39 -0
  210. package/types/Schemas.js +2 -0
  211. package/types/Secrets.d.ts +3 -0
  212. package/types/Secrets.js +2 -0
  213. package/types/Utils.d.ts +6 -0
  214. package/types/Utils.js +2 -0
  215. package/types/developerTestAccounts.d.ts +12 -0
  216. package/types/developerTestAccounts.js +2 -0
  217. package/utils/PortManagerServer.d.ts +26 -0
  218. package/utils/PortManagerServer.js +158 -0
  219. package/utils/accounts.d.ts +4 -0
  220. package/utils/accounts.js +28 -0
  221. package/utils/cms/fieldsJS.d.ts +2 -0
  222. package/utils/cms/fieldsJS.js +18 -0
  223. package/utils/cms/modules.d.ts +4 -0
  224. package/utils/cms/modules.js +54 -0
  225. package/utils/detectPort.d.ts +1 -0
  226. package/utils/detectPort.js +102 -0
  227. package/utils/git.d.ts +3 -0
  228. package/utils/git.js +71 -0
  229. package/utils/lang.d.ts +6 -0
  230. package/utils/lang.js +88 -0
@@ -0,0 +1,36 @@
1
+ export declare const BUILD_STATUS: {
2
+ readonly BUILDING: "BUILDING";
3
+ readonly FAILURE: "FAILURE";
4
+ readonly PREPARING: "PREPARING";
5
+ readonly PENDING: "PENDING";
6
+ readonly SUCCESS: "SUCCESS";
7
+ };
8
+ export declare const SUBBUILD_TYPES: {
9
+ readonly APP: "APP";
10
+ readonly PRIVATE_APP: "PRIVATE_APP";
11
+ readonly THEME: "THEME";
12
+ readonly REACT_THEME: "REACT_THEME";
13
+ readonly NO_SUBBUILDS: "NO_SUBBUILDS";
14
+ };
15
+ export declare const DEPLOYABLE_STATES: {
16
+ DEPLOYABLE: string;
17
+ DEPRECATED: string;
18
+ };
19
+ export declare const COMPONENT_TYPES: {
20
+ readonly APP: "APP";
21
+ readonly PRIVATE_APP: "PRIVATE_APP";
22
+ readonly THEME: "THEME";
23
+ readonly REACT_THEME: "REACT_THEME";
24
+ };
25
+ export declare const SUBCOMPONENT_TYPES: {
26
+ readonly APP_ID: "APP_ID";
27
+ readonly PACKAGE_LOCK_FILE: "PACKAGE_LOCK_FILE";
28
+ readonly CRM_CARD_V2: "CRM_CARD_V2";
29
+ readonly CARD_V2: "CARD_V2";
30
+ readonly SERVERLESS_PKG: "SERVERLESS_PKG";
31
+ readonly SERVERLESS_ROUTE: "SERVERLESS_ROUTE";
32
+ readonly SERVERLESS_FUNCTION: "SERVERLESS_FUNCTION";
33
+ readonly APP_FUNCTION: "APP_FUNCTION";
34
+ readonly AUTOMATION_ACTION: "AUTOMATION_ACTION";
35
+ readonly REACT_EXTENSION: "REACT_EXTENSION";
36
+ };
package/enums/build.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUBCOMPONENT_TYPES = exports.COMPONENT_TYPES = exports.DEPLOYABLE_STATES = exports.SUBBUILD_TYPES = exports.BUILD_STATUS = void 0;
4
+ exports.BUILD_STATUS = {
5
+ BUILDING: 'BUILDING',
6
+ FAILURE: 'FAILURE',
7
+ PREPARING: 'PREPARING',
8
+ PENDING: 'PENDING',
9
+ SUCCESS: 'SUCCESS',
10
+ };
11
+ exports.SUBBUILD_TYPES = {
12
+ APP: 'APP',
13
+ PRIVATE_APP: 'PRIVATE_APP',
14
+ THEME: 'THEME',
15
+ REACT_THEME: 'REACT_THEME',
16
+ NO_SUBBUILDS: 'NO_SUBBUILDS',
17
+ };
18
+ exports.DEPLOYABLE_STATES = {
19
+ DEPLOYABLE: 'DEPLOYABLE',
20
+ DEPRECATED: 'DEPRECATED_APP_NON_SUBCOMPONENT',
21
+ };
22
+ exports.COMPONENT_TYPES = {
23
+ APP: 'APP',
24
+ PRIVATE_APP: 'PRIVATE_APP',
25
+ THEME: 'THEME',
26
+ REACT_THEME: 'REACT_THEME',
27
+ };
28
+ exports.SUBCOMPONENT_TYPES = {
29
+ APP_ID: 'APP_ID',
30
+ PACKAGE_LOCK_FILE: 'PACKAGE_LOCK_FILE',
31
+ CRM_CARD_V2: 'CRM_CARD_V2',
32
+ CARD_V2: 'CARD_V2',
33
+ SERVERLESS_PKG: 'SERVERLESS_PKG',
34
+ SERVERLESS_ROUTE: 'SERVERLESS_ROUTE',
35
+ SERVERLESS_FUNCTION: 'SERVERLESS_FUNCTION',
36
+ APP_FUNCTION: 'APP_FUNCTION',
37
+ AUTOMATION_ACTION: 'AUTOMATION_ACTION',
38
+ REACT_EXTENSION: 'REACT_EXTENSION',
39
+ };
@@ -0,0 +1,11 @@
1
+ export declare const DEPLOY_STATUS: {
2
+ readonly DEPLOYING: "DEPLOYING";
3
+ readonly FAILURE: "FAILURE";
4
+ readonly PENDING: "PENDING";
5
+ readonly SUCCESS: "SUCCESS";
6
+ readonly FINISHED: "FINISHED";
7
+ };
8
+ export declare const DEPLOY_ACTION: {
9
+ REMOVE: string;
10
+ INSTALL: string;
11
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEPLOY_ACTION = exports.DEPLOY_STATUS = void 0;
4
+ exports.DEPLOY_STATUS = {
5
+ DEPLOYING: 'DEPLOYING',
6
+ FAILURE: 'FAILURE',
7
+ PENDING: 'PENDING',
8
+ SUCCESS: 'SUCCESS',
9
+ FINISHED: 'FINISHED',
10
+ };
11
+ exports.DEPLOY_ACTION = {
12
+ REMOVE: 'REMOVE',
13
+ INSTALL: 'INSTALL',
14
+ };
@@ -0,0 +1,6 @@
1
+ export declare const ACTIVITY_SOURCE: {
2
+ readonly GITHUB_USER: "GITHUB_USER";
3
+ readonly HUBSPOT: "HUBSPOT";
4
+ readonly HUBSPOT_USER: "HUBSPOT_USER";
5
+ readonly DEPRECATED_AUTO_UNDEPLOY: "DEPRECATED_AUTO_UNDEPLOY";
6
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ACTIVITY_SOURCE = void 0;
4
+ exports.ACTIVITY_SOURCE = {
5
+ GITHUB_USER: 'GITHUB_USER',
6
+ HUBSPOT: 'HUBSPOT',
7
+ HUBSPOT_USER: 'HUBSPOT_USER',
8
+ DEPRECATED_AUTO_UNDEPLOY: 'DEPRECATED_AUTO_UNDEPLOY',
9
+ };
@@ -0,0 +1,3 @@
1
+ import { BaseError, FileSystemErrorContext, ErrorContext } from '../types/Error';
2
+ export declare function logErrorInstance(error: BaseError, context?: ErrorContext): void;
3
+ export declare function logFileSystemErrorInstance(error: BaseError, context: FileSystemErrorContext): void;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logFileSystemErrorInstance = exports.logErrorInstance = void 0;
4
+ function isSystemError(err) {
5
+ return err.errno != null && err.code != null && err.syscall != null;
6
+ }
7
+ function debugErrorAndContext(error, context) {
8
+ console.debug('Error: %o', error);
9
+ console.debug('Context: %o', context);
10
+ }
11
+ function logErrorInstance(error, context) {
12
+ // SystemError
13
+ if (isSystemError(error)) {
14
+ console.error(`A system error has occurred: ${error.message}`);
15
+ debugErrorAndContext(error, context);
16
+ return;
17
+ }
18
+ if (error instanceof Error ||
19
+ error.message ||
20
+ error.reason) {
21
+ // Error or Error subclass
22
+ const name = error.name || 'Error';
23
+ const message = [`A ${name} has occurred.`];
24
+ [error.message, error.reason].forEach(msg => {
25
+ if (msg) {
26
+ message.push(msg);
27
+ }
28
+ });
29
+ console.error(message.join(' '));
30
+ }
31
+ else {
32
+ // Unknown errors
33
+ console.error(`An unknown error has occurred.`);
34
+ }
35
+ debugErrorAndContext(error, context);
36
+ }
37
+ exports.logErrorInstance = logErrorInstance;
38
+ function logFileSystemErrorInstance(error, context) {
39
+ let fileAction = '';
40
+ if (context.operation === 'read') {
41
+ fileAction = 'reading from';
42
+ }
43
+ else if (context.operation === 'write') {
44
+ fileAction = 'writing to';
45
+ }
46
+ else {
47
+ fileAction = 'accessing';
48
+ }
49
+ const filepath = context.filepath
50
+ ? `"${context.filepath}"`
51
+ : 'a file or folder';
52
+ const message = [`An error occurred while ${fileAction} ${filepath}.`];
53
+ // Many `fs` errors will be `SystemError`s
54
+ if (isSystemError(error)) {
55
+ message.push(`This is the result of a system error: ${error.message}`);
56
+ }
57
+ console.error(message.join(' '));
58
+ debugErrorAndContext(error, context);
59
+ }
60
+ exports.logFileSystemErrorInstance = logFileSystemErrorInstance;
@@ -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;
@@ -0,0 +1,9 @@
1
+ import { HttpOptions } from '../types/Http';
2
+ import { AxiosRequestConfig } from 'axios';
3
+ export declare const USER_AGENTS: {
4
+ [key: string]: string;
5
+ };
6
+ export declare function getDefaultUserAgentHeader(): {
7
+ 'User-Agent': string;
8
+ };
9
+ export declare function getAxiosConfig(options: HttpOptions): AxiosRequestConfig;
@@ -0,0 +1,66 @@
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.getAxiosConfig = exports.getDefaultUserAgentHeader = exports.USER_AGENTS = void 0;
7
+ const package_json_1 = require("../package.json");
8
+ const config_1 = require("../config");
9
+ const urls_1 = require("../lib/urls");
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,
41
+ };
42
+ function getAxiosConfig(options) {
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
+ }
53
+ return {
54
+ baseURL: (0, urls_1.getHubSpotApiOrigin)(env, localHostOverride ? false : httpUseLocalhost),
55
+ headers: {
56
+ ...getDefaultUserAgentHeader(),
57
+ ...(headers || {}),
58
+ },
59
+ timeout: httpTimeout,
60
+ transitional: DEFAULT_TRANSITIONAL,
61
+ httpAgent,
62
+ httpsAgent,
63
+ ...rest,
64
+ };
65
+ }
66
+ exports.getAxiosConfig = getAxiosConfig;
@@ -0,0 +1,17 @@
1
+ import { AxiosPromise } from 'axios';
2
+ import { HttpOptions } from '../types/Http';
3
+ export declare function addUserAgentHeader(key: string, value: string): void;
4
+ declare function getRequest<T>(accountId: number, options: HttpOptions): AxiosPromise<T>;
5
+ declare function postRequest<T>(accountId: number, options: HttpOptions): AxiosPromise<T>;
6
+ declare function putRequest<T>(accountId: number, options: HttpOptions): AxiosPromise<T>;
7
+ declare function patchRequest<T>(accountId: number, options: HttpOptions): AxiosPromise<T>;
8
+ declare function deleteRequest<T>(accountId: number, options: HttpOptions): AxiosPromise<T>;
9
+ export declare const http: {
10
+ get: typeof getRequest;
11
+ post: typeof postRequest;
12
+ put: typeof putRequest;
13
+ patch: typeof patchRequest;
14
+ delete: typeof deleteRequest;
15
+ getOctetStream: (accountId: number, options: HttpOptions, destPath: string) => AxiosPromise<any>;
16
+ };
17
+ export {};
package/http/index.js ADDED
@@ -0,0 +1,173 @@
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 = exports.addUserAgentHeader = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const content_disposition_1 = __importDefault(require("content-disposition"));
10
+ const axios_1 = __importDefault(require("axios"));
11
+ const config_1 = require("../config");
12
+ const getAxiosConfig_1 = require("./getAxiosConfig");
13
+ const addQueryParams_1 = require("./addQueryParams");
14
+ const personalAccessKey_1 = require("../lib/personalAccessKey");
15
+ const oauth_1 = require("../lib/oauth");
16
+ const logger_1 = require("../lib/logger");
17
+ const lang_1 = require("../utils/lang");
18
+ const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
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;
29
+ async function withOauth(accountId, accountConfig, axiosConfig) {
30
+ const { headers } = axiosConfig;
31
+ const oauth = (0, oauth_1.getOauthManager)(accountId, accountConfig);
32
+ if (!oauth) {
33
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withOauth`, { accountId }));
34
+ }
35
+ const accessToken = await oauth.accessToken();
36
+ return {
37
+ ...axiosConfig,
38
+ headers: {
39
+ ...headers,
40
+ Authorization: `Bearer ${accessToken}`,
41
+ },
42
+ };
43
+ }
44
+ async function withPersonalAccessKey(accountId, axiosConfig) {
45
+ const { headers } = axiosConfig;
46
+ const accessToken = await (0, personalAccessKey_1.accessTokenForPersonalAccessKey)(accountId);
47
+ return {
48
+ ...axiosConfig,
49
+ headers: {
50
+ ...headers,
51
+ Authorization: `Bearer ${accessToken}`,
52
+ },
53
+ };
54
+ }
55
+ function withPortalId(portalId, axiosConfig) {
56
+ const { params } = axiosConfig;
57
+ return {
58
+ ...axiosConfig,
59
+ params: {
60
+ ...params,
61
+ portalId,
62
+ },
63
+ };
64
+ }
65
+ async function withAuth(accountId, options) {
66
+ const accountConfig = (0, config_1.getAccountConfig)(accountId);
67
+ if (!accountConfig) {
68
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withAuth`, { accountId }));
69
+ }
70
+ const { env, authType, apiKey } = accountConfig;
71
+ const axiosConfig = withPortalId(accountId, (0, getAxiosConfig_1.getAxiosConfig)({ env, ...options }));
72
+ if (authType === 'personalaccesskey') {
73
+ return withPersonalAccessKey(accountId, axiosConfig);
74
+ }
75
+ if (authType === 'oauth2') {
76
+ return withOauth(accountId, accountConfig, axiosConfig);
77
+ }
78
+ const { params } = axiosConfig;
79
+ return {
80
+ ...axiosConfig,
81
+ params: {
82
+ ...params,
83
+ hapikey: apiKey,
84
+ },
85
+ };
86
+ }
87
+ async function getRequest(accountId, options) {
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);
92
+ }
93
+ async function postRequest(accountId, options) {
94
+ const requestConfig = await withAuth(accountId, options);
95
+ return (0, axios_1.default)({ ...requestConfig, method: 'post' });
96
+ }
97
+ async function putRequest(accountId, options) {
98
+ const requestConfig = await withAuth(accountId, options);
99
+ return (0, axios_1.default)({ ...requestConfig, method: 'put' });
100
+ }
101
+ async function patchRequest(accountId, options) {
102
+ const requestConfig = await withAuth(accountId, options);
103
+ return (0, axios_1.default)({ ...requestConfig, method: 'patch' });
104
+ }
105
+ async function deleteRequest(accountId, options) {
106
+ const requestConfig = await withAuth(accountId, options);
107
+ return (0, axios_1.default)({ ...requestConfig, method: 'delete' });
108
+ }
109
+ function createGetRequestStream(contentType) {
110
+ return async (accountId, options, destPath) => {
111
+ const { params, ...rest } = options;
112
+ const axiosConfig = (0, addQueryParams_1.addQueryParams)(rest, params);
113
+ // eslint-disable-next-line no-async-promise-executor
114
+ return new Promise(async (resolve, reject) => {
115
+ try {
116
+ const { headers, ...opts } = await withAuth(accountId, axiosConfig);
117
+ const res = await (0, axios_1.default)({
118
+ method: 'get',
119
+ ...opts,
120
+ headers: {
121
+ ...headers,
122
+ accept: contentType,
123
+ },
124
+ responseType: 'stream',
125
+ });
126
+ if (res.status >= 200 && res.status < 300) {
127
+ let filepath = destPath;
128
+ if (fs_extra_1.default.existsSync(destPath)) {
129
+ const stat = fs_extra_1.default.statSync(destPath);
130
+ if (stat.isDirectory()) {
131
+ const { parameters } = content_disposition_1.default.parse(res.headers['content-disposition'] || '');
132
+ filepath = path_1.default.join(destPath, parameters.filename);
133
+ }
134
+ }
135
+ try {
136
+ fs_extra_1.default.ensureFileSync(filepath);
137
+ }
138
+ catch (err) {
139
+ reject(err);
140
+ }
141
+ const writeStream = fs_extra_1.default.createWriteStream(filepath, {
142
+ encoding: 'binary',
143
+ });
144
+ res.data.pipe(writeStream);
145
+ writeStream.on('error', err => {
146
+ reject(err);
147
+ });
148
+ writeStream.on('close', async () => {
149
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createGetRequestStream.onWrite`, {
150
+ filepath,
151
+ }));
152
+ resolve(res);
153
+ });
154
+ }
155
+ else {
156
+ reject(res);
157
+ }
158
+ }
159
+ catch (err) {
160
+ reject(err);
161
+ }
162
+ });
163
+ };
164
+ }
165
+ const getOctetStream = createGetRequestStream('application/octet-stream');
166
+ exports.http = {
167
+ get: getRequest,
168
+ post: postRequest,
169
+ put: putRequest,
170
+ patch: patchRequest,
171
+ delete: deleteRequest,
172
+ getOctetStream,
173
+ };
@@ -0,0 +1,15 @@
1
+ import { AxiosPromise } from 'axios';
2
+ import { HttpOptions } from '../types/Http';
3
+ declare function getRequest<T>(options: HttpOptions): AxiosPromise<T>;
4
+ declare function postRequest<T>(options: HttpOptions): AxiosPromise<T>;
5
+ declare function putRequest<T>(options: HttpOptions): AxiosPromise<T>;
6
+ declare function patchRequest<T>(options: HttpOptions): AxiosPromise<T>;
7
+ declare function deleteRequest<T>(options: HttpOptions): AxiosPromise<T>;
8
+ export declare const http: {
9
+ get: typeof getRequest;
10
+ post: typeof postRequest;
11
+ put: typeof putRequest;
12
+ patch: typeof patchRequest;
13
+ delete: typeof deleteRequest;
14
+ };
15
+ 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
+ };