biz-slide-core 1.2.85 → 1.2.87
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/dist/entity/analytic.entity.js +4 -4
- package/dist/entity/config.enity.js +2 -2
- package/dist/entity/cron.entity.js +2 -2
- package/dist/entity/customer.entity.js +3 -3
- package/dist/entity/image.entity.js +2 -2
- package/dist/entity/logs.entity.js +2 -2
- package/dist/entity/png-svg.entity.js +2 -2
- package/dist/entity/ppt-email-queue.entity.js +2 -2
- package/dist/entity/ppt-event.entity.js +2 -2
- package/dist/entity/ppt-slide.entity.js +2 -2
- package/dist/entity/ppt.entity.d.ts +1 -0
- package/dist/entity/ppt.entity.d.ts.map +1 -1
- package/dist/entity/ppt.entity.js +2 -2
- package/dist/entity/slide-layout.entity.js +4 -4
- package/dist/entity/slide.entity.js +3 -3
- package/dist/entity/socket.entity.js +2 -2
- package/dist/entity/template-type.entity.js +6 -6
- package/dist/entity/template.entity.js +2 -2
- package/dist/entity/training-queue.entity.js +2 -2
- package/dist/entity/user.entity.js +2 -2
- package/dist/middleware/authentication.js +112 -215
- package/dist/middleware/schemaValidate.js +10 -52
- package/dist/resHandler/errorHandler.js +20 -42
- package/dist/resHandler/successHandler.js +1 -1
- package/dist/utilities/callWithRetries.js +9 -67
- package/dist/utilities/createFolder.js +10 -51
- package/dist/utilities/encryptionUtils.js +14 -54
- package/dist/utilities/hasAbusiveWords.js +4 -5
- package/package.json +3 -1
- package/src/entity/analytic.entity.ts +0 -62
- package/src/entity/common.ts +0 -19
- package/src/entity/config.enity.ts +0 -18
- package/src/entity/cron.entity.ts +0 -22
- package/src/entity/customer.entity.ts +0 -40
- package/src/entity/image.entity.ts +0 -32
- package/src/entity/index.ts +0 -20
- package/src/entity/logs.entity.ts +0 -20
- package/src/entity/png-svg.entity.ts +0 -44
- package/src/entity/ppt-email-queue.entity.ts +0 -22
- package/src/entity/ppt-event.entity.ts +0 -25
- package/src/entity/ppt-slide.entity.ts +0 -40
- package/src/entity/ppt.entity.ts +0 -79
- package/src/entity/slide-layout.entity.ts +0 -56
- package/src/entity/slide.entity.ts +0 -61
- package/src/entity/socket.entity.ts +0 -20
- package/src/entity/template-type.entity.ts +0 -87
- package/src/entity/template.entity.ts +0 -38
- package/src/entity/training-queue.entity.ts +0 -26
- package/src/entity/user.entity.ts +0 -24
- package/src/index.ts +0 -6
- package/src/middleware/authentication.ts +0 -150
- package/src/middleware/index.ts +0 -3
- package/src/middleware/role.ts +0 -5
- package/src/middleware/schemaValidate.ts +0 -20
- package/src/resHandler/errorHandler.ts +0 -66
- package/src/resHandler/index.ts +0 -2
- package/src/resHandler/successHandler.ts +0 -11
- package/src/types/IController.ts +0 -6
- package/src/types/IRequest.ts +0 -8
- package/src/types/index.ts +0 -11
- package/src/utilities/callWithRetries.ts +0 -9
- package/src/utilities/createFolder.ts +0 -11
- package/src/utilities/encryptionUtils.ts +0 -26
- package/src/utilities/hasAbusiveWords.ts +0 -33
- package/src/utilities/index.ts +0 -5
- package/src/utilities/pngSvgCategories.ts +0 -167
- package/tsconfig.json +0 -11
@@ -1,56 +0,0 @@
|
|
1
|
-
import { Schema, model, Types } from "mongoose";
|
2
|
-
import { ISystemLayout, IMessageSchema } from "./common";
|
3
|
-
|
4
|
-
|
5
|
-
export interface ISlideLayoutSchema {
|
6
|
-
name: string;
|
7
|
-
alias: string[];
|
8
|
-
templateTypeId: Types.ObjectId;
|
9
|
-
createdAt: Date;
|
10
|
-
updatedAt: Date;
|
11
|
-
deletedAt: Date;
|
12
|
-
published: boolean;
|
13
|
-
insertSelectionPrompt: ISystemLayout;
|
14
|
-
newSelectionPrompt: ISystemLayout;
|
15
|
-
slideSelectionQuestion: string;
|
16
|
-
category: string;
|
17
|
-
subCategory: string[];
|
18
|
-
displayName: string;
|
19
|
-
}
|
20
|
-
|
21
|
-
const messageSchema = new Schema<IMessageSchema>({
|
22
|
-
message: { type: String },
|
23
|
-
keys: { type: [String] },
|
24
|
-
}, {
|
25
|
-
timestamps: false,
|
26
|
-
_id: false
|
27
|
-
})
|
28
|
-
|
29
|
-
const systemSchema = new Schema<ISystemLayout>({
|
30
|
-
system: messageSchema,
|
31
|
-
user: messageSchema
|
32
|
-
}, {
|
33
|
-
timestamps: false,
|
34
|
-
_id: false
|
35
|
-
})
|
36
|
-
|
37
|
-
const SlideLayoutSchema = new Schema<ISlideLayoutSchema>(
|
38
|
-
{
|
39
|
-
published: { type: Boolean, default: false },
|
40
|
-
name: { type: String, default: "", required: true },
|
41
|
-
displayName: { type: String, default: "" },
|
42
|
-
alias: { type: [String], default: [], _id: false },
|
43
|
-
templateTypeId: { type: Schema.Types.ObjectId, ref: "template-type" },
|
44
|
-
deletedAt: { type: Date, default: null },
|
45
|
-
insertSelectionPrompt: systemSchema,
|
46
|
-
newSelectionPrompt: systemSchema,
|
47
|
-
category: { type: String, default: "Default"},
|
48
|
-
subCategory: { type: [String], default: [], _id: false },
|
49
|
-
slideSelectionQuestion: { type: String, default: ""}
|
50
|
-
},
|
51
|
-
{
|
52
|
-
timestamps: true,
|
53
|
-
}
|
54
|
-
);
|
55
|
-
|
56
|
-
export const SlideLayoutModel = model<ISlideLayoutSchema>("slide-layout", SlideLayoutSchema);
|
@@ -1,61 +0,0 @@
|
|
1
|
-
import { Schema, model, Types } from "mongoose";
|
2
|
-
|
3
|
-
interface layer {
|
4
|
-
metaType: String;
|
5
|
-
optionsMeta: String;
|
6
|
-
chatMeta: string;
|
7
|
-
}
|
8
|
-
|
9
|
-
const layerSchema = new Schema<layer>({
|
10
|
-
metaType: { type: String, enum: ['text', 'image', 'shape', 'list', 'table'] },
|
11
|
-
optionsMeta: { type: String },
|
12
|
-
chatMeta: { type: String },
|
13
|
-
}, {
|
14
|
-
timestamps: false,
|
15
|
-
_id: false
|
16
|
-
})
|
17
|
-
|
18
|
-
export interface ISlideSchema {
|
19
|
-
name: string;
|
20
|
-
postfix: string;
|
21
|
-
rules: string;
|
22
|
-
slideLayoutId: Types.ObjectId;
|
23
|
-
templateId: Types.ObjectId;
|
24
|
-
layers: layer[];
|
25
|
-
createdAt: Date;
|
26
|
-
updatedAt: Date;
|
27
|
-
deletedAt: Date;
|
28
|
-
isDelete: boolean;
|
29
|
-
published: boolean;
|
30
|
-
stage: string;
|
31
|
-
isDefault: boolean;
|
32
|
-
category: string;
|
33
|
-
}
|
34
|
-
|
35
|
-
const SlideSchema = new Schema<ISlideSchema>(
|
36
|
-
{
|
37
|
-
name: { type: String, default: "", required: true },
|
38
|
-
published: { type: Boolean, default: false },
|
39
|
-
postfix: { type: String, default: "" },
|
40
|
-
rules: { type: String, default: "" },
|
41
|
-
layers: [layerSchema],
|
42
|
-
slideLayoutId: { type: Schema.Types.ObjectId, ref: "slide-layout" },
|
43
|
-
templateId: { type: Schema.Types.ObjectId, ref: "template" },
|
44
|
-
deletedAt: { type: Date, default: null },
|
45
|
-
isDelete: { type: Boolean, default: false },
|
46
|
-
stage: { type: String, default: ""},
|
47
|
-
isDefault: { type: Boolean, default: false },
|
48
|
-
category: { type: String, default: "Default"}
|
49
|
-
},
|
50
|
-
{
|
51
|
-
timestamps: true,
|
52
|
-
}
|
53
|
-
);
|
54
|
-
|
55
|
-
SlideSchema.index({ name: 1, slideLayoutId: 1, templateId: 1 });
|
56
|
-
SlideSchema.index({ slideLayoutId: 1, templateId: 1 });
|
57
|
-
SlideSchema.index({ templateId: 1 });
|
58
|
-
SlideSchema.index({ name: 1, templateId: 1, slideLayoutId: 1, published: 1 });
|
59
|
-
SlideSchema.index({ slideLayoutId: 1, templateId: 1, published: 1, isDelete: 1 });
|
60
|
-
|
61
|
-
export const SlideModel = model<ISlideSchema>("slide", SlideSchema);
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { Schema, model, Types } from "mongoose";
|
2
|
-
|
3
|
-
export interface ISocketSchema {
|
4
|
-
userId: string;
|
5
|
-
socketIds: Array<string>;
|
6
|
-
createdAt?: Date;
|
7
|
-
updatedAt?: Date;
|
8
|
-
}
|
9
|
-
|
10
|
-
const SocketSchema = new Schema<ISocketSchema>(
|
11
|
-
{
|
12
|
-
userId: { type: String, default: null },
|
13
|
-
socketIds: { type: [String], default: [] }
|
14
|
-
},
|
15
|
-
{
|
16
|
-
timestamps: true,
|
17
|
-
}
|
18
|
-
);
|
19
|
-
|
20
|
-
export const SocketModel = model<ISocketSchema>("socket", SocketSchema);
|
@@ -1,87 +0,0 @@
|
|
1
|
-
import { Schema, model } from "mongoose";
|
2
|
-
import { IVariantsSystemLayout, ISystemLayout, IMessageSchema } from "./common";
|
3
|
-
|
4
|
-
export interface ITemplateLayout {
|
5
|
-
title: string;
|
6
|
-
layoutType: string;
|
7
|
-
}
|
8
|
-
|
9
|
-
|
10
|
-
export interface ITemplateTypeSchema{
|
11
|
-
name: string;
|
12
|
-
layouts: Array<ITemplateLayout>;
|
13
|
-
createdAt: Date;
|
14
|
-
updatedAt: Date;
|
15
|
-
deletedAt: Date;
|
16
|
-
suggestionPrompts: Array<string>;
|
17
|
-
topicPrompt: IVariantsSystemLayout;
|
18
|
-
layoutPrompt: IVariantsSystemLayout;
|
19
|
-
insertTopicPrompt: ISystemLayout;
|
20
|
-
slidePrompt: IMessageSchema; // Predefine systame message
|
21
|
-
defaultLayout: string;
|
22
|
-
published: boolean;
|
23
|
-
colorPalletes: Array<Array<string>>;
|
24
|
-
}
|
25
|
-
|
26
|
-
const layoutsSchema = new Schema<ITemplateLayout>({
|
27
|
-
title: { type: String },
|
28
|
-
layoutType: { type: String },
|
29
|
-
}, {
|
30
|
-
timestamps: false,
|
31
|
-
_id: false
|
32
|
-
})
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
const messageSchema = new Schema<IMessageSchema>({
|
37
|
-
message: { type: String },
|
38
|
-
keys: { type: [String] },
|
39
|
-
}, {
|
40
|
-
timestamps: false,
|
41
|
-
_id: false
|
42
|
-
})
|
43
|
-
|
44
|
-
const systemSchema = new Schema<ISystemLayout>({
|
45
|
-
system: messageSchema,
|
46
|
-
user: messageSchema
|
47
|
-
}, {
|
48
|
-
timestamps: false,
|
49
|
-
_id: false
|
50
|
-
})
|
51
|
-
|
52
|
-
const variantsSystemSchema = new Schema<IVariantsSystemLayout>({
|
53
|
-
single: systemSchema,
|
54
|
-
multiple: systemSchema
|
55
|
-
}, {
|
56
|
-
timestamps: false,
|
57
|
-
_id: false
|
58
|
-
})
|
59
|
-
|
60
|
-
const TemplateTypeSchema = new Schema<ITemplateTypeSchema>(
|
61
|
-
{
|
62
|
-
published: { type: Boolean, default: false },
|
63
|
-
name: { type: String, default: "", required: true },
|
64
|
-
layouts: [layoutsSchema],
|
65
|
-
suggestionPrompts: {type: [String], default: [], _id: false},
|
66
|
-
slidePrompt: messageSchema,
|
67
|
-
topicPrompt: variantsSystemSchema,
|
68
|
-
layoutPrompt: variantsSystemSchema,
|
69
|
-
insertTopicPrompt: systemSchema,
|
70
|
-
defaultLayout: { type: String, default: "" },
|
71
|
-
deletedAt: { type: Date, default: null },
|
72
|
-
colorPalletes: {
|
73
|
-
type: [
|
74
|
-
{
|
75
|
-
type: [String],
|
76
|
-
default: [],
|
77
|
-
_id: false
|
78
|
-
}
|
79
|
-
], default: [], _id: false
|
80
|
-
},
|
81
|
-
},
|
82
|
-
{
|
83
|
-
timestamps: true,
|
84
|
-
}
|
85
|
-
);
|
86
|
-
|
87
|
-
export const TemplateTypeModel = model<ITemplateTypeSchema>("template-type", TemplateTypeSchema);
|
@@ -1,38 +0,0 @@
|
|
1
|
-
import { Schema, model, Types } from "mongoose";
|
2
|
-
|
3
|
-
export interface ITemplateSchema{
|
4
|
-
name: string;
|
5
|
-
templateTypeId: Types.ObjectId;
|
6
|
-
createdAt: Date,
|
7
|
-
updatedAt: Date,
|
8
|
-
deletedAt: Date,
|
9
|
-
defaultColorPallete: Array<string>;
|
10
|
-
colorPalletes: Array<Array<string>>;
|
11
|
-
staticImageDir: string;
|
12
|
-
published: boolean;
|
13
|
-
}
|
14
|
-
|
15
|
-
const TemplateSchema = new Schema<ITemplateSchema>(
|
16
|
-
{
|
17
|
-
name: { type: String, default: "", required: true },
|
18
|
-
published: { type: Boolean, default: false },
|
19
|
-
templateTypeId: { type: Schema.Types.ObjectId, ref: "template-type" },
|
20
|
-
defaultColorPallete: { type: [String], default: [], _id: false },
|
21
|
-
colorPalletes: {
|
22
|
-
type: [
|
23
|
-
{
|
24
|
-
type: [String],
|
25
|
-
default: [],
|
26
|
-
_id: false
|
27
|
-
}
|
28
|
-
], default: [], _id: false
|
29
|
-
},
|
30
|
-
deletedAt: { type: Date, default: null },
|
31
|
-
staticImageDir: { type: String, default: "", required: true }
|
32
|
-
},
|
33
|
-
{
|
34
|
-
timestamps: true,
|
35
|
-
}
|
36
|
-
);
|
37
|
-
|
38
|
-
export const TemplateModel = model<ITemplateSchema>("template", TemplateSchema);
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { Schema, model, Types } from "mongoose";
|
2
|
-
|
3
|
-
interface ITrainingQueue {
|
4
|
-
filename: string,
|
5
|
-
isCompleted: boolean,
|
6
|
-
isLocked: boolean,
|
7
|
-
userId: Types.ObjectId;
|
8
|
-
createdAt: Date,
|
9
|
-
updatedAt: Date,
|
10
|
-
deletedAt: Date
|
11
|
-
}
|
12
|
-
|
13
|
-
const TrainingQueueSchema = new Schema<ITrainingQueue>(
|
14
|
-
{
|
15
|
-
filename: { type: String, default: null },
|
16
|
-
isCompleted: { type: Boolean, default: false },
|
17
|
-
userId: { type: Schema.Types.ObjectId, ref: "user" },
|
18
|
-
isLocked: { type: Boolean, default: false },
|
19
|
-
deletedAt: { type: Date, default: null},
|
20
|
-
},
|
21
|
-
{
|
22
|
-
timestamps: true,
|
23
|
-
}
|
24
|
-
);
|
25
|
-
|
26
|
-
export const TrainingQueueModel = model<ITrainingQueue>("training-queue", TrainingQueueSchema);
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import { Schema, model } from "mongoose";
|
2
|
-
|
3
|
-
interface IUser {
|
4
|
-
email: string | null;
|
5
|
-
password: string,
|
6
|
-
role: string,
|
7
|
-
createdAt: Date,
|
8
|
-
updatedAt: Date,
|
9
|
-
deletedAt: Date
|
10
|
-
}
|
11
|
-
|
12
|
-
const UserSchema = new Schema<IUser>(
|
13
|
-
{
|
14
|
-
email: { type: String, unique: true, sparse: true },
|
15
|
-
password: { type: String, default: null },
|
16
|
-
role: { type: String, default: null },
|
17
|
-
deletedAt: { type: Date, default: null},
|
18
|
-
},
|
19
|
-
{
|
20
|
-
timestamps: true,
|
21
|
-
}
|
22
|
-
);
|
23
|
-
|
24
|
-
export const UserModel = model<IUser>("user", UserSchema);
|
package/src/index.ts
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
import { Response, NextFunction } from "express";
|
2
|
-
import { verifyUid } from "../utilities";
|
3
|
-
import { IRequest } from "../types";
|
4
|
-
import { UserModel, CustomerModel } from "../entity";
|
5
|
-
|
6
|
-
|
7
|
-
const authorize = (roles: string[]) => {
|
8
|
-
return async function (req: IRequest, res: Response, next: NextFunction) {
|
9
|
-
if (!req.headers.authorization) {
|
10
|
-
return res.status(401).json({ message: 'Unauthorized' })
|
11
|
-
}
|
12
|
-
if (!roles.length) {
|
13
|
-
return res.status(401).json({ message: 'Unauthorized' })
|
14
|
-
}
|
15
|
-
if (req.headers.authorization) {
|
16
|
-
const token = await verifyUid(req.headers.authorization);
|
17
|
-
if (!token) {
|
18
|
-
return res.status(401).json({ message: 'Session Expired' })
|
19
|
-
}
|
20
|
-
|
21
|
-
let user: any = await UserModel.findOne({ email: token.value.email })
|
22
|
-
|
23
|
-
if (!user) {
|
24
|
-
return res.status(401).json({ message: 'No User Found' })
|
25
|
-
}
|
26
|
-
|
27
|
-
const hasAccess = roles.find(role => role === user.role);
|
28
|
-
|
29
|
-
if (!hasAccess) {
|
30
|
-
return res.status(403).json({ message: 'Forbbiden' })
|
31
|
-
}
|
32
|
-
|
33
|
-
const { createdAt, updatedAt, deletedAt, password, ...rest } = user.toObject();
|
34
|
-
|
35
|
-
req.user = {...rest, userId: rest.email};
|
36
|
-
next();
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
const createUser = async (emailId: string, userId: string, appName: string) => {
|
42
|
-
const customer = await CustomerModel.findOne({userId});
|
43
|
-
if(!customer) {
|
44
|
-
const newCustomer = new CustomerModel({
|
45
|
-
appName: appName || "default",
|
46
|
-
emailId,
|
47
|
-
emailTemplateStatus: {},
|
48
|
-
userId
|
49
|
-
})
|
50
|
-
await newCustomer.save();
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
const authorizeWithSlideApp = () => {
|
55
|
-
return async function (req: IRequest, res: Response, next: NextFunction) {
|
56
|
-
const ipAddress = req.headers['x-forwarded-for'] || (req as any).connection.remoteAddress;
|
57
|
-
const sessionId = req.headers['x-fingerprint-key'];
|
58
|
-
|
59
|
-
if (!req.headers.authorization) {
|
60
|
-
return res.status(401).json({ message: 'Unauthorized' })
|
61
|
-
}
|
62
|
-
|
63
|
-
if (req.headers.authorization) {
|
64
|
-
const token = await verifyUid(req.headers.authorization);
|
65
|
-
if (!token) {
|
66
|
-
return res.status(401).json({ message: 'Session Expired' })
|
67
|
-
}
|
68
|
-
|
69
|
-
const userId = token?.customer_id || token?.value?.email;
|
70
|
-
|
71
|
-
if(!userId) {
|
72
|
-
return res.status(401).json({ message: 'userId not found' })
|
73
|
-
}
|
74
|
-
|
75
|
-
|
76
|
-
req.user = {
|
77
|
-
userId: userId,
|
78
|
-
sessionId,
|
79
|
-
ipAddress,
|
80
|
-
appName: req.headers['x-app-name'],
|
81
|
-
email: token?.customer_email || ""
|
82
|
-
}
|
83
|
-
|
84
|
-
await createUser(req.user.email, req.user.userId, req.user.appName);
|
85
|
-
next();
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
const nonAuthorizeWithSlideApp = () => {
|
91
|
-
return async function (req: IRequest, res: Response, next: NextFunction) {
|
92
|
-
const ipAddress = req.headers['x-forwarded-for'] || (req as any).connection.remoteAddress;
|
93
|
-
const sessionId = req.headers['x-fingerprint-key'];
|
94
|
-
let userId = "guest";
|
95
|
-
let email = "";
|
96
|
-
|
97
|
-
if (req.headers.authorization) {
|
98
|
-
const token = await verifyUid(req.headers.authorization);
|
99
|
-
if (!token) {
|
100
|
-
return res.status(401).json({ message: 'Session Expired' })
|
101
|
-
}
|
102
|
-
|
103
|
-
userId = token?.customer_id || token?.value?.email;
|
104
|
-
email = token?.customer_email || "";
|
105
|
-
if(!userId) {
|
106
|
-
return res.status(401).json({ message: 'userId not found' })
|
107
|
-
}
|
108
|
-
await createUser(email, userId, req.headers['x-app-name'] as string);
|
109
|
-
} else {
|
110
|
-
if(!ipAddress || !sessionId) {
|
111
|
-
return res.status(401).json({ message: 'We are not able to track your actions'})
|
112
|
-
}
|
113
|
-
}
|
114
|
-
|
115
|
-
req.user = {
|
116
|
-
userId,
|
117
|
-
sessionId,
|
118
|
-
ipAddress,
|
119
|
-
appName: req.headers['x-app-name'],
|
120
|
-
email
|
121
|
-
}
|
122
|
-
|
123
|
-
next();
|
124
|
-
}
|
125
|
-
}
|
126
|
-
|
127
|
-
// TODO: Delete It
|
128
|
-
const authorizeWithGpt = () => {
|
129
|
-
return async function (req: IRequest, res: Response, next: NextFunction) {
|
130
|
-
const secret = req.headers['authorization'];
|
131
|
-
const secretKey: Array<string> = secret ? secret.split(":") : undefined!;
|
132
|
-
|
133
|
-
if(secretKey && secretKey.length === 2 && secretKey[0]!==`Bearer ${process.env.GPT_API_KEY}`) {
|
134
|
-
return res.status(401).json({ message: 'keys not matching' })
|
135
|
-
}
|
136
|
-
|
137
|
-
const ipAddress = req.headers['x-forwarded-for'] || (req as any).connection.remoteAddress;
|
138
|
-
let userId = "guest";
|
139
|
-
|
140
|
-
req.user = {
|
141
|
-
userId,
|
142
|
-
ipAddress,
|
143
|
-
appName: secretKey[1],
|
144
|
-
navigateFromGPT: true
|
145
|
-
}
|
146
|
-
next();
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
|
-
export {authorize, authorizeWithSlideApp, nonAuthorizeWithSlideApp, authorizeWithGpt};
|
package/src/middleware/index.ts
DELETED
package/src/middleware/role.ts
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
import { NextFunction, Response } from "express";
|
2
|
-
import Joi from 'joi';
|
3
|
-
|
4
|
-
import { IRequest } from "../types";
|
5
|
-
|
6
|
-
export const validateSchema = (schema: Joi.ObjectSchema<any>) => {
|
7
|
-
return async function (req: IRequest, res: Response, next: NextFunction) {
|
8
|
-
|
9
|
-
const { error } = schema.validate(req.body, { abortEarly: false });
|
10
|
-
|
11
|
-
if(error) {
|
12
|
-
const errorMessage = error.details.map((err) => err.message).join(', ');
|
13
|
-
return res.status(400).json({ message: errorMessage });
|
14
|
-
} else {
|
15
|
-
next();
|
16
|
-
}
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
|
@@ -1,66 +0,0 @@
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
2
|
-
|
3
|
-
export class BadRequestError extends Error {
|
4
|
-
constructor(message: string) {
|
5
|
-
super(message);
|
6
|
-
Object.setPrototypeOf(this, BadRequestError.prototype);
|
7
|
-
this.name = 'BadRequestError';
|
8
|
-
}
|
9
|
-
}
|
10
|
-
|
11
|
-
export class NotFoundRequestError extends Error {
|
12
|
-
constructor(message: string) {
|
13
|
-
super(message);
|
14
|
-
Object.setPrototypeOf(this, NotFoundRequestError.prototype);
|
15
|
-
this.name = 'NotFoundRequestError';
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
export class CustomRequestError {
|
20
|
-
name: string;
|
21
|
-
message: {
|
22
|
-
title: string,
|
23
|
-
description: string
|
24
|
-
};
|
25
|
-
|
26
|
-
constructor(title: string, description: string) {
|
27
|
-
this.name = 'CustomRequestError';
|
28
|
-
this.message = {
|
29
|
-
title,
|
30
|
-
description
|
31
|
-
};
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
// Custom error handler middleware
|
38
|
-
export const errorHandler = (
|
39
|
-
err: Error,
|
40
|
-
req: Request,
|
41
|
-
res: Response,
|
42
|
-
next: NextFunction
|
43
|
-
) => {
|
44
|
-
|
45
|
-
let statusCode = 500; // Default status code
|
46
|
-
let errorMessage = 'Internal Server Error'; // Default error message
|
47
|
-
|
48
|
-
if (err instanceof BadRequestError) {
|
49
|
-
statusCode = 400;
|
50
|
-
errorMessage = err.message;
|
51
|
-
} else if(err instanceof NotFoundRequestError) {
|
52
|
-
statusCode = 404;
|
53
|
-
errorMessage = err.message;
|
54
|
-
} else if(err instanceof CustomRequestError) {
|
55
|
-
statusCode = 422;
|
56
|
-
errorMessage = err.message;
|
57
|
-
} else {
|
58
|
-
console.error(err.stack); // Log the error for debugging
|
59
|
-
}
|
60
|
-
|
61
|
-
// Send an error response
|
62
|
-
res.status(statusCode).json({
|
63
|
-
message: errorMessage,
|
64
|
-
error: err.name // Optionally send the error name/type
|
65
|
-
});
|
66
|
-
};
|
package/src/resHandler/index.ts
DELETED
package/src/types/IController.ts
DELETED
package/src/types/IRequest.ts
DELETED
package/src/types/index.ts
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
export * from "./IController";
|
2
|
-
export * from "./IRequest";
|
3
|
-
|
4
|
-
export enum QUEUES {
|
5
|
-
IMAGE_MODEL_BULK = "image-model-bulk", // Will be used for bulk training model
|
6
|
-
IMAGE_MODEL_SINGLE = "image-model-single", // Will be used for single image training
|
7
|
-
NOTIFICATION = "notification", // Notify to user
|
8
|
-
THUMBNAIL = "thumbnail", // To create thubmnail
|
9
|
-
PPT = "ppt", // to call PPT Service
|
10
|
-
PNG_SVG = "png-svg" // to convert raster to vector image
|
11
|
-
}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
export async function callWithRetries(retryCount: number, failedMessage: string, functionRef: Function, ...args: any): Promise<any> {
|
2
|
-
try {
|
3
|
-
return await functionRef(...args)
|
4
|
-
} catch (error: any) {
|
5
|
-
if (retryCount <= 0) throw error;
|
6
|
-
console.log("callWithRetries", error?.message || error)
|
7
|
-
return callWithRetries(retryCount - 1, failedMessage, functionRef, ...args);
|
8
|
-
}
|
9
|
-
}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import jwt from 'jsonwebtoken';
|
2
|
-
|
3
|
-
const signUid = (value: object) => {
|
4
|
-
return jwt.sign({ value }, process.env.JWTSECRET || 'secret', {
|
5
|
-
expiresIn: '8h' // expires in 8 hours
|
6
|
-
});
|
7
|
-
};
|
8
|
-
|
9
|
-
const verifyUid = async (token: string): Promise<any> =>
|
10
|
-
new Promise(resolve => {
|
11
|
-
const jwtToken = token.split(" ")[1] || token;
|
12
|
-
jwt.verify(
|
13
|
-
jwtToken,
|
14
|
-
process.env.JWTSECRET || 'secret',
|
15
|
-
(err, decoded) => {
|
16
|
-
if (err) {
|
17
|
-
// console.log("error verifyUid", err)
|
18
|
-
resolve(null);
|
19
|
-
} else {
|
20
|
-
resolve(decoded);
|
21
|
-
}
|
22
|
-
},
|
23
|
-
);
|
24
|
-
});
|
25
|
-
|
26
|
-
export { signUid, verifyUid }
|