mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-08 13:00:05 +00:00
fix: new axios requires form data content type, es6 strict issues with iterations
This commit is contained in:
@@ -73,8 +73,10 @@ export class SasjsJobExecutor extends BaseJobExecutor {
|
||||
/* The NodeFormData object does not set the request header - so, set it */
|
||||
const contentType =
|
||||
formData instanceof NodeFormData && typeof FormData === 'undefined'
|
||||
? `multipart/form-data; boundary=${formData.getBoundary()}`
|
||||
: undefined
|
||||
? `multipart/form-data; boundary=${
|
||||
formData.getHeaders()['content-type']
|
||||
}`
|
||||
: 'multipart/form-data'
|
||||
|
||||
const requestPromise = new Promise((resolve, reject) => {
|
||||
this.requestClient!.post(
|
||||
|
||||
@@ -150,8 +150,10 @@ export class WebJobExecutor extends BaseJobExecutor {
|
||||
/* The NodeFormData object does not set the request header - so, set it */
|
||||
const contentType =
|
||||
formData instanceof NodeFormData && typeof FormData === 'undefined'
|
||||
? `multipart/form-data; boundary=${formData.getBoundary()}`
|
||||
: undefined
|
||||
? `multipart/form-data; boundary=${
|
||||
formData.getHeaders()['content-type']
|
||||
}`
|
||||
: 'multipart/form-data'
|
||||
|
||||
const requestPromise = new Promise((resolve, reject) => {
|
||||
this.requestClient!.post(
|
||||
|
||||
@@ -191,6 +191,13 @@ export class RequestClient implements HttpClient {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contentType Newer version of Axios is more strict so if you don't
|
||||
* set the contentType to `form data` while sending a FormData object
|
||||
* application/json will be used by default, axios won’t treat it as FormData.
|
||||
* Instead, it serializes data as JSON—resulting in a payload like
|
||||
* {"sometable":{}} and we lose the multipart/form-data formatting.
|
||||
*/
|
||||
public async post<T>(
|
||||
url: string,
|
||||
data: any,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { isNode } from './'
|
||||
import NodeFormData from 'form-data'
|
||||
|
||||
export const getFormData = () =>
|
||||
export const getFormData = (): NodeFormData | FormData =>
|
||||
isNode() ? new NodeFormData() : new FormData()
|
||||
|
||||
@@ -52,19 +52,22 @@ export const validateInput = (
|
||||
}
|
||||
}
|
||||
|
||||
for (const item of data[key]) {
|
||||
if (getType(item) !== 'object') {
|
||||
return {
|
||||
status: false,
|
||||
msg: `Table ${key} contains invalid structure. ${MORE_INFO}`
|
||||
}
|
||||
} else {
|
||||
const attributes = Object.keys(item)
|
||||
for (const attribute of attributes) {
|
||||
if (item[attribute] === undefined) {
|
||||
return {
|
||||
status: false,
|
||||
msg: `A row in table ${key} contains invalid value. Can't assign undefined to ${attribute}.`
|
||||
// ES6 is stricter so we had to include the check for the array
|
||||
if (Array.isArray(data[key])) {
|
||||
for (const item of data[key]) {
|
||||
if (getType(item) !== 'object') {
|
||||
return {
|
||||
status: false,
|
||||
msg: `Table ${key} contains invalid structure. ${MORE_INFO}`
|
||||
}
|
||||
} else {
|
||||
const attributes = Object.keys(item)
|
||||
for (const attribute of attributes) {
|
||||
if (item[attribute] === undefined) {
|
||||
return {
|
||||
status: false,
|
||||
msg: `A row in table ${key} contains invalid value. Can't assign undefined to ${attribute}.`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user