biz-slide-core 1.2.28 → 1.2.30
Sign up to get free protection for your applications and to get access to all the features.
- package/{entity → dist/entity}/template.entity.js +1 -0
- package/dist/package-lock.json +1770 -0
- package/dist/package.json +23 -0
- package/{utilities → dist/utilities}/index.js +1 -0
- package/dist/utilities/sendEmail.js +83 -0
- package/package.json +4 -2
- package/src/entity/config.enity.ts +18 -0
- package/src/entity/image.entity.ts +32 -0
- package/src/entity/index.ts +16 -0
- package/src/entity/logs.entity.ts +20 -0
- package/src/entity/png-svg.entity.ts +42 -0
- package/src/entity/ppt-event.entity.ts +23 -0
- package/src/entity/ppt-slide.entity.ts +29 -0
- package/src/entity/ppt.entity.ts +48 -0
- package/src/entity/slide-layout.entity.ts +22 -0
- package/src/entity/slide.entity.ts +47 -0
- package/src/entity/socket.entity.ts +20 -0
- package/src/entity/template-type.entity.ts +57 -0
- package/src/entity/template.entity.ts +38 -0
- package/src/entity/training-queue.entity.ts +26 -0
- package/src/entity/user.entity.ts +24 -0
- package/src/index.ts +6 -0
- package/src/middleware/authentication.ts +68 -0
- package/src/middleware/index.ts +3 -0
- package/src/middleware/role.ts +5 -0
- package/src/middleware/schemaValidate.ts +20 -0
- package/src/resHandler/errorHandler.ts +65 -0
- package/src/resHandler/index.ts +2 -0
- package/src/resHandler/successHandler.ts +11 -0
- package/src/types/IController.ts +6 -0
- package/src/types/IRequest.ts +8 -0
- package/src/types/index.ts +11 -0
- package/src/utilities/callWithRetries.ts +9 -0
- package/src/utilities/createFolder.ts +11 -0
- package/src/utilities/encryptionUtils.ts +26 -0
- package/src/utilities/hasAbusiveWords.ts +33 -0
- package/src/utilities/index.ts +6 -0
- package/src/utilities/pngSvgCategories.ts +167 -0
- package/src/utilities/sendEmail.ts +30 -0
- package/tsconfig.json +11 -0
- /package/{entity → dist/entity}/config.enity.js +0 -0
- /package/{entity → dist/entity}/image.entity.js +0 -0
- /package/{entity → dist/entity}/index.js +0 -0
- /package/{entity → dist/entity}/logs.entity.js +0 -0
- /package/{entity → dist/entity}/png-svg.entity.js +0 -0
- /package/{entity → dist/entity}/ppt-event.entity.js +0 -0
- /package/{entity → dist/entity}/ppt-slide.entity.js +0 -0
- /package/{entity → dist/entity}/ppt.entity.js +0 -0
- /package/{entity → dist/entity}/slide-layout.entity.js +0 -0
- /package/{entity → dist/entity}/slide.entity.js +0 -0
- /package/{entity → dist/entity}/socket.entity.js +0 -0
- /package/{entity → dist/entity}/template-type.entity.js +0 -0
- /package/{entity → dist/entity}/training-queue.entity.js +0 -0
- /package/{entity → dist/entity}/user.entity.js +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{middleware → dist/middleware}/authentication.js +0 -0
- /package/{middleware → dist/middleware}/index.js +0 -0
- /package/{middleware → dist/middleware}/role.js +0 -0
- /package/{middleware → dist/middleware}/schemaValidate.js +0 -0
- /package/{resHandler → dist/resHandler}/errorHandler.js +0 -0
- /package/{resHandler → dist/resHandler}/index.js +0 -0
- /package/{resHandler → dist/resHandler}/successHandler.js +0 -0
- /package/{types → dist/types}/IController.js +0 -0
- /package/{types → dist/types}/IRequest.js +0 -0
- /package/{types → dist/types}/index.js +0 -0
- /package/{utilities → dist/utilities}/callWithRetries.js +0 -0
- /package/{utilities → dist/utilities}/createFolder.js +0 -0
- /package/{utilities → dist/utilities}/encryptionUtils.js +0 -0
- /package/{utilities → dist/utilities}/hasAbusiveWords.js +0 -0
- /package/{utilities → dist/utilities}/pngSvgCategories.js +0 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
import { Response, NextFunction } from "express";
|
2
|
+
import { verifyUid } from "../utilities";
|
3
|
+
import { IRequest } from "../types";
|
4
|
+
import { UserModel } 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 authorizeWithSlideApp = () => {
|
42
|
+
return async function (req: IRequest, res: Response, next: NextFunction) {
|
43
|
+
if (!req.headers.authorization) {
|
44
|
+
return res.status(401).json({ message: 'Unauthorized' })
|
45
|
+
}
|
46
|
+
|
47
|
+
if (req.headers.authorization) {
|
48
|
+
const token = await verifyUid(req.headers.authorization);
|
49
|
+
if (!token) {
|
50
|
+
return res.status(401).json({ message: 'Session Expired' })
|
51
|
+
}
|
52
|
+
|
53
|
+
const userId = token?.customer_id || token?.value?.email;
|
54
|
+
|
55
|
+
if(!userId) {
|
56
|
+
return res.status(401).json({ message: 'userId not found' })
|
57
|
+
}
|
58
|
+
|
59
|
+
req.user = {
|
60
|
+
userId: userId
|
61
|
+
}
|
62
|
+
|
63
|
+
next();
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
export {authorize, authorizeWithSlideApp};
|
@@ -0,0 +1,20 @@
|
|
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
|
+
|
@@ -0,0 +1,65 @@
|
|
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
|
+
console.error(err.stack); // Log the error for debugging
|
45
|
+
|
46
|
+
let statusCode = 500; // Default status code
|
47
|
+
let errorMessage = 'Internal Server Error'; // Default error message
|
48
|
+
|
49
|
+
if (err instanceof BadRequestError) {
|
50
|
+
statusCode = 400;
|
51
|
+
errorMessage = err.message;
|
52
|
+
} else if(err instanceof NotFoundRequestError) {
|
53
|
+
statusCode = 404;
|
54
|
+
errorMessage = err.message;
|
55
|
+
} else if(err instanceof CustomRequestError) {
|
56
|
+
statusCode = 422;
|
57
|
+
errorMessage = err.message;
|
58
|
+
}
|
59
|
+
|
60
|
+
// Send an error response
|
61
|
+
res.status(statusCode).json({
|
62
|
+
message: errorMessage,
|
63
|
+
error: err.name // Optionally send the error name/type
|
64
|
+
});
|
65
|
+
};
|
@@ -0,0 +1,11 @@
|
|
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
|
+
}
|
@@ -0,0 +1,9 @@
|
|
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)
|
7
|
+
return callWithRetries(retryCount - 1, failedMessage, functionRef, ...args);
|
8
|
+
}
|
9
|
+
}
|
@@ -0,0 +1,26 @@
|
|
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 }
|
@@ -0,0 +1,33 @@
|
|
1
|
+
export function hasExactMatch(str: string, word: string) {
|
2
|
+
// Construct a regular expression to match the word as a whole word
|
3
|
+
const regex = new RegExp('\\b' + word + '\\b', 'i'); // 'i' for case-insensitive matching
|
4
|
+
|
5
|
+
// Test if the word has an exact match in the string
|
6
|
+
return regex.test(str);
|
7
|
+
}
|
8
|
+
|
9
|
+
export function hasSpecialCharacter(str: string) {
|
10
|
+
// Define a regular expression with a character class containing special characters
|
11
|
+
const regex = /[!@#$%^&*()_+\-=\[\]{};:\\|<>\/?]/;
|
12
|
+
|
13
|
+
// Test if the string contains any special character
|
14
|
+
return regex.test(str);
|
15
|
+
}
|
16
|
+
|
17
|
+
|
18
|
+
export function hasAbusiveWords(str: string, words: string[]) {
|
19
|
+
// Convert the string to lowercase for case-insensitive matching
|
20
|
+
const lowerStr = str.toLowerCase();
|
21
|
+
|
22
|
+
if(hasSpecialCharacter(lowerStr)) {
|
23
|
+
return true;
|
24
|
+
}
|
25
|
+
|
26
|
+
// Check if any abusive word exists in the string
|
27
|
+
for (const word of words) {
|
28
|
+
if(hasExactMatch(lowerStr, word.toLowerCase())) {
|
29
|
+
return true
|
30
|
+
}
|
31
|
+
}
|
32
|
+
return false;
|
33
|
+
}
|
@@ -0,0 +1,167 @@
|
|
1
|
+
export const pngSvgCategories = {
|
2
|
+
"Logo": {
|
3
|
+
"Outline": {
|
4
|
+
"alias": ""
|
5
|
+
},
|
6
|
+
"Monogram": {
|
7
|
+
"alias": ""
|
8
|
+
},
|
9
|
+
"Wordmark": {
|
10
|
+
"alias": ""
|
11
|
+
},
|
12
|
+
"Emblem": {
|
13
|
+
"alias": ""
|
14
|
+
},
|
15
|
+
"Abstract Logo": {
|
16
|
+
"alias": ""
|
17
|
+
},
|
18
|
+
"Mascot": {
|
19
|
+
"alias": ""
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"Icons": {
|
23
|
+
"Outline": {
|
24
|
+
"alias": ""
|
25
|
+
},
|
26
|
+
"Pictogram": {
|
27
|
+
"alias": ""
|
28
|
+
},
|
29
|
+
"Broken Line": {
|
30
|
+
"alias": ""
|
31
|
+
},
|
32
|
+
"Gradient Line": {
|
33
|
+
"alias": ""
|
34
|
+
},
|
35
|
+
"Gradient Shape": {
|
36
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme."
|
37
|
+
},
|
38
|
+
"Doodle": {
|
39
|
+
"alias": ""
|
40
|
+
},
|
41
|
+
"Flat": {
|
42
|
+
"alias": ""
|
43
|
+
},
|
44
|
+
"Minimalistic": {
|
45
|
+
"alias": ""
|
46
|
+
},
|
47
|
+
"Isometric": {
|
48
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme. "
|
49
|
+
},
|
50
|
+
"3D Icons": {
|
51
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme."
|
52
|
+
}
|
53
|
+
},
|
54
|
+
"Illustrations": {
|
55
|
+
"Hand Drawn": {
|
56
|
+
"alias": ""
|
57
|
+
},
|
58
|
+
"Glow": {
|
59
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme. "
|
60
|
+
},
|
61
|
+
"Pixel Art": {
|
62
|
+
"alias": ""
|
63
|
+
},
|
64
|
+
"Watercolour": {
|
65
|
+
"alias": ""
|
66
|
+
},
|
67
|
+
"Psychedelic": {
|
68
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme. "
|
69
|
+
},
|
70
|
+
"80's": {
|
71
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme. "
|
72
|
+
},
|
73
|
+
"Digital Art": {
|
74
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme. "
|
75
|
+
},
|
76
|
+
"Abstract": {
|
77
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme. "
|
78
|
+
},
|
79
|
+
"Realistic": {
|
80
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme. "
|
81
|
+
},
|
82
|
+
"Comic Style": {
|
83
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme. "
|
84
|
+
},
|
85
|
+
"Fantasy": {
|
86
|
+
"alias": "The icon should have strong and dramatic lighting and have a clean look on white background and should have only the suggested colour scheme. "
|
87
|
+
},
|
88
|
+
"Anime": {
|
89
|
+
"alias": ""
|
90
|
+
},
|
91
|
+
"Minimalist": {
|
92
|
+
"alias": ""
|
93
|
+
},
|
94
|
+
"Pencil Sketch": {
|
95
|
+
"alias": ""
|
96
|
+
},
|
97
|
+
},
|
98
|
+
"3D illustration": {
|
99
|
+
"Wireframe": {
|
100
|
+
"alias": ""
|
101
|
+
},
|
102
|
+
"Low Poly": {
|
103
|
+
"alias": ""
|
104
|
+
},
|
105
|
+
"Cartoon 3D": {
|
106
|
+
"alias": ""
|
107
|
+
},
|
108
|
+
"Plastic 3D": {
|
109
|
+
"alias": ""
|
110
|
+
},
|
111
|
+
"3D render": {
|
112
|
+
"alias": ""
|
113
|
+
},
|
114
|
+
},
|
115
|
+
"Photorealism": {
|
116
|
+
"Photorealistic Painting": {
|
117
|
+
"alias": ""
|
118
|
+
},
|
119
|
+
"Photorealistic Drawing": {
|
120
|
+
"alias": ""
|
121
|
+
},
|
122
|
+
"Hyperealism": {
|
123
|
+
"alias": ""
|
124
|
+
},
|
125
|
+
"Photorealism": {
|
126
|
+
"alias": ""
|
127
|
+
},
|
128
|
+
},
|
129
|
+
"Vector Art": {
|
130
|
+
"Line Art": {
|
131
|
+
"alias": ""
|
132
|
+
},
|
133
|
+
"Cartoon": {
|
134
|
+
"alias": ""
|
135
|
+
},
|
136
|
+
"Vector Kawai": {
|
137
|
+
"alias": ""
|
138
|
+
},
|
139
|
+
"Linocut": {
|
140
|
+
"alias": ""
|
141
|
+
},
|
142
|
+
"Engraving": {
|
143
|
+
"alias": ""
|
144
|
+
},
|
145
|
+
"Doodle Line Art": {
|
146
|
+
"alias": ""
|
147
|
+
},
|
148
|
+
"Geometric": {
|
149
|
+
"alias": ""
|
150
|
+
},
|
151
|
+
"Abstract": {
|
152
|
+
"alias": ""
|
153
|
+
},
|
154
|
+
"Vintage": {
|
155
|
+
"alias": ""
|
156
|
+
},
|
157
|
+
"Minimalist": {
|
158
|
+
"alias": ""
|
159
|
+
},
|
160
|
+
"Stylized": {
|
161
|
+
"alias": ""
|
162
|
+
},
|
163
|
+
"Flat Design": {
|
164
|
+
"alias": ""
|
165
|
+
},
|
166
|
+
}
|
167
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import nodemailer from "nodemailer";
|
2
|
+
|
3
|
+
export async function sendEmail(to: string[], subject: string, text: string, attachments: [{ filename: string, path?: string, content?: any }]) {
|
4
|
+
// Create a Nodemailer transporter using AWS SES SMTP credentials
|
5
|
+
const transporter = nodemailer.createTransport({
|
6
|
+
host: process.env.EMAIL_HOST, // SES SMTP endpoint for your region
|
7
|
+
port: 465,
|
8
|
+
secure: true, // use TLS
|
9
|
+
auth: {
|
10
|
+
user: process.env.EMAIL_USER, // SMTP username (not used but still required)
|
11
|
+
pass: process.env.EMAIL_PASS // Access token
|
12
|
+
}
|
13
|
+
});
|
14
|
+
|
15
|
+
// Define email options
|
16
|
+
const mailOptions: any = {
|
17
|
+
from: process.env.EMAIL_SUPPORT, // sender email address
|
18
|
+
to, // recipient email address
|
19
|
+
subject, // subject of the email
|
20
|
+
text, // plaintext body
|
21
|
+
attachments: attachments || []
|
22
|
+
};
|
23
|
+
try {
|
24
|
+
const info = await transporter.sendMail(mailOptions);
|
25
|
+
console.log('Email sent:', info.response);
|
26
|
+
} catch (error) {
|
27
|
+
console.error('Error sending email: ', error);
|
28
|
+
return undefined;
|
29
|
+
}
|
30
|
+
}
|
package/tsconfig.json
ADDED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|