@hubspot/local-dev-lib 1.13.1 → 2.0.1

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 (105) hide show
  1. package/api/appsDev.d.ts +6 -5
  2. package/api/appsDev.js +6 -10
  3. package/api/customObjects.d.ts +7 -6
  4. package/api/customObjects.js +13 -16
  5. package/api/designManager.d.ts +3 -2
  6. package/api/designManager.js +5 -8
  7. package/api/developerTestAccounts.d.ts +5 -4
  8. package/api/developerTestAccounts.js +9 -10
  9. package/api/fileManager.d.ts +5 -4
  10. package/api/fileManager.js +9 -9
  11. package/api/fileMapper.d.ts +8 -8
  12. package/api/fileMapper.js +16 -16
  13. package/api/fileTransport.d.ts +4 -3
  14. package/api/fileTransport.js +5 -5
  15. package/api/functions.d.ts +6 -5
  16. package/api/functions.js +11 -14
  17. package/api/github.d.ts +6 -6
  18. package/api/github.js +29 -13
  19. package/api/hubdb.d.ts +9 -8
  20. package/api/hubdb.js +17 -20
  21. package/api/lighthouseScore.d.ts +4 -3
  22. package/api/lighthouseScore.js +7 -10
  23. package/api/localDevAuth.d.ts +5 -4
  24. package/api/localDevAuth.js +8 -9
  25. package/api/marketplaceValidation.d.ts +4 -3
  26. package/api/marketplaceValidation.js +4 -7
  27. package/api/projects.d.ts +31 -30
  28. package/api/projects.js +52 -52
  29. package/api/sandboxHubs.d.ts +5 -4
  30. package/api/sandboxHubs.js +9 -10
  31. package/api/sandboxSync.d.ts +4 -4
  32. package/api/sandboxSync.js +5 -14
  33. package/api/secrets.d.ts +5 -4
  34. package/api/secrets.js +9 -12
  35. package/api/validateHubl.d.ts +2 -1
  36. package/api/validateHubl.js +3 -6
  37. package/config/CLIConfiguration.d.ts +3 -3
  38. package/config/CLIConfiguration.js +22 -20
  39. package/config/configFile.js +7 -14
  40. package/config/config_DEPRECATED.js +5 -2
  41. package/config/index.js +45 -48
  42. package/errors/errors_DEPRECATED.js +2 -2
  43. package/errors/index.d.ts +18 -0
  44. package/errors/index.js +63 -0
  45. package/http/addQueryParams.d.ts +2 -0
  46. package/http/addQueryParams.js +14 -0
  47. package/http/getAxiosConfig.d.ts +2 -2
  48. package/http/getAxiosConfig.js +10 -2
  49. package/http/index.d.ts +9 -14
  50. package/http/index.js +28 -53
  51. package/http/unauthed.d.ts +15 -0
  52. package/http/unauthed.js +38 -0
  53. package/lang/en.json +1 -2
  54. package/lang/lang/en.json +1 -2
  55. package/lib/archive.js +11 -10
  56. package/lib/cms/functions.d.ts +7 -1
  57. package/lib/cms/functions.js +22 -18
  58. package/lib/cms/handleFieldsJS.js +8 -7
  59. package/lib/cms/modules.js +4 -5
  60. package/lib/cms/processFieldsJs.js +8 -7
  61. package/lib/cms/templates.js +2 -3
  62. package/lib/cms/uploadFolder.js +16 -14
  63. package/lib/cms/validate.js +1 -1
  64. package/lib/cms/watch.js +16 -9
  65. package/lib/customObjects.js +4 -15
  66. package/lib/fileManager.js +22 -21
  67. package/lib/fileMapper.js +24 -31
  68. package/lib/fs.js +2 -2
  69. package/lib/github.js +21 -21
  70. package/lib/gitignore.js +2 -2
  71. package/lib/hubdb.d.ts +3 -2
  72. package/lib/hubdb.js +11 -9
  73. package/lib/notify.js +2 -2
  74. package/lib/oauth.d.ts +1 -1
  75. package/lib/oauth.js +8 -17
  76. package/lib/personalAccessKey.js +16 -21
  77. package/lib/portManager.js +2 -2
  78. package/lib/trackUsage.js +3 -3
  79. package/models/FileSystemError.d.ts +6 -0
  80. package/models/FileSystemError.js +47 -0
  81. package/models/HubSpotHttpError.d.ts +24 -0
  82. package/models/HubSpotHttpError.js +197 -0
  83. package/models/OAuth2Manager.d.ts +1 -2
  84. package/models/OAuth2Manager.js +13 -28
  85. package/package.json +2 -1
  86. package/types/Error.d.ts +7 -5
  87. package/types/Files.d.ts +4 -4
  88. package/types/Http.d.ts +6 -10
  89. package/types/Sandbox.d.ts +0 -5
  90. package/utils/PortManagerServer.d.ts +3 -3
  91. package/utils/PortManagerServer.js +9 -9
  92. package/utils/cms/modules.js +2 -2
  93. package/utils/detectPort.js +3 -3
  94. package/errors/apiErrors.d.ts +0 -25
  95. package/errors/apiErrors.js +0 -176
  96. package/errors/fileSystemErrors.d.ts +0 -6
  97. package/errors/fileSystemErrors.js +0 -35
  98. package/errors/standardErrors.d.ts +0 -20
  99. package/errors/standardErrors.js +0 -62
  100. package/lib/developerTestAccounts.d.ts +0 -4
  101. package/lib/developerTestAccounts.js +0 -35
  102. package/lib/sandboxes.d.ts +0 -14
  103. package/lib/sandboxes.js +0 -70
  104. package/models/HubSpotAuthError.d.ts +0 -12
  105. package/models/HubSpotAuthError.js +0 -20
package/config/index.js CHANGED
@@ -22,48 +22,45 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.updateDefaultMode = exports.findConfig = exports.setConfigPath = exports.setConfig = exports.getOrderedConfig = exports.getOrderedAccount = exports.getConfigAccountId = exports.getConfigDefaultAccount = exports.getConfigAccounts = exports.getAccountType = exports.getEnv = exports.isTrackingAllowed = exports.isConfigFlagEnabled = exports.deleteConfigFile = exports.updateAllowUsageTracking = exports.updateHttpTimeout = exports.deleteAccount = exports.removeSandboxAccountFromConfig = exports.getAccountId = exports.renameAccount = exports.updateDefaultAccount = exports.updateAccountConfig = exports.accountNameExistsInConfig = exports.getAccountConfig = exports.getConfigPath = exports.writeConfig = exports.getConfig = exports.deleteEmptyConfigFile = exports.createEmptyConfigFile = exports.loadConfigFromEnvironment = exports.validateConfig = exports.getAndLoadConfigIfNeeded = exports.loadConfig = void 0;
30
27
  const config_DEPRECATED = __importStar(require("./config_DEPRECATED"));
31
- const CLIConfiguration_1 = __importDefault(require("./CLIConfiguration"));
28
+ const CLIConfiguration_1 = require("./CLIConfiguration");
32
29
  const configFile_1 = require("./configFile");
33
30
  const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
34
31
  // Use new config if it exists
35
32
  function loadConfig(path, options = {}) {
36
33
  // Attempt to load the root config
37
34
  if ((0, configFile_1.configFileExists)()) {
38
- return CLIConfiguration_1.default.init(options);
35
+ return CLIConfiguration_1.CLIConfiguration.init(options);
39
36
  }
40
37
  return config_DEPRECATED.loadConfig(path, options);
41
38
  }
42
39
  exports.loadConfig = loadConfig;
43
40
  function getAndLoadConfigIfNeeded(options) {
44
- if (CLIConfiguration_1.default.isActive()) {
45
- return CLIConfiguration_1.default.config;
41
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
42
+ return CLIConfiguration_1.CLIConfiguration.config;
46
43
  }
47
44
  return config_DEPRECATED.getAndLoadConfigIfNeeded(options);
48
45
  }
49
46
  exports.getAndLoadConfigIfNeeded = getAndLoadConfigIfNeeded;
50
47
  function validateConfig() {
51
- if (CLIConfiguration_1.default.isActive()) {
52
- return CLIConfiguration_1.default.validate();
48
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
49
+ return CLIConfiguration_1.CLIConfiguration.validate();
53
50
  }
54
51
  return config_DEPRECATED.validateConfig();
55
52
  }
56
53
  exports.validateConfig = validateConfig;
57
54
  function loadConfigFromEnvironment() {
58
- if (CLIConfiguration_1.default.isActive()) {
59
- return CLIConfiguration_1.default.useEnvConfig;
55
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
56
+ return CLIConfiguration_1.CLIConfiguration.useEnvConfig;
60
57
  }
61
58
  return Boolean(config_DEPRECATED.loadConfigFromEnvironment());
62
59
  }
63
60
  exports.loadConfigFromEnvironment = loadConfigFromEnvironment;
64
61
  function createEmptyConfigFile(options = {}, useRootConfig = false) {
65
62
  if (useRootConfig) {
66
- CLIConfiguration_1.default.write({ accounts: [] });
63
+ CLIConfiguration_1.CLIConfiguration.write({ accounts: [] });
67
64
  }
68
65
  else {
69
66
  return config_DEPRECATED.createEmptyConfigFile(options);
@@ -71,25 +68,25 @@ function createEmptyConfigFile(options = {}, useRootConfig = false) {
71
68
  }
72
69
  exports.createEmptyConfigFile = createEmptyConfigFile;
73
70
  function deleteEmptyConfigFile() {
74
- if (CLIConfiguration_1.default.isActive()) {
75
- return CLIConfiguration_1.default.delete();
71
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
72
+ return CLIConfiguration_1.CLIConfiguration.delete();
76
73
  }
77
74
  return config_DEPRECATED.deleteEmptyConfigFile();
78
75
  }
79
76
  exports.deleteEmptyConfigFile = deleteEmptyConfigFile;
80
77
  function getConfig() {
81
- if (CLIConfiguration_1.default.isActive()) {
82
- return CLIConfiguration_1.default.config;
78
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
79
+ return CLIConfiguration_1.CLIConfiguration.config;
83
80
  }
84
81
  return config_DEPRECATED.getConfig();
85
82
  }
86
83
  exports.getConfig = getConfig;
87
84
  function writeConfig(options = {}) {
88
- if (CLIConfiguration_1.default.isActive()) {
85
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
89
86
  const config = options.source
90
87
  ? JSON.parse(options.source)
91
88
  : undefined;
92
- CLIConfiguration_1.default.write(config);
89
+ CLIConfiguration_1.CLIConfiguration.write(config);
93
90
  }
94
91
  else {
95
92
  config_DEPRECATED.writeConfig(options);
@@ -97,30 +94,30 @@ function writeConfig(options = {}) {
97
94
  }
98
95
  exports.writeConfig = writeConfig;
99
96
  function getConfigPath(path) {
100
- if (CLIConfiguration_1.default.isActive()) {
97
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
101
98
  return (0, configFile_1.getConfigFilePath)();
102
99
  }
103
100
  return config_DEPRECATED.getConfigPath(path);
104
101
  }
105
102
  exports.getConfigPath = getConfigPath;
106
103
  function getAccountConfig(accountId) {
107
- if (CLIConfiguration_1.default.isActive()) {
108
- return CLIConfiguration_1.default.getConfigForAccount(accountId);
104
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
105
+ return CLIConfiguration_1.CLIConfiguration.getConfigForAccount(accountId);
109
106
  }
110
107
  return config_DEPRECATED.getAccountConfig(accountId) || null;
111
108
  }
112
109
  exports.getAccountConfig = getAccountConfig;
113
110
  function accountNameExistsInConfig(name) {
114
- if (CLIConfiguration_1.default.isActive()) {
115
- return CLIConfiguration_1.default.isAccountInConfig(name);
111
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
112
+ return CLIConfiguration_1.CLIConfiguration.isAccountInConfig(name);
116
113
  }
117
114
  return config_DEPRECATED.accountNameExistsInConfig(name);
118
115
  }
119
116
  exports.accountNameExistsInConfig = accountNameExistsInConfig;
120
117
  function updateAccountConfig(configOptions) {
121
118
  const accountIdentifier = (0, getAccountIdentifier_1.getAccountIdentifier)(configOptions);
122
- if (CLIConfiguration_1.default.isActive()) {
123
- return CLIConfiguration_1.default.updateAccount({
119
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
120
+ return CLIConfiguration_1.CLIConfiguration.updateAccount({
124
121
  ...configOptions,
125
122
  accountId: accountIdentifier,
126
123
  });
@@ -132,8 +129,8 @@ function updateAccountConfig(configOptions) {
132
129
  }
133
130
  exports.updateAccountConfig = updateAccountConfig;
134
131
  function updateDefaultAccount(nameOrId) {
135
- if (CLIConfiguration_1.default.isActive()) {
136
- CLIConfiguration_1.default.updateDefaultAccount(nameOrId);
132
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
133
+ CLIConfiguration_1.CLIConfiguration.updateDefaultAccount(nameOrId);
137
134
  }
138
135
  else {
139
136
  config_DEPRECATED.updateDefaultAccount(nameOrId);
@@ -141,8 +138,8 @@ function updateDefaultAccount(nameOrId) {
141
138
  }
142
139
  exports.updateDefaultAccount = updateDefaultAccount;
143
140
  async function renameAccount(currentName, newName) {
144
- if (CLIConfiguration_1.default.isActive()) {
145
- CLIConfiguration_1.default.renameAccount(currentName, newName);
141
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
142
+ CLIConfiguration_1.CLIConfiguration.renameAccount(currentName, newName);
146
143
  }
147
144
  else {
148
145
  config_DEPRECATED.renameAccount(currentName, newName);
@@ -150,22 +147,22 @@ async function renameAccount(currentName, newName) {
150
147
  }
151
148
  exports.renameAccount = renameAccount;
152
149
  function getAccountId(nameOrId) {
153
- if (CLIConfiguration_1.default.isActive()) {
154
- return CLIConfiguration_1.default.getAccountId(nameOrId);
150
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
151
+ return CLIConfiguration_1.CLIConfiguration.getAccountId(nameOrId);
155
152
  }
156
153
  return config_DEPRECATED.getAccountId(nameOrId) || null;
157
154
  }
158
155
  exports.getAccountId = getAccountId;
159
156
  function removeSandboxAccountFromConfig(nameOrId) {
160
- if (CLIConfiguration_1.default.isActive()) {
161
- return CLIConfiguration_1.default.removeAccountFromConfig(nameOrId);
157
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
158
+ return CLIConfiguration_1.CLIConfiguration.removeAccountFromConfig(nameOrId);
162
159
  }
163
160
  return config_DEPRECATED.removeSandboxAccountFromConfig(nameOrId);
164
161
  }
165
162
  exports.removeSandboxAccountFromConfig = removeSandboxAccountFromConfig;
166
163
  async function deleteAccount(accountName) {
167
- if (CLIConfiguration_1.default.isActive()) {
168
- CLIConfiguration_1.default.removeAccountFromConfig(accountName);
164
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
165
+ CLIConfiguration_1.CLIConfiguration.removeAccountFromConfig(accountName);
169
166
  }
170
167
  else {
171
168
  config_DEPRECATED.deleteAccount(accountName);
@@ -173,8 +170,8 @@ async function deleteAccount(accountName) {
173
170
  }
174
171
  exports.deleteAccount = deleteAccount;
175
172
  function updateHttpTimeout(timeout) {
176
- if (CLIConfiguration_1.default.isActive()) {
177
- CLIConfiguration_1.default.updateHttpTimeout(timeout);
173
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
174
+ CLIConfiguration_1.CLIConfiguration.updateHttpTimeout(timeout);
178
175
  }
179
176
  else {
180
177
  config_DEPRECATED.updateHttpTimeout(timeout);
@@ -182,8 +179,8 @@ function updateHttpTimeout(timeout) {
182
179
  }
183
180
  exports.updateHttpTimeout = updateHttpTimeout;
184
181
  function updateAllowUsageTracking(isEnabled) {
185
- if (CLIConfiguration_1.default.isActive()) {
186
- CLIConfiguration_1.default.updateAllowUsageTracking(isEnabled);
182
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
183
+ CLIConfiguration_1.CLIConfiguration.updateAllowUsageTracking(isEnabled);
187
184
  }
188
185
  else {
189
186
  config_DEPRECATED.updateAllowUsageTracking(isEnabled);
@@ -191,7 +188,7 @@ function updateAllowUsageTracking(isEnabled) {
191
188
  }
192
189
  exports.updateAllowUsageTracking = updateAllowUsageTracking;
193
190
  function deleteConfigFile() {
194
- if (CLIConfiguration_1.default.isActive()) {
191
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
195
192
  (0, configFile_1.deleteConfigFile)();
196
193
  }
197
194
  else {
@@ -200,29 +197,29 @@ function deleteConfigFile() {
200
197
  }
201
198
  exports.deleteConfigFile = deleteConfigFile;
202
199
  function isConfigFlagEnabled(flag) {
203
- if (CLIConfiguration_1.default.isActive()) {
204
- return CLIConfiguration_1.default.isConfigFlagEnabled(flag);
200
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
201
+ return CLIConfiguration_1.CLIConfiguration.isConfigFlagEnabled(flag);
205
202
  }
206
203
  return config_DEPRECATED.isConfigFlagEnabled(flag);
207
204
  }
208
205
  exports.isConfigFlagEnabled = isConfigFlagEnabled;
209
206
  function isTrackingAllowed() {
210
- if (CLIConfiguration_1.default.isActive()) {
211
- return CLIConfiguration_1.default.isTrackingAllowed();
207
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
208
+ return CLIConfiguration_1.CLIConfiguration.isTrackingAllowed();
212
209
  }
213
210
  return config_DEPRECATED.isTrackingAllowed();
214
211
  }
215
212
  exports.isTrackingAllowed = isTrackingAllowed;
216
213
  function getEnv(nameOrId) {
217
- if (CLIConfiguration_1.default.isActive()) {
218
- return CLIConfiguration_1.default.getEnv(nameOrId);
214
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
215
+ return CLIConfiguration_1.CLIConfiguration.getEnv(nameOrId);
219
216
  }
220
217
  return config_DEPRECATED.getEnv(nameOrId);
221
218
  }
222
219
  exports.getEnv = getEnv;
223
220
  function getAccountType(accountType, sandboxAccountType) {
224
- if (CLIConfiguration_1.default.isActive()) {
225
- return CLIConfiguration_1.default.getAccountType(accountType, sandboxAccountType);
221
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
222
+ return CLIConfiguration_1.CLIConfiguration.getAccountType(accountType, sandboxAccountType);
226
223
  }
227
224
  return config_DEPRECATED.getAccountType(accountType, sandboxAccountType);
228
225
  }
@@ -37,10 +37,10 @@ function logErrorInstance(error, context) {
37
37
  exports.logErrorInstance = logErrorInstance;
38
38
  function logFileSystemErrorInstance(error, context) {
39
39
  let fileAction = '';
40
- if (context.read) {
40
+ if (context.operation === 'read') {
41
41
  fileAction = 'reading from';
42
42
  }
43
- else if (context.write) {
43
+ else if (context.operation === 'write') {
44
44
  fileAction = 'writing to';
45
45
  }
46
46
  else {
@@ -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,4 +1,4 @@
1
- import { AxiosConfigOptions } from '../types/Http';
1
+ import { HttpOptions } from '../types/Http';
2
2
  import { AxiosRequestConfig } from 'axios';
3
3
  export declare const USER_AGENTS: {
4
4
  [key: string]: string;
@@ -6,4 +6,4 @@ export declare const USER_AGENTS: {
6
6
  export declare function getDefaultUserAgentHeader(): {
7
7
  'User-Agent': string;
8
8
  };
9
- export declare function getAxiosConfig(options: AxiosConfigOptions): AxiosRequestConfig;
9
+ export declare function getAxiosConfig(options: HttpOptions): AxiosRequestConfig;
@@ -41,14 +41,22 @@ const DEFAULT_TRANSITIONAL = {
41
41
  };
42
42
  function getAxiosConfig(options) {
43
43
  const { env, localHostOverride, headers, ...rest } = options;
44
- const { httpTimeout, httpUseLocalhost } = (0, config_1.getAndLoadConfigIfNeeded)();
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
+ }
45
53
  return {
46
54
  baseURL: (0, urls_1.getHubSpotApiOrigin)(env, localHostOverride ? false : httpUseLocalhost),
47
55
  headers: {
48
56
  ...getDefaultUserAgentHeader(),
49
57
  ...(headers || {}),
50
58
  },
51
- timeout: httpTimeout || 15000,
59
+ timeout: httpTimeout,
52
60
  transitional: DEFAULT_TRANSITIONAL,
53
61
  httpAgent,
54
62
  httpsAgent,
package/http/index.d.ts CHANGED
@@ -1,22 +1,17 @@
1
- import { AxiosResponse } from 'axios';
1
+ import { AxiosPromise } from 'axios';
2
2
  import { HttpOptions } from '../types/Http';
3
3
  export declare function addUserAgentHeader(key: string, value: string): void;
4
- declare function getRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
5
- declare function getRequest<T>(accountId: number, options: HttpOptions, withFullResponse: true): Promise<AxiosResponse<T>>;
6
- declare function postRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
7
- declare function postRequest<T>(accountId: number, options: HttpOptions, withFullResponse: true): Promise<AxiosResponse<T>>;
8
- declare function putRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
9
- declare function putRequest<T>(accountId: number, options: HttpOptions, withFullResponse: true): Promise<AxiosResponse<T>>;
10
- declare function patchRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
11
- declare function patchRequest<T>(accountId: number, options: HttpOptions, withFullResponse: true): Promise<AxiosResponse<T>>;
12
- declare function deleteRequest<T>(accountId: number, options: HttpOptions): Promise<T>;
13
- declare function deleteRequest<T>(accountId: number, options: HttpOptions, withFullResponse: true): Promise<AxiosResponse<T>>;
14
- declare const http: {
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: {
15
10
  get: typeof getRequest;
16
11
  post: typeof postRequest;
17
12
  put: typeof putRequest;
18
13
  patch: typeof patchRequest;
19
14
  delete: typeof deleteRequest;
20
- getOctetStream: (accountId: number, options: HttpOptions, destPath: string) => Promise<AxiosResponse>;
15
+ getOctetStream: (accountId: number, options: HttpOptions, destPath: string) => AxiosPromise<any>;
21
16
  };
22
- export default http;
17
+ export {};
package/http/index.js CHANGED
@@ -3,19 +3,25 @@ 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.addUserAgentHeader = void 0;
6
+ exports.http = exports.addUserAgentHeader = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const content_disposition_1 = __importDefault(require("content-disposition"));
10
10
  const axios_1 = __importDefault(require("axios"));
11
11
  const config_1 = require("../config");
12
12
  const getAxiosConfig_1 = require("./getAxiosConfig");
13
+ const addQueryParams_1 = require("./addQueryParams");
13
14
  const personalAccessKey_1 = require("../lib/personalAccessKey");
14
15
  const oauth_1 = require("../lib/oauth");
15
- const standardErrors_1 = require("../errors/standardErrors");
16
16
  const logger_1 = require("../lib/logger");
17
17
  const lang_1 = require("../utils/lang");
18
+ const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
18
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
+ });
19
25
  function addUserAgentHeader(key, value) {
20
26
  getAxiosConfig_1.USER_AGENTS[key] = value;
21
27
  }
@@ -24,7 +30,7 @@ async function withOauth(accountId, accountConfig, axiosConfig) {
24
30
  const { headers } = axiosConfig;
25
31
  const oauth = (0, oauth_1.getOauthManager)(accountId, accountConfig);
26
32
  if (!oauth) {
27
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.withOauth`, { accountId });
33
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withOauth`, { accountId }));
28
34
  }
29
35
  const accessToken = await oauth.accessToken();
30
36
  return {
@@ -59,7 +65,7 @@ function withPortalId(portalId, axiosConfig) {
59
65
  async function withAuth(accountId, options) {
60
66
  const accountConfig = (0, config_1.getAccountConfig)(accountId);
61
67
  if (!accountConfig) {
62
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.withAuth`, { accountId });
68
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withAuth`, { accountId }));
63
69
  }
64
70
  const { env, authType, apiKey } = accountConfig;
65
71
  const axiosConfig = withPortalId(accountId, (0, getAxiosConfig_1.getAxiosConfig)({ env, ...options }));
@@ -78,62 +84,32 @@ async function withAuth(accountId, options) {
78
84
  },
79
85
  };
80
86
  }
81
- function addQueryParams(configOptions, queryParams = {}) {
82
- const { params } = configOptions;
83
- return {
84
- ...configOptions,
85
- params: {
86
- ...queryParams,
87
- ...params,
88
- },
89
- };
90
- }
91
- async function getRequest(accountId, options, withFullResponse) {
87
+ async function getRequest(accountId, options) {
92
88
  const { params, ...rest } = options;
93
- const axiosConfig = addQueryParams(rest, params);
94
- const configWithAuth = await withAuth(accountId, axiosConfig);
95
- const response = await (0, axios_1.default)(configWithAuth);
96
- if (withFullResponse) {
97
- return response;
98
- }
99
- return response.data;
89
+ const optionsWithParams = (0, addQueryParams_1.addQueryParams)(rest, params);
90
+ const requestConfig = await withAuth(accountId, optionsWithParams);
91
+ return (0, axios_1.default)(requestConfig);
100
92
  }
101
- async function postRequest(accountId, options, withFullResponse) {
102
- const configWithAuth = await withAuth(accountId, options);
103
- const response = await (0, axios_1.default)({ ...configWithAuth, method: 'post' });
104
- if (withFullResponse) {
105
- return response;
106
- }
107
- return response.data;
93
+ async function postRequest(accountId, options) {
94
+ const requestConfig = await withAuth(accountId, options);
95
+ return (0, axios_1.default)({ ...requestConfig, method: 'post' });
108
96
  }
109
- async function putRequest(accountId, options, withFullResponse) {
110
- const configWithAuth = await withAuth(accountId, options);
111
- const response = await (0, axios_1.default)({ ...configWithAuth, method: 'put' });
112
- if (withFullResponse) {
113
- return response;
114
- }
115
- return response.data;
97
+ async function putRequest(accountId, options) {
98
+ const requestConfig = await withAuth(accountId, options);
99
+ return (0, axios_1.default)({ ...requestConfig, method: 'put' });
116
100
  }
117
- async function patchRequest(accountId, options, withFullResponse) {
118
- const configWithAuth = await withAuth(accountId, options);
119
- const response = await (0, axios_1.default)({ ...configWithAuth, method: 'patch' });
120
- if (withFullResponse) {
121
- return response;
122
- }
123
- return response.data;
101
+ async function patchRequest(accountId, options) {
102
+ const requestConfig = await withAuth(accountId, options);
103
+ return (0, axios_1.default)({ ...requestConfig, method: 'patch' });
124
104
  }
125
- async function deleteRequest(accountId, options, withFullResponse = false) {
126
- const configWithAuth = await withAuth(accountId, options);
127
- const response = await (0, axios_1.default)({ ...configWithAuth, method: 'delete' });
128
- if (withFullResponse) {
129
- return response;
130
- }
131
- return response.data;
105
+ async function deleteRequest(accountId, options) {
106
+ const requestConfig = await withAuth(accountId, options);
107
+ return (0, axios_1.default)({ ...requestConfig, method: 'delete' });
132
108
  }
133
109
  function createGetRequestStream(contentType) {
134
110
  return async (accountId, options, destPath) => {
135
111
  const { params, ...rest } = options;
136
- const axiosConfig = addQueryParams(rest, params);
112
+ const axiosConfig = (0, addQueryParams_1.addQueryParams)(rest, params);
137
113
  // eslint-disable-next-line no-async-promise-executor
138
114
  return new Promise(async (resolve, reject) => {
139
115
  try {
@@ -187,7 +163,7 @@ function createGetRequestStream(contentType) {
187
163
  };
188
164
  }
189
165
  const getOctetStream = createGetRequestStream('application/octet-stream');
190
- const http = {
166
+ exports.http = {
191
167
  get: getRequest,
192
168
  post: postRequest,
193
169
  put: putRequest,
@@ -195,4 +171,3 @@ const http = {
195
171
  delete: deleteRequest,
196
172
  getOctetStream,
197
173
  };
198
- exports.default = http;
@@ -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
+ };
package/lang/en.json CHANGED
@@ -384,7 +384,6 @@
384
384
  "400Generic": "The {{ messageDetail }} failed due to a client error.",
385
385
  "generic": "The {{ messageDetail }} failed."
386
386
  }
387
- },
388
- "generic": "{{ name }}:"
387
+ }
389
388
  }
390
389
  }
package/lang/lang/en.json CHANGED
@@ -384,7 +384,6 @@
384
384
  "400Generic": "The {{ messageDetail }} failed due to a client error.",
385
385
  "generic": "The {{ messageDetail }} failed."
386
386
  }
387
- },
388
- "generic": "{{ name }}:"
387
+ }
389
388
  }
390
389
  }