Implementing the block definitions as list APIs for the workflow, meaning client has to retrieve structure from API instead of inherently knowing it.
This commit is contained in:
parent
6dcaa3c4d8
commit
79cb0c522f
|
@ -4,5 +4,6 @@
|
||||||
"singleQuote": false,
|
"singleQuote": false,
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"plugins": ["prettier-plugin-svelte"],
|
"plugins": ["prettier-plugin-svelte"],
|
||||||
"svelteSortOrder" : "scripts-markup-styles"
|
"svelteSortOrder" : "scripts-markup-styles",
|
||||||
|
"printWidth": 100
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ exports.authenticate = async ctx => {
|
||||||
const { clientId } = await masterDb.get(ctx.user.appId)
|
const { clientId } = await masterDb.get(ctx.user.appId)
|
||||||
|
|
||||||
if (!clientId) {
|
if (!clientId) {
|
||||||
ctx.throw(400, "ClientId not suplied")
|
ctx.throw(400, "ClientId not supplied")
|
||||||
}
|
}
|
||||||
// find the instance that the user is associated with
|
// find the instance that the user is associated with
|
||||||
const db = new CouchDB(ClientDb.name(clientId))
|
const db = new CouchDB(ClientDb.name(clientId))
|
||||||
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
const ACTION = {
|
||||||
|
SAVE_RECORD: {
|
||||||
|
name: "Save Record",
|
||||||
|
tagline: "<b>Save</b> a <b>{{record.model.name}}</b> record",
|
||||||
|
icon: "ri-save-3-fill",
|
||||||
|
description: "Save a record to your database.",
|
||||||
|
environment: "SERVER",
|
||||||
|
params: {
|
||||||
|
record: "record",
|
||||||
|
},
|
||||||
|
args: {
|
||||||
|
record: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DELETE_RECORD: {
|
||||||
|
description: "Delete a record from your database.",
|
||||||
|
icon: "ri-delete-bin-line",
|
||||||
|
name: "Delete Record",
|
||||||
|
tagline: "<b>Delete</b> a <b>{{record.model.name}}</b> record",
|
||||||
|
environment: "SERVER",
|
||||||
|
params: {
|
||||||
|
record: "record",
|
||||||
|
},
|
||||||
|
args: {
|
||||||
|
record: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// FIND_RECORD: {
|
||||||
|
// description: "Find a record in your database.",
|
||||||
|
// tagline: "<b>Find</b> a <b>{{record.model.name}}</b> record",
|
||||||
|
// icon: "ri-search-line",
|
||||||
|
// name: "Find Record",
|
||||||
|
// environment: "SERVER",
|
||||||
|
// params: {
|
||||||
|
// record: "string",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
CREATE_USER: {
|
||||||
|
description: "Create a new user.",
|
||||||
|
tagline: "Create user <b>{{username}}</b>",
|
||||||
|
icon: "ri-user-add-fill",
|
||||||
|
name: "Create User",
|
||||||
|
environment: "SERVER",
|
||||||
|
params: {
|
||||||
|
username: "string",
|
||||||
|
password: "password",
|
||||||
|
accessLevelId: "accessLevel",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
SEND_EMAIL: {
|
||||||
|
description: "Send an email.",
|
||||||
|
tagline: "Send email to <b>{{to}}</b>",
|
||||||
|
icon: "ri-mail-open-fill",
|
||||||
|
name: "Send Email",
|
||||||
|
environment: "SERVER",
|
||||||
|
params: {
|
||||||
|
to: "string",
|
||||||
|
from: "string",
|
||||||
|
subject: "longText",
|
||||||
|
text: "longText",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const TRIGGER = {
|
||||||
|
RECORD_SAVED: {
|
||||||
|
name: "Record Saved",
|
||||||
|
event: "record:save",
|
||||||
|
icon: "ri-save-line",
|
||||||
|
tagline: "Record is added to <b>{{model.name}}</b>",
|
||||||
|
description: "Save a record to your database.",
|
||||||
|
environment: "SERVER",
|
||||||
|
params: {
|
||||||
|
model: "model",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RECORD_DELETED: {
|
||||||
|
name: "Record Deleted",
|
||||||
|
event: "record:delete",
|
||||||
|
icon: "ri-delete-bin-line",
|
||||||
|
tagline: "Record is deleted from <b>{{model.name}}</b>",
|
||||||
|
description: "Fired when a record is deleted from your database.",
|
||||||
|
environment: "SERVER",
|
||||||
|
params: {
|
||||||
|
model: "model",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const LOGIC = {
|
||||||
|
FILTER: {
|
||||||
|
name: "Filter",
|
||||||
|
tagline: "{{field}} <b>{{condition}}</b> {{value}}",
|
||||||
|
icon: "ri-git-branch-line",
|
||||||
|
description: "Filter any workflows which do not meet certain conditions.",
|
||||||
|
environment: "CLIENT",
|
||||||
|
params: {
|
||||||
|
filter: "string",
|
||||||
|
condition: ["equals"],
|
||||||
|
value: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DELAY: {
|
||||||
|
name: "Delay",
|
||||||
|
icon: "ri-time-fill",
|
||||||
|
tagline: "Delay for <b>{{time}}</b> milliseconds",
|
||||||
|
description: "Delay the workflow until an amount of time has passed.",
|
||||||
|
environment: "CLIENT",
|
||||||
|
params: {
|
||||||
|
time: "number",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
ACTION,
|
||||||
|
TRIGGER,
|
||||||
|
LOGIC,
|
||||||
|
}
|
|
@ -1,5 +1,12 @@
|
||||||
const CouchDB = require("../../../db")
|
const CouchDB = require("../../../db")
|
||||||
const newid = require("../../../db/newid")
|
const newid = require("../../../db/newid")
|
||||||
|
const blockDefinitions = require("./blockDefinitions")
|
||||||
|
|
||||||
|
/*************************
|
||||||
|
* *
|
||||||
|
* BUILDER FUNCTIONS *
|
||||||
|
* *
|
||||||
|
*************************/
|
||||||
|
|
||||||
exports.create = async function(ctx) {
|
exports.create = async function(ctx) {
|
||||||
const db = new CouchDB(ctx.user.instanceId)
|
const db = new CouchDB(ctx.user.instanceId)
|
||||||
|
@ -53,22 +60,41 @@ exports.find = async function(ctx) {
|
||||||
ctx.body = await db.get(ctx.params.id)
|
ctx.body = await db.get(ctx.params.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.executeAction = async function(ctx) {
|
|
||||||
const { args, action } = ctx.request.body
|
|
||||||
const workflowAction = require(`./actions/${action}`)
|
|
||||||
const response = await workflowAction({
|
|
||||||
args,
|
|
||||||
instanceId: ctx.user.instanceId,
|
|
||||||
})
|
|
||||||
ctx.body = response
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.fetchActionScript = async function(ctx) {
|
exports.fetchActionScript = async function(ctx) {
|
||||||
const workflowAction = require(`./actions/${ctx.action}`)
|
ctx.body = require(`./actions/${ctx.action}`)
|
||||||
ctx.body = workflowAction
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.destroy = async function(ctx) {
|
exports.destroy = async function(ctx) {
|
||||||
const db = new CouchDB(ctx.user.instanceId)
|
const db = new CouchDB(ctx.user.instanceId)
|
||||||
ctx.body = await db.remove(ctx.params.id, ctx.params.rev)
|
ctx.body = await db.remove(ctx.params.id, ctx.params.rev)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.executeAction = async function(ctx) {
|
||||||
|
const { args, action } = ctx.request.body
|
||||||
|
const workflowAction = require(`./actions/${action}`)
|
||||||
|
ctx.body = await workflowAction({
|
||||||
|
args,
|
||||||
|
instanceId: ctx.user.instanceId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getActionList = async function(ctx) {
|
||||||
|
ctx.body = blockDefinitions.ACTION
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getTriggerList = async function(ctx) {
|
||||||
|
ctx.body = blockDefinitions.TRIGGER
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getLogicList = async function(ctx) {
|
||||||
|
ctx.body = blockDefinitions.ACTION
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* *
|
||||||
|
* API FUNCTIONS *
|
||||||
|
* *
|
||||||
|
*********************/
|
||||||
|
|
||||||
|
exports.trigger = async function(ctx) {
|
||||||
|
}
|
||||||
|
|
|
@ -6,16 +6,15 @@ const { BUILDER } = require("../../utilities/accessLevels")
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
|
.get("/api/workflows/trigger/list", authorized(BUILDER), controller.getTriggerList)
|
||||||
|
.get("/api/workflows/action/list", authorized(BUILDER), controller.getActionList)
|
||||||
|
.get("/api/workflows/logic/list", authorized(BUILDER), controller.getLogicList)
|
||||||
.get("/api/workflows", authorized(BUILDER), controller.fetch)
|
.get("/api/workflows", authorized(BUILDER), controller.fetch)
|
||||||
.get("/api/workflows/:id", authorized(BUILDER), controller.find)
|
.get("/api/workflows/:id", authorized(BUILDER), controller.find)
|
||||||
.get(
|
.get("/api/workflows/:id/:action", authorized(BUILDER), controller.fetchActionScript)
|
||||||
"/api/workflows/:id/:action",
|
|
||||||
authorized(BUILDER),
|
|
||||||
controller.fetchActionScript
|
|
||||||
)
|
|
||||||
.put("/api/workflows", authorized(BUILDER), controller.update)
|
.put("/api/workflows", authorized(BUILDER), controller.update)
|
||||||
.post("/api/workflows", authorized(BUILDER), controller.create)
|
.post("/api/workflows", authorized(BUILDER), controller.create)
|
||||||
.post("/api/workflows/action", controller.executeAction)
|
.post("/api/workflows/trigger", controller.trigger)
|
||||||
.delete("/api/workflows/:id/:rev", authorized(BUILDER), controller.destroy)
|
.delete("/api/workflows/:id/:rev", authorized(BUILDER), controller.destroy)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
Loading…
Reference in New Issue