Linting and adding JSON header.

This commit is contained in:
mike12345567 2021-12-13 18:20:02 +00:00
parent 17f083e586
commit 64fa8055ce
4 changed files with 31 additions and 11 deletions

View File

@ -3,7 +3,7 @@ import { queryValidation } from "../validation"
import { generateQueryID } from "../../../../db/utils"
import { ImportInfo, ImportSource } from "./sources/base"
import { OpenAPI2 } from "./sources/openapi2"
import { Query } from './../../../../definitions/common';
import { Query } from "./../../../../definitions/common"
import { Curl } from "./sources/curl"
interface ImportResult {
errorQueries: Query[]

View File

@ -29,7 +29,7 @@ const parseBody = (curl: any) => {
}
const parseCookie = (curl: any) => {
if (curl.cookies){
if (curl.cookies) {
return Object.entries(curl.cookies).reduce((acc, entry) => {
const [key, value] = entry
return acc + `${key}=${value}; `

View File

@ -1,6 +1,6 @@
export interface IntegrationBase {
create?(query: any): Promise<any[]|any>
read?(query: any): Promise<any[]|any>
update?(query: any): Promise<any[]|any>
delete?(query: any): Promise<any[]|any>
create?(query: any): Promise<any[] | any>
read?(query: any): Promise<any[] | any>
update?(query: any): Promise<any[] | any>
delete?(query: any): Promise<any[] | any>
}

View File

@ -115,7 +115,9 @@ module RestModule {
data = await response.text()
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`
headers = response.headers.raw()
for (let [key, value] of Object.entries(headers)) {
@ -148,7 +150,15 @@ module RestModule {
}
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.config.defaultHeaders,
...headers,
@ -166,15 +176,25 @@ module RestModule {
if (requestBody) {
switch (bodyType) {
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
break
default: case BodyTypes.JSON:
default:
case BodyTypes.JSON:
try {
// confirm its json
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.headers["Content-Type"] = "application/json"
}
} catch (err) {
throw "Invalid JSON for request body"