|
1 |
| -import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios' |
| 1 | +import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios' |
2 | 2 | import { makeRequest, makePaginate, PaginationOptions, PaginationApiMethod } from './BaseAPI'
|
3 | 3 | import promiseRetry from 'promise-retry'
|
4 | 4 | import type { CWMOptions } from './ManageAPI'
|
5 | 5 | import { CWLogger, DataResponse, ErrorResponse, RequestOptions, RetryOptions } from './types'
|
6 | 6 |
|
7 | 7 | const CW_MANAGE_DEBUG = !!process.env.CW_MANAGE_DEBUG
|
8 | 8 |
|
| 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 | + */ |
9 | 16 | export const DEFAULTS: {
|
10 | 17 | retryOptions: RetryOptions
|
11 | 18 | apiPath: string
|
@@ -43,6 +50,12 @@ export const DEFAULTS: {
|
43 | 50 | },
|
44 | 51 | }
|
45 | 52 |
|
| 53 | +/** |
| 54 | + * Represents a class for managing configuration options. |
| 55 | + * |
| 56 | + * @interface |
| 57 | + * @extends CWMOptions |
| 58 | + */ |
46 | 59 | export interface ManageConfig extends CWMOptions {
|
47 | 60 | authorization: string
|
48 | 61 | entryPoint: string
|
@@ -133,19 +146,25 @@ export default class Manage {
|
133 | 146 | },
|
134 | 147 | })
|
135 | 148 |
|
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 | + ) { |
138 | 157 | //check for requests to /system/documents/{id}/download
|
139 |
| - const documentDownloadEndpointRegExp = /^\/system\/documents\/[0-9]*\/download$/; |
| 158 | + const documentDownloadEndpointRegExp = /^\/system\/documents\/[0-9]*\/download$/ |
140 | 159 | if (documentDownloadEndpointRegExp.test(config.url)) {
|
141 | 160 | //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') |
143 | 162 | //add response type 'stream' to axios response type
|
144 |
| - config.responseType = 'stream'; |
| 163 | + config.responseType = 'stream' |
145 | 164 | }
|
146 | 165 | }
|
147 |
| - return config; |
148 |
| - }); |
| 166 | + return config |
| 167 | + }) |
149 | 168 |
|
150 | 169 | this.request = makeRequest({ config: this.config, api: this.api, thisObj: this })
|
151 | 170 | this.paginate = makePaginate({ thisObj: this })
|
|
0 commit comments