@capriza/connector-controller
Advanced tools
Comparing version 1.0.87 to 1.1.0
@@ -32,3 +32,13 @@ const path = require('path'); | ||
async sendApprovals(approvalsObj) { | ||
approvalsObj.approvals.forEach(ap=>LocalAPI.approvals[ap.private.id]=ap); | ||
approvalsObj.approvals.forEach(ap=>{ | ||
if (ap.deleted){ | ||
delete LocalAPI.approvals[ap.id]; | ||
return; | ||
} | ||
if (!ap.id) { | ||
ap.id = ap.private.id; | ||
} | ||
LocalAPI.approvals[ap.id]=ap; | ||
}); | ||
LocalAPI.approvalsState.push(approvalsObj); | ||
@@ -35,0 +45,0 @@ } |
@@ -5,2 +5,3 @@ const express = require('express'); | ||
const sse = require('./sse'); | ||
const bodyParser = require("body-parser"); | ||
@@ -24,3 +25,6 @@ function getUITemplateData(approval, UITemplate){ | ||
this.connections = []; | ||
this.app.use(cors()); | ||
this.app.use(bodyParser.urlencoded({ extended: false })); | ||
this.app.use(bodyParser.json()); | ||
} | ||
@@ -32,6 +36,10 @@ | ||
generateTaskId(){ | ||
return "task-" + this.syncCounter++; | ||
} | ||
async start(){ | ||
var logger = this.logger; | ||
this.app.get('/fetch', async (req, res) => { | ||
var taskId = "sync-" + this.syncCounter++; | ||
var taskId = this.generateTaskId(); | ||
var task = new this.TaskClasses.Task({ id : taskId, type : "sync" }), | ||
@@ -58,2 +66,28 @@ backend = task.backend, result; | ||
this.app.post('/action',async (req,res)=>{ | ||
var data = req.body.data; | ||
this.logger.info(`Action Data ${JSON.stringify(data)}`); | ||
var taskId = data.id = this.generateTaskId(); | ||
var task = new this.TaskClasses.Task(data), | ||
backend = task.backend, result; | ||
try{ | ||
await task.execute(); | ||
var approvalsResult = backend.getApprovalState(), | ||
taskStatus = backend.getTaskStatus(taskId); | ||
approvalsResult.forEach(approvalsObj=>{ | ||
approvalsObj.uiApprovals = approvalsObj.transformedApprovals.map(approval=>getUITemplateData(approval.public, backend.getUITemplate(approval.schemaId))); | ||
}); | ||
result = JSON.stringify({approvalsResult, taskStatus}); | ||
} catch(ex){ | ||
result = `Action error ${ex.stack}`; | ||
} | ||
res.send(result); | ||
res.end(); | ||
}); | ||
this.app.get('/ServerMessages', async (req, res)=>{ | ||
@@ -60,0 +94,0 @@ sse(res); |
{ | ||
"name": "@capriza/connector-controller", | ||
"version": "1.0.87", | ||
"version": "1.1.0", | ||
"description": "Capriza connectors controller", | ||
@@ -28,4 +28,8 @@ "license": "MIT", | ||
"dependencies": { | ||
"@capriza/schemas": "^1.0.0", | ||
"async-exit-hook": "2.0.1", | ||
"axios": "0.17.1", | ||
"body-parser": "^1.18.3", | ||
"chokidar": "1.7.0", | ||
"cors": "~2.8.4", | ||
"deepmerge": "2.0.1", | ||
@@ -38,2 +42,3 @@ "express": "4.16.3", | ||
"object-hash": "1.2.0", | ||
"opn": "^5.1.0", | ||
"path": "0.12.7", | ||
@@ -43,7 +48,3 @@ "pino": "4.10.2", | ||
"syswide-cas": "^5.0.0", | ||
"ws": "^5.1.1", | ||
"@capriza/schemas": "^1.0.0", | ||
"chokidar": "1.7.0", | ||
"opn": "^5.1.0", | ||
"cors": "~2.8.4" | ||
"ws": "^5.1.1" | ||
}, | ||
@@ -50,0 +51,0 @@ "devDependencies": { |
151118
2683
19
+ Addedbody-parser@^1.18.3
+ Addedbody-parser@1.20.3(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedon-finished@2.4.1(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedraw-body@2.5.2(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedtoidentifier@1.0.1(transitive)