@daedalus/wso2
Version:
This is a set of tools to help connect and manage interactions with various WSO2 products. Please see README.MD for more details.
115 lines (108 loc) • 2.78 kB
JavaScript
const https = require("https");
const axios = require("axios").create({
httpsAgent: new https.Agent({
rejectUnauthorized: false
}),
proxy: false
});
const serviceResource = "bpmn/form/form-data/";
/*
data = {
server: {
url: ""
},
auth: {
username: "",
password: ""
}
}
*/
//GET
//https://<Host Name>:<Port>/bpmn/form/form-data/?taskId={taskId}
const getTaskFormData = (taskid, data, callback) => {
let url = data.server.url + serviceResource + "?taskId=" + taskid;
let options = {
auth: data.auth
};
axios
.get(url, options)
.then(response => {
callback(null, response.data);
})
.catch(error => {
if (error.response && error.response.data) {
callback(null, { success: false, msg: error.response.data });
} else {
callback(null, { success: false, msg: "Uknown Error from Axios" });
}
});
};
//GET
//https://<Host Name>:<Port>/bpmn/form/form-data/?processDefinitionId={processDefinitionId}
const getProcessDefinitionFormData = (processDefinitionId, data, callback) => {
//The processDefinitionId is made up of {deploymentKey}:{version}:{deploymentId}
//Because there are ':' in the string, it will cause the call to fail.
let encodedId = encodeURIComponent(processDefinitionId);
let url =
data.server.url + serviceResource + "?processDefinitionId=" + encodedId;
let options = {
auth: data.auth
};
axios
.get(url, options)
.then(response => {
callback(null, response.data);
})
.catch(error => {
if (error.response && error.response.data) {
callback(null, { success: false, msg: error.response.data });
} else {
callback(null, { success: false, msg: "Uknown Error from Axios" });
}
});
};
/*
data.body = {
"taskId" : "5",
"properties" : [
{
"id" : "room",
"value" : "normal"
}
]
}
OR
data.body = {
"processDefinitionId" : "5",
"businessKey" : "myKey",
"properties" : [
{
"id" : "room",
"value" : "normal"
}
]
}
*/
const submitFormData = (data, callback) => {
let url = data.server.url + serviceResource;
let options = {
auth: data.auth
};
axios
.post(url, data.body, options)
.then(response => {
callback(null, response.data);
})
.catch(error => {
if (error.response && error.response.data) {
callback(null, { success: false, msg: error.response.data });
} else {
callback(null, { success: false, msg: "Uknown Error from Axios" });
}
});
};
module.exports = {
getTaskFormData,
getProcessDefinitionFormData,
submitFormData
};