oute-services-canvas-sdk
v0.0.84
Published
- Initialization
Downloads
99
Readme
This module expose helper functions
- Initialization
params = {
url: @server url
token: @access token
}
Canvas = require("oute-services-canvas-sdk")
canvas_instance = new Canvas(params)
Cache functions
- get inputs from published canvas
published_canvas = {
"_id": "cjalQm9pU",
"canvas_id": "wQ3nf3XTb",
"task_graph": [
[ "start", [] ],
[ "http", [ "start" ] ],
[ "ifelse", [ "http" ] ],
[ "success", [ "ifelse" ] ]
],
"flow": {
"start": { "_id": "start", "type": "START", "inputs": [ { "key": "a" } ], "outputs": [] },
"http": { "_id": "http", "type": "HTTP", "inputs": [], "outputs": [] },
"ifelse": { "_id": "ifelse", "type": "IFELSE", "inputs": [], "outputs": [] },
"success": { "_id": "success", "type": "SUCCESS", "inputs": [], "outputs": [] }
},
"state": "ACTIVE",
"created_at": "2023-09-28T09:59:14.086Z",
"updated_at": "2023-10-06T06:00:34.402Z",
"__v": 0,
"project_id": "x1QBwyqbN"
}
await canvas_instance.getBoundsIOOfPublishedCanvas(published_canvas)
- get start node from published canvas
published_canvas = {
"_id": "cjalQm9pU",
"canvas_id": "wQ3nf3XTb",
"task_graph": [],
"flow": {},
"state": "ACTIVE",
"created_at": "2023-09-28T09:59:14.086Z",
"updated_at": "2023-10-06T06:00:34.402Z",
"__v": 0,
"project_id": "x1QBwyqbN"
}
canvas_instance.getStartNodeOfPublishedCanvas(published_canvas)
- get bounds input and output from canvas data
canvas_data = "{ \"class\": \"GraphLinksModel\"}"
canvas_instance.getBoundsIOOfCanvasData(canvas_data)
- get bounds of untransformed canvas
canvas_data = "{ \"class\": \"GraphLinksModel\"}"
canvas_instance.getBoundsIOOfCanvasData(canvas_data)
- Transform canvas to published
canvas_data = {_id: "test", _r: ""}
canvas_instance.transformCanvas(canvas_data)
Core functions
- Save canvas
body = {
"asset_id" : "1ZXZKMvvE",
"_r" : "{}",
"meta": {},
"workspace_id": "ZzBfJMpfQ",
"name" : "test canvas",
"parent_id" : null,
"type" : "WORKFLOW",
"user_id" : "[email protected]",
"share_to_all": true
}
await canvas_instance.saveCanvas(body)
- Find One
query = {
"asset_id": "1ZXZKMvvE"
}
await canvas_instance.findOne(query)
- Get Init inputs of canvas
query = {
"asset_id": "1ZXZKMvvE",
"workspace_id": "ZzBfJMpfQ"
}
await canvas_instance.getBoundsIOOfCanvas(query)
Publish canvas
- publish canvas
body = {
"asset_id" : "1ZXZKMvvE",
"_r" : "{}",
"meta": {},
"workspace_id": "ZzBfJMpfQ",
"name" : "test canvas",
"publish_name" : "test canvas1",
"parent_id" : null,
"type" : "WORKFLOW",
"user_id" : "[email protected]",
"project_id": "x1QBwyqbN"
"published_id": "cjalQm9pU", //This only needed if want to update the existing published data
"annotation": "IC",
"_id": "abc",
"share_to_all": true
}
await canvas_instance.publishCanvas(body)
- Get list of published canvas by project id
query = {
"project_id": "1ZXZKMvvE"
}
await canvas_instance.getPublishedListByProject(query)
- Get latest of published canvas by asset id
query = {
"asset_id": "1ZXZKMvvE"
}
await canvas_instance.getPublishedByAsset(query)
- Transform canvas to published
body = {
"asset_id" : "1ZXZKMvvE",
"_r" : "{ \"class\": \"GraphLinksModel\",\n \"nodeCategoryProperty\": \"template\",\n \"linkKeyProperty\": \"key\",\n \"nodeDataArray\": [\n{\"key\":\"1692361625690\",\"src\":\"/static/media/input-setup.6bc4e1375793765dd9b1e7463776f5c9.svg\",\"text\":\"\",\"subText\":\"\",\"type\":\"Input Setup\", \"tf_data\": {\"_id\": \"start\", \"type\": \"START\", \"inputs\": [{\"key\": \"a\"}], \"outputs\": []},\"template\":\"startNode\",\"background\":\"rgb(33, 150, 243)\",\"foreground\":\"#fff\",\"viewSpot\":\"0 0.5\",\"location\":\"-746 0\"},\n{\"key\":\"1692361625695\",\"src\":\"/static/media/failure-setup.2e6fe9f6dcb6fb35de5a33083c93486e.svg\",\"text\":\"\",\"subText\":\"\",\"type\":\"Failure Setup\", \"tf_data\": {\"_id\": \"failed\", \"type\": \"FAILED\", \"inputs\": [], \"outputs\": []},\"template\":\"endNode\",\"background\":\"rgb(255, 82, 82)\",\"foreground\":\"#fff\",\"viewSpot\":\"1 0.6667\",\"location\":\"766 133.36\"},\n{\"key\":\"16923616256952\",\"src\":\"/static/media/success-setup.b7611cf8ee605348416961dad01f45bc.svg\",\"text\":\"\",\"subText\":\"\",\"type\":\"Success Setup\", \"tf_data\": {\"_id\": \"success\", \"type\": \"SUCCESS\", \"inputs\": [], \"outputs\": []},\"template\":\"endNode\",\"background\":\"rgb(76, 175, 80)\",\"foreground\":\"#fff\",\"viewSpot\":\"1 0.3333\",\"location\":\"766 -133.36\"},\n{\"key\":\"1692361631573\",\"src\":\"/static/media/http.7e60c9cb780694dcb54bfa896b38083f.svg\",\"text\":\"Method\",\"subText\":\"HTTP\", \"tf_data\": {\"_id\": \"http\", \"type\": \"HTTP\", \"inputs\": [], \"outputs\": []},\"type\":\"HTTP\",\"template\":\"\",\"background\":\"#be63f9\",\"foreground\":\"#fff\",\"module\":\"Flow Controls\",\"location\":\"-416.2578125 -85.8671875\"},\n{\"key\":\"1692361641779\",\"src\":\"/static/media/ifelse.60d2e8e0ecf5753156427c8d55b0459c.svg\",\"text\":\"If Else\", \"tf_data\": {\"_id\": \"ifelse\", \"type\": \"IFELSE\", \"inputs\": [], \"outputs\": []},\"subText\":\"Condition\",\"type\":\"If Else\",\"template\":\"\",\"background\":\"rgb(33, 150, 243)\",\"foreground\":\"#fff\",\"module\":\"Flow Controls\",\"location\":\"-135.7578125 -85.90234375\"}\n],\n \"linkDataArray\": [\n{\"from\":\"1692361625690\",\"to\":\"1692361631573\",\"key\":-1},\n{\"from\":\"1692361631573\",\"to\":\"1692361641779\",\"key\":-2},\n{\"from\":\"1692361641779\",\"to\":\"16923616256952\",\"key\":-3}\n]}",
"meta": {},
"workspace_id": "ZzBfJMpfQ",
"name" : "test canvas",
"publish_name" : "test canvas1",
"parent_id" : null,
"type" : "WORKFLOW",
"user_id" : "[email protected]",
"project_id": "x1QBwyqbN"
"published_id": "cjalQm9pU",
"_id": "abc",
"share_to_all": true
}
canvas_instance.canvasToPublished(body)
- Execute canvas
canvas_data = {
_id: "test",
_r: ""
}
state = {}
await canvas_instance.executeCanvas(canvas_data, state)
- Execute transformed canvas
body = {flow: {}, state: {}}
await canvas_instance.executeTransformedCanvas(body)