1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-10 17:04:36 +00:00

fix: usage and typings, axios, nodeFormData, cookiejar...

This commit is contained in:
2025-02-28 15:04:51 +01:00
parent be3ce56b85
commit 77306fedee
21 changed files with 1284 additions and 633 deletions

View File

@@ -142,6 +142,8 @@ module.exports = {
// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
testEnvironment: 'jest-environment-jsdom',
// Adds a location field to test results
// testLocationInResults: false,

1849
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -46,7 +46,7 @@
"devDependencies": {
"@cypress/webpack-preprocessor": "5.9.1",
"@types/express": "4.17.13",
"@types/jest": "27.4.0",
"@types/jest": "29.5.14",
"@types/mime": "2.0.3",
"@types/pem": "1.9.6",
"@types/tough-cookie": "4.0.2",
@@ -55,8 +55,9 @@
"cypress": "7.7.0",
"dotenv": "16.0.0",
"express": "4.17.3",
"jest": "27.4.7",
"jest-extended": "2.0.0",
"jest": "29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-extended": "4.0.2",
"node-polyfill-webpack-plugin": "1.1.4",
"path": "0.12.7",
"pem": "1.14.5",
@@ -64,13 +65,13 @@
"process": "0.11.10",
"semantic-release": "19.0.3",
"terser-webpack-plugin": "5.3.6",
"ts-jest": "27.1.3",
"ts-jest": "29.2.6",
"ts-loader": "9.4.0",
"tslint": "6.1.3",
"tslint-config-prettier": "1.18.0",
"typedoc": "0.23.24",
"typedoc-plugin-rename-defaults": "0.6.4",
"typescript": "4.8.3",
"typescript": "4.9.5",
"webpack": "5.76.2",
"webpack-cli": "4.9.2"
},

View File

@@ -1,6 +1,6 @@
import * as https from 'https'
import { generateTimestamp } from '@sasjs/utils/time'
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import { Sas9RequestClient } from './request/Sas9RequestClient'
import { isUrl } from './utils'

View File

@@ -1,5 +1,5 @@
import { isRelativePath, isUri, isUrl } from './utils'
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import {
Job,
Session,

View File

@@ -1,4 +1,4 @@
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import { AuthConfig, ServerType, ServicePackSASjs } from '@sasjs/utils/types'
import { prefixMessage } from '@sasjs/utils/error'
import { ExecutionQuery } from './types'

View File

@@ -1,6 +1,6 @@
import { SasAuthResponse, ServerType } from '@sasjs/utils/types'
import { prefixMessage } from '@sasjs/utils/error'
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import { RequestClient } from '../request/RequestClient'
import { isNode } from '../utils'
import { getTokenRequestErrorPrefix } from './getTokenRequestErrorPrefix'

View File

@@ -1,5 +1,5 @@
import { AuthConfig } from '@sasjs/utils/types'
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import { generateToken, mockAuthResponse } from './mockResponses'
import { RequestClient } from '../../request/RequestClient'
import { getAccessTokenForViya } from '../getAccessTokenForViya'

View File

@@ -1,5 +1,5 @@
import { AuthConfig, ServerType } from '@sasjs/utils/types'
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import { generateToken, mockAuthResponse } from './mockResponses'
import { RequestClient } from '../../request/RequestClient'
import { refreshTokensForViya } from '../refreshTokensForViya'

View File

@@ -1,4 +1,4 @@
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import { convertToCSV } from '../utils/convertToCsv'
import { isNode } from '../utils'

View File

@@ -1,4 +1,4 @@
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import { convertToCSV, isFormatsTable } from '../utils/convertToCsv'
import { splitChunks } from '../utils/splitChunks'

View File

@@ -1,6 +1,6 @@
import { generateFileUploadForm } from '../generateFileUploadForm'
import { convertToCSV } from '../../utils/convertToCsv'
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import * as isNodeModule from '../../utils/isNode'
describe('generateFileUploadForm', () => {

View File

@@ -1,6 +1,6 @@
import * as https from 'https'
import { ServerType } from '@sasjs/utils/types'
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import { ErrorResponse } from '../types/errors'
import { convertToCSV, isRelativePath } from '../utils'
import { BaseJobExecutor } from './JobExecutor'

View File

@@ -1,4 +1,4 @@
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import {
AuthConfig,
ExtraResponseAttributes,

View File

@@ -1,4 +1,4 @@
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
import {
AuthConfig,
ExtraResponseAttributes,

View File

@@ -1,6 +1,6 @@
import * as https from 'https'
import { AxiosRequestConfig } from 'axios'
import axiosCookieJarSupport from 'axios-cookiejar-support'
import { wrapper } from 'axios-cookiejar-support'
import * as tough from 'tough-cookie'
import { prefixMessage } from '@sasjs/utils/error'
import { RequestClient, throwIfError } from './RequestClient'
@@ -17,8 +17,8 @@ export class Sas9RequestClient extends RequestClient {
this.httpClient.defaults.validateStatus = (status) =>
status >= 200 && status < 303
if (axiosCookieJarSupport) {
axiosCookieJarSupport(this.httpClient)
if (wrapper) {
wrapper(this.httpClient)
this.httpClient.defaults.jar = new tough.CookieJar()
}
}

View File

@@ -1,6 +1,6 @@
import { SASJS_LOGS_SEPARATOR, SasjsRequestClient } from '../SasjsRequestClient'
import { SasjsParsedResponse } from '../../types'
import { AxiosResponse } from 'axios'
import { AxiosHeaders, AxiosResponse } from 'axios'
describe('SasjsRequestClient', () => {
const requestClient = new SasjsRequestClient('')
@@ -37,7 +37,7 @@ ${SASJS_LOGS_SEPARATOR}`,
status,
statusText: 'ok',
headers: { etag },
config: {}
config: { headers: new AxiosHeaders() }
}
const expectedParsedResponse: SasjsParsedResponse<string> = {
@@ -65,7 +65,7 @@ ${printOutput}`,
status,
statusText: 'ok',
headers: { etag },
config: {}
config: { headers: new AxiosHeaders() }
}
const expectedParsedResponse: SasjsParsedResponse<string> = {
@@ -100,7 +100,7 @@ ${SASJS_LOGS_SEPARATOR}`,
status,
statusText: 'ok',
headers: { etag },
config: {}
config: { headers: new AxiosHeaders() }
}
const expectedParsedResponse: SasjsParsedResponse<string> = {
@@ -139,7 +139,7 @@ ${printOutput}`,
status,
statusText: 'ok',
headers: { etag },
config: {}
config: { headers: new AxiosHeaders() }
}
const expectedParsedResponse: SasjsParsedResponse<string> = {

View File

@@ -5,7 +5,7 @@ import { app, mockedAuthResponse } from './SAS_server_app'
import { ServerType } from '@sasjs/utils/types'
import SASjs from '../SASjs'
import * as axiosModules from '../utils/createAxiosInstance'
import axios from 'axios'
import axios, { AxiosHeaders } from 'axios'
import {
LoginRequiredError,
AuthorizeError,
@@ -209,7 +209,7 @@ ${noValueMessage}
status,
statusText: '',
headers: {},
config: { data: reqData },
config: { data: reqData, headers: new AxiosHeaders() },
request: { _header: reqHeaders, res: { rawHeaders: resHeaders } }
}
@@ -278,7 +278,7 @@ ${noValueMessage}
status,
statusText: '',
headers: {},
config: { data: reqData },
config: { data: reqData, headers: new AxiosHeaders() },
request: { _header: reqHeaders, res: { rawHeaders: resHeaders } }
}
const mockedAxiosError = {
@@ -328,7 +328,7 @@ ${resHeaders[0]}: ${resHeaders[1]}${
status,
statusText: '',
headers: {},
config: { data: reqData },
config: { data: reqData, headers: new AxiosHeaders() },
request: { _header: reqHeaders, res: { rawHeaders: resHeaders } }
}
const mockedAxiosError = {

View File

@@ -1,5 +1,5 @@
import { isNode } from './'
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
export const getFormData = () =>
isNode() ? new NodeFormData() : new FormData()

View File

@@ -1,6 +1,6 @@
import { getFormData } from '..'
import * as isNodeModule from '../isNode'
import * as NodeFormData from 'form-data'
import NodeFormData from 'form-data'
describe('getFormData', () => {
it('should return NodeFormData if environment is Node', () => {

View File

@@ -1,10 +1,11 @@
{
"compilerOptions": {
"lib": ["ES2018", "DOM", "ES2019.String"],
"target": "es5",
"target": "es6",
"module": "commonjs",
"declaration": true,
"outDir": "./build",
"esModuleInterop": true,
"strict": true,
"sourceMap": true,
"typeRoots": ["./node_modules/@types", "./src/types/system"]