(config)
| 93 | */ |
| 94 | class REST extends Helper { |
| 95 | constructor(config) { |
| 96 | super(config) |
| 97 | |
| 98 | // Set defaults first |
| 99 | const defaults = { |
| 100 | timeout: 10000, |
| 101 | defaultHeaders: {}, |
| 102 | endpoint: '', |
| 103 | prettyPrintJson: false, |
| 104 | onRequest: null, |
| 105 | onResponse: null, |
| 106 | } |
| 107 | |
| 108 | // Merge config with defaults |
| 109 | this._setConfig(config) |
| 110 | this.options = { ...defaults, ...this.options } |
| 111 | |
| 112 | if (this.options.maxContentLength) { |
| 113 | const maxContentLength = this.options.maxUploadFileSize * 1024 * 1024 |
| 114 | this.options.maxContentLength = maxContentLength |
| 115 | this.options.maxBodyLength = maxContentLength |
| 116 | } |
| 117 | |
| 118 | this.headers = { ...this.options.defaultHeaders } |
| 119 | |
| 120 | // Create an agent with SSL certificate |
| 121 | if (this.options.httpAgent) { |
| 122 | // if one of those keys is there, all good to go |
| 123 | if (this.options.httpAgent.ca || this.options.httpAgent.key || this.options.httpAgent.cert) { |
| 124 | this.httpsAgent = new Agent(this.options.httpAgent) |
| 125 | } else { |
| 126 | // otherwise, throws an error of httpAgent config |
| 127 | throw Error('Please recheck your httpAgent config!') |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | this.axios = this.httpsAgent ? axios.create({ httpsAgent: this.httpsAgent }) : axios.create() |
| 132 | // @ts-ignore |
| 133 | this.axios.defaults.headers = this.options.defaultHeaders |
| 134 | } |
| 135 | |
| 136 | static _config() { |
| 137 | return [ |
nothing calls this directly
no test coverage detected