1
0
Fork 0
mirror of synced 2024-07-16 11:45:47 +12:00

Merge branch 'master' of github.com:Budibase/budibase into feature/audit-log-sqs

This commit is contained in:
mike12345567 2024-05-24 16:32:43 +01:00
commit 821708e79a
8 changed files with 76 additions and 33 deletions

View file

@ -74,8 +74,8 @@
"build:docker:single:multiarch": "docker buildx build --platform linux/arm64,linux/amd64 -f hosting/single/Dockerfile -t budibase:latest .",
"build:docker:single": "./scripts/build-single-image.sh",
"build:docker:dependencies": "docker build -f hosting/dependencies/Dockerfile -t budibase/dependencies:latest ./hosting",
"publish:docker:couch": "docker buildx build --platform linux/arm64,linux/amd64 -f hosting/couchdb/Dockerfile -t budibase/couchdb:latest -t budibase/couchdb:v3.2.1 --push ./hosting/couchdb",
"publish:docker:couch-sqs": "docker buildx build --platform linux/arm64,linux/amd64 -f hosting/couchdb/Dockerfile.v2 -t budibase/couchdb:v3.2.1-sqs --push ./hosting/couchdb",
"publish:docker:couch": "docker buildx build --platform linux/arm64,linux/amd64 -f hosting/couchdb/Dockerfile -t budibase/couchdb:latest -t budibase/couchdb:v3.3.3 --push ./hosting/couchdb",
"publish:docker:couch-sqs": "docker buildx build --platform linux/arm64,linux/amd64 -f hosting/couchdb/Dockerfile.v2 -t budibase/couchdb:v3.3.3-sqs --push ./hosting/couchdb",
"publish:docker:dependencies": "docker buildx build --platform linux/arm64,linux/amd64 -f hosting/dependencies/Dockerfile -t budibase/dependencies:latest -t budibase/dependencies:v3.2.1 --push ./hosting",
"release:helm": "node scripts/releaseHelmChart",
"env:multi:enable": "lerna run --stream env:multi:enable",

View file

@ -309,7 +309,7 @@
{#if links?.length}
<DataSourceCategory
dividerState={true}
heading="Links"
heading="Relationships"
dataSet={links}
{value}
onSelect={handleSelected}

View file

@ -64,13 +64,11 @@ describe("rest", () => {
cached = await getCachedVariable(basedOnQuery._id!, "foo")
expect(cached).toBeNull()
nock("http://one.example.com")
.get("/")
.reply(200, [{ name: "one" }])
const body1 = [{ name: "one" }]
const body2 = [{ name: "two" }]
nock("http://one.example.com").get("/").reply(200, body1)
nock("http://two.example.com").get("/?test=one").reply(500)
nock("http://two.example.com")
.get("/?test=one")
.reply(200, [{ name: "two" }])
nock("http://two.example.com").get("/?test=one").reply(200, body2)
const res = await config.api.query.preview({
datasourceId: datasource._id!,

View file

@ -148,6 +148,10 @@ class RestIntegration implements IntegrationBase {
response.headers,
{ downloadImages: this.config.downloadImages }
)
let contentLength = response.headers.get("content-length")
if (!contentLength && raw) {
contentLength = Buffer.byteLength(raw, "utf8").toString()
}
if (
contentDisposition.includes("filename") ||
contentDisposition.includes("attachment") ||
@ -156,36 +160,46 @@ class RestIntegration implements IntegrationBase {
filename =
path.basename(parse(contentDisposition).parameters?.filename) || ""
}
let triedParsing: boolean = false,
responseTxt: string | undefined
try {
if (filename) {
return handleFileResponse(response, filename, this.startTimeMs)
} else {
responseTxt = response.text ? await response.text() : ""
const hasContent =
(contentLength && parseInt(contentLength) > 0) ||
responseTxt.length > 0
if (response.status === 204) {
data = []
raw = ""
} else if (contentType.includes("application/json")) {
data = await response.json()
raw = JSON.stringify(data)
} else if (hasContent && contentType.includes("application/json")) {
triedParsing = true
data = JSON.parse(responseTxt)
raw = responseTxt
} else if (
contentType.includes("text/xml") ||
(hasContent && contentType.includes("text/xml")) ||
contentType.includes("application/xml")
) {
let xmlResponse = await handleXml(response)
triedParsing = true
let xmlResponse = await handleXml(responseTxt)
data = xmlResponse.data
raw = xmlResponse.rawXml
} else {
data = await response.text()
data = responseTxt
raw = data as string
}
}
} catch (err) {
throw `Failed to parse response body: ${err}`
if (triedParsing) {
data = responseTxt
raw = data as string
} else {
throw new Error(`Failed to parse response body: ${err}`)
}
}
let contentLength = response.headers.get("content-length")
if (!contentLength && raw) {
contentLength = Buffer.byteLength(raw, "utf8").toString()
}
const size = formatBytes(contentLength || "0")
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
headers = response.headers.raw()

View file

@ -1,19 +1,27 @@
jest.mock("node-fetch", () => {
const obj = {
my_next_cursor: 123,
}
const str = JSON.stringify(obj)
return jest.fn(() => ({
headers: {
raw: () => {
return { "content-type": ["application/json"] }
return {
"content-type": ["application/json"],
"content-length": str.length,
}
},
get: (name: string) => {
if (name.toLowerCase() === "content-type") {
const lcName = name.toLowerCase()
if (lcName === "content-type") {
return ["application/json"]
} else if (lcName === "content-length") {
return str.length
}
},
},
json: jest.fn(() => ({
my_next_cursor: 123,
})),
text: jest.fn(),
json: jest.fn(() => obj),
text: jest.fn(() => str),
}))
})
@ -231,7 +239,8 @@ describe("REST Integration", () => {
}
it("should be able to parse JSON response", async () => {
const input = buildInput({ a: 1 }, null, "application/json")
const obj = { a: 1 }
const input = buildInput(obj, JSON.stringify(obj), "application/json")
const output = await config.integration.parseResponse(input)
expect(output.data).toEqual({ a: 1 })
expect(output.info.code).toEqual(200)
@ -261,7 +270,7 @@ describe("REST Integration", () => {
test.each([...contentTypes, undefined])(
"should not throw an error on 204 no content",
async contentType => {
const input = buildInput(undefined, null, contentType, 204)
const input = buildInput(undefined, "", contentType, 204)
const output = await config.integration.parseResponse(input)
expect(output.data).toEqual([])
expect(output.extra.raw).toEqual("")

View file

@ -330,10 +330,8 @@ export function checkExternalTables(
return errors
}
export async function handleXml(response: any) {
let data,
rawXml = await response.text()
data =
export async function handleXml(rawXml: string) {
let data =
(await xmlParser(rawXml, {
explicitArray: false,
trim: true,

View file

@ -22,5 +22,29 @@
"devDependencies": {
"rimraf": "3.0.2",
"typescript": "5.2.2"
},
"nx": {
"targets": {
"build": {
"dependsOn": [
{
"projects": [
"@budibase/types"
],
"target": "build"
}
]
},
"dev": {
"dependsOn": [
{
"projects": [
"@budibase/types"
],
"target": "build"
}
]
}
}
}
}

View file

@ -3,7 +3,7 @@
"version": "0.0.0",
"description": "Budibase types",
"main": "dist/index.js",
"types": "src/index.ts",
"types": "dist/index.d.ts",
"author": "Budibase",
"license": "GPL-3.0",
"scripts": {