@avakado.ai/schemas 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avakado.ai/schemas",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Canonical Mongo schemas, models, enums and index declarations shared by the Avakado services.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -1,5 +1,41 @@
1
1
  import { Schema } from "mongoose";
2
2
  import { defineModel } from "../runtime.js";
3
+ const taskNodeCoreExecutionSchema = new Schema({
4
+ template: {
5
+ id: String,
6
+ data: Schema.Types.Mixed,
7
+ },
8
+ compiledInstructions: String,
9
+ });
10
+ const taskNodeCoreSchema = new Schema({
11
+ type: { type: String, required: true, enum: ['task', 'conditional'] },
12
+ input: {
13
+ schema: Schema.Types.Mixed,
14
+ mapper: Schema.Types.Mixed,
15
+ preset: Schema.Types.Mixed,
16
+ },
17
+ output: {
18
+ schema: Schema.Types.Mixed,
19
+ mapper: Schema.Types.Mixed,
20
+ },
21
+ coreExecution: taskNodeCoreExecutionSchema,
22
+ meta: { label: String, apiId: String }
23
+ });
24
+ const taskNodeChildrenSchema = new Schema({
25
+ id: String,
26
+ key: String,
27
+ });
28
+ const taskNodesSchema = new Schema({
29
+ id: String,
30
+ meta: { label: String },
31
+ core: taskNodeCoreSchema,
32
+ children: [taskNodeChildrenSchema],
33
+ });
34
+ export const Task_Tree = new Schema({
35
+ rootId: String,
36
+ rootKey: String,
37
+ nodes: [taskNodesSchema],
38
+ });
3
39
  const ActionSchema = new Schema({
4
40
  name: String,
5
41
  business: { type: Schema.Types.ObjectId, ref: 'Businesses' },
@@ -11,7 +47,7 @@ const ActionSchema = new Schema({
11
47
  functionString: String,
12
48
  errorFunction: String,
13
49
  UI: Schema.Types.Mixed,
14
- isPublic: { type: Boolean, default: false },
50
+ task: Task_Tree
15
51
  }, {
16
52
  timestamps: true
17
53
  });
@@ -0,0 +1,13 @@
1
+ import { Schema } from "mongoose";
2
+ import { defineModel } from "../runtime.js";
3
+
4
+ const TriggerTemplateSchema = new Schema({
5
+ name: { type: String, required: true, unique: true }, // convers
6
+ description: String,
7
+ type: String,
8
+ payload: Schema.Types.Mixed,
9
+ }, {
10
+ timestamps: true,
11
+ });
12
+ TriggerTemplateSchema.index({ name: 1 });
13
+ export const TriggerTemplate = defineModel("TriggerTemplate", TriggerTemplateSchema, "TriggerTemplate");
@@ -1,44 +1,44 @@
1
1
  import { Schema } from "mongoose";
2
2
  import { defineModel } from "../runtime.js";
3
-
3
+ import { Task_Tree } from "./Action.js";
4
4
  const WorkflowSchema = new Schema({
5
5
  name: { type: String, default: "Untitled Workflow" },
6
- status: { type: String, enum: ["draft", "active", "disabled"], default: "draft" },
7
- nodes: Object,
8
- connections: Object,
6
+ trigger: { type: String, required: true },
9
7
  business: { type: Schema.Types.ObjectId, ref: "Businesses" },
8
+ status: { type: String, enum: ["active", "disabled"], default: "active" },
9
+ task: Task_Tree,
10
10
  createdBy: { type: Schema.Types.ObjectId, ref: "Users" },
11
11
  }, {
12
12
  timestamps: true,
13
13
  });
14
- WorkflowSchema.index({ createdBy: 1 });
14
+ WorkflowSchema.index({ trigger: 1, business: 1, status: 1 });
15
15
  WorkflowSchema.index({ status: 1 });
16
16
  WorkflowSchema.methods.updateStatus = function (status) {
17
17
  this.status = status;
18
18
  return this.save();
19
19
  };
20
- WorkflowSchema.methods.getNextNode = function ({ currentNode = "", outputPortsOfCurentNode = [] } = {}) {
21
- const nextNodes = [];
22
- if (!currentNode) return [Object.keys(this.nodes).find((ele) => this.nodes[ele].type === "trigger")];
23
- const { type } = this.nodes[currentNode];
24
- Object.values(this.connections).forEach((ele) => {
25
- if (!ele?.from || !ele?.to) {
26
- console.log("errored no from or to");
27
- return;
28
- }
29
- const [fromNodeId, , portId] = ele.from.split("/");
30
- if (fromNodeId !== currentNode) {
31
- return;
32
- }
33
- const [toNodeId] = ele.to.split("/");
34
- if (type === "conditionalNode") {
35
- if (outputPortsOfCurentNode.includes(portId)) nextNodes.push(toNodeId);
36
- return;
37
- }
38
- nextNodes.push(toNodeId);
39
- });
40
- return nextNodes;
41
- };
20
+ // WorkflowSchema.methods.getNextNode = function ({ currentNode = "", outputPortsOfCurentNode = [] } = {}) {
21
+ // const nextNodes = [];
22
+ // if (!currentNode) return [Object.keys(this.nodes).find((ele) => this.nodes[ele].type === "trigger")];
23
+ // const { type } = this.nodes[currentNode];
24
+ // Object.values(this.connections).forEach((ele) => {
25
+ // if (!ele?.from || !ele?.to) {
26
+ // console.log("errored no from or to");
27
+ // return;
28
+ // }
29
+ // const [fromNodeId, , portId] = ele.from.split("/");
30
+ // if (fromNodeId !== currentNode) {
31
+ // return;
32
+ // }
33
+ // const [toNodeId] = ele.to.split("/");
34
+ // if (type === "conditionalNode") {
35
+ // if (outputPortsOfCurentNode.includes(portId)) nextNodes.push(toNodeId);
36
+ // return;
37
+ // }
38
+ // nextNodes.push(toNodeId);
39
+ // });
40
+ // return nextNodes;
41
+ // };
42
42
 
43
43
  export { WorkflowSchema };
44
44
  export const Workflow = defineModel("Workflow", WorkflowSchema, "Workflow");
@@ -1,19 +0,0 @@
1
- import { Schema } from "mongoose";
2
- import { defineModel } from "../runtime.js";
3
- const NodeSchema = new Schema(
4
- {
5
- type: { type: String, required: true, enum: ['trigger', 'task', 'conditional'] },
6
- core: {
7
- inputMapper: String,
8
- inputSchema: Schema.Types.Mixed,
9
- outputSchema: Schema.Types.Mixed,
10
- configSchema: Schema.Types.Mixed,
11
- handlerFunction: { type: String, required: true },
12
- errorFunction: { type: String }
13
- },
14
- meta: { label: String }
15
- },
16
- { timestamps: true }
17
- );
18
- export const NodeModel = defineModel('Node', NodeSchema, 'Nodes');
19
- export const Node = NodeModel;
@@ -1,17 +0,0 @@
1
- import { Schema } from "mongoose";
2
- import { defineModel } from "../runtime.js";
3
-
4
- const TriggerSchema = new Schema({
5
- business: { type: Schema.Types.ObjectId, ref: 'Businesses' },
6
- name: String, // conversationStatusUpdated, leadStatusUpdated,
7
- description: String,
8
- type: String, // [open, pending, snoozed, completed, closed, archived, spam] || [new, contacted, qualified, converted, lost]
9
- workflows: [{ type: Schema.Types.ObjectId, ref: "Workflow" }],
10
- }, {
11
- timestamps: true,
12
- });
13
-
14
- export { TriggerSchema };
15
- // No explicit collection name, matching the services: mongoose pluralises this to `triggers`.
16
- export const Trigger = defineModel('Trigger', TriggerSchema);
17
- export default Trigger;