@hubspot/local-dev-lib 4.0.1 → 4.0.2-beta.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.
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.generateDeveloperTestAccountPersonalAccessKey = exports.fetchDeveloperTestAccountGateSyncStatus = exports.fetchDeveloperTestAccountOauthAppInstallStatus = exports.installOauthAppIntoDeveloperTestAccount = exports.fetchDeveloperTestAccountData = exports.deleteDeveloperTestAccount = exports.createDeveloperTestAccount = exports.fetchDeveloperTestAccounts = void 0;
7
- const axios_1 = __importDefault(require("axios"));
4
+ const client_1 = require("../http/client");
8
5
  const http_1 = require("../http");
9
6
  const getAxiosConfig_1 = require("../http/getAxiosConfig");
10
7
  const environments_1 = require("../constants/environments");
@@ -56,7 +53,7 @@ function fetchDeveloperTestAccountData(accessToken, accountId, env = environment
56
53
  Authorization: `Bearer ${accessToken}`,
57
54
  },
58
55
  };
59
- return (0, axios_1.default)(reqWithToken);
56
+ return (0, client_1.httpClient)(reqWithToken);
60
57
  }
61
58
  exports.fetchDeveloperTestAccountData = fetchDeveloperTestAccountData;
62
59
  function installOauthAppIntoDeveloperTestAccount(accountId, testAccountId, projectName, appUId) {
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchEnabledFeatures = exports.fetchAppInstallationData = exports.fetchScopeAuthorizationData = exports.fetchScopeData = exports.fetchAccessToken = exports.LOCALDEVAUTH_ACCESS_TOKEN_PATH = void 0;
7
4
  const getAxiosConfig_1 = require("../http/getAxiosConfig");
8
5
  const http_1 = require("../http");
9
6
  const environments_1 = require("../constants/environments");
10
- const axios_1 = __importDefault(require("axios"));
7
+ const client_1 = require("../http/client");
11
8
  const LOCALDEVAUTH_API_AUTH_PATH = 'localdevauth/v1/auth';
12
9
  exports.LOCALDEVAUTH_ACCESS_TOKEN_PATH = `${LOCALDEVAUTH_API_AUTH_PATH}/refresh`;
13
10
  function fetchAccessToken(personalAccessKey, env = environments_1.ENVIRONMENTS.PROD, portalId) {
@@ -20,7 +17,7 @@ function fetchAccessToken(personalAccessKey, env = environments_1.ENVIRONMENTS.P
20
17
  },
21
18
  params: portalId ? { portalId } : {},
22
19
  });
23
- return (0, axios_1.default)({
20
+ return (0, client_1.httpClient)({
24
21
  ...axiosConfig,
25
22
  method: 'post',
26
23
  });
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getSandboxPersonalAccessKey = exports.createV2Sandbox = exports.fetchSandboxHubData = exports.getSandboxUsageLimits = exports.deleteSandbox = exports.createSandbox = void 0;
7
- const axios_1 = __importDefault(require("axios"));
4
+ const client_1 = require("../http/client");
8
5
  const http_1 = require("../http");
9
6
  const getAxiosConfig_1 = require("../http/getAxiosConfig");
10
7
  const environments_1 = require("../constants/environments");
@@ -44,7 +41,7 @@ function fetchSandboxHubData(accessToken, accountId, env = environments_1.ENVIRO
44
41
  Authorization: `Bearer ${accessToken}`,
45
42
  },
46
43
  };
47
- return (0, axios_1.default)(reqWithToken);
44
+ return (0, client_1.httpClient)(reqWithToken);
48
45
  }
49
46
  exports.fetchSandboxHubData = fetchSandboxHubData;
50
47
  function createV2Sandbox(accountId, name, type, syncObjectRecords) {
@@ -0,0 +1 @@
1
+ export declare const httpClient: import("axios").AxiosInstance;
package/http/client.js ADDED
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.httpClient = void 0;
27
+ const axios_1 = __importStar(require("axios"));
28
+ const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
29
+ const logger_1 = require("../lib/logger");
30
+ const localDevAuth_1 = require("../api/localDevAuth");
31
+ const fireAlarm_1 = require("../api/fireAlarm");
32
+ const util = __importStar(require("util"));
33
+ const trackUsage_1 = require("../lib/trackUsage");
34
+ // Create an isolated axios instance for this copy of local-dev-lib.
35
+ // This prevents issues when multiple copies are loaded and share the global
36
+ // axios, where each copy would register interceptors on the shared instance
37
+ // causing errors to be wrapped multiple times.
38
+ exports.httpClient = axios_1.default.create();
39
+ const IGNORE_URLS_NETWORK_DEBUG = [
40
+ localDevAuth_1.LOCALDEVAUTH_ACCESS_TOKEN_PATH,
41
+ trackUsage_1.CMS_CLI_USAGE_PATH,
42
+ trackUsage_1.VSCODE_USAGE_PATH,
43
+ fireAlarm_1.FIREALARM_API_AUTH_PATH,
44
+ ];
45
+ function logRequest(response) {
46
+ try {
47
+ if (!process.env.HUBSPOT_NETWORK_LOGGING) {
48
+ return;
49
+ }
50
+ if (!process.env.HUBSPOT_DEBUG_LOGGING_VERBOSE &&
51
+ IGNORE_URLS_NETWORK_DEBUG.some(url => response?.config?.url && response.config.url.includes(url))) {
52
+ return;
53
+ }
54
+ logger_1.logger.debug(util.inspect({
55
+ method: response.config.method,
56
+ baseURL: response.config.baseURL,
57
+ url: response.config.url,
58
+ data: response.data,
59
+ status: response.status,
60
+ }, false, null, true));
61
+ }
62
+ catch (error) {
63
+ // Ignore any errors that occur while logging the response
64
+ }
65
+ }
66
+ // Register interceptor on our isolated instance
67
+ exports.httpClient.interceptors.response.use((response) => {
68
+ logRequest(response);
69
+ return response;
70
+ }, error => {
71
+ try {
72
+ if ((0, axios_1.isAxiosError)(error) && error.response) {
73
+ logRequest(error.response);
74
+ }
75
+ }
76
+ catch (e) {
77
+ // Ignore any errors that occur while logging the response
78
+ }
79
+ // Wrap all axios errors in our own Error class. Attach the error
80
+ // as the cause for the new error, so we maintain the stack trace
81
+ return Promise.reject(new HubSpotHttpError_1.HubSpotHttpError(error.message, { cause: error }));
82
+ });
package/http/index.js CHANGED
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
@@ -30,7 +7,6 @@ exports.http = exports.addUserAgentHeader = void 0;
30
7
  const path_1 = __importDefault(require("path"));
31
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
32
9
  const content_disposition_1 = __importDefault(require("content-disposition"));
33
- const axios_1 = __importStar(require("axios"));
34
10
  const config_1 = require("../config");
35
11
  const getAxiosConfig_1 = require("./getAxiosConfig");
36
12
  const addQueryParams_1 = require("./addQueryParams");
@@ -38,56 +14,9 @@ const personalAccessKey_1 = require("../lib/personalAccessKey");
38
14
  const oauth_1 = require("../lib/oauth");
39
15
  const logger_1 = require("../lib/logger");
40
16
  const lang_1 = require("../utils/lang");
41
- const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
42
17
  const auth_1 = require("../constants/auth");
43
- const localDevAuth_1 = require("../api/localDevAuth");
44
- const fireAlarm_1 = require("../api/fireAlarm");
45
- const util = __importStar(require("util"));
46
- const trackUsage_1 = require("../lib/trackUsage");
18
+ const client_1 = require("./client");
47
19
  const i18nKey = 'http.index';
48
- const IGNORE_URLS_NETWORK_DEBUG = [
49
- localDevAuth_1.LOCALDEVAUTH_ACCESS_TOKEN_PATH,
50
- trackUsage_1.CMS_CLI_USAGE_PATH,
51
- trackUsage_1.VSCODE_USAGE_PATH,
52
- fireAlarm_1.FIREALARM_API_AUTH_PATH,
53
- ];
54
- function logRequest(response) {
55
- try {
56
- if (!process.env.HUBSPOT_NETWORK_LOGGING) {
57
- return;
58
- }
59
- if (!process.env.HUBSPOT_DEBUG_LOGGING_VERBOSE &&
60
- IGNORE_URLS_NETWORK_DEBUG.some(url => response?.config?.url && response.config.url.includes(url))) {
61
- return;
62
- }
63
- logger_1.logger.debug(util.inspect({
64
- method: response.config.method,
65
- baseURL: response.config.baseURL,
66
- url: response.config.url,
67
- data: response.data,
68
- status: response.status,
69
- }, false, null, true));
70
- }
71
- catch (error) {
72
- // Ignore any errors that occur while logging the response
73
- }
74
- }
75
- axios_1.default.interceptors.response.use((response) => {
76
- logRequest(response);
77
- return response;
78
- }, error => {
79
- try {
80
- if ((0, axios_1.isAxiosError)(error) && error.response) {
81
- logRequest(error.response);
82
- }
83
- }
84
- catch (e) {
85
- // Ignore any errors that occur while logging the response
86
- }
87
- // Wrap all axios errors in our own Error class. Attach the error
88
- // as the cause for the new error, so we maintain the stack trace
89
- return Promise.reject(new HubSpotHttpError_1.HubSpotHttpError(error.message, { cause: error }));
90
- });
91
20
  function addUserAgentHeader(key, value) {
92
21
  getAxiosConfig_1.USER_AGENTS[key] = value;
93
22
  }
@@ -157,23 +86,23 @@ async function getRequest(accountId, options) {
157
86
  const { params, ...rest } = options;
158
87
  const optionsWithParams = (0, addQueryParams_1.addQueryParams)(rest, params);
159
88
  const requestConfig = await withAuth(accountId, optionsWithParams);
160
- return (0, axios_1.default)(requestConfig);
89
+ return (0, client_1.httpClient)(requestConfig);
161
90
  }
162
91
  async function postRequest(accountId, options) {
163
92
  const requestConfig = await withAuth(accountId, options);
164
- return (0, axios_1.default)({ ...requestConfig, method: 'post' });
93
+ return (0, client_1.httpClient)({ ...requestConfig, method: 'post' });
165
94
  }
166
95
  async function putRequest(accountId, options) {
167
96
  const requestConfig = await withAuth(accountId, options);
168
- return (0, axios_1.default)({ ...requestConfig, method: 'put' });
97
+ return (0, client_1.httpClient)({ ...requestConfig, method: 'put' });
169
98
  }
170
99
  async function patchRequest(accountId, options) {
171
100
  const requestConfig = await withAuth(accountId, options);
172
- return (0, axios_1.default)({ ...requestConfig, method: 'patch' });
101
+ return (0, client_1.httpClient)({ ...requestConfig, method: 'patch' });
173
102
  }
174
103
  async function deleteRequest(accountId, options) {
175
104
  const requestConfig = await withAuth(accountId, options);
176
- return (0, axios_1.default)({ ...requestConfig, method: 'delete' });
105
+ return (0, client_1.httpClient)({ ...requestConfig, method: 'delete' });
177
106
  }
178
107
  function createGetRequestStream(contentType) {
179
108
  return async (accountId, options, destPath) => {
@@ -183,7 +112,7 @@ function createGetRequestStream(contentType) {
183
112
  return new Promise(async (resolve, reject) => {
184
113
  try {
185
114
  const { headers, ...opts } = await withAuth(accountId, axiosConfig);
186
- const res = await (0, axios_1.default)({
115
+ const res = await (0, client_1.httpClient)({
187
116
  method: 'get',
188
117
  ...opts,
189
118
  headers: {
package/http/unauthed.js CHANGED
@@ -1,33 +1,30 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.http = void 0;
7
- const axios_1 = __importDefault(require("axios"));
4
+ const client_1 = require("./client");
8
5
  const getAxiosConfig_1 = require("./getAxiosConfig");
9
6
  const addQueryParams_1 = require("./addQueryParams");
10
7
  async function getRequest(options) {
11
8
  const { params, ...rest } = options;
12
9
  const optionsWithParams = (0, addQueryParams_1.addQueryParams)(rest, params);
13
10
  const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(optionsWithParams);
14
- return (0, axios_1.default)(requestConfig);
11
+ return (0, client_1.httpClient)(requestConfig);
15
12
  }
16
13
  async function postRequest(options) {
17
14
  const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
18
- return (0, axios_1.default)({ ...requestConfig, method: 'post' });
15
+ return (0, client_1.httpClient)({ ...requestConfig, method: 'post' });
19
16
  }
20
17
  async function putRequest(options) {
21
18
  const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
22
- return (0, axios_1.default)({ ...requestConfig, method: 'put' });
19
+ return (0, client_1.httpClient)({ ...requestConfig, method: 'put' });
23
20
  }
24
21
  async function patchRequest(options) {
25
22
  const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
26
- return (0, axios_1.default)({ ...requestConfig, method: 'patch' });
23
+ return (0, client_1.httpClient)({ ...requestConfig, method: 'patch' });
27
24
  }
28
25
  async function deleteRequest(options) {
29
26
  const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
30
- return (0, axios_1.default)({ ...requestConfig, method: 'delete' });
27
+ return (0, client_1.httpClient)({ ...requestConfig, method: 'delete' });
31
28
  }
32
29
  exports.http = {
33
30
  get: getRequest,
package/lib/trackUsage.js CHANGED
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.trackUsage = exports.VSCODE_USAGE_PATH = exports.CMS_CLI_USAGE_PATH = void 0;
7
- const axios_1 = __importDefault(require("axios"));
4
+ const client_1 = require("../http/client");
8
5
  const getAxiosConfig_1 = require("../http/getAxiosConfig");
9
6
  const logger_1 = require("./logger");
10
7
  const http_1 = require("../http");
@@ -62,6 +59,6 @@ async function trackUsage(eventName, eventClass, meta = {}, accountId) {
62
59
  resolveWithFullResponse: true,
63
60
  });
64
61
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventUnauthenticated`));
65
- return (0, axios_1.default)({ ...axiosConfig, method: 'post' });
62
+ return (0, client_1.httpClient)({ ...axiosConfig, method: 'post' });
66
63
  }
67
64
  exports.trackUsage = trackUsage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "4.0.1",
3
+ "version": "4.0.2-beta.0",
4
4
  "description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "devDependencies": {
23
- "@hubspot/npm-scripts": "0.0.4",
23
+ "@hubspot/npm-scripts": "0.0.6",
24
24
  "@types/content-disposition": "^0.5.5",
25
25
  "@types/cors": "^2.8.15",
26
26
  "@types/debounce": "^1.2.1",
package/utils/git.js CHANGED
@@ -12,7 +12,7 @@ const GITIGNORE_FILE = '.gitignore';
12
12
  function makeComparisonDir(filepath) {
13
13
  if (typeof filepath !== 'string')
14
14
  return null;
15
- let dir = path_1.default.dirname(path_1.default.resolve(filepath)).toLowerCase();
15
+ const dir = path_1.default.dirname(path_1.default.resolve(filepath)).toLowerCase();
16
16
  // Append sep to make comparisons easier e.g. 'foos'.startsWith('foo')
17
17
  return dir + (!dir.endsWith(path_1.default.sep) ? path_1.default.sep : '');
18
18
  }