1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-09 05:20:05 +00:00

chore: removed httpsAgent type + clean up

This commit is contained in:
Saad Jutt
2021-10-07 13:45:50 +05:00
parent 2849e6ed07
commit 6ff8eece7b
11 changed files with 46 additions and 143 deletions

View File

@@ -1,4 +1,5 @@
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
import * as https from 'https'
import { CsrfToken } from '..'
import { isAuthorizeFormRequired, isLogInRequired } from '../auth'
import {
@@ -17,7 +18,6 @@ import {
parseSourceCode,
createAxiosInstance
} from '../utils'
import { HttpsAgent } from '../types/HttpsAgent'
export interface HttpClient {
get<T>(
@@ -59,12 +59,15 @@ export class RequestClient implements HttpClient {
protected fileUploadCsrfToken: CsrfToken | undefined
protected httpClient!: AxiosInstance
constructor(protected baseUrl: string, httpsAgentConfiguration?: HttpsAgent) {
this.createHttpClient(baseUrl, httpsAgentConfiguration)
constructor(
protected baseUrl: string,
httpsAgentOptions?: https.AgentOptions
) {
this.createHttpClient(baseUrl, httpsAgentOptions)
}
public setConfig(baseUrl: string, httpsAgentConfiguration?: HttpsAgent) {
this.createHttpClient(baseUrl, httpsAgentConfiguration)
public setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions) {
this.createHttpClient(baseUrl, httpsAgentOptions)
}
public getCsrfToken(type: 'general' | 'file' = 'general') {
@@ -518,24 +521,12 @@ export class RequestClient implements HttpClient {
private createHttpClient(
baseUrl: string,
httpsAgentConfiguration: HttpsAgent = {}
httpsAgentOptions?: https.AgentOptions
) {
const https = require('https')
const { selfSigned, clientCA, allowInsecure } = httpsAgentConfiguration
const httpsAgentOptions = selfSigned
? { ca: selfSigned.ca }
: clientCA
? { key: clientCA.key, cert: clientCA.cert, requestCert: true }
: allowInsecure
? { rejectUnauthorized: !allowInsecure }
const httpsAgent = httpsAgentOptions
? new https.Agent(httpsAgentOptions)
: undefined
const httpsAgent =
httpsAgentOptions && https.Agent
? new https.Agent(httpsAgentOptions)
: undefined
this.httpClient = createAxiosInstance(baseUrl, httpsAgent)
this.httpClient.defaults.validateStatus = (status) =>

View File

@@ -1,17 +1,17 @@
import * as https from 'https'
import { AxiosRequestConfig } from 'axios'
import axiosCookieJarSupport from 'axios-cookiejar-support'
import * as tough from 'tough-cookie'
import { prefixMessage } from '@sasjs/utils/error'
import { RequestClient, throwIfError } from './RequestClient'
import { HttpsAgent } from '../types/HttpsAgent'
/**
* Specific request client for SAS9 in Node.js environments.
* Handles redirects and cookie management.
*/
export class Sas9RequestClient extends RequestClient {
constructor(baseUrl: string, httpsAgentConfiguration?: HttpsAgent) {
super(baseUrl, httpsAgentConfiguration)
constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions) {
super(baseUrl, httpsAgentOptions)
this.httpClient.defaults.maxRedirects = 0
this.httpClient.defaults.validateStatus = (status) =>
status >= 200 && status < 303