@avakado.ai/schemas 1.1.4 → 1.1.7
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 +1 -1
- package/src/models/Action.js +37 -1
- package/src/models/TriggersTemplate.js +13 -0
- package/src/models/Workflow.js +27 -27
- package/src/models/index.js +2 -5
- package/src/models/InbuiltNodes.js +0 -19
- package/src/models/Integrations.js +0 -36
- package/src/models/Job.js +0 -117
- package/src/models/Triggers.js +0 -17
package/package.json
CHANGED
package/src/models/Action.js
CHANGED
|
@@ -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
|
-
|
|
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");
|
package/src/models/Workflow.js
CHANGED
|
@@ -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
|
-
|
|
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({
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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");
|
package/src/models/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { Subscription, SubscriptionSchema } from "./Subscriptions.js";
|
|
|
4
4
|
export { UsageLog, UsageLogSchema } from "./UsageLogs.js";
|
|
5
5
|
export { Conversation, ConversationSchema } from "./Conversations.js";
|
|
6
6
|
export { Campaign, CampaignSchema, Task, TaskSchema } from "./Campaign.js";
|
|
7
|
-
export {
|
|
7
|
+
export { TriggerTemplate } from "./TriggersTemplate.js";
|
|
8
8
|
export { User, ScopesEnum, RoleScopes } from "./User.js";
|
|
9
9
|
export { AgentModel } from "./Agent.js";
|
|
10
10
|
export { Channel, ChannelCapabilityDefaults } from "./Channels.js";
|
|
@@ -20,13 +20,10 @@ export { ApiAuthenticators, ApiAuthenticationSchema } from "./apiAuthenticator.j
|
|
|
20
20
|
export { DemonstrationModel } from "./Demonstarations.js";
|
|
21
21
|
export { Action } from "./Action.js";
|
|
22
22
|
export { Collection } from "./Collection.js";
|
|
23
|
-
export { Node, NodeModel } from "./InbuiltNodes.js";
|
|
24
|
-
export { Integration } from "./Integrations.js";
|
|
25
|
-
export { Job } from "./Job.js";
|
|
26
23
|
export { Notification } from "./notifications.js";
|
|
27
24
|
export { Ticket } from "./Tickets.js";
|
|
28
25
|
export { Document } from "./Document.js";
|
|
29
26
|
export { Data } from "./Data.js";
|
|
30
|
-
export { Workflow
|
|
27
|
+
export { Workflow } from "./Workflow.js";
|
|
31
28
|
export { WorkflowLogs } from "./WorkflowLogs.js";
|
|
32
29
|
export { OAuthClient, OAuthAuthorizationCode, OAuthRefreshToken, OAuthRevokedJti } from "./OAuth.js";
|
|
@@ -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,36 +0,0 @@
|
|
|
1
|
-
import { Schema } from "mongoose";
|
|
2
|
-
import { defineModel } from "../runtime.js";
|
|
3
|
-
|
|
4
|
-
const IntegrationSchema = new Schema({
|
|
5
|
-
business: { type: Schema.Types.ObjectId, ref: 'Businesses' },
|
|
6
|
-
metaData: {
|
|
7
|
-
name: String,
|
|
8
|
-
description: String,
|
|
9
|
-
icon: String,
|
|
10
|
-
color: String,
|
|
11
|
-
purpose: Schema.Types.Mixed,
|
|
12
|
-
type: { type: String, enum: ['zoho', 'twilio', 'exotel','tataTele','whatsapp'], required: true },
|
|
13
|
-
},
|
|
14
|
-
secrets: {
|
|
15
|
-
tokenType: String,
|
|
16
|
-
accessToken: String,
|
|
17
|
-
refreshToken: String,
|
|
18
|
-
apiKey: String,
|
|
19
|
-
apiToken: String,
|
|
20
|
-
},
|
|
21
|
-
config: {
|
|
22
|
-
AccountSid: String,
|
|
23
|
-
state: String,
|
|
24
|
-
apiDomainUrl: String,
|
|
25
|
-
domain: String,
|
|
26
|
-
scope: String,
|
|
27
|
-
expiresAt: Date,
|
|
28
|
-
region:String
|
|
29
|
-
},
|
|
30
|
-
accountDetails: Schema.Types.Mixed,
|
|
31
|
-
isActive: { type: Boolean, default: true },
|
|
32
|
-
createdBy: { type: Schema.Types.ObjectId, ref: 'Users' },
|
|
33
|
-
}, {
|
|
34
|
-
timestamps: true
|
|
35
|
-
});
|
|
36
|
-
export const Integration = defineModel('Integration', IntegrationSchema, "Integration");
|
package/src/models/Job.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { Schema } from "mongoose";
|
|
2
|
-
import { defineModel } from "../runtime.js";
|
|
3
|
-
const jobStatusEnum = ["scheduled", "active", "completed", "failed", "canceled", "delayed", "waiting", "stalled"];
|
|
4
|
-
const backoff = new Schema({
|
|
5
|
-
type: { type: String, enum: ["exponential", "fixed"], required: true },
|
|
6
|
-
delay_ms: { type: Number, required: true },
|
|
7
|
-
attempts: { max: Number, made: Number, reason: String },
|
|
8
|
-
}, { _id: false })
|
|
9
|
-
|
|
10
|
-
const logEntry = new Schema({
|
|
11
|
-
level: { type: String, enum: ["info", "warn", "error", "debug"], required: true },
|
|
12
|
-
message: String,
|
|
13
|
-
timestamp: { type: Date, default: Date.now },
|
|
14
|
-
data: Schema.Types.Mixed
|
|
15
|
-
}, { _id: false });
|
|
16
|
-
/* ───────────────────────────── Base Job ───────────────────────────── */
|
|
17
|
-
const JobSchema = new Schema({
|
|
18
|
-
name: String,
|
|
19
|
-
campaign: { type: Schema.Types.ObjectId, ref: "Campaign" },
|
|
20
|
-
description: String,
|
|
21
|
-
status: { type: String, enum: jobStatusEnum, default: 'waiting' },
|
|
22
|
-
priority: Number, // 1 (highest) .. 10 (lowest)
|
|
23
|
-
schedule: {
|
|
24
|
-
type: { type: String, enum: ["once", "cron"], default: "once" },
|
|
25
|
-
run_at: Date, // for one-off
|
|
26
|
-
cron: String, // for recurring
|
|
27
|
-
timezone: String,
|
|
28
|
-
backoff: { type: backoff, default: undefined },
|
|
29
|
-
cancel_requested: { type: Boolean, default: false },
|
|
30
|
-
},
|
|
31
|
-
jobType: { type: String, enum: ["outboundCall"], default: "outboundCall" },
|
|
32
|
-
result_ref: Schema.Types.Mixed,
|
|
33
|
-
error_ref: Schema.Types.Mixed,
|
|
34
|
-
log: [logEntry],
|
|
35
|
-
tags: [String],
|
|
36
|
-
createdBy: { type: Schema.Types.ObjectId, ref: 'Users' },
|
|
37
|
-
business: { type: Schema.Types.ObjectId, ref: 'Businesses' },
|
|
38
|
-
}, {
|
|
39
|
-
discriminatorKey: 'jobType', timestamps: true, index: [
|
|
40
|
-
{ status: 1, 'schedule.run_at': 1 },
|
|
41
|
-
{ business: 1, status: 1 },
|
|
42
|
-
{ 'schedule.type': 1, 'schedule.run_at': 1 }
|
|
43
|
-
]
|
|
44
|
-
});
|
|
45
|
-
// Pre-save middleware for validation
|
|
46
|
-
JobSchema.pre('save', function (next) {
|
|
47
|
-
// Validate schedule based on type
|
|
48
|
-
if (this.schedule.type === 'once' && !this.schedule.run_at) {
|
|
49
|
-
return next(new Error('run_at is required for one-time jobs'));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (this.schedule.type === 'cron' && !this.schedule.cron) {
|
|
53
|
-
return next(new Error('cron expression is required for recurring jobs'));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Validate priority
|
|
57
|
-
if (this.priority < 1 || this.priority > 10) {
|
|
58
|
-
return next(new Error('Priority must be between 1 and 10'));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
next();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Instance methods
|
|
65
|
-
JobSchema.methods.addLog = function (level, message, data = {}) {
|
|
66
|
-
this.log.push({
|
|
67
|
-
level,
|
|
68
|
-
message,
|
|
69
|
-
data,
|
|
70
|
-
timestamp: new Date()
|
|
71
|
-
});
|
|
72
|
-
return this.save();
|
|
73
|
-
};
|
|
74
|
-
JobSchema.methods.markAsStarted = function () {
|
|
75
|
-
this.status = 'active';
|
|
76
|
-
this.lastExecutedAt = new Date();
|
|
77
|
-
this.executionCount += 1;
|
|
78
|
-
return this.save();
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
JobSchema.methods.markAsCompleted = function (result = null, duration = null) {
|
|
82
|
-
this.status = 'completed';
|
|
83
|
-
this.result_ref = result;
|
|
84
|
-
if (duration) this.actualDuration = duration;
|
|
85
|
-
return this.save();
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
JobSchema.methods.markAsFailed = function (error, duration = null) {
|
|
89
|
-
this.status = 'failed';
|
|
90
|
-
this.error_ref = {
|
|
91
|
-
message: error.message,
|
|
92
|
-
stack: error.stack,
|
|
93
|
-
timestamp: new Date()
|
|
94
|
-
};
|
|
95
|
-
if (duration) this.actualDuration = duration;
|
|
96
|
-
return this.save();
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// if schedule is updated then trigger sync
|
|
100
|
-
|
|
101
|
-
// channelId, to, agentId, PreContext
|
|
102
|
-
|
|
103
|
-
export const Job = defineModel('Job', JobSchema, 'Job');
|
|
104
|
-
const outboundCallPayload = new Schema({
|
|
105
|
-
channel: { type: Schema.Types.ObjectId, ref: "Channel" },
|
|
106
|
-
agent: { type: Schema.Types.ObjectId, ref: "Agent" },
|
|
107
|
-
to: { type: String, required: true },
|
|
108
|
-
accessToken: { type: String, required: true },
|
|
109
|
-
PreContext: String,
|
|
110
|
-
expectedDuration: Number,
|
|
111
|
-
maxRetries: { type: Number, default: 3 },
|
|
112
|
-
callbackUrl: String,
|
|
113
|
-
cps: Number,
|
|
114
|
-
conversationId: { type: Schema.Types.ObjectId, ref: 'conversation' }
|
|
115
|
-
}, { _id: false })
|
|
116
|
-
/* ───────────────────────────── Outbound Call Job ──────────────────────────── */
|
|
117
|
-
Job.discriminator('outboundCall', new Schema({ payload: outboundCallPayload }, { timestamps: true, discriminatorKey: 'jobType' }));
|
package/src/models/Triggers.js
DELETED
|
@@ -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;
|