diff --git a/src/SASjs.ts b/src/SASjs.ts index 993922f..1d560a1 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -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 { diff --git a/src/request/RequestClient.ts b/src/request/RequestClient.ts index b9586c7..2b70d9e 100644 --- a/src/request/RequestClient.ts +++ b/src/request/RequestClient.ts @@ -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( - url: string, - accessToken: string | undefined, - contentType: string, - overrideHeaders: { [key: string]: string | number } - ): Promise<{ result: T; etag: string }> - - post( - url: string, - data: any, - accessToken: string | undefined, - contentType: string, - overrideHeaders: { [key: string]: string | number } - ): Promise<{ result: T; etag: string }> - - put( - url: string, - data: any, - accessToken: string | undefined, - overrideHeaders: { [key: string]: string | number } - ): Promise<{ result: T; etag: string }> - - delete( - 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 diff --git a/src/request/SasjsRequestClient.ts b/src/request/SasjsRequestClient.ts index 760c5c8..175c68c 100644 --- a/src/request/SasjsRequestClient.ts +++ b/src/request/SasjsRequestClient.ts @@ -1,19 +1,11 @@ import { RequestClient } from './RequestClient' import { AxiosResponse } from 'axios' - -export interface SasjsParsedResponse { - 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 = {} diff --git a/src/request/spec/SasjsRequestClient.spec.ts b/src/request/spec/SasjsRequestClient.spec.ts index b70007b..1018fcb 100644 --- a/src/request/spec/SasjsRequestClient.spec.ts +++ b/src/request/spec/SasjsRequestClient.spec.ts @@ -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', () => { diff --git a/src/test/RequestClient.spec.ts b/src/test/RequestClient.spec.ts index e9650e9..d592797 100644 --- a/src/test/RequestClient.spec.ts +++ b/src/test/RequestClient.spec.ts @@ -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' diff --git a/src/types/RequestClient.ts b/src/types/RequestClient.ts index 4765575..08072c3 100644 --- a/src/types/RequestClient.ts +++ b/src/types/RequestClient.ts @@ -1 +1,55 @@ +import { CsrfToken } from '..' + +export interface HttpClient { + get( + url: string, + accessToken: string | undefined, + contentType: string, + overrideHeaders: { [key: string]: string | number } + ): Promise<{ result: T; etag: string }> + + post( + url: string, + data: any, + accessToken: string | undefined, + contentType: string, + overrideHeaders: { [key: string]: string | number } + ): Promise<{ result: T; etag: string }> + + put( + url: string, + data: any, + accessToken: string | undefined, + overrideHeaders: { [key: string]: string | number } + ): Promise<{ result: T; etag: string }> + + delete( + 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 { + result: T + log: string + etag: string + status: number + printOutput?: string +} + export type VerboseMode = boolean | 'bleached' diff --git a/src/types/SASjsRequest.ts b/src/types/SASjsRequest.ts deleted file mode 100644 index f0646bb..0000000 --- a/src/types/SASjsRequest.ts +++ /dev/null @@ -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 -} diff --git a/src/types/index.ts b/src/types/index.ts index 5d51e4a..a3a6978 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -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' diff --git a/src/utils/compareTimestamps.ts b/src/utils/compareTimestamps.ts index 4e6f943..d08f9cd 100644 --- a/src/utils/compareTimestamps.ts +++ b/src/utils/compareTimestamps.ts @@ -1,4 +1,4 @@ -import { SASjsRequest } from '../types/SASjsRequest' +import { SASjsRequest } from '../types' /** * Comparator for SASjs request timestamps.