11import path from 'path' ;
22import fs from 'fs-extra' ;
33import contentDisposition from 'content-disposition' ;
4- import axios , {
4+ import {
55 AxiosRequestConfig ,
66 AxiosResponse ,
77 AxiosPromise ,
@@ -23,76 +23,10 @@ import {
2323 OAUTH_AUTH_METHOD ,
2424 API_KEY_AUTH_METHOD ,
2525} from '../constants/auth' ;
26- import { LOCALDEVAUTH_ACCESS_TOKEN_PATH } from '../api/localDevAuth' ;
27- import { FIREALARM_API_AUTH_PATH } from '../api/fireAlarm' ;
28- import * as util from 'util' ;
29- import { CMS_CLI_USAGE_PATH , VSCODE_USAGE_PATH } from '../lib/trackUsage' ;
26+ import { httpClient } from './client' ;
3027
3128const i18nKey = 'http.index' ;
3229
33- const IGNORE_URLS_NETWORK_DEBUG = [
34- LOCALDEVAUTH_ACCESS_TOKEN_PATH ,
35- CMS_CLI_USAGE_PATH ,
36- VSCODE_USAGE_PATH ,
37- FIREALARM_API_AUTH_PATH ,
38- ] ;
39-
40- function logRequest ( response : AxiosResponse ) {
41- try {
42- if ( ! process . env . HUBSPOT_NETWORK_LOGGING ) {
43- return ;
44- }
45-
46- if (
47- ! process . env . HUBSPOT_DEBUG_LOGGING_VERBOSE &&
48- IGNORE_URLS_NETWORK_DEBUG . some (
49- url => response ?. config ?. url && response . config . url . includes ( url )
50- )
51- ) {
52- return ;
53- }
54-
55- logger . debug (
56- util . inspect (
57- {
58- method : response . config . method ,
59- baseURL : response . config . baseURL ,
60- url : response . config . url ,
61- data : response . data ,
62- status : response . status ,
63- } ,
64- false ,
65- null ,
66- true
67- )
68- ) ;
69- } catch ( error ) {
70- // Ignore any errors that occur while logging the response
71- }
72- }
73-
74- axios . interceptors . response . use (
75- ( response : AxiosResponse ) => {
76- logRequest ( response ) ;
77- return response ;
78- } ,
79- error => {
80- try {
81- if ( isAxiosError ( error ) && error . response ) {
82- logRequest ( error . response ) ;
83- }
84- } catch ( e ) {
85- // Ignore any errors that occur while logging the response
86- }
87-
88- // Wrap all axios errors in our own Error class. Attach the error
89- // as the cause for the new error, so we maintain the stack trace
90- return Promise . reject (
91- new HubSpotHttpError ( error . message , { cause : error } )
92- ) ;
93- }
94- ) ;
95-
9630export function addUserAgentHeader ( key : string , value : string ) {
9731 USER_AGENTS [ key ] = value ;
9832}
@@ -198,39 +132,39 @@ async function getRequest<T>(
198132 const optionsWithParams = addQueryParams ( rest , params ) ;
199133 const requestConfig = await withAuth ( accountId , optionsWithParams ) ;
200134
201- return axios < T > ( requestConfig ) ;
135+ return httpClient < T > ( requestConfig ) ;
202136}
203137
204138async function postRequest < T > (
205139 accountId : number ,
206140 options : HttpOptions
207141) : HubSpotPromise < T > {
208142 const requestConfig = await withAuth ( accountId , options ) ;
209- return axios < T > ( { ...requestConfig , method : 'post' } ) ;
143+ return httpClient < T > ( { ...requestConfig , method : 'post' } ) ;
210144}
211145
212146async function putRequest < T > (
213147 accountId : number ,
214148 options : HttpOptions
215149) : HubSpotPromise < T > {
216150 const requestConfig = await withAuth ( accountId , options ) ;
217- return axios < T > ( { ...requestConfig , method : 'put' } ) ;
151+ return httpClient < T > ( { ...requestConfig , method : 'put' } ) ;
218152}
219153
220154async function patchRequest < T > (
221155 accountId : number ,
222156 options : HttpOptions
223157) : HubSpotPromise < T > {
224158 const requestConfig = await withAuth ( accountId , options ) ;
225- return axios < T > ( { ...requestConfig , method : 'patch' } ) ;
159+ return httpClient < T > ( { ...requestConfig , method : 'patch' } ) ;
226160}
227161
228162async function deleteRequest < T > (
229163 accountId : number ,
230164 options : HttpOptions
231165) : HubSpotPromise < T > {
232166 const requestConfig = await withAuth ( accountId , options ) ;
233- return axios < T > ( { ...requestConfig , method : 'delete' } ) ;
167+ return httpClient < T > ( { ...requestConfig , method : 'delete' } ) ;
234168}
235169
236170function createGetRequestStream ( contentType : string ) {
@@ -246,7 +180,7 @@ function createGetRequestStream(contentType: string) {
246180 return new Promise < AxiosResponse > ( async ( resolve , reject ) => {
247181 try {
248182 const { headers, ...opts } = await withAuth ( accountId , axiosConfig ) ;
249- const res = await axios ( {
183+ const res = await httpClient ( {
250184 method : 'get' ,
251185 ...opts ,
252186 headers : {
0 commit comments