refactor: lint
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { cancelRunningRequest, sendNetworkRequest } from "../network"
|
||||
|
||||
import AxiosStrategy, { cancelRunningAxiosRequest } from "../strategies/AxiosStrategy"
|
||||
import AxiosStrategy, {
|
||||
cancelRunningAxiosRequest,
|
||||
} from "../strategies/AxiosStrategy"
|
||||
import ExtensionStrategy, {
|
||||
cancelRunningExtensionRequest,
|
||||
hasExtensionInstalled,
|
||||
@@ -23,9 +25,9 @@ jest.mock("~/newstore/settings", () => {
|
||||
return {
|
||||
settingsStore: {
|
||||
value: {
|
||||
EXTENSIONS_ENABLED: false
|
||||
}
|
||||
}
|
||||
EXTENSIONS_ENABLED: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -60,7 +62,6 @@ describe("cancelRunningRequest", () => {
|
||||
})
|
||||
|
||||
describe("sendNetworkRequest", () => {
|
||||
|
||||
test("runs only axios request if extension not allowed in settings and extension is installed and clears the progress bar", async () => {
|
||||
hasExtensionInstalled.mockReturnValue(true)
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
|
||||
import { cancelRunningRequest, sendNetworkRequest } from "../network"
|
||||
|
||||
import AxiosStrategy, { cancelRunningAxiosRequest } from "../strategies/AxiosStrategy"
|
||||
import AxiosStrategy, {
|
||||
cancelRunningAxiosRequest,
|
||||
} from "../strategies/AxiosStrategy"
|
||||
import ExtensionStrategy, {
|
||||
cancelRunningExtensionRequest,
|
||||
hasExtensionInstalled,
|
||||
@@ -24,9 +25,9 @@ jest.mock("~/newstore/settings", () => {
|
||||
return {
|
||||
settingsStore: {
|
||||
value: {
|
||||
EXTENSIONS_ENABLED: true
|
||||
}
|
||||
}
|
||||
EXTENSIONS_ENABLED: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { PASS, FAIL } from "../postwomanTesting"
|
||||
import runTestScriptWithVariables from "../postwomanTesting"
|
||||
import runTestScriptWithVariables, { PASS, FAIL } from "../postwomanTesting"
|
||||
|
||||
function getTestResult(script, index) {
|
||||
return runTestScriptWithVariables(script).testResults[index].result
|
||||
@@ -41,8 +40,12 @@ describe("toBe", () => {
|
||||
test("test for negative assertion (.not.toBe)", () => {
|
||||
expect(getTestResult("pw.expect(1).not.toBe(1)", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(1).not.toBe(2)", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('world').not.toBe('planet')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('world').not.toBe('world')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('world').not.toBe('planet')", 0)).toEqual(
|
||||
PASS
|
||||
)
|
||||
expect(getTestResult("pw.expect('world').not.toBe('world')", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -54,16 +57,29 @@ describe("toHaveProperty", () => {
|
||||
|
||||
test("test for positive assertion (.toHaveProperty)", () => {
|
||||
expect(
|
||||
getTestResult(`pw.expect(${JSON.stringify(dummyResponse)}).toHaveProperty("id")`, 0)
|
||||
getTestResult(
|
||||
`pw.expect(${JSON.stringify(dummyResponse)}).toHaveProperty("id")`,
|
||||
0
|
||||
)
|
||||
).toEqual(PASS)
|
||||
expect(
|
||||
getTestResult(`pw.expect(${dummyResponse.id}).toBe(843)`, 0)
|
||||
).toEqual(PASS)
|
||||
expect(getTestResult(`pw.expect(${dummyResponse.id}).toBe(843)`, 0)).toEqual(PASS)
|
||||
})
|
||||
test("test for negative assertion (.not.toHaveProperty)", () => {
|
||||
expect(
|
||||
getTestResult(`pw.expect(${JSON.stringify(dummyResponse)}).not.toHaveProperty("type")`, 0)
|
||||
getTestResult(
|
||||
`pw.expect(${JSON.stringify(
|
||||
dummyResponse
|
||||
)}).not.toHaveProperty("type")`,
|
||||
0
|
||||
)
|
||||
).toEqual(PASS)
|
||||
expect(
|
||||
getTestResult(`pw.expect(${JSON.stringify(dummyResponse)}).toHaveProperty("type")`, 0)
|
||||
getTestResult(
|
||||
`pw.expect(${JSON.stringify(dummyResponse)}).toHaveProperty("type")`,
|
||||
0
|
||||
)
|
||||
).toEqual(FAIL)
|
||||
})
|
||||
})
|
||||
@@ -77,12 +93,18 @@ describe("toBeLevel2xx", () => {
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('200').toBeLevel2xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('200').not.toBeLevel2xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('200').not.toBeLevel2xx()", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(getTestResult("pw.expect('300').toBeLevel2xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('300').not.toBeLevel2xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('300').not.toBeLevel2xx()", 0)).toEqual(
|
||||
PASS
|
||||
)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel2xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel2xx()", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel2xx()", 0)).toEqual(FAIL)
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel2xx()")
|
||||
@@ -99,12 +121,18 @@ describe("toBeLevel3xx()", () => {
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('300').toBeLevel3xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('300').not.toBeLevel3xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('300').not.toBeLevel3xx()", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(getTestResult("pw.expect('400').toBeLevel3xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('400').not.toBeLevel3xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('400').not.toBeLevel3xx()", 0)).toEqual(
|
||||
PASS
|
||||
)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel3xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel3xx()", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel3xx()", 0)).toEqual(FAIL)
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel3xx()")
|
||||
@@ -121,12 +149,18 @@ describe("toBeLevel4xx()", () => {
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('400').toBeLevel4xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('400').not.toBeLevel4xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('400').not.toBeLevel4xx()", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(getTestResult("pw.expect('500').toBeLevel4xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('500').not.toBeLevel4xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('500').not.toBeLevel4xx()", 0)).toEqual(
|
||||
PASS
|
||||
)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel4xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel4xx()", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel4xx()", 0)).toEqual(FAIL)
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel4xx()")
|
||||
@@ -143,12 +177,18 @@ describe("toBeLevel5xx()", () => {
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('500').toBeLevel5xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('500').not.toBeLevel5xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('500').not.toBeLevel5xx()", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(getTestResult("pw.expect('200').toBeLevel5xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('200').not.toBeLevel5xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('200').not.toBeLevel5xx()", 0)).toEqual(
|
||||
PASS
|
||||
)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel5xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel5xx()", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel5xx()", 0)).toEqual(FAIL)
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel5xx()")
|
||||
@@ -160,40 +200,85 @@ describe("toHaveLength()", () => {
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('word').toHaveLength(4)", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('word').toHaveLength(5)", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('word').not.toHaveLength(4)", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('word').not.toHaveLength(5)", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('word').not.toHaveLength(4)", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(getTestResult("pw.expect('word').not.toHaveLength(5)", 0)).toEqual(
|
||||
PASS
|
||||
)
|
||||
})
|
||||
test("test for arrays", () => {
|
||||
const fruits = "['apples', 'bananas', 'oranges', 'grapes', 'strawberries', 'cherries']"
|
||||
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(6)`, 0)).toEqual(PASS)
|
||||
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(7)`, 0)).toEqual(FAIL)
|
||||
expect(getTestResult(`pw.expect(${fruits}).not.toHaveLength(6)`, 0)).toEqual(FAIL)
|
||||
expect(getTestResult(`pw.expect(${fruits}).not.toHaveLength(7)`, 0)).toEqual(PASS)
|
||||
const fruits =
|
||||
"['apples', 'bananas', 'oranges', 'grapes', 'strawberries', 'cherries']"
|
||||
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(6)`, 0)).toEqual(
|
||||
PASS
|
||||
)
|
||||
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(7)`, 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(
|
||||
getTestResult(`pw.expect(${fruits}).not.toHaveLength(6)`, 0)
|
||||
).toEqual(FAIL)
|
||||
expect(
|
||||
getTestResult(`pw.expect(${fruits}).not.toHaveLength(7)`, 0)
|
||||
).toEqual(PASS)
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeType()", () => {
|
||||
test("test for positive assertion", () => {
|
||||
expect(getTestResult("pw.expect('random').toBeType('string')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(true).toBeType('boolean')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('random').toBeType('string')", 0)).toEqual(
|
||||
PASS
|
||||
)
|
||||
expect(getTestResult("pw.expect(true).toBeType('boolean')", 0)).toEqual(
|
||||
PASS
|
||||
)
|
||||
expect(getTestResult("pw.expect(5).toBeType('number')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(new Date()).toBeType('object')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(undefined).toBeType('undefined')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(BigInt(123)).toBeType('bigint')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(Symbol('test')).toBeType('symbol')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(function() {}).toBeType('function')", 0)).toEqual(PASS)
|
||||
expect(
|
||||
getTestResult("pw.expect(new Date()).toBeType('object')", 0)
|
||||
).toEqual(PASS)
|
||||
expect(
|
||||
getTestResult("pw.expect(undefined).toBeType('undefined')", 0)
|
||||
).toEqual(PASS)
|
||||
expect(
|
||||
getTestResult("pw.expect(BigInt(123)).toBeType('bigint')", 0)
|
||||
).toEqual(PASS)
|
||||
expect(
|
||||
getTestResult("pw.expect(Symbol('test')).toBeType('symbol')", 0)
|
||||
).toEqual(PASS)
|
||||
expect(
|
||||
getTestResult("pw.expect(function() {}).toBeType('function')", 0)
|
||||
).toEqual(PASS)
|
||||
})
|
||||
test("test for negative assertion", () => {
|
||||
expect(getTestResult("pw.expect('random').not.toBeType('string')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(true).not.toBeType('boolean')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(5).not.toBeType('number')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(new Date()).not.toBeType('object')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(undefined).not.toBeType('undefined')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(BigInt(123)).not.toBeType('bigint')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(Symbol('test')).not.toBeType('symbol')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(function() {}).not.toBeType('function')", 0)).toEqual(FAIL)
|
||||
expect(
|
||||
getTestResult("pw.expect('random').not.toBeType('string')", 0)
|
||||
).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(true).not.toBeType('boolean')", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(getTestResult("pw.expect(5).not.toBeType('number')", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
expect(
|
||||
getTestResult("pw.expect(new Date()).not.toBeType('object')", 0)
|
||||
).toEqual(FAIL)
|
||||
expect(
|
||||
getTestResult("pw.expect(undefined).not.toBeType('undefined')", 0)
|
||||
).toEqual(FAIL)
|
||||
expect(
|
||||
getTestResult("pw.expect(BigInt(123)).not.toBeType('bigint')", 0)
|
||||
).toEqual(FAIL)
|
||||
expect(
|
||||
getTestResult("pw.expect(Symbol('test')).not.toBeType('symbol')", 0)
|
||||
).toEqual(FAIL)
|
||||
expect(
|
||||
getTestResult("pw.expect(function() {}).not.toBeType('function')", 0)
|
||||
).toEqual(FAIL)
|
||||
})
|
||||
test("unexpected type", () => {
|
||||
expect(getTestResult("pw.expect('random').toBeType('unknown')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('random').toBeType('unknown')", 0)).toEqual(
|
||||
FAIL
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { ApolloClient, HttpLink, InMemoryCache, split } from "@apollo/client/core"
|
||||
import {
|
||||
ApolloClient,
|
||||
HttpLink,
|
||||
InMemoryCache,
|
||||
split,
|
||||
} from "@apollo/client/core"
|
||||
import { WebSocketLink } from "@apollo/client/link/ws"
|
||||
import { setContext } from "@apollo/client/link/context"
|
||||
import { fb } from "./fb"
|
||||
import { getMainDefinition } from "@apollo/client/utilities"
|
||||
import { fb } from "./fb"
|
||||
|
||||
let authToken: String | null = null
|
||||
|
||||
@@ -56,7 +61,10 @@ const wsLink = new WebSocketLink({
|
||||
const splitLink = split(
|
||||
({ query }) => {
|
||||
const definition = getMainDefinition(query)
|
||||
return definition.kind === "OperationDefinition" && definition.operation === "subscription"
|
||||
return (
|
||||
definition.kind === "OperationDefinition" &&
|
||||
definition.operation === "subscription"
|
||||
)
|
||||
},
|
||||
wsLink,
|
||||
httpLink
|
||||
|
||||
@@ -8,7 +8,7 @@ const TEST_HTTP_PASSWORD = "mockPassword"
|
||||
const TEST_BEARER_TOKEN = "abcdefghijklmn"
|
||||
const TEST_RAW_REQUEST_BODY = "foo=bar&baz=qux"
|
||||
const TEST_RAW_PARAMS_JSON = '{"foo": "bar", "baz": "qux"}'
|
||||
const TEST_RAW_PARAMS_XML = `<?xml version=\'1.0\' encoding=\'utf-8\'?>
|
||||
const TEST_RAW_PARAMS_XML = `<?xml version='1.0' encoding='utf-8'?>
|
||||
<xml>
|
||||
<element foo="bar"></element>
|
||||
</xml>`
|
||||
|
||||
@@ -20,13 +20,20 @@ export const CLibcurlCodegen = {
|
||||
const requestString = []
|
||||
|
||||
requestString.push("CURL *hnd = curl_easy_init();")
|
||||
requestString.push(`curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "${method}");`)
|
||||
requestString.push(`curl_easy_setopt(hnd, CURLOPT_URL, "${url}${pathName}${queryString}");`)
|
||||
requestString.push(
|
||||
`curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "${method}");`
|
||||
)
|
||||
requestString.push(
|
||||
`curl_easy_setopt(hnd, CURLOPT_URL, "${url}${pathName}${queryString}");`
|
||||
)
|
||||
requestString.push(`struct curl_slist *headers = NULL;`)
|
||||
|
||||
if (headers) {
|
||||
headers.forEach(({ key, value }) => {
|
||||
if (key) requestString.push(`headers = curl_slist_append(headers, "${key}: ${value}");`)
|
||||
if (key)
|
||||
requestString.push(
|
||||
`headers = curl_slist_append(headers, "${key}: ${value}");`
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -50,10 +57,15 @@ export const CLibcurlCodegen = {
|
||||
requestBody = `"${requestBody}"`
|
||||
} else requestBody = JSON.stringify(requestBody)
|
||||
|
||||
requestString.push(`headers = curl_slist_append(headers, "Content-Type: ${contentType}");`)
|
||||
requestString.push(
|
||||
`headers = curl_slist_append(headers, "Content-Type: ${contentType}");`
|
||||
)
|
||||
requestString.push("curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);")
|
||||
requestString.push(
|
||||
`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${requestBody});`
|
||||
)
|
||||
} else
|
||||
requestString.push("curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);")
|
||||
requestString.push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${requestBody});`)
|
||||
} else requestString.push("curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);")
|
||||
|
||||
requestString.push(`CURLcode ret = curl_easy_perform(hnd);`)
|
||||
return requestString.join("\n")
|
||||
|
||||
@@ -57,12 +57,16 @@ export const CsRestsharpCodegen = {
|
||||
`client.Authenticator = new HttpBasicAuthenticator("${httpUser}", "${httpPassword}");\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
requestString.push(`request.AddHeader("Authorization", "Bearer ${bearerToken}");\n`)
|
||||
requestString.push(
|
||||
`request.AddHeader("Authorization", "Bearer ${bearerToken}");\n`
|
||||
)
|
||||
}
|
||||
|
||||
// content type
|
||||
if (contentType) {
|
||||
requestString.push(`request.AddHeader("Content-Type", "${contentType}");\n`)
|
||||
requestString.push(
|
||||
`request.AddHeader("Content-Type", "${contentType}");\n`
|
||||
)
|
||||
}
|
||||
|
||||
// custom headers
|
||||
|
||||
@@ -23,7 +23,9 @@ export const CurlCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
requestString.push(
|
||||
` -H 'Authorization: Basic ${window.btoa(unescape(encodeURIComponent(basic)))}'`
|
||||
` -H 'Authorization: Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}'`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
requestString.push(` -H 'Authorization: Bearer ${bearerToken}'`)
|
||||
|
||||
@@ -22,8 +22,8 @@ export const GoNativeCodegen = {
|
||||
const requestString = []
|
||||
let genHeaders = []
|
||||
// initial request setup
|
||||
let requestBody = rawInput ? rawParams : rawRequestBody
|
||||
if (method == "GET") {
|
||||
const requestBody = rawInput ? rawParams : rawRequestBody
|
||||
if (method === "GET") {
|
||||
requestString.push(
|
||||
`req, err := http.NewRequest("${method}", "${url}${pathName}${queryString}")\n`
|
||||
)
|
||||
@@ -52,7 +52,9 @@ export const GoNativeCodegen = {
|
||||
)}")\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(`req.Header.Set("Authorization", "Bearer ${bearerToken}")\n`)
|
||||
genHeaders.push(
|
||||
`req.Header.Set("Authorization", "Bearer ${bearerToken}")\n`
|
||||
)
|
||||
}
|
||||
// custom headers
|
||||
if (headers) {
|
||||
@@ -62,7 +64,9 @@ export const GoNativeCodegen = {
|
||||
}
|
||||
genHeaders = genHeaders.join("").slice(0, -1)
|
||||
requestString.push(`${genHeaders}\n`)
|
||||
requestString.push(`if err != nil {\n log.Fatalf("An Error Occured %v", err)\n}\n\n`)
|
||||
requestString.push(
|
||||
`if err != nil {\n log.Fatalf("An Error Occured %v", err)\n}\n\n`
|
||||
)
|
||||
|
||||
// request boilerplate
|
||||
requestString.push(`client := &http.Client{}\n`)
|
||||
|
||||
@@ -19,7 +19,9 @@ export const JavaOkhttpCodegen = {
|
||||
}) => {
|
||||
const requestString = []
|
||||
|
||||
requestString.push("OkHttpClient client = new OkHttpClient().newBuilder().build();")
|
||||
requestString.push(
|
||||
"OkHttpClient client = new OkHttpClient().newBuilder().build();"
|
||||
)
|
||||
|
||||
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
|
||||
let requestBody = rawInput ? rawParams : rawRequestBody
|
||||
@@ -28,17 +30,21 @@ export const JavaOkhttpCodegen = {
|
||||
requestBody = `"${requestBody}"`
|
||||
} else requestBody = JSON.stringify(requestBody)
|
||||
|
||||
requestString.push(`MediaType mediaType = MediaType.parse("${contentType}");`)
|
||||
requestString.push(`RequestBody body = RequestBody.create(mediaType,${requestBody});`)
|
||||
requestString.push(
|
||||
`MediaType mediaType = MediaType.parse("${contentType}");`
|
||||
)
|
||||
requestString.push(
|
||||
`RequestBody body = RequestBody.create(mediaType,${requestBody});`
|
||||
)
|
||||
}
|
||||
|
||||
requestString.push("Request request = new Request.Builder()")
|
||||
requestString.push(`.url(\"${url}${pathName}${queryString}\")`)
|
||||
requestString.push(`.url("${url}${pathName}${queryString}")`)
|
||||
|
||||
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
|
||||
requestString.push(`.method(\"${method}\", body)`)
|
||||
requestString.push(`.method("${method}", body)`)
|
||||
} else {
|
||||
requestString.push(`.method(\"${method}\", null)`)
|
||||
requestString.push(`.method("${method}", null)`)
|
||||
}
|
||||
|
||||
if (auth === "Basic Auth") {
|
||||
@@ -49,12 +55,14 @@ export const JavaOkhttpCodegen = {
|
||||
)}") \n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
requestString.push(`.addHeader("authorization", "Bearer ${bearerToken}" ) \n`)
|
||||
requestString.push(
|
||||
`.addHeader("authorization", "Bearer ${bearerToken}" ) \n`
|
||||
)
|
||||
}
|
||||
|
||||
if (headers) {
|
||||
headers.forEach(({ key, value }) => {
|
||||
if (key) requestString.push(`.addHeader(\"${key}\", \"${value}\")`)
|
||||
if (key) requestString.push(`.addHeader("${key}", "${value}")`)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,9 @@ export const JavaUnirestCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
requestString.push(
|
||||
`.header("authorization", "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}") \n`
|
||||
`.header("authorization", "Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}") \n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
requestString.push(`.header("authorization", "Bearer ${bearerToken}") \n`)
|
||||
|
||||
@@ -26,7 +26,9 @@ export const JavascriptFetchCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
genHeaders.push(
|
||||
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
|
||||
` "Authorization": "Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}",\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
|
||||
|
||||
@@ -18,9 +18,11 @@ export const JavascriptJqueryCodegen = {
|
||||
headers,
|
||||
}) => {
|
||||
const requestString = []
|
||||
let genHeaders = []
|
||||
const genHeaders = []
|
||||
|
||||
requestString.push(`jQuery.ajax({\n url: "${url}${pathName}${queryString}"`)
|
||||
requestString.push(
|
||||
`jQuery.ajax({\n url: "${url}${pathName}${queryString}"`
|
||||
)
|
||||
requestString.push(`,\n method: "${method.toUpperCase()}"`)
|
||||
const requestBody = rawInput ? rawParams : rawRequestBody
|
||||
|
||||
@@ -41,12 +43,16 @@ export const JavascriptJqueryCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
genHeaders.push(
|
||||
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
|
||||
` "Authorization": "Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}",\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
|
||||
}
|
||||
requestString.push(`,\n headers: {\n${genHeaders.join("").slice(0, -2)}\n }\n})`)
|
||||
requestString.push(
|
||||
`,\n headers: {\n${genHeaders.join("").slice(0, -2)}\n }\n})`
|
||||
)
|
||||
requestString.push(".then(response => {\n")
|
||||
requestString.push(" console.log(response);\n")
|
||||
requestString.push("})")
|
||||
|
||||
@@ -28,11 +28,14 @@ export const JavascriptXhrCodegen = {
|
||||
`xhr.open('${method}', '${url}${pathName}${queryString}', true, ${user}, ${password})`
|
||||
)
|
||||
if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
requestString.push(`xhr.setRequestHeader('Authorization', 'Bearer ${bearerToken}')`)
|
||||
requestString.push(
|
||||
`xhr.setRequestHeader('Authorization', 'Bearer ${bearerToken}')`
|
||||
)
|
||||
}
|
||||
if (headers) {
|
||||
headers.forEach(({ key, value }) => {
|
||||
if (key) requestString.push(`xhr.setRequestHeader('${key}', '${value}')`)
|
||||
if (key)
|
||||
requestString.push(`xhr.setRequestHeader('${key}', '${value}')`)
|
||||
})
|
||||
}
|
||||
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
|
||||
@@ -42,7 +45,9 @@ export const JavascriptXhrCodegen = {
|
||||
} else if (contentType.includes("x-www-form-urlencoded")) {
|
||||
requestBody = `"${requestBody}"`
|
||||
}
|
||||
requestString.push(`xhr.setRequestHeader('Content-Type', '${contentType}; charset=utf-8')`)
|
||||
requestString.push(
|
||||
`xhr.setRequestHeader('Content-Type', '${contentType}; charset=utf-8')`
|
||||
)
|
||||
requestString.push(`xhr.send(${requestBody})`)
|
||||
} else {
|
||||
requestString.push("xhr.send()")
|
||||
|
||||
@@ -18,10 +18,12 @@ export const NodejsAxiosCodegen = {
|
||||
headers,
|
||||
}) => {
|
||||
const requestString = []
|
||||
let genHeaders = []
|
||||
let requestBody = rawInput ? rawParams : rawRequestBody
|
||||
const genHeaders = []
|
||||
const requestBody = rawInput ? rawParams : rawRequestBody
|
||||
|
||||
requestString.push(`axios.${method.toLowerCase()}('${url}${pathName}${queryString}'`)
|
||||
requestString.push(
|
||||
`axios.${method.toLowerCase()}('${url}${pathName}${queryString}'`
|
||||
)
|
||||
if (requestBody.length !== 0) {
|
||||
requestString.push(", ")
|
||||
}
|
||||
@@ -36,12 +38,16 @@ export const NodejsAxiosCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
genHeaders.push(
|
||||
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
|
||||
` "Authorization": "Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}",\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
|
||||
}
|
||||
requestString.push(`${requestBody},{ \n headers : {${genHeaders.join("").slice(0, -2)}}\n})`)
|
||||
requestString.push(
|
||||
`${requestBody},{ \n headers : {${genHeaders.join("").slice(0, -2)}}\n})`
|
||||
)
|
||||
requestString.push(".then(response => {\n")
|
||||
requestString.push(" console.log(response);\n")
|
||||
requestString.push("})")
|
||||
|
||||
@@ -32,7 +32,9 @@ export const NodejsNativeCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
genHeaders.push(
|
||||
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
|
||||
` "Authorization": "Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}",\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
|
||||
@@ -47,7 +49,9 @@ export const NodejsNativeCodegen = {
|
||||
requestBody = `\`${requestBody}\``
|
||||
}
|
||||
if (contentType) {
|
||||
genHeaders.push(` "Content-Type": "${contentType}; charset=utf-8",\n`)
|
||||
genHeaders.push(
|
||||
` "Content-Type": "${contentType}; charset=utf-8",\n`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,11 +61,15 @@ export const NodejsNativeCodegen = {
|
||||
})
|
||||
}
|
||||
if (genHeaders.length > 0 || headers.length > 0) {
|
||||
requestString.push(` headers: {\n${genHeaders.join("").slice(0, -2)}\n }`)
|
||||
requestString.push(
|
||||
` headers: {\n${genHeaders.join("").slice(0, -2)}\n }`
|
||||
)
|
||||
}
|
||||
requestString.push(`};\n\n`)
|
||||
|
||||
requestString.push(`const request = http.request(url, options, (response) => {\n`)
|
||||
requestString.push(
|
||||
`const request = http.request(url, options, (response) => {\n`
|
||||
)
|
||||
requestString.push(` console.log(response);\n`)
|
||||
requestString.push(`});\n\n`)
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export const NodejsRequestCodegen = {
|
||||
headers,
|
||||
}) => {
|
||||
const requestString = []
|
||||
let genHeaders = []
|
||||
const genHeaders = []
|
||||
|
||||
requestString.push(`const request = require('request');\n`)
|
||||
requestString.push(`const options = {\n`)
|
||||
@@ -30,7 +30,9 @@ export const NodejsRequestCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
genHeaders.push(
|
||||
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
|
||||
` "Authorization": "Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}",\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
|
||||
@@ -58,7 +60,9 @@ export const NodejsRequestCodegen = {
|
||||
reqBodyType = "body"
|
||||
}
|
||||
if (contentType) {
|
||||
genHeaders.push(` "Content-Type": "${contentType}; charset=utf-8",\n`)
|
||||
genHeaders.push(
|
||||
` "Content-Type": "${contentType}; charset=utf-8",\n`
|
||||
)
|
||||
}
|
||||
requestString.push(`,\n ${reqBodyType}: ${requestBody}`)
|
||||
}
|
||||
@@ -69,7 +73,9 @@ export const NodejsRequestCodegen = {
|
||||
})
|
||||
}
|
||||
if (genHeaders.length > 0 || headers.length > 0) {
|
||||
requestString.push(`,\n headers: {\n${genHeaders.join("").slice(0, -2)}\n }`)
|
||||
requestString.push(
|
||||
`,\n headers: {\n${genHeaders.join("").slice(0, -2)}\n }`
|
||||
)
|
||||
}
|
||||
|
||||
requestString.push(`\n}`)
|
||||
|
||||
@@ -20,16 +20,20 @@ export const NodejsUnirestCodegen = {
|
||||
headers,
|
||||
}) => {
|
||||
const requestString = []
|
||||
let genHeaders = []
|
||||
const genHeaders = []
|
||||
|
||||
requestString.push(`const unirest = require('unirest');\n`)
|
||||
requestString.push(`const req = unirest(\n`)
|
||||
requestString.push(`'${method.toLowerCase()}', '${url}${pathName}${queryString}')\n`)
|
||||
requestString.push(
|
||||
`'${method.toLowerCase()}', '${url}${pathName}${queryString}')\n`
|
||||
)
|
||||
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
genHeaders.push(
|
||||
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
|
||||
` "Authorization": "Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}",\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
|
||||
@@ -58,7 +62,9 @@ export const NodejsUnirestCodegen = {
|
||||
reqBodyType = "send"
|
||||
}
|
||||
if (contentType) {
|
||||
genHeaders.push(` "Content-Type": "${contentType}; charset=utf-8",\n`)
|
||||
genHeaders.push(
|
||||
` "Content-Type": "${contentType}; charset=utf-8",\n`
|
||||
)
|
||||
}
|
||||
requestString.push(`.\n ${reqBodyType}( ${requestBody})`)
|
||||
}
|
||||
@@ -69,7 +75,9 @@ export const NodejsUnirestCodegen = {
|
||||
})
|
||||
}
|
||||
if (genHeaders.length > 0 || headers.length > 0) {
|
||||
requestString.push(`.\n headers({\n${genHeaders.join("").slice(0, -2)}\n }`)
|
||||
requestString.push(
|
||||
`.\n headers({\n${genHeaders.join("").slice(0, -2)}\n }`
|
||||
)
|
||||
}
|
||||
|
||||
requestString.push(`\n)`)
|
||||
|
||||
@@ -20,7 +20,7 @@ export const PhpCurlCodegen = {
|
||||
headers,
|
||||
}) => {
|
||||
const requestString = []
|
||||
let genHeaders = []
|
||||
const genHeaders = []
|
||||
|
||||
requestString.push(`<?php\n`)
|
||||
requestString.push(`$curl = curl_init();\n`)
|
||||
@@ -37,7 +37,9 @@ export const PhpCurlCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
genHeaders.push(
|
||||
` "Authorization: Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
|
||||
` "Authorization: Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}",\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(` "Authorization: Bearer ${bearerToken}",\n`)
|
||||
@@ -79,7 +81,9 @@ export const PhpCurlCodegen = {
|
||||
}
|
||||
if (genHeaders.length > 0 || headers.length > 0) {
|
||||
requestString.push(
|
||||
` CURLOPT_HTTPHEADER => array(\n${genHeaders.join("").slice(0, -2)}\n )\n`
|
||||
` CURLOPT_HTTPHEADER => array(\n${genHeaders
|
||||
.join("")
|
||||
.slice(0, -2)}\n )\n`
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@ export const PowershellRestmethodCodegen = {
|
||||
headers,
|
||||
}) => {
|
||||
const methodsWithBody = ["Put", "Post", "Delete"]
|
||||
const formattedMethod = method[0].toUpperCase() + method.substring(1).toLowerCase()
|
||||
const formattedMethod =
|
||||
method[0].toUpperCase() + method.substring(1).toLowerCase()
|
||||
const includeBody = methodsWithBody.includes(formattedMethod)
|
||||
const requestString = []
|
||||
let genHeaders = []
|
||||
@@ -46,7 +47,9 @@ export const PowershellRestmethodCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
genHeaders.push(
|
||||
` 'Authorization' = 'Basic ${window.btoa(unescape(encodeURIComponent(basic)))}'\n`
|
||||
` 'Authorization' = 'Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}'\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(` 'Authorization' = 'Bearer ${bearerToken}'\n`)
|
||||
|
||||
@@ -28,24 +28,28 @@ export const PythonHttpClientCodegen = {
|
||||
headers,
|
||||
}) => {
|
||||
const requestString = []
|
||||
let genHeaders = []
|
||||
const genHeaders = []
|
||||
|
||||
requestString.push(`import http.client\n`)
|
||||
requestString.push(`import mimetypes\n`)
|
||||
|
||||
const currentUrl = new URL(url)
|
||||
let hostname = currentUrl["hostname"]
|
||||
let port = currentUrl["port"]
|
||||
const hostname = currentUrl.hostname
|
||||
const port = currentUrl.port
|
||||
if (!port) {
|
||||
requestString.push(`conn = http.client.HTTPSConnection("${hostname}")\n`)
|
||||
} else {
|
||||
requestString.push(`conn = http.client.HTTPSConnection("${hostname}", ${port})\n`)
|
||||
requestString.push(
|
||||
`conn = http.client.HTTPSConnection("${hostname}", ${port})\n`
|
||||
)
|
||||
}
|
||||
// auth headers
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
genHeaders.push(
|
||||
`'Authorization': 'Basic ${window.btoa(unescape(encodeURIComponent(basic)))}'`
|
||||
`'Authorization': 'Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}'`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(`'Authorization': 'Bearer ${bearerToken}'`)
|
||||
@@ -60,7 +64,7 @@ export const PythonHttpClientCodegen = {
|
||||
|
||||
// initial request setup
|
||||
let requestBody = rawInput ? rawParams : rawRequestBody
|
||||
if (method == "GET") {
|
||||
if (method === "GET") {
|
||||
requestString.push(...printHeaders(genHeaders))
|
||||
requestString.push(`payload = ''\n`)
|
||||
}
|
||||
@@ -86,7 +90,9 @@ export const PythonHttpClientCodegen = {
|
||||
requestString.push(`paylod = '''${requestBody}'''\n`)
|
||||
}
|
||||
}
|
||||
requestString.push(`conn.request("${method}", "${pathName}${queryString}", payload, headers)\n`)
|
||||
requestString.push(
|
||||
`conn.request("${method}", "${pathName}${queryString}", payload, headers)\n`
|
||||
)
|
||||
requestString.push(`res = conn.getresponse()\n`)
|
||||
requestString.push(`data = res.read()\n`)
|
||||
requestString.push(`print(data.decode("utf-8"))`)
|
||||
|
||||
@@ -28,7 +28,7 @@ export const PythonRequestsCodegen = {
|
||||
headers,
|
||||
}) => {
|
||||
const requestString = []
|
||||
let genHeaders = []
|
||||
const genHeaders = []
|
||||
|
||||
requestString.push(`import requests\n\n`)
|
||||
requestString.push(`url = '${url}${pathName}${queryString}'\n`)
|
||||
@@ -37,7 +37,9 @@ export const PythonRequestsCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
genHeaders.push(
|
||||
`'Authorization': 'Basic ${window.btoa(unescape(encodeURIComponent(basic)))}'`
|
||||
`'Authorization': 'Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}'`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
genHeaders.push(`'Authorization': 'Bearer ${bearerToken}'`)
|
||||
@@ -52,7 +54,7 @@ export const PythonRequestsCodegen = {
|
||||
|
||||
// initial request setup
|
||||
let requestBody = rawInput ? rawParams : rawRequestBody
|
||||
if (method == "GET") {
|
||||
if (method === "GET") {
|
||||
requestString.push(...printHeaders(genHeaders))
|
||||
requestString.push(`response = requests.request(\n`)
|
||||
requestString.push(` '${method}',\n`)
|
||||
|
||||
@@ -71,7 +71,9 @@ export const RubyNetHttpCodeGen = {
|
||||
|
||||
// analyse result
|
||||
requestString.push(`unless response.is_a?(Net::HTTPSuccess) then`)
|
||||
requestString.push(` raise "An error occurred: #{response.code} #{response.message}"`)
|
||||
requestString.push(
|
||||
` raise "An error occurred: #{response.code} #{response.message}"`
|
||||
)
|
||||
requestString.push(`else`)
|
||||
requestString.push(` puts response.body`)
|
||||
requestString.push(`end`)
|
||||
|
||||
@@ -29,7 +29,9 @@ export const SalesforceApexCodegen = {
|
||||
// create request
|
||||
requestString.push(`HttpRequest request = new HttpRequest();\n`)
|
||||
requestString.push(`request.setMethod('${method}');\n`)
|
||||
requestString.push(`request.setEndpoint('${url}${pathName}${queryString}');\n\n`)
|
||||
requestString.push(
|
||||
`request.setEndpoint('${url}${pathName}${queryString}');\n\n`
|
||||
)
|
||||
|
||||
// authentification
|
||||
if (auth === "Basic Auth") {
|
||||
@@ -40,12 +42,16 @@ export const SalesforceApexCodegen = {
|
||||
)}');\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
requestString.push(`request.setHeader('Authorization', 'Bearer ${bearerToken}');\n`)
|
||||
requestString.push(
|
||||
`request.setHeader('Authorization', 'Bearer ${bearerToken}');\n`
|
||||
)
|
||||
}
|
||||
|
||||
// content type
|
||||
if (contentType) {
|
||||
requestString.push(`request.setHeader('Content-Type', '${contentType}');\n`)
|
||||
requestString.push(
|
||||
`request.setHeader('Content-Type', '${contentType}');\n`
|
||||
)
|
||||
}
|
||||
|
||||
// custom headers
|
||||
@@ -70,7 +76,9 @@ export const SalesforceApexCodegen = {
|
||||
requestString.push(` HttpResponse response = client.send(request);\n`)
|
||||
requestString.push(` System.debug(response.getBody());\n`)
|
||||
requestString.push(`} catch (CalloutException ex) {\n`)
|
||||
requestString.push(` System.debug('An error occured ' + ex.getMessage());\n`)
|
||||
requestString.push(
|
||||
` System.debug('An error occured ' + ex.getMessage());\n`
|
||||
)
|
||||
requestString.push(`}`)
|
||||
|
||||
return requestString.join("")
|
||||
|
||||
@@ -48,7 +48,9 @@ export const ShellHttpieCodegen = {
|
||||
|
||||
if (headers) {
|
||||
headers.forEach(({ key, value }) => {
|
||||
requestString.push(` $'${key.replace(/'/g, "\\'")}:${value.replace(/'/g, "\\'")}'`)
|
||||
requestString.push(
|
||||
` $'${key.replace(/'/g, "\\'")}:${value.replace(/'/g, "\\'")}'`
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ export const ShellWgetCodegen = {
|
||||
if (auth === "Basic Auth") {
|
||||
const basic = `${httpUser}:${httpPassword}`
|
||||
requestString.push(
|
||||
` --header='Authorization: Basic ${window.btoa(unescape(encodeURIComponent(basic)))}'`
|
||||
` --header='Authorization: Basic ${window.btoa(
|
||||
unescape(encodeURIComponent(basic))
|
||||
)}'`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
requestString.push(` --header='Authorization: Bearer ${bearerToken}'`)
|
||||
@@ -35,7 +37,9 @@ export const ShellWgetCodegen = {
|
||||
}
|
||||
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
|
||||
const requestBody = rawInput ? rawParams : rawRequestBody
|
||||
requestString.push(` --header='Content-Type: ${contentType}; charset=utf-8'`)
|
||||
requestString.push(
|
||||
` --header='Content-Type: ${contentType}; charset=utf-8'`
|
||||
)
|
||||
requestString.push(` --body-data='${requestBody}'`)
|
||||
}
|
||||
return requestString.join(" \\\n")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as cookie from "cookie"
|
||||
import * as URL from "url"
|
||||
import * as querystring from "querystring"
|
||||
import * as cookie from "cookie"
|
||||
import parser from "yargs-parser"
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ const joinDataArguments = (dataArguments) => {
|
||||
}
|
||||
|
||||
const parseCurlCommand = (curlCommand) => {
|
||||
let newlineFound = /\\/gi.test(curlCommand)
|
||||
const newlineFound = /\\/gi.test(curlCommand)
|
||||
if (newlineFound) {
|
||||
// remove '\' and newlines
|
||||
curlCommand = curlCommand.replace(/\\/gi, "")
|
||||
@@ -34,12 +34,12 @@ const parseCurlCommand = (curlCommand) => {
|
||||
curlCommand = curlCommand.replace(/ -XPATCH/, " -X PATCH")
|
||||
curlCommand = curlCommand.replace(/ -XDELETE/, " -X DELETE")
|
||||
curlCommand = curlCommand.trim()
|
||||
let parsedArguments = parser(curlCommand)
|
||||
const parsedArguments = parser(curlCommand)
|
||||
let cookieString
|
||||
let cookies
|
||||
let url = parsedArguments._[1]
|
||||
if (!url) {
|
||||
for (let argName in parsedArguments) {
|
||||
for (const argName in parsedArguments) {
|
||||
if (typeof parsedArguments[argName] === "string") {
|
||||
if (["http", "www."].includes(parsedArguments[argName])) {
|
||||
url = parsedArguments[argName]
|
||||
@@ -62,9 +62,9 @@ const parseCurlCommand = (curlCommand) => {
|
||||
// stupid javascript tricks: closure
|
||||
cookieString = header
|
||||
} else {
|
||||
let colonIndex = header.indexOf(":")
|
||||
let headerName = header.substring(0, colonIndex)
|
||||
let headerValue = header.substring(colonIndex + 1).trim()
|
||||
const colonIndex = header.indexOf(":")
|
||||
const headerName = header.substring(0, colonIndex)
|
||||
const headerValue = header.substring(colonIndex + 1).trim()
|
||||
headers[headerName] = headerValue
|
||||
}
|
||||
})
|
||||
@@ -109,12 +109,15 @@ const parseCurlCommand = (curlCommand) => {
|
||||
}
|
||||
// separate out cookie headers into separate data structure
|
||||
// note: cookie is case insensitive
|
||||
cookies = cookie.parse(cookieString.replace(/^Cookie: /gi, ""), cookieParseOptions)
|
||||
cookies = cookie.parse(
|
||||
cookieString.replace(/^Cookie: /gi, ""),
|
||||
cookieParseOptions
|
||||
)
|
||||
}
|
||||
let method
|
||||
if (parsedArguments.X === "POST") {
|
||||
method = "post"
|
||||
} else if (parsedArguments.X === "PUT" || parsedArguments["T"]) {
|
||||
} else if (parsedArguments.X === "PUT" || parsedArguments.T) {
|
||||
method = "put"
|
||||
} else if (parsedArguments.X === "PATCH") {
|
||||
method = "patch"
|
||||
@@ -123,29 +126,30 @@ const parseCurlCommand = (curlCommand) => {
|
||||
} else if (parsedArguments.X === "OPTIONS") {
|
||||
method = "options"
|
||||
} else if (
|
||||
(parsedArguments["d"] ||
|
||||
parsedArguments["data"] ||
|
||||
(parsedArguments.d ||
|
||||
parsedArguments.data ||
|
||||
parsedArguments["data-ascii"] ||
|
||||
parsedArguments["data-binary"] ||
|
||||
parsedArguments["F"] ||
|
||||
parsedArguments["form"]) &&
|
||||
!(parsedArguments["G"] || parsedArguments["get"])
|
||||
parsedArguments.F ||
|
||||
parsedArguments.form) &&
|
||||
!(parsedArguments.G || parsedArguments.get)
|
||||
) {
|
||||
method = "post"
|
||||
} else if (parsedArguments["I"] || parsedArguments["head"]) {
|
||||
} else if (parsedArguments.I || parsedArguments.head) {
|
||||
method = "head"
|
||||
} else {
|
||||
method = "get"
|
||||
}
|
||||
|
||||
let compressed = !!parsedArguments.compressed
|
||||
const compressed = !!parsedArguments.compressed
|
||||
let urlObject = URL.parse(url) // eslint-disable-line
|
||||
|
||||
// if GET request with data, convert data to query string
|
||||
// NB: the -G flag does not change the http verb. It just moves the data into the url.
|
||||
if (parsedArguments["G"] || parsedArguments["get"]) {
|
||||
if (parsedArguments.G || parsedArguments.get) {
|
||||
urlObject.query = urlObject.query ? urlObject.query : ""
|
||||
let option = "d" in parsedArguments ? "d" : "data" in parsedArguments ? "data" : null
|
||||
const option =
|
||||
"d" in parsedArguments ? "d" : "data" in parsedArguments ? "data" : null
|
||||
if (option) {
|
||||
let urlQueryString = ""
|
||||
|
||||
@@ -165,7 +169,7 @@ const parseCurlCommand = (curlCommand) => {
|
||||
delete parsedArguments[option]
|
||||
}
|
||||
}
|
||||
let query = querystring.parse(urlObject.query, null, null, {
|
||||
const query = querystring.parse(urlObject.query, null, null, {
|
||||
maxKeys: 10000,
|
||||
})
|
||||
|
||||
@@ -175,7 +179,7 @@ const parseCurlCommand = (curlCommand) => {
|
||||
urlWithoutQuery: URL.format(urlObject),
|
||||
}
|
||||
if (compressed) {
|
||||
request["compressed"] = true
|
||||
request.compressed = true
|
||||
}
|
||||
|
||||
if (Object.keys(query).length > 0) {
|
||||
@@ -184,7 +188,7 @@ const parseCurlCommand = (curlCommand) => {
|
||||
if (headers) {
|
||||
request.headers = headers
|
||||
}
|
||||
request["method"] = method
|
||||
request.method = method
|
||||
|
||||
if (cookies) {
|
||||
request.cookies = cookies
|
||||
@@ -198,24 +202,24 @@ const parseCurlCommand = (curlCommand) => {
|
||||
} else if (parsedArguments["data-binary"]) {
|
||||
request.data = parsedArguments["data-binary"]
|
||||
request.isDataBinary = true
|
||||
} else if (parsedArguments["d"]) {
|
||||
request.data = parsedArguments["d"]
|
||||
} else if (parsedArguments.d) {
|
||||
request.data = parsedArguments.d
|
||||
} else if (parsedArguments["data-ascii"]) {
|
||||
request.data = parsedArguments["data-ascii"]
|
||||
}
|
||||
|
||||
if (parsedArguments["u"]) {
|
||||
request.auth = parsedArguments["u"]
|
||||
if (parsedArguments.u) {
|
||||
request.auth = parsedArguments.u
|
||||
}
|
||||
if (parsedArguments["user"]) {
|
||||
request.auth = parsedArguments["user"]
|
||||
if (parsedArguments.user) {
|
||||
request.auth = parsedArguments.user
|
||||
}
|
||||
if (Array.isArray(request.data)) {
|
||||
request.dataArray = request.data
|
||||
request.data = joinDataArguments(request.data)
|
||||
}
|
||||
|
||||
if (parsedArguments["k"] || parsedArguments["insecure"]) {
|
||||
if (parsedArguments.k || parsedArguments.insecure) {
|
||||
request.insecure = true
|
||||
}
|
||||
return request
|
||||
|
||||
@@ -21,7 +21,11 @@ describe("getSuitableLenses", () => {
|
||||
})
|
||||
|
||||
const contentTypes = {
|
||||
JSON: ["application/json", "application/ld+json", "application/hal+json; charset=utf8"],
|
||||
JSON: [
|
||||
"application/json",
|
||||
"application/ld+json",
|
||||
"application/hal+json; charset=utf8",
|
||||
],
|
||||
Image: [
|
||||
"image/gif",
|
||||
"image/jpeg; foo=bar",
|
||||
@@ -32,11 +36,15 @@ describe("getSuitableLenses", () => {
|
||||
"image/vnd.microsoft.icon",
|
||||
],
|
||||
HTML: ["text/html", "application/xhtml+xml", "text/html; charset=utf-8"],
|
||||
XML: ["text/xml", "application/xml", "application/xhtml+xml; charset=utf-8"],
|
||||
XML: [
|
||||
"text/xml",
|
||||
"application/xml",
|
||||
"application/xhtml+xml; charset=utf-8",
|
||||
],
|
||||
}
|
||||
|
||||
lenses
|
||||
.filter(({ lensName }) => lensName != rawLens.lensName)
|
||||
.filter(({ lensName }) => lensName !== rawLens.lensName)
|
||||
.forEach((el) => {
|
||||
test(`returns ${el.lensName} lens for its content-types`, () => {
|
||||
contentTypes[el.lensName].forEach((contentType) => {
|
||||
|
||||
@@ -3,7 +3,8 @@ const htmlLens = {
|
||||
isSupportedContentType: (contentType) =>
|
||||
/\btext\/html|application\/xhtml\+xml\b/i.test(contentType),
|
||||
renderer: "htmlres",
|
||||
rendererImport: () => import("~/components/lenses/renderers/HTMLLensRenderer"),
|
||||
rendererImport: () =>
|
||||
import("~/components/lenses/renderers/HTMLLensRenderer"),
|
||||
}
|
||||
|
||||
export default htmlLens
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
const imageLens = {
|
||||
lensName: "Image",
|
||||
isSupportedContentType: (contentType) =>
|
||||
/\bimage\/(?:gif|jpeg|png|bmp|svg\+xml|x-icon|vnd\.microsoft\.icon)\b/i.test(contentType),
|
||||
/\bimage\/(?:gif|jpeg|png|bmp|svg\+xml|x-icon|vnd\.microsoft\.icon)\b/i.test(
|
||||
contentType
|
||||
),
|
||||
renderer: "imageres",
|
||||
rendererImport: () => import("~/components/lenses/renderers/ImageLensRenderer"),
|
||||
rendererImport: () =>
|
||||
import("~/components/lenses/renderers/ImageLensRenderer"),
|
||||
}
|
||||
|
||||
export default imageLens
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { isJSONContentType } from "../utils/contenttypes";
|
||||
import { isJSONContentType } from "../utils/contenttypes"
|
||||
|
||||
const jsonLens = {
|
||||
lensName: "JSON",
|
||||
isSupportedContentType: isJSONContentType,
|
||||
renderer: "json",
|
||||
rendererImport: () => import("~/components/lenses/renderers/JSONLensRenderer"),
|
||||
rendererImport: () =>
|
||||
import("~/components/lenses/renderers/JSONLensRenderer"),
|
||||
}
|
||||
|
||||
export default jsonLens
|
||||
|
||||
@@ -7,7 +7,9 @@ import { settingsStore, applySetting } from "~/newstore/settings"
|
||||
|
||||
export function performMigrations(): void {
|
||||
// Migrate old default proxy URL to the new proxy URL (if not set / overridden)
|
||||
if (settingsStore.value.PROXY_URL === "https://hoppscotch.apollosoftware.xyz/") {
|
||||
if (
|
||||
settingsStore.value.PROXY_URL === "https://hoppscotch.apollosoftware.xyz/"
|
||||
) {
|
||||
applySetting("PROXY_URL", "https://proxy.hoppscotch.io/")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import AxiosStrategy, { cancelRunningAxiosRequest } from "./strategies/AxiosStrategy"
|
||||
import AxiosStrategy, {
|
||||
cancelRunningAxiosRequest,
|
||||
} from "./strategies/AxiosStrategy"
|
||||
import ExtensionStrategy, {
|
||||
cancelRunningExtensionRequest,
|
||||
hasExtensionInstalled,
|
||||
|
||||
@@ -43,7 +43,10 @@ const parseQueryString = (searchQuery) => {
|
||||
return {}
|
||||
}
|
||||
const segments = searchQuery.split("&").map((s) => s.split("="))
|
||||
const queryString = segments.reduce((obj, el) => ({ ...obj, [el[0]]: el[1] }), {})
|
||||
const queryString = segments.reduce(
|
||||
(obj, el) => ({ ...obj, [el[0]]: el[1] }),
|
||||
{}
|
||||
)
|
||||
return queryString
|
||||
}
|
||||
|
||||
@@ -145,25 +148,26 @@ const tokenRequest = async ({
|
||||
}) => {
|
||||
// Check oauth configuration
|
||||
if (oidcDiscoveryUrl !== "") {
|
||||
const { authorization_endpoint, token_endpoint } = await getTokenConfiguration(oidcDiscoveryUrl)
|
||||
authUrl = authorization_endpoint
|
||||
accessTokenUrl = token_endpoint
|
||||
const { authorizationEndpoint, tokenEndpoint } =
|
||||
await getTokenConfiguration(oidcDiscoveryUrl)
|
||||
authUrl = authorizationEndpoint
|
||||
accessTokenUrl = tokenEndpoint
|
||||
}
|
||||
|
||||
// Store oauth information
|
||||
localStorage.setItem("token_endpoint", accessTokenUrl)
|
||||
localStorage.setItem("tokenEndpoint", accessTokenUrl)
|
||||
localStorage.setItem("client_id", clientId)
|
||||
|
||||
// Create and store a random state value
|
||||
const state = generateRandomString()
|
||||
localStorage.setItem("pkce_state", state)
|
||||
|
||||
// Create and store a new PKCE code_verifier (the plaintext random secret)
|
||||
const code_verifier = generateRandomString()
|
||||
localStorage.setItem("pkce_code_verifier", code_verifier)
|
||||
// Create and store a new PKCE codeVerifier (the plaintext random secret)
|
||||
const codeVerifier = generateRandomString()
|
||||
localStorage.setItem("pkce_codeVerifier", codeVerifier)
|
||||
|
||||
// Hash and base64-urlencode the secret to use as the challenge
|
||||
const code_challenge = await pkceChallengeFromVerifier(code_verifier)
|
||||
const codeChallenge = await pkceChallengeFromVerifier(codeVerifier)
|
||||
|
||||
// Build the authorization URL
|
||||
const buildUrl = () =>
|
||||
@@ -171,9 +175,11 @@ const tokenRequest = async ({
|
||||
clientId
|
||||
)}&state=${encodeURIComponent(state)}&scope=${encodeURIComponent(
|
||||
scope
|
||||
)}&redirect_uri=${encodeURIComponent(redirectUri)}&code_challenge=${encodeURIComponent(
|
||||
code_challenge
|
||||
)}&code_challenge_method=S256`
|
||||
)}&redirect_uri=${encodeURIComponent(
|
||||
redirectUri
|
||||
)}&codeChallenge=${encodeURIComponent(
|
||||
codeChallenge
|
||||
)}&codeChallenge_method=S256`
|
||||
|
||||
// Redirect to the authorization server
|
||||
window.location = buildUrl()
|
||||
@@ -190,7 +196,7 @@ const tokenRequest = async ({
|
||||
|
||||
const oauthRedirect = async () => {
|
||||
let tokenResponse = ""
|
||||
let q = parseQueryString(window.location.search.substring(1))
|
||||
const q = parseQueryString(window.location.search.substring(1))
|
||||
// Check if the server returned an error string
|
||||
if (q.error) {
|
||||
alert(`Error returned from authorization server: ${q.error}`)
|
||||
@@ -198,26 +204,29 @@ const oauthRedirect = async () => {
|
||||
// If the server returned an authorization code, attempt to exchange it for an access token
|
||||
if (q.code) {
|
||||
// Verify state matches what we set at the beginning
|
||||
if (localStorage.getItem("pkce_state") != q.state) {
|
||||
if (localStorage.getItem("pkce_state") !== q.state) {
|
||||
alert("Invalid state")
|
||||
} else {
|
||||
try {
|
||||
// Exchange the authorization code for an access token
|
||||
tokenResponse = await sendPostRequest(localStorage.getItem("token_endpoint"), {
|
||||
grant_type: "authorization_code",
|
||||
code: q.code,
|
||||
client_id: localStorage.getItem("client_id"),
|
||||
redirect_uri: redirectUri,
|
||||
code_verifier: localStorage.getItem("pkce_code_verifier"),
|
||||
})
|
||||
tokenResponse = await sendPostRequest(
|
||||
localStorage.getItem("tokenEndpoint"),
|
||||
{
|
||||
grant_type: "authorization_code",
|
||||
code: q.code,
|
||||
client_id: localStorage.getItem("client_id"),
|
||||
redirect_uri: redirectUri,
|
||||
codeVerifier: localStorage.getItem("pkce_codeVerifier"),
|
||||
}
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(`${error.error}\n\n${error.error_description}`)
|
||||
}
|
||||
}
|
||||
// Clean these up since we don't need them anymore
|
||||
localStorage.removeItem("pkce_state")
|
||||
localStorage.removeItem("pkce_code_verifier")
|
||||
localStorage.removeItem("token_endpoint")
|
||||
localStorage.removeItem("pkce_codeVerifier")
|
||||
localStorage.removeItem("tokenEndpoint")
|
||||
localStorage.removeItem("client_id")
|
||||
return tokenResponse
|
||||
}
|
||||
|
||||
@@ -15,21 +15,21 @@ export default () => {
|
||||
}
|
||||
|
||||
const linkParents = (node) => {
|
||||
if (node.kind == "Object") {
|
||||
if (node.kind === "Object") {
|
||||
if (node.members) {
|
||||
node.members.forEach((m) => {
|
||||
m.parent = node
|
||||
linkParents(m)
|
||||
})
|
||||
}
|
||||
} else if (node.kind == "Array") {
|
||||
} else if (node.kind === "Array") {
|
||||
if (node.values) {
|
||||
node.values.forEach((v) => {
|
||||
v.parent = node
|
||||
linkParents(v)
|
||||
})
|
||||
}
|
||||
} else if (node.kind == "Member") {
|
||||
} else if (node.kind === "Member") {
|
||||
if (node.value) {
|
||||
node.value.parent = node
|
||||
linkParents(node.value)
|
||||
@@ -41,20 +41,20 @@ export default () => {
|
||||
let output = {}
|
||||
path = []
|
||||
let current = jsonAST
|
||||
if (current.kind == "Object") {
|
||||
if (current.kind === "Object") {
|
||||
path.push({ label: "{}", obj: "root" })
|
||||
} else if (current.kind == "Array") {
|
||||
} else if (current.kind === "Array") {
|
||||
path.push({ label: "[]", obj: "root" })
|
||||
}
|
||||
let over = false
|
||||
|
||||
try {
|
||||
while (!over) {
|
||||
if (current.kind == "Object") {
|
||||
if (current.kind === "Object") {
|
||||
let i = 0
|
||||
let found = false
|
||||
while (i < current.members.length) {
|
||||
let m = current.members[i]
|
||||
const m = current.members[i]
|
||||
if (m.start <= index && m.end >= index) {
|
||||
path.push({ label: m.key.value, obj: m })
|
||||
current = current.members[i]
|
||||
@@ -64,12 +64,12 @@ export default () => {
|
||||
i++
|
||||
}
|
||||
if (!found) over = true
|
||||
} else if (current.kind == "Array") {
|
||||
} else if (current.kind === "Array") {
|
||||
if (current.values) {
|
||||
let i = 0
|
||||
let found = false
|
||||
while (i < current.values.length) {
|
||||
let m = current.values[i]
|
||||
const m = current.values[i]
|
||||
if (m.start <= index && m.end >= index) {
|
||||
path.push({ label: `[${i.toString()}]`, obj: m })
|
||||
current = current.values[i]
|
||||
@@ -80,17 +80,17 @@ export default () => {
|
||||
}
|
||||
if (!found) over = true
|
||||
} else over = true
|
||||
} else if (current.kind == "Member") {
|
||||
} else if (current.kind === "Member") {
|
||||
if (current.value) {
|
||||
if (current.value.start <= index && current.value.end >= index) {
|
||||
current = current.value
|
||||
} else over = true
|
||||
} else over = true
|
||||
} else if (
|
||||
current.kind == "String" ||
|
||||
current.kind == "Number" ||
|
||||
current.kind == "Boolean" ||
|
||||
current.kind == "Null"
|
||||
current.kind === "String" ||
|
||||
current.kind === "Number" ||
|
||||
current.kind === "Boolean" ||
|
||||
current.kind === "Null"
|
||||
) {
|
||||
if (current.start <= index && current.end >= index) {
|
||||
path.push({ label: `${current.value}`, obj: current })
|
||||
@@ -106,15 +106,13 @@ export default () => {
|
||||
}
|
||||
|
||||
const getSiblings = (index) => {
|
||||
let parent = path[index].obj.parent
|
||||
const parent = path[index].obj.parent
|
||||
if (!parent) return []
|
||||
else {
|
||||
if (parent.kind == "Object") {
|
||||
return parent.members
|
||||
} else if (parent.kind == "Array") {
|
||||
return parent.values
|
||||
} else return []
|
||||
}
|
||||
else if (parent.kind === "Object") {
|
||||
return parent.members
|
||||
} else if (parent.kind === "Array") {
|
||||
return parent.values
|
||||
} else return []
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
export default () => {
|
||||
//*** Determine whether or not the PWA has been installed. ***//
|
||||
//* ** Determine whether or not the PWA has been installed. ***//
|
||||
|
||||
// Step 1: Check local storage
|
||||
let pwaInstalled = localStorage.getItem("pwaInstalled") === "yes"
|
||||
|
||||
// Step 2: Check if the display-mode is standalone. (Only permitted for PWAs.)
|
||||
if (!pwaInstalled && window.matchMedia("(display-mode: standalone)").matches) {
|
||||
if (
|
||||
!pwaInstalled &&
|
||||
window.matchMedia("(display-mode: standalone)").matches
|
||||
) {
|
||||
localStorage.setItem("pwaInstalled", "yes")
|
||||
pwaInstalled = true
|
||||
}
|
||||
@@ -16,7 +19,7 @@ export default () => {
|
||||
pwaInstalled = true
|
||||
}
|
||||
|
||||
//*** If the PWA has not been installed, show the install PWA prompt.. ***//
|
||||
//* ** If the PWA has not been installed, show the install PWA prompt.. ***//
|
||||
let deferredPrompt = null
|
||||
window.addEventListener("beforeinstallprompt", (event) => {
|
||||
deferredPrompt = event
|
||||
@@ -28,7 +31,7 @@ export default () => {
|
||||
})
|
||||
|
||||
// When the app is installed, remove install prompts.
|
||||
window.addEventListener("appinstalled", (event) => {
|
||||
window.addEventListener("appinstalled", () => {
|
||||
localStorage.setItem("pwaInstalled", "yes")
|
||||
pwaInstalled = true
|
||||
document.getElementById("installPWA").style.display = "none"
|
||||
@@ -38,12 +41,14 @@ export default () => {
|
||||
return async () => {
|
||||
if (deferredPrompt) {
|
||||
deferredPrompt.prompt()
|
||||
let outcome = await deferredPrompt.userChoice
|
||||
const outcome = await deferredPrompt.userChoice
|
||||
|
||||
if (outcome === "accepted") {
|
||||
console.log("Hoppscotch was installed successfully.")
|
||||
} else {
|
||||
console.log("Hoppscotch could not be installed. (Installation rejected by user.)")
|
||||
console.log(
|
||||
"Hoppscotch could not be installed. (Installation rejected by user.)"
|
||||
)
|
||||
}
|
||||
deferredPrompt = null
|
||||
}
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
export function hasPathParams(params) {
|
||||
return params
|
||||
.filter((item) => (item.hasOwnProperty("active") ? item.active == true : true))
|
||||
.filter((item) =>
|
||||
Object.prototype.hasOwnProperty.call(item, "active")
|
||||
? item.active === true
|
||||
: true
|
||||
)
|
||||
.some(({ type }) => type === "path")
|
||||
}
|
||||
|
||||
export function addPathParamsToVariables(params, variables) {
|
||||
params
|
||||
.filter((item) => (item.hasOwnProperty("active") ? item.active == true : true))
|
||||
.filter((item) =>
|
||||
Object.prototype.hasOwnProperty.call(item, "active")
|
||||
? item.active === true
|
||||
: true
|
||||
)
|
||||
.filter(({ key }) => !!key)
|
||||
.filter(({ type }) => type === "path")
|
||||
.forEach(({ key, value }) => (variables[key] = value))
|
||||
@@ -15,7 +23,11 @@ export function addPathParamsToVariables(params, variables) {
|
||||
|
||||
export function getQueryParams(params) {
|
||||
return params
|
||||
.filter((item) => (item.hasOwnProperty("active") ? item.active == true : true))
|
||||
.filter((item) =>
|
||||
Object.prototype.hasOwnProperty.call(item, "active")
|
||||
? item.active === true
|
||||
: true
|
||||
)
|
||||
.filter(({ key }) => !!key)
|
||||
.filter(({ type }) => type != "path")
|
||||
.filter(({ type }) => type !== "path")
|
||||
}
|
||||
|
||||
@@ -5,13 +5,18 @@ export const hasExtensionInstalled = () =>
|
||||
typeof window.__POSTWOMAN_EXTENSION_HOOK__ !== "undefined"
|
||||
|
||||
export const hasChromeExtensionInstalled = () =>
|
||||
hasExtensionInstalled() && /Chrome/i.test(navigator.userAgent) && /Google/i.test(navigator.vendor)
|
||||
hasExtensionInstalled() &&
|
||||
/Chrome/i.test(navigator.userAgent) &&
|
||||
/Google/i.test(navigator.vendor)
|
||||
|
||||
export const hasFirefoxExtensionInstalled = () =>
|
||||
hasExtensionInstalled() && /Firefox/i.test(navigator.userAgent)
|
||||
|
||||
export const cancelRunningExtensionRequest = () => {
|
||||
if (hasExtensionInstalled() && window.__POSTWOMAN_EXTENSION_HOOK__.cancelRunningRequest) {
|
||||
if (
|
||||
hasExtensionInstalled() &&
|
||||
window.__POSTWOMAN_EXTENSION_HOOK__.cancelRunningRequest
|
||||
) {
|
||||
window.__POSTWOMAN_EXTENSION_HOOK__.cancelRunningRequest()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ jest.mock("~/newstore/settings", () => {
|
||||
__esModule: true,
|
||||
settingsStore: {
|
||||
value: {
|
||||
PROXY_ENABLED: false
|
||||
}
|
||||
}
|
||||
PROXY_ENABLED: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -18,7 +18,6 @@ axios.mockResolvedValue({})
|
||||
|
||||
describe("axiosStrategy", () => {
|
||||
describe("No-Proxy Requests", () => {
|
||||
|
||||
test("sends request to the actual sender if proxy disabled", async () => {
|
||||
await axiosStrategy({ url: "test" })
|
||||
|
||||
@@ -43,14 +42,14 @@ describe("axiosStrategy", () => {
|
||||
await expect(axiosStrategy({})).resolves.toBeDefined()
|
||||
})
|
||||
|
||||
test("rejects cancel errors with text 'cancellation'", async () => {
|
||||
test("rejects cancel errors with text 'cancellation'", () => {
|
||||
axios.isCancel.mockReturnValueOnce(true)
|
||||
axios.mockRejectedValue("err")
|
||||
|
||||
expect(axiosStrategy({})).rejects.toBe("cancellation")
|
||||
})
|
||||
|
||||
test("rejects non-cancellation errors as-is", async () => {
|
||||
test("rejects non-cancellation errors as-is", () => {
|
||||
axios.isCancel.mockReturnValueOnce(false)
|
||||
axios.mockRejectedValue("err")
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import axios from "axios"
|
||||
import axiosStrategy, { testables, cancelRunningAxiosRequest } from "../AxiosStrategy"
|
||||
import axiosStrategy, {
|
||||
testables,
|
||||
cancelRunningAxiosRequest,
|
||||
} from "../AxiosStrategy"
|
||||
|
||||
jest.mock("../../utils/b64", () => ({
|
||||
__esModule: true,
|
||||
@@ -11,9 +14,9 @@ jest.mock("~/newstore/settings", () => {
|
||||
settingsStore: {
|
||||
value: {
|
||||
PROXY_ENABLED: true,
|
||||
PROXY_URL: "test"
|
||||
}
|
||||
}
|
||||
PROXY_URL: "test",
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -28,7 +31,6 @@ describe("cancelRunningAxiosRequest", () => {
|
||||
|
||||
describe("axiosStrategy", () => {
|
||||
describe("Proxy Requests", () => {
|
||||
|
||||
test("sends POST request to proxy if proxy is enabled", async () => {
|
||||
let passedURL
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import extensionStrategy, {
|
||||
hasExtensionInstalled,
|
||||
hasChromeExtensionInstalled,
|
||||
@@ -17,9 +16,9 @@ jest.mock("~/newstore/settings", () => {
|
||||
settingsStore: {
|
||||
value: {
|
||||
EXTENSIONS_ENABLED: true,
|
||||
PROXY_ENABLED: false
|
||||
}
|
||||
}
|
||||
PROXY_ENABLED: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -140,7 +139,6 @@ describe("extensionStrategy", () => {
|
||||
})
|
||||
|
||||
describe("Non-Proxy Requests", () => {
|
||||
|
||||
test("ask extension to send request", async () => {
|
||||
global.__POSTWOMAN_EXTENSION_HOOK__ = {
|
||||
sendRequest: sendReqFunc,
|
||||
@@ -162,7 +160,7 @@ describe("extensionStrategy", () => {
|
||||
sendRequest: sendReqFunc,
|
||||
}
|
||||
|
||||
sendReqFunc.mockImplementation(({ method, url }) => {
|
||||
sendReqFunc.mockImplementation(({ url }) => {
|
||||
passedUrl = url
|
||||
|
||||
return Promise.resolve({
|
||||
|
||||
@@ -17,9 +17,9 @@ jest.mock("~/newstore/settings", () => {
|
||||
value: {
|
||||
EXTENSIONS_ENABLED: true,
|
||||
PROXY_ENABLED: true,
|
||||
PROXY_URL: "test"
|
||||
}
|
||||
}
|
||||
PROXY_URL: "test",
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -140,7 +140,6 @@ describe("extensionStrategy", () => {
|
||||
})
|
||||
|
||||
describe("Proxy Requests", () => {
|
||||
|
||||
test("asks extension to send request", async () => {
|
||||
global.__POSTWOMAN_EXTENSION_HOOK__ = {
|
||||
sendRequest: sendReqFunc,
|
||||
|
||||
@@ -6,7 +6,9 @@ export function defineGQLLanguageMode(ace) {
|
||||
(aceRequire, exports) => {
|
||||
const oop = aceRequire("ace/lib/oop")
|
||||
|
||||
const TextHighlightRules = aceRequire("ace/mode/text_highlight_rules").TextHighlightRules
|
||||
const TextHighlightRules = aceRequire(
|
||||
"ace/mode/text_highlight_rules"
|
||||
).TextHighlightRules
|
||||
|
||||
const GQLQueryTextHighlightRules = function () {
|
||||
const keywords =
|
||||
@@ -35,7 +37,7 @@ export function defineGQLLanguageMode(ace) {
|
||||
},
|
||||
{
|
||||
token: "paren.lparen",
|
||||
regex: /[\[({]/,
|
||||
regex: /[[({]/,
|
||||
next: "start",
|
||||
},
|
||||
{
|
||||
@@ -74,7 +76,7 @@ export function defineGQLLanguageMode(ace) {
|
||||
},
|
||||
{
|
||||
token: "constant.numeric",
|
||||
regex: /\d+\.?\d*[eE]?[\+\-]?\d*/,
|
||||
regex: /\d+\.?\d*[eE]?[+-]?\d*/,
|
||||
},
|
||||
{
|
||||
token: "variable",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { fb } from "../fb"
|
||||
import { BehaviorSubject } from "rxjs"
|
||||
import { apolloClient } from "../apollo"
|
||||
import gql from "graphql-tag"
|
||||
import { fb } from "../fb"
|
||||
import { apolloClient } from "../apollo"
|
||||
|
||||
/*
|
||||
* This file deals with interfacing data provided by the
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { BehaviorSubject } from "rxjs"
|
||||
import { TeamCollection } from "./TeamCollection"
|
||||
import { TeamRequest } from "./TeamRequest"
|
||||
import { apolloClient } from "~/helpers/apollo"
|
||||
import { rootCollectionsOfTeam, getCollectionChildren, getCollectionRequests } from "./utils"
|
||||
import { gql } from "graphql-tag"
|
||||
import pull from "lodash/pull"
|
||||
import remove from "lodash/remove"
|
||||
import { TeamCollection } from "./TeamCollection"
|
||||
import { TeamRequest } from "./TeamRequest"
|
||||
import {
|
||||
rootCollectionsOfTeam,
|
||||
getCollectionChildren,
|
||||
getCollectionRequests,
|
||||
} from "./utils"
|
||||
import { apolloClient } from "~/helpers/apollo"
|
||||
|
||||
/*
|
||||
* NOTE: These functions deal with REFERENCES to objects and mutates them, for a simpler implementation.
|
||||
@@ -31,7 +35,7 @@ function findParentOfColl(
|
||||
): TeamCollection | null {
|
||||
for (const coll of tree) {
|
||||
// If the root is parent, return null
|
||||
if (coll.id === collID) return currentParent ? currentParent : null
|
||||
if (coll.id === collID) return currentParent || null
|
||||
|
||||
// Else run it in children
|
||||
if (coll.children) {
|
||||
@@ -51,7 +55,10 @@ function findParentOfColl(
|
||||
*
|
||||
* @returns REFERENCE to the collection or null if not found
|
||||
*/
|
||||
function findCollInTree(tree: TeamCollection[], targetID: string): TeamCollection | null {
|
||||
function findCollInTree(
|
||||
tree: TeamCollection[],
|
||||
targetID: string
|
||||
): TeamCollection | null {
|
||||
for (const coll of tree) {
|
||||
// If the direct child matched, then return that
|
||||
if (coll.id === targetID) return coll
|
||||
@@ -75,7 +82,10 @@ function findCollInTree(tree: TeamCollection[], targetID: string): TeamCollectio
|
||||
*
|
||||
* @returns REFERENCE to the collection or null if request not found
|
||||
*/
|
||||
function findCollWithReqIDInTree(tree: TeamCollection[], reqID: string): TeamCollection | null {
|
||||
function findCollWithReqIDInTree(
|
||||
tree: TeamCollection[],
|
||||
reqID: string
|
||||
): TeamCollection | null {
|
||||
for (const coll of tree) {
|
||||
// Check in root collections (if expanded)
|
||||
if (coll.requests) {
|
||||
@@ -101,7 +111,10 @@ function findCollWithReqIDInTree(tree: TeamCollection[], reqID: string): TeamCol
|
||||
*
|
||||
* @returns REFERENCE to the request or null if request not found
|
||||
*/
|
||||
function findReqInTree(tree: TeamCollection[], reqID: string): TeamRequest | null {
|
||||
function findReqInTree(
|
||||
tree: TeamCollection[],
|
||||
reqID: string
|
||||
): TeamRequest | null {
|
||||
for (const coll of tree) {
|
||||
// Check in root collections (if expanded)
|
||||
if (coll.requests) {
|
||||
@@ -251,7 +264,10 @@ export default class TeamCollectionAdapter {
|
||||
* @param {TeamCollection} collection - The collection to add to the tree
|
||||
* @param {string | null} parentCollectionID - The parent of the new collection, pass null if this collection is in root
|
||||
*/
|
||||
private addCollection(collection: TeamCollection, parentCollectionID: string | null) {
|
||||
private addCollection(
|
||||
collection: TeamCollection,
|
||||
parentCollectionID: string | null
|
||||
) {
|
||||
const tree = this.collections$.value
|
||||
|
||||
if (!parentCollectionID) {
|
||||
@@ -276,7 +292,9 @@ export default class TeamCollectionAdapter {
|
||||
*
|
||||
* @param {Partial<TeamCollection> & Pick<TeamCollection, "id">} collectionUpdate - Object defining the fields that need to be updated (ID is required to find the target)
|
||||
*/
|
||||
private updateCollection(collectionUpdate: Partial<TeamCollection> & Pick<TeamCollection, "id">) {
|
||||
private updateCollection(
|
||||
collectionUpdate: Partial<TeamCollection> & Pick<TeamCollection, "id">
|
||||
) {
|
||||
const tree = this.collections$.value
|
||||
|
||||
updateCollInTree(tree, collectionUpdate)
|
||||
@@ -342,7 +360,9 @@ export default class TeamCollectionAdapter {
|
||||
*
|
||||
* @param {Partial<TeamRequest> & Pick<TeamRequest, 'id'>} requestUpdate - Object defining all the fields to update in request (ID of the request is required)
|
||||
*/
|
||||
private updateRequest(requestUpdate: Partial<TeamRequest> & Pick<TeamRequest, "id">) {
|
||||
private updateRequest(
|
||||
requestUpdate: Partial<TeamRequest> & Pick<TeamRequest, "id">
|
||||
) {
|
||||
const tree = this.collections$.value
|
||||
|
||||
// Find request, if not present, don't update
|
||||
@@ -526,7 +546,7 @@ export default class TeamCollectionAdapter {
|
||||
).map<TeamRequest>((el) => {
|
||||
return {
|
||||
id: el.id,
|
||||
collectionID: collectionID,
|
||||
collectionID,
|
||||
title: el.title,
|
||||
request: JSON.parse(el.request),
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export default class TeamMemberAdapter {
|
||||
cursor,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
debugger
|
||||
|
||||
result.push(...response.data.team.members)
|
||||
|
||||
@@ -3,5 +3,8 @@ export default function parseTemplateString(string, variables) {
|
||||
return string
|
||||
}
|
||||
const searchTerm = /<<([^>]*)>>/g // "<<myVariable>>"
|
||||
return decodeURI(encodeURI(string)).replace(searchTerm, (match, p1) => variables[p1] || "")
|
||||
return decodeURI(encodeURI(string)).replace(
|
||||
searchTerm,
|
||||
(_, p1) => variables[p1] || ""
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import tern from "tern"
|
||||
|
||||
import { registerTernLinter } from "./ternlint"
|
||||
import ECMA_DEF from "~/helpers/terndoc/ecma.json"
|
||||
import PW_PRE_DEF from "~/helpers/terndoc/pw-pre.json"
|
||||
import PW_TEST_DEF from "~/helpers/terndoc/pw-test.json"
|
||||
import PW_EXTRAS_DEF from "~/helpers/terndoc/pw-extras.json"
|
||||
|
||||
import { registerTernLinter } from "./ternlint"
|
||||
|
||||
const server = new tern.Server({
|
||||
defs: [ECMA_DEF, PW_EXTRAS_DEF],
|
||||
plugins: {
|
||||
|
||||
@@ -5,7 +5,9 @@ describe("decodeB64StringToArrayBuffer", () => {
|
||||
test("decodes content correctly", () => {
|
||||
const decoder = new TextDecoder("utf-8")
|
||||
expect(
|
||||
decoder.decode(decodeB64StringToArrayBuffer("aG9wcHNjb3RjaCBpcyBhd2Vzb21lIQ=="))
|
||||
decoder.decode(
|
||||
decodeB64StringToArrayBuffer("aG9wcHNjb3RjaCBpcyBhd2Vzb21lIQ==")
|
||||
)
|
||||
).toMatch("hoppscotch is awesome!")
|
||||
})
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@ describe("isJSONContentType", () => {
|
||||
|
||||
test("returns true for JSON types with charset specified", () => {
|
||||
expect(isJSONContentType("application/json; charset=utf-8")).toBe(true)
|
||||
expect(isJSONContentType("application/vnd.api+json; charset=utf-8")).toBe(true)
|
||||
expect(isJSONContentType("application/vnd.api+json; charset=utf-8")).toBe(
|
||||
true
|
||||
)
|
||||
expect(isJSONContentType("application/hal+json; charset=utf-8")).toBe(true)
|
||||
expect(isJSONContentType("application/ld+json; charset=utf-8")).toBe(true)
|
||||
})
|
||||
@@ -25,7 +27,9 @@ describe("isJSONContentType", () => {
|
||||
test("returns false for non-JSON content types with charset", () => {
|
||||
expect(isJSONContentType("application/xml; charset=utf-8")).toBe(false)
|
||||
expect(isJSONContentType("text/html; charset=utf-8")).toBe(false)
|
||||
expect(isJSONContentType("application/x-www-form-urlencoded; charset=utf-8")).toBe(false)
|
||||
expect(
|
||||
isJSONContentType("application/x-www-form-urlencoded; charset=utf-8")
|
||||
).toBe(false)
|
||||
expect(isJSONContentType("foo/jsoninword; charset=utf-8")).toBe(false)
|
||||
})
|
||||
|
||||
|
||||
@@ -3,16 +3,17 @@ export const decodeB64StringToArrayBuffer = (input) => {
|
||||
const ab = new ArrayBuffer(bytes)
|
||||
const uarray = new Uint8Array(ab)
|
||||
|
||||
const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
||||
const keyStr =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
||||
|
||||
let chr1, chr2, chr3
|
||||
let enc1, enc2, enc3, enc4
|
||||
let j = 0
|
||||
|
||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "")
|
||||
input = input.replace(/[^A-Za-z0-9+/=]/g, "")
|
||||
|
||||
for (let i = 0; i < bytes; i += 3) {
|
||||
//get the 3 octets in 4 ASCII chars
|
||||
// get the 3 octets in 4 ASCII chars
|
||||
enc1 = keyStr.indexOf(input.charAt(j++))
|
||||
enc2 = keyStr.indexOf(input.charAt(j++))
|
||||
enc3 = keyStr.indexOf(input.charAt(j++))
|
||||
@@ -23,8 +24,8 @@ export const decodeB64StringToArrayBuffer = (input) => {
|
||||
chr3 = ((enc3 & 3) << 6) | enc4
|
||||
|
||||
uarray[i] = chr1
|
||||
if (enc3 != 64) uarray[i + 1] = chr2
|
||||
if (enc4 != 64) uarray[i + 2] = chr3
|
||||
if (enc3 !== 64) uarray[i + 1] = chr2
|
||||
if (enc4 !== 64) uarray[i + 2] = chr3
|
||||
}
|
||||
|
||||
return ab
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
export function parseUrlAndPath(value) {
|
||||
let result = {}
|
||||
const result = {}
|
||||
try {
|
||||
let url = new URL(value)
|
||||
const url = new URL(value)
|
||||
result.url = url.origin
|
||||
result.path = url.pathname
|
||||
} catch (error) {
|
||||
let uriRegex = value.match(/^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/)
|
||||
const uriRegex = value.match(
|
||||
/^((http[s]?:\/\/)?(<<[^/]+>>)?[^/]*|)(\/?.*)$/
|
||||
)
|
||||
result.url = uriRegex[1]
|
||||
result.path = uriRegex[4]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const [wsRegexIP, wsRegexHostname] = generateREForProtocol("^(wss?:\\/\\/)?")
|
||||
const [sseRegexIP, sseRegexHostname] = generateREForProtocol("^(https?:\\/\\/)?")
|
||||
const [sseRegexIP, sseRegexHostname] =
|
||||
generateREForProtocol("^(https?:\\/\\/)?")
|
||||
const [socketioRegexIP, socketioRegexHostname] = generateREForProtocol(
|
||||
"^((wss?:\\/\\/)|(https?:\\/\\/))?"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user