1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-03 10:40:06 +00:00

refactor(request-client): put related types in one file

This commit is contained in:
Yury Shkoda
2023-08-14 10:55:09 +03:00
parent f18a523087
commit 5731b0f9b1
9 changed files with 69 additions and 69 deletions

View File

@@ -4,7 +4,11 @@ import {
UploadFile,
EditContextInput,
PollOptions,
LoginMechanism
LoginMechanism,
VerboseMode,
ErrorResponse,
LoginOptions,
LoginResult
} from './types'
import { SASViyaApiClient } from './SASViyaApiClient'
import { SAS9ApiClient } from './SAS9ApiClient'
@@ -29,8 +33,6 @@ import {
Sas9JobExecutor,
FileUploader
} from './job-execution'
import { ErrorResponse } from './types/errors'
import { LoginOptions, LoginResult } from './types/Login'
import { AxiosResponse } from 'axios'
interface ExecuteScriptParams {

View File

@@ -10,7 +10,7 @@ import {
JobExecutionError,
CertificateError
} from '../types/errors'
import { VerboseMode } from '../types'
import { SASjsRequest, HttpClient, VerboseMode } from '../types'
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
import { prefixMessage } from '@sasjs/utils/error'
import { SAS9AuthError } from '../types/errors/SAS9AuthError'
@@ -22,41 +22,6 @@ import {
import { InvalidSASjsCsrfError } from '../types/errors/InvalidSASjsCsrfError'
import { inspect } from 'util'
export interface HttpClient {
get<T>(
url: string,
accessToken: string | undefined,
contentType: string,
overrideHeaders: { [key: string]: string | number }
): Promise<{ result: T; etag: string }>
post<T>(
url: string,
data: any,
accessToken: string | undefined,
contentType: string,
overrideHeaders: { [key: string]: string | number }
): Promise<{ result: T; etag: string }>
put<T>(
url: string,
data: any,
accessToken: string | undefined,
overrideHeaders: { [key: string]: string | number }
): Promise<{ result: T; etag: string }>
delete<T>(
url: string,
accessToken: string | undefined
): Promise<{ result: T; etag: string }>
getCsrfToken(type: 'general' | 'file'): CsrfToken | undefined
saveLocalStorageToken(accessToken: string, refreshToken: string): void
clearCsrfTokens(): void
clearLocalStorageTokens(): void
getBaseUrl(): string
}
export class RequestClient implements HttpClient {
private requests: SASjsRequest[] = []
private requestsLimit: number = 10

View File

@@ -1,19 +1,11 @@
import { RequestClient } from './RequestClient'
import { AxiosResponse } from 'axios'
export interface SasjsParsedResponse<T> {
result: T
log: string
etag: string
status: number
printOutput?: string
}
import { SasjsParsedResponse } from '../types'
/**
* Specific request client for SASJS.
* Append tokens in headers.
*/
export class SasjsRequestClient extends RequestClient {
getHeaders = (accessToken: string | undefined, contentType: string) => {
const headers: any = {}

View File

@@ -1,8 +1,5 @@
import {
SASJS_LOGS_SEPARATOR,
SasjsRequestClient,
SasjsParsedResponse
} from '../SasjsRequestClient'
import { SASJS_LOGS_SEPARATOR, SasjsRequestClient } from '../SasjsRequestClient'
import { SasjsParsedResponse } from '../../types'
import { AxiosResponse } from 'axios'
describe('SasjsRequestClient', () => {

View File

@@ -9,9 +9,9 @@ import {
LoginRequiredError,
AuthorizeError,
NotFoundError,
InternalServerError
} from '../types/errors'
import { VerboseMode } from '../types'
InternalServerError,
VerboseMode
} from '../types'
import { RequestClient } from '../request/RequestClient'
import { getTokenRequestErrorPrefixResponse } from '../auth/getTokenRequestErrorPrefix'
import { AxiosResponse } from 'axios'

View File

@@ -1 +1,55 @@
import { CsrfToken } from '..'
export interface HttpClient {
get<T>(
url: string,
accessToken: string | undefined,
contentType: string,
overrideHeaders: { [key: string]: string | number }
): Promise<{ result: T; etag: string }>
post<T>(
url: string,
data: any,
accessToken: string | undefined,
contentType: string,
overrideHeaders: { [key: string]: string | number }
): Promise<{ result: T; etag: string }>
put<T>(
url: string,
data: any,
accessToken: string | undefined,
overrideHeaders: { [key: string]: string | number }
): Promise<{ result: T; etag: string }>
delete<T>(
url: string,
accessToken: string | undefined
): Promise<{ result: T; etag: string }>
getCsrfToken(type: 'general' | 'file'): CsrfToken | undefined
saveLocalStorageToken(accessToken: string, refreshToken: string): void
clearCsrfTokens(): void
clearLocalStorageTokens(): void
getBaseUrl(): string
}
export interface SASjsRequest {
serviceLink: string
timestamp: Date
sourceCode: string
generatedCode: string
logFile: string
SASWORK: any
}
export interface SasjsParsedResponse<T> {
result: T
log: string
etag: string
status: number
printOutput?: string
}
export type VerboseMode = boolean | 'bleached'

View File

@@ -1,12 +0,0 @@
/**
* Represents a SASjs request, its response and logs.
*
*/
export interface SASjsRequest {
serviceLink: string
timestamp: Date
sourceCode: string
generatedCode: string
logFile: string
SASWORK: any
}

View File

@@ -6,6 +6,7 @@ export * from './Job'
export * from './JobDefinition'
export * from './JobResult'
export * from './Link'
export * from './Login'
export * from './SASjsConfig'
export * from './RequestClient'
export * from './Session'
@@ -13,3 +14,4 @@ export * from './UploadFile'
export * from './PollOptions'
export * from './WriteStream'
export * from './ExecuteScript'
export * from './errors'

View File

@@ -1,4 +1,4 @@
import { SASjsRequest } from '../types/SASjsRequest'
import { SASjsRequest } from '../types'
/**
* Comparator for SASjs request timestamps.