Skip to content

Commit 8c8cd07

Browse files
committed
Add additional documentation, fix type on axios 1.x
1 parent c636249 commit 8c8cd07

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
"homepage": "https://github.com/covenanttechnologysolutions/connectwise-rest",
5151
"dependencies": {
52-
"axios": "^0.26.1",
52+
"axios": "^1.6.7",
5353
"promise-retry": "^2.0.1"
5454
},
5555
"devDependencies": {

src/Manage.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
1+
import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios'
22
import { makeRequest, makePaginate, PaginationOptions, PaginationApiMethod } from './BaseAPI'
33
import promiseRetry from 'promise-retry'
44
import type { CWMOptions } from './ManageAPI'
55
import { CWLogger, DataResponse, ErrorResponse, RequestOptions, RetryOptions } from './types'
66

77
const CW_MANAGE_DEBUG = !!process.env.CW_MANAGE_DEBUG
88

9+
/**
10+
* DEFAULTS variable.
11+
* @type {Object}
12+
* @property {RetryOptions} retryOptions - Retry options for API requests.
13+
* @property {string} apiPath - The endpoint path for API requests.
14+
* @property {(debug: boolean) => CWLogger} logger - Logger function that takes a boolean flag to enable debug mode.
15+
*/
916
export const DEFAULTS: {
1017
retryOptions: RetryOptions
1118
apiPath: string
@@ -43,6 +50,12 @@ export const DEFAULTS: {
4350
},
4451
}
4552

53+
/**
54+
* Represents a class for managing configuration options.
55+
*
56+
* @interface
57+
* @extends CWMOptions
58+
*/
4659
export interface ManageConfig extends CWMOptions {
4760
authorization: string
4861
entryPoint: string
@@ -133,19 +146,25 @@ export default class Manage {
133146
},
134147
})
135148

136-
this.instance.interceptors.request.use((config: AxiosRequestConfig) => {
137-
if (config.url && config.headers && config.method === 'get' && config.headers.Accept && typeof config.headers.Accept === 'string') {
149+
this.instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
150+
if (
151+
config.url &&
152+
config.headers &&
153+
config.method === 'get' &&
154+
config.headers.Accept &&
155+
typeof config.headers.Accept === 'string'
156+
) {
138157
//check for requests to /system/documents/{id}/download
139-
const documentDownloadEndpointRegExp = /^\/system\/documents\/[0-9]*\/download$/;
158+
const documentDownloadEndpointRegExp = /^\/system\/documents\/[0-9]*\/download$/
140159
if (documentDownloadEndpointRegExp.test(config.url)) {
141160
//replace the string "application/json" with "blob" in the Accept header
142-
config.headers.Accept = config.headers.Accept.replace('application\/json', 'blob');
161+
config.headers.Accept = config.headers.Accept.replace('application/json', 'blob')
143162
//add response type 'stream' to axios response type
144-
config.responseType = 'stream';
163+
config.responseType = 'stream'
145164
}
146165
}
147-
return config;
148-
});
166+
return config
167+
})
149168

150169
this.request = makeRequest({ config: this.config, api: this.api, thisObj: this })
151170
this.paginate = makePaginate({ thisObj: this })

0 commit comments

Comments
 (0)