@avakado.ai/schemas 1.1.1 → 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 +1 -1
- package/src/enums/index.js +2 -0
- package/src/models/Action.js +37 -1
- package/src/models/OAuth.js +60 -0
- package/src/models/TriggersTemplate.js +13 -0
- package/src/models/Workflow.js +27 -27
- package/src/models/index.js +1 -0
- package/src/models/InbuiltNodes.js +0 -19
- package/src/models/Triggers.js +0 -17
package/package.json
CHANGED
package/src/enums/index.js
CHANGED
|
@@ -62,3 +62,5 @@ export const CAMPAIGN_STATUS = ["pending", "active", "completed"];
|
|
|
62
62
|
export const TASK_STATUS = ["pending", "in-progress", "completed", "failed", "skipped"];
|
|
63
63
|
export const TASK_TYPES = ["quick", "webhook"];
|
|
64
64
|
export const TASK_REFERENCE_TYPES = ["Message", "CallSession"];
|
|
65
|
+
|
|
66
|
+
export const OAUTH_GRANT_MODES = ["access_refresh", "access_only", "permanent"];
|
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,60 @@
|
|
|
1
|
+
import { Schema } from "mongoose";
|
|
2
|
+
import { defineModel } from "../runtime.js";
|
|
3
|
+
import { OAUTH_GRANT_MODES } from "../enums/index.js";
|
|
4
|
+
|
|
5
|
+
const OAuthClientSchema = new Schema({
|
|
6
|
+
clientId: { type: String, required: true, unique: true, index: true },
|
|
7
|
+
name: { type: String, required: true },
|
|
8
|
+
business: { type: Schema.Types.ObjectId, ref: "Businesses", index: true },
|
|
9
|
+
createdBy: { type: Schema.Types.ObjectId, ref: "Users", unique: true, sparse: true },
|
|
10
|
+
secretHash: { type: String, default: null },
|
|
11
|
+
secretVersion: { type: Number, default: 1 },
|
|
12
|
+
redirectUris: { type: [String], default: [] },
|
|
13
|
+
allowedOrigins: { type: [String], default: [] },
|
|
14
|
+
grantMode: { type: String, enum: OAUTH_GRANT_MODES, required: true, default: "access_refresh" },
|
|
15
|
+
isFirstParty: { type: Boolean, default: false },
|
|
16
|
+
revokedAt: { type: Date, default: null },
|
|
17
|
+
}, { timestamps: true });
|
|
18
|
+
|
|
19
|
+
OAuthClientSchema.index({ business: 1, revokedAt: 1 });
|
|
20
|
+
OAuthClientSchema.index({ allowedOrigins: 1, revokedAt: 1 });
|
|
21
|
+
|
|
22
|
+
const OAuthAuthorizationCodeSchema = new Schema({
|
|
23
|
+
codeHash: { type: String, required: true, unique: true },
|
|
24
|
+
clientId: { type: String, required: true, index: true },
|
|
25
|
+
user: { type: Schema.Types.ObjectId, ref: "Users", required: true },
|
|
26
|
+
redirectUri: { type: String, required: true },
|
|
27
|
+
scope: { type: String, default: "" },
|
|
28
|
+
codeChallenge: { type: String, default: null },
|
|
29
|
+
codeChallengeMethod: { type: String, enum: ["S256", "plain"], default: null },
|
|
30
|
+
expiresAt: { type: Date, required: true },
|
|
31
|
+
consumedAt: { type: Date, default: null },
|
|
32
|
+
}, { timestamps: true });
|
|
33
|
+
|
|
34
|
+
OAuthAuthorizationCodeSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
35
|
+
|
|
36
|
+
const OAuthRefreshTokenSchema = new Schema({
|
|
37
|
+
tokenHash: { type: String, required: true, unique: true },
|
|
38
|
+
clientId: { type: String, required: true, index: true },
|
|
39
|
+
user: { type: Schema.Types.ObjectId, ref: "Users", required: true, index: true },
|
|
40
|
+
familyId: { type: String, required: true, index: true },
|
|
41
|
+
expiresAt: { type: Date, required: true },
|
|
42
|
+
usedAt: { type: Date, default: null },
|
|
43
|
+
revokedAt: { type: Date, default: null },
|
|
44
|
+
}, { timestamps: true });
|
|
45
|
+
|
|
46
|
+
OAuthRefreshTokenSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
47
|
+
OAuthRefreshTokenSchema.index({ clientId: 1, revokedAt: 1 });
|
|
48
|
+
OAuthRefreshTokenSchema.index({ user: 1, revokedAt: 1 });
|
|
49
|
+
|
|
50
|
+
const OAuthRevokedJtiSchema = new Schema({
|
|
51
|
+
jti: { type: String, required: true, unique: true },
|
|
52
|
+
expiresAt: { type: Date, required: true },
|
|
53
|
+
}, { timestamps: true });
|
|
54
|
+
|
|
55
|
+
OAuthRevokedJtiSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
56
|
+
|
|
57
|
+
export const OAuthClient = defineModel("OAuthClient", OAuthClientSchema, "OAuthClients");
|
|
58
|
+
export const OAuthAuthorizationCode = defineModel("OAuthAuthorizationCode", OAuthAuthorizationCodeSchema, "OAuthAuthorizationCodes");
|
|
59
|
+
export const OAuthRefreshToken = defineModel("OAuthRefreshToken", OAuthRefreshTokenSchema, "OAuthRefreshTokens");
|
|
60
|
+
export const OAuthRevokedJti = defineModel("OAuthRevokedJti", OAuthRevokedJtiSchema, "OAuthRevokedJtis");
|
|
@@ -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
|
@@ -29,3 +29,4 @@ export { Document } from "./Document.js";
|
|
|
29
29
|
export { Data } from "./Data.js";
|
|
30
30
|
export { Workflow, WorkflowSchema } from "./Workflow.js";
|
|
31
31
|
export { WorkflowLogs } from "./WorkflowLogs.js";
|
|
32
|
+
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;
|
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;
|