Adding in the ability to retrieve and view the headers from a rest response.
This commit is contained in:
parent
dad8524023
commit
d774aade45
|
@ -1,12 +1,30 @@
|
||||||
<script>
|
<script>
|
||||||
import { Icon } from "@budibase/bbui"
|
import { Icon, Body } from "@budibase/bbui"
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a target="_blank" href="https://github.com/Budibase/budibase/discussions">
|
<a target="_blank" href="https://github.com/Budibase/budibase/discussions">
|
||||||
<Icon hoverable name="Help" size="XXL" />
|
<div class="inner hoverable">
|
||||||
|
<div class="hidden hoverable">
|
||||||
|
<Body size="S">Need help? Go to our forums</Body>
|
||||||
|
</div>
|
||||||
|
<Icon name="Help" size="XXL" />
|
||||||
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
.inner {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--spacing-s);
|
||||||
|
}
|
||||||
|
.inner :global(*) {
|
||||||
|
pointer-events: all;
|
||||||
|
transition: color var(--spectrum-global-animation-duration-100, 130ms);
|
||||||
|
}
|
||||||
|
.inner:hover :global(*) {
|
||||||
|
color: var(--spectrum-alias-icon-color-selected-hover);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
a {
|
a {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -14,4 +32,10 @@
|
||||||
right: var(--spacing-m);
|
right: var(--spacing-m);
|
||||||
border-radius: 55%;
|
border-radius: 55%;
|
||||||
}
|
}
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.inner:hover .hidden {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -134,4 +134,7 @@
|
||||||
.container-active {
|
.container-active {
|
||||||
grid-template-columns: 1fr 1fr 50px 20px;
|
grid-template-columns: 1fr 1fr 50px 20px;
|
||||||
}
|
}
|
||||||
|
.readOnly {
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -266,7 +266,10 @@
|
||||||
/>
|
/>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab title="Raw">
|
<Tab title="Raw">
|
||||||
<TextArea disabled value={response.raw} height="300" />
|
<TextArea disabled value={response.extra?.raw} height="300" />
|
||||||
|
</Tab>
|
||||||
|
<Tab title="Headers">
|
||||||
|
<KeyValueBuilder object={response.extra?.headers} readOnly />
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab title="Preview">
|
<Tab title="Preview">
|
||||||
{#if response}
|
{#if response}
|
||||||
|
|
|
@ -151,7 +151,7 @@ exports.preview = async function (ctx) {
|
||||||
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { rows, keys, info, raw } = await Runner.run({
|
const { rows, keys, info, extra } = await Runner.run({
|
||||||
datasource,
|
datasource,
|
||||||
queryVerb,
|
queryVerb,
|
||||||
query: enrichedQuery,
|
query: enrichedQuery,
|
||||||
|
@ -162,7 +162,7 @@ exports.preview = async function (ctx) {
|
||||||
rows,
|
rows,
|
||||||
schemaFields: [...new Set(keys)],
|
schemaFields: [...new Set(keys)],
|
||||||
info,
|
info,
|
||||||
raw,
|
extra,
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err)
|
||||||
|
|
|
@ -122,7 +122,7 @@ module RestModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseResponse(response: any) {
|
async parseResponse(response: any) {
|
||||||
let data, raw
|
let data, raw, headers
|
||||||
const contentType = response.headers.get("content-type")
|
const contentType = response.headers.get("content-type")
|
||||||
if (contentType && contentType.indexOf("application/json") !== -1) {
|
if (contentType && contentType.indexOf("application/json") !== -1) {
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
|
@ -133,6 +133,10 @@ module RestModule {
|
||||||
}
|
}
|
||||||
const size = formatBytes(response.headers.get("content-length") || 0)
|
const size = formatBytes(response.headers.get("content-length") || 0)
|
||||||
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
|
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
|
||||||
|
headers = response.headers.raw()
|
||||||
|
for (let [key, value] of Object.entries(headers)) {
|
||||||
|
headers[key] = Array.isArray(value) ? value[0] : value
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
info: {
|
info: {
|
||||||
|
@ -140,7 +144,10 @@ module RestModule {
|
||||||
size,
|
size,
|
||||||
time,
|
time,
|
||||||
},
|
},
|
||||||
|
extra: {
|
||||||
raw,
|
raw,
|
||||||
|
headers,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,8 @@ function hasExtraData(response) {
|
||||||
return (
|
return (
|
||||||
typeof response === "object" &&
|
typeof response === "object" &&
|
||||||
!Array.isArray(response) &&
|
!Array.isArray(response) &&
|
||||||
response.data &&
|
response.data != null &&
|
||||||
response.info
|
response.info != null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,11 +34,11 @@ async function runAndTransform(datasource, queryVerb, query, transformer) {
|
||||||
let output = formatResponse(await integration[queryVerb](query))
|
let output = formatResponse(await integration[queryVerb](query))
|
||||||
let rows = output,
|
let rows = output,
|
||||||
info = undefined,
|
info = undefined,
|
||||||
raw = undefined
|
extra = undefined
|
||||||
if (hasExtraData(output)) {
|
if (hasExtraData(output)) {
|
||||||
rows = output.data
|
rows = output.data
|
||||||
info = output.info
|
info = output.info
|
||||||
raw = output.raw
|
extra = output.extra
|
||||||
}
|
}
|
||||||
|
|
||||||
// transform as required
|
// transform as required
|
||||||
|
@ -64,7 +64,7 @@ async function runAndTransform(datasource, queryVerb, query, transformer) {
|
||||||
integration.end()
|
integration.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
return { rows, keys, info, raw }
|
return { rows, keys, info, extra }
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (input, callback) => {
|
module.exports = (input, callback) => {
|
||||||
|
|
Loading…
Reference in New Issue