Linting and adding JSON header.
This commit is contained in:
parent
ac49d718a4
commit
8d6dc14608
|
@ -3,7 +3,7 @@ import { queryValidation } from "../validation"
|
||||||
import { generateQueryID } from "../../../../db/utils"
|
import { generateQueryID } from "../../../../db/utils"
|
||||||
import { ImportInfo, ImportSource } from "./sources/base"
|
import { ImportInfo, ImportSource } from "./sources/base"
|
||||||
import { OpenAPI2 } from "./sources/openapi2"
|
import { OpenAPI2 } from "./sources/openapi2"
|
||||||
import { Query } from './../../../../definitions/common';
|
import { Query } from "./../../../../definitions/common"
|
||||||
import { Curl } from "./sources/curl"
|
import { Curl } from "./sources/curl"
|
||||||
interface ImportResult {
|
interface ImportResult {
|
||||||
errorQueries: Query[]
|
errorQueries: Query[]
|
||||||
|
|
|
@ -29,7 +29,7 @@ const parseBody = (curl: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseCookie = (curl: any) => {
|
const parseCookie = (curl: any) => {
|
||||||
if (curl.cookies){
|
if (curl.cookies) {
|
||||||
return Object.entries(curl.cookies).reduce((acc, entry) => {
|
return Object.entries(curl.cookies).reduce((acc, entry) => {
|
||||||
const [key, value] = entry
|
const [key, value] = entry
|
||||||
return acc + `${key}=${value}; `
|
return acc + `${key}=${value}; `
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export interface IntegrationBase {
|
export interface IntegrationBase {
|
||||||
create?(query: any): Promise<any[]|any>
|
create?(query: any): Promise<any[] | any>
|
||||||
read?(query: any): Promise<any[]|any>
|
read?(query: any): Promise<any[] | any>
|
||||||
update?(query: any): Promise<any[]|any>
|
update?(query: any): Promise<any[] | any>
|
||||||
delete?(query: any): Promise<any[]|any>
|
delete?(query: any): Promise<any[] | any>
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,9 @@ module RestModule {
|
||||||
data = await response.text()
|
data = await response.text()
|
||||||
raw = data
|
raw = data
|
||||||
}
|
}
|
||||||
const size = formatBytes(response.headers.get("content-length") || Buffer.byteLength(raw, "utf8"))
|
const size = formatBytes(
|
||||||
|
response.headers.get("content-length") || Buffer.byteLength(raw, "utf8")
|
||||||
|
)
|
||||||
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
|
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
|
||||||
headers = response.headers.raw()
|
headers = response.headers.raw()
|
||||||
for (let [key, value] of Object.entries(headers)) {
|
for (let [key, value] of Object.entries(headers)) {
|
||||||
|
@ -148,7 +150,15 @@ module RestModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _req(query: RestQuery) {
|
async _req(query: RestQuery) {
|
||||||
const { path = "", queryString = "", headers = {}, method = "GET", disabledHeaders, bodyType, requestBody } = query
|
const {
|
||||||
|
path = "",
|
||||||
|
queryString = "",
|
||||||
|
headers = {},
|
||||||
|
method = "GET",
|
||||||
|
disabledHeaders,
|
||||||
|
bodyType,
|
||||||
|
requestBody,
|
||||||
|
} = query
|
||||||
this.headers = {
|
this.headers = {
|
||||||
...this.config.defaultHeaders,
|
...this.config.defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
|
@ -166,15 +176,25 @@ module RestModule {
|
||||||
if (requestBody) {
|
if (requestBody) {
|
||||||
switch (bodyType) {
|
switch (bodyType) {
|
||||||
case BodyTypes.TEXT:
|
case BodyTypes.TEXT:
|
||||||
const text = typeof requestBody !== "string" ? JSON.stringify(requestBody) : requestBody
|
const text =
|
||||||
|
typeof requestBody !== "string"
|
||||||
|
? JSON.stringify(requestBody)
|
||||||
|
: requestBody
|
||||||
|
// content type defaults to plaintext
|
||||||
input.body = text
|
input.body = text
|
||||||
break
|
break
|
||||||
default: case BodyTypes.JSON:
|
default:
|
||||||
|
case BodyTypes.JSON:
|
||||||
try {
|
try {
|
||||||
// confirm its json
|
// confirm its json
|
||||||
const json = JSON.parse(requestBody)
|
const json = JSON.parse(requestBody)
|
||||||
if (json && typeof json === "object" && Object.keys(json).length > 0) {
|
if (
|
||||||
|
json &&
|
||||||
|
typeof json === "object" &&
|
||||||
|
Object.keys(json).length > 0
|
||||||
|
) {
|
||||||
input.body = requestBody
|
input.body = requestBody
|
||||||
|
input.headers["Content-Type"] = "application/json"
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw "Invalid JSON for request body"
|
throw "Invalid JSON for request body"
|
||||||
|
|
Loading…
Reference in New Issue