diff --git a/.prettierrc b/.prettierrc
index e23b0be753..6c36d6b4be 100644
--- a/.prettierrc
+++ b/.prettierrc
@@ -4,5 +4,6 @@
"singleQuote": false,
"trailingComma": "es5",
"plugins": ["prettier-plugin-svelte"],
- "svelteSortOrder" : "scripts-markup-styles"
+ "svelteSortOrder" : "scripts-markup-styles",
+ "printWidth": 100
}
\ No newline at end of file
diff --git a/packages/server/src/api/controllers/auth.js b/packages/server/src/api/controllers/auth.js
index 4f0ddbf0d8..ea12e5cc24 100644
--- a/packages/server/src/api/controllers/auth.js
+++ b/packages/server/src/api/controllers/auth.js
@@ -16,7 +16,7 @@ exports.authenticate = async ctx => {
const { clientId } = await masterDb.get(ctx.user.appId)
if (!clientId) {
- ctx.throw(400, "ClientId not suplied")
+ ctx.throw(400, "ClientId not supplied")
}
// find the instance that the user is associated with
const db = new CouchDB(ClientDb.name(clientId))
diff --git a/packages/server/src/api/controllers/workflow/blockDefinitions.js b/packages/server/src/api/controllers/workflow/blockDefinitions.js
new file mode 100644
index 0000000000..5df44e307d
--- /dev/null
+++ b/packages/server/src/api/controllers/workflow/blockDefinitions.js
@@ -0,0 +1,119 @@
+const ACTION = {
+ SAVE_RECORD: {
+ name: "Save Record",
+ tagline: "Save a {{record.model.name}} 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: "Delete a {{record.model.name}} record",
+ environment: "SERVER",
+ params: {
+ record: "record",
+ },
+ args: {
+ record: {},
+ },
+ },
+ // FIND_RECORD: {
+ // description: "Find a record in your database.",
+ // tagline: "Find a {{record.model.name}} record",
+ // icon: "ri-search-line",
+ // name: "Find Record",
+ // environment: "SERVER",
+ // params: {
+ // record: "string",
+ // },
+ // },
+ CREATE_USER: {
+ description: "Create a new user.",
+ tagline: "Create user {{username}}",
+ 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 {{to}}",
+ 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 {{model.name}}",
+ 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 {{model.name}}",
+ description: "Fired when a record is deleted from your database.",
+ environment: "SERVER",
+ params: {
+ model: "model",
+ },
+ },
+}
+
+const LOGIC = {
+ FILTER: {
+ name: "Filter",
+ tagline: "{{field}} {{condition}} {{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 {{time}} milliseconds",
+ description: "Delay the workflow until an amount of time has passed.",
+ environment: "CLIENT",
+ params: {
+ time: "number",
+ },
+ },
+}
+
+module.exports = {
+ ACTION,
+ TRIGGER,
+ LOGIC,
+}
diff --git a/packages/server/src/api/controllers/workflow/index.js b/packages/server/src/api/controllers/workflow/index.js
index 5c77bbfaa6..3f489ceede 100644
--- a/packages/server/src/api/controllers/workflow/index.js
+++ b/packages/server/src/api/controllers/workflow/index.js
@@ -1,5 +1,12 @@
const CouchDB = require("../../../db")
const newid = require("../../../db/newid")
+const blockDefinitions = require("./blockDefinitions")
+
+/*************************
+ * *
+ * BUILDER FUNCTIONS *
+ * *
+ *************************/
exports.create = async function(ctx) {
const db = new CouchDB(ctx.user.instanceId)
@@ -53,22 +60,41 @@ exports.find = async function(ctx) {
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) {
- const workflowAction = require(`./actions/${ctx.action}`)
- ctx.body = workflowAction
+ ctx.body = require(`./actions/${ctx.action}`)
}
exports.destroy = async function(ctx) {
const db = new CouchDB(ctx.user.instanceId)
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) {
+}
diff --git a/packages/server/src/api/routes/workflow.js b/packages/server/src/api/routes/workflow.js
index 987e18a60f..a2191e44d4 100644
--- a/packages/server/src/api/routes/workflow.js
+++ b/packages/server/src/api/routes/workflow.js
@@ -6,16 +6,15 @@ const { BUILDER } = require("../../utilities/accessLevels")
const 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/:id", authorized(BUILDER), controller.find)
- .get(
- "/api/workflows/:id/:action",
- authorized(BUILDER),
- controller.fetchActionScript
- )
+ .get("/api/workflows/:id/:action", authorized(BUILDER), controller.fetchActionScript)
.put("/api/workflows", authorized(BUILDER), controller.update)
.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)
module.exports = router