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

chore: merge master

This commit is contained in:
2022-03-02 12:38:38 +05:00
4 changed files with 384 additions and 362 deletions

699
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -43,32 +43,32 @@
"@types/axios": "0.14.0", "@types/axios": "0.14.0",
"@types/express": "4.17.13", "@types/express": "4.17.13",
"@types/form-data": "2.5.0", "@types/form-data": "2.5.0",
"@types/jest": "27.0.2", "@types/jest": "27.4.0",
"@types/mime": "2.0.3", "@types/mime": "2.0.3",
"@types/pem": "1.9.6", "@types/pem": "1.9.6",
"@types/tough-cookie": "4.0.1", "@types/tough-cookie": "4.0.1",
"copyfiles": "2.4.1", "copyfiles": "2.4.1",
"cp": "0.2.0", "cp": "0.2.0",
"dotenv": "10.0.0", "dotenv": "16.0.0",
"express": "4.17.1", "express": "4.17.3",
"jest": "27.4.7", "jest": "27.4.7",
"jest-extended": "2.0.0", "jest-extended": "2.0.0",
"node-polyfill-webpack-plugin": "1.1.4", "node-polyfill-webpack-plugin": "1.1.4",
"path": "0.12.7", "path": "0.12.7",
"pem": "1.14.4", "pem": "1.14.6",
"process": "0.11.10", "process": "0.11.10",
"rimraf": "3.0.2", "rimraf": "3.0.2",
"semantic-release": "18.0.0", "semantic-release": "18.0.0",
"terser-webpack-plugin": "5.3.0", "terser-webpack-plugin": "5.3.1",
"ts-jest": "27.1.3", "ts-jest": "27.1.3",
"ts-loader": "9.2.6", "ts-loader": "9.2.6",
"tslint": "6.1.3", "tslint": "6.1.3",
"tslint-config-prettier": "1.18.0", "tslint-config-prettier": "1.18.0",
"typedoc": "0.22.11", "typedoc": "0.22.11",
"typedoc-plugin-rename-defaults": "^0.4.0", "typedoc-plugin-rename-defaults": "^0.4.0",
"typescript": "4.5.4", "typescript": "4.5.5",
"webpack": "5.66.0", "webpack": "5.69.0",
"webpack-cli": "4.7.2" "webpack-cli": "4.9.2"
}, },
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,5 @@
import { SasAuthResponse } from '@sasjs/utils/types' import { SasAuthResponse } from '@sasjs/utils/types'
import { prefixMessage } from '@sasjs/utils/error' import { prefixMessage } from '@sasjs/utils/error'
import * as NodeFormData from 'form-data'
import { RequestClient } from '../request/RequestClient' import { RequestClient } from '../request/RequestClient'
/** /**
@@ -24,26 +23,17 @@ export async function getAccessTokenForViya(
token = Buffer.from(clientId + ':' + clientSecret).toString('base64') token = Buffer.from(clientId + ':' + clientSecret).toString('base64')
} }
const headers = { const headers = {
Authorization: 'Basic ' + token Authorization: 'Basic ' + token,
Accept: 'application/json'
} }
let formData const data = new URLSearchParams({
if (typeof FormData === 'undefined') { grant_type: 'authorization_code',
formData = new NodeFormData() code: authCode
} else { })
formData = new FormData()
}
formData.append('grant_type', 'authorization_code')
formData.append('code', authCode)
const authResponse = await requestClient const authResponse = await requestClient
.post( .post(url, data, undefined, 'application/x-www-form-urlencoded', headers)
url,
formData,
undefined,
'multipart/form-data; boundary=' + (formData as any)._boundary,
headers
)
.then((res) => res.result as SasAuthResponse) .then((res) => res.result as SasAuthResponse)
.catch((err) => { .catch((err) => {
throw prefixMessage(err, 'Error while getting access token. ') throw prefixMessage(err, 'Error while getting access token. ')

View File

@@ -35,11 +35,12 @@ describe('getAccessTokenForViya', () => {
expect(requestClient.post).toHaveBeenCalledWith( expect(requestClient.post).toHaveBeenCalledWith(
'/SASLogon/oauth/token', '/SASLogon/oauth/token',
expect.any(NodeFormData), expect.any(URLSearchParams),
undefined, undefined,
expect.stringContaining('multipart/form-data; boundary='), 'application/x-www-form-urlencoded',
{ {
Authorization: 'Basic ' + token Authorization: 'Basic ' + token,
Accept: 'application/json'
} }
) )
}) })