Skip to content

Commit

Permalink
Support SOAP Action and return JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
melohagan committed Nov 24, 2022
1 parent 3204cc3 commit 427019f
Show file tree
Hide file tree
Showing 5 changed files with 5,089 additions and 4,940 deletions.
79 changes: 55 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "budibase-soap",
"version": "1.0.0",
"version": "1.1.0",
"description": "Connect to web services using SOAP in Budibase",
"main": "src/index.ts",
"license": "MIT",
Expand All @@ -10,7 +10,8 @@
},
"dependencies": {
"@budibase/types": "^2.0.13",
"easy-soap-request": "^5.2.0"
"easy-soap-request": "^5.2.0",
"xml2js": "^0.4.23"
},
"devDependencies": {
"@babel/core": "^7.19.0",
Expand Down
56 changes: 52 additions & 4 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,64 @@
},
"query": {
"create": {
"type": "sql"
"type": "fields",
"readable": true,
"fields": {
"soapAction": {
"type": "string",
"required": false,
"display": "SOAP Action"
},
"body": {
"type": "json",
"required": false
}
}
},
"update": {
"type": "sql"
"type": "fields",
"readable": true,
"fields": {
"soapAction": {
"type": "string",
"required": false,
"display": "SOAP Action"
},
"body": {
"type": "json",
"required": false
}
}
},
"read": {
"type": "sql"
"type": "fields",
"readable": true,
"fields": {
"soapAction": {
"type": "string",
"required": false,
"display": "SOAP Action"
},
"body": {
"type": "json",
"required": false
}
}
},
"delete": {
"type": "sql"
"type": "fields",
"readable": true,
"fields": {
"soapAction": {
"type": "string",
"required": false,
"display": "SOAP Action"
},
"body": {
"type": "json",
"required": false
}
}
}
}
}
Expand Down
28 changes: 20 additions & 8 deletions src/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { IntegrationBase } from "@budibase/types"
// @ts-ignore
import soapRequest from "easy-soap-request"
// @ts-ignore
import xml2js from "xml2js"

class CustomIntegration implements IntegrationBase {
private readonly url: string
Expand All @@ -9,30 +11,40 @@ class CustomIntegration implements IntegrationBase {
this.url = config.url
}

async execute(query: { sql: string }) {
const headers = {
async execute(query: { body: string; soapAction: string }) {
const headers: any = {
'Content-Type': 'text/xml;charset=UTF-8',
}
return await soapRequest({
if (query.soapAction) {
headers["soapAction"] = query.soapAction
}
const responseBody = await soapRequest({
url: this.url,
headers,
xml: query.sql
xml: query.body
})
const parseString = xml2js.parseString
let jsonBody
parseString(responseBody?.response?.body, (err: any, res: any) => {
jsonBody = res["soap:Envelope"]["soap:Body"][0]
if (err) throw err
})
return jsonBody
}

async create(query: { sql: string }) {
async create(query: { body: string; soapAction: string }) {
return await this.execute(query)
}

async read(query: { sql: string }) {
async read(query: { body: string; soapAction: string }) {
return await this.execute(query)
}

async update(query: { sql: string }) {
async update(query: { body: string; soapAction: string }) {
return await this.execute(query)
}

async delete(query: { sql: string }) {
async delete(query: { body: string; soapAction: string }) {
return await this.execute(query)
}
}
Expand Down
Loading

0 comments on commit 427019f

Please sign in to comment.