@avakado.ai/schemas 1.1.0 → 1.1.4
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/Job.js +1 -3
- package/src/models/OAuth.js +60 -0
- package/src/models/index.js +1 -0
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/Job.js
CHANGED
|
@@ -18,7 +18,6 @@ const JobSchema = new Schema({
|
|
|
18
18
|
name: String,
|
|
19
19
|
campaign: { type: Schema.Types.ObjectId, ref: "Campaign" },
|
|
20
20
|
description: String,
|
|
21
|
-
bullMQJobId: String, // bullmq job id
|
|
22
21
|
status: { type: String, enum: jobStatusEnum, default: 'waiting' },
|
|
23
22
|
priority: Number, // 1 (highest) .. 10 (lowest)
|
|
24
23
|
schedule: {
|
|
@@ -40,8 +39,7 @@ const JobSchema = new Schema({
|
|
|
40
39
|
discriminatorKey: 'jobType', timestamps: true, index: [
|
|
41
40
|
{ status: 1, 'schedule.run_at': 1 },
|
|
42
41
|
{ business: 1, status: 1 },
|
|
43
|
-
{ 'schedule.type': 1, 'schedule.run_at': 1 }
|
|
44
|
-
{ bullMQJobId: 1 }
|
|
42
|
+
{ 'schedule.type': 1, 'schedule.run_at': 1 }
|
|
45
43
|
]
|
|
46
44
|
});
|
|
47
45
|
// Pre-save middleware for validation
|
|
@@ -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");
|
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";
|