biz-slide-core 1.2.84 → 1.2.85

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. package/dist/entity/analytic.entity.d.ts +50 -0
  2. package/dist/entity/analytic.entity.d.ts.map +1 -0
  3. package/dist/entity/common.d.ts +19 -0
  4. package/dist/entity/common.d.ts.map +1 -0
  5. package/dist/entity/config.enity.d.ts +33 -0
  6. package/dist/entity/config.enity.d.ts.map +1 -0
  7. package/dist/entity/cron.entity.d.ts +33 -0
  8. package/dist/entity/cron.entity.d.ts.map +1 -0
  9. package/dist/entity/customer.entity.d.ts +38 -0
  10. package/dist/entity/customer.entity.d.ts.map +1 -0
  11. package/dist/entity/image.entity.d.ts +44 -0
  12. package/dist/entity/image.entity.d.ts.map +1 -0
  13. package/dist/entity/index.d.ts +19 -0
  14. package/dist/entity/index.d.ts.map +1 -0
  15. package/dist/entity/logs.entity.d.ts +34 -0
  16. package/dist/entity/logs.entity.d.ts.map +1 -0
  17. package/dist/entity/png-svg.entity.d.ts +47 -0
  18. package/dist/entity/png-svg.entity.d.ts.map +1 -0
  19. package/dist/entity/ppt-email-queue.entity.d.ts +34 -0
  20. package/dist/entity/ppt-email-queue.entity.d.ts.map +1 -0
  21. package/dist/entity/ppt-event.entity.d.ts +37 -0
  22. package/dist/entity/ppt-event.entity.d.ts.map +1 -0
  23. package/dist/entity/ppt-slide.entity.d.ts +44 -0
  24. package/dist/entity/ppt-slide.entity.d.ts.map +1 -0
  25. package/dist/entity/ppt.entity.d.ts +62 -0
  26. package/dist/entity/ppt.entity.d.ts.map +1 -0
  27. package/{entity → dist/entity}/ppt.entity.js +2 -1
  28. package/dist/entity/slide-layout.entity.d.ts +45 -0
  29. package/dist/entity/slide-layout.entity.d.ts.map +1 -0
  30. package/dist/entity/slide.entity.d.ts +51 -0
  31. package/dist/entity/slide.entity.d.ts.map +1 -0
  32. package/dist/entity/socket.entity.d.ts +35 -0
  33. package/dist/entity/socket.entity.d.ts.map +1 -0
  34. package/dist/entity/template-type.entity.d.ts +49 -0
  35. package/dist/entity/template-type.entity.d.ts.map +1 -0
  36. package/dist/entity/template.entity.d.ts +40 -0
  37. package/dist/entity/template.entity.d.ts.map +1 -0
  38. package/dist/entity/training-queue.entity.d.ts +39 -0
  39. package/dist/entity/training-queue.entity.d.ts.map +1 -0
  40. package/dist/entity/user.entity.d.ts +38 -0
  41. package/dist/entity/user.entity.d.ts.map +1 -0
  42. package/dist/index.d.ts +6 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/middleware/authentication.d.ts +8 -0
  45. package/dist/middleware/authentication.d.ts.map +1 -0
  46. package/{middleware → dist/middleware}/authentication.js +1 -0
  47. package/dist/middleware/index.d.ts +4 -0
  48. package/dist/middleware/index.d.ts.map +1 -0
  49. package/dist/middleware/role.d.ts +6 -0
  50. package/dist/middleware/role.d.ts.map +1 -0
  51. package/dist/middleware/schemaValidate.d.ts +5 -0
  52. package/dist/middleware/schemaValidate.d.ts.map +1 -0
  53. package/dist/resHandler/errorHandler.d.ts +17 -0
  54. package/dist/resHandler/errorHandler.d.ts.map +1 -0
  55. package/dist/resHandler/index.d.ts +3 -0
  56. package/dist/resHandler/index.d.ts.map +1 -0
  57. package/dist/resHandler/successHandler.d.ts +3 -0
  58. package/dist/resHandler/successHandler.d.ts.map +1 -0
  59. package/dist/types/IController.d.ts +6 -0
  60. package/dist/types/IController.d.ts.map +1 -0
  61. package/dist/types/IRequest.d.ts +8 -0
  62. package/dist/types/IRequest.d.ts.map +1 -0
  63. package/dist/types/index.d.ts +11 -0
  64. package/dist/types/index.d.ts.map +1 -0
  65. package/dist/utilities/callWithRetries.d.ts +2 -0
  66. package/dist/utilities/callWithRetries.d.ts.map +1 -0
  67. package/dist/utilities/createFolder.d.ts +2 -0
  68. package/dist/utilities/createFolder.d.ts.map +1 -0
  69. package/dist/utilities/encryptionUtils.d.ts +4 -0
  70. package/dist/utilities/encryptionUtils.d.ts.map +1 -0
  71. package/dist/utilities/hasAbusiveWords.d.ts +4 -0
  72. package/dist/utilities/hasAbusiveWords.d.ts.map +1 -0
  73. package/dist/utilities/index.d.ts +6 -0
  74. package/dist/utilities/index.d.ts.map +1 -0
  75. package/dist/utilities/pngSvgCategories.d.ts +168 -0
  76. package/dist/utilities/pngSvgCategories.d.ts.map +1 -0
  77. package/package.json +2 -1
  78. package/src/entity/analytic.entity.ts +62 -0
  79. package/src/entity/common.ts +19 -0
  80. package/src/entity/config.enity.ts +18 -0
  81. package/src/entity/cron.entity.ts +22 -0
  82. package/src/entity/customer.entity.ts +40 -0
  83. package/src/entity/image.entity.ts +32 -0
  84. package/src/entity/index.ts +20 -0
  85. package/src/entity/logs.entity.ts +20 -0
  86. package/src/entity/png-svg.entity.ts +44 -0
  87. package/src/entity/ppt-email-queue.entity.ts +22 -0
  88. package/src/entity/ppt-event.entity.ts +25 -0
  89. package/src/entity/ppt-slide.entity.ts +40 -0
  90. package/src/entity/ppt.entity.ts +79 -0
  91. package/src/entity/slide-layout.entity.ts +56 -0
  92. package/src/entity/slide.entity.ts +61 -0
  93. package/src/entity/socket.entity.ts +20 -0
  94. package/src/entity/template-type.entity.ts +87 -0
  95. package/src/entity/template.entity.ts +38 -0
  96. package/src/entity/training-queue.entity.ts +26 -0
  97. package/src/entity/user.entity.ts +24 -0
  98. package/src/index.ts +6 -0
  99. package/src/middleware/authentication.ts +150 -0
  100. package/src/middleware/index.ts +3 -0
  101. package/src/middleware/role.ts +5 -0
  102. package/src/middleware/schemaValidate.ts +20 -0
  103. package/src/resHandler/errorHandler.ts +66 -0
  104. package/src/resHandler/index.ts +2 -0
  105. package/src/resHandler/successHandler.ts +11 -0
  106. package/src/types/IController.ts +6 -0
  107. package/src/types/IRequest.ts +8 -0
  108. package/src/types/index.ts +11 -0
  109. package/src/utilities/callWithRetries.ts +9 -0
  110. package/src/utilities/createFolder.ts +11 -0
  111. package/src/utilities/encryptionUtils.ts +26 -0
  112. package/src/utilities/hasAbusiveWords.ts +33 -0
  113. package/src/utilities/index.ts +5 -0
  114. package/src/utilities/pngSvgCategories.ts +167 -0
  115. package/tsconfig.json +11 -0
  116. /package/{entity → dist/entity}/analytic.entity.js +0 -0
  117. /package/{entity → dist/entity}/common.js +0 -0
  118. /package/{entity → dist/entity}/config.enity.js +0 -0
  119. /package/{entity → dist/entity}/cron.entity.js +0 -0
  120. /package/{entity → dist/entity}/customer.entity.js +0 -0
  121. /package/{entity → dist/entity}/image.entity.js +0 -0
  122. /package/{entity → dist/entity}/index.js +0 -0
  123. /package/{entity → dist/entity}/logs.entity.js +0 -0
  124. /package/{entity → dist/entity}/png-svg.entity.js +0 -0
  125. /package/{entity → dist/entity}/ppt-email-queue.entity.js +0 -0
  126. /package/{entity → dist/entity}/ppt-event.entity.js +0 -0
  127. /package/{entity → dist/entity}/ppt-slide.entity.js +0 -0
  128. /package/{entity → dist/entity}/slide-layout.entity.js +0 -0
  129. /package/{entity → dist/entity}/slide.entity.js +0 -0
  130. /package/{entity → dist/entity}/socket.entity.js +0 -0
  131. /package/{entity → dist/entity}/template-type.entity.js +0 -0
  132. /package/{entity → dist/entity}/template.entity.js +0 -0
  133. /package/{entity → dist/entity}/training-queue.entity.js +0 -0
  134. /package/{entity → dist/entity}/user.entity.js +0 -0
  135. /package/{index.js → dist/index.js} +0 -0
  136. /package/{middleware → dist/middleware}/index.js +0 -0
  137. /package/{middleware → dist/middleware}/role.js +0 -0
  138. /package/{middleware → dist/middleware}/schemaValidate.js +0 -0
  139. /package/{resHandler → dist/resHandler}/errorHandler.js +0 -0
  140. /package/{resHandler → dist/resHandler}/index.js +0 -0
  141. /package/{resHandler → dist/resHandler}/successHandler.js +0 -0
  142. /package/{types → dist/types}/IController.js +0 -0
  143. /package/{types → dist/types}/IRequest.js +0 -0
  144. /package/{types → dist/types}/index.js +0 -0
  145. /package/{utilities → dist/utilities}/callWithRetries.js +0 -0
  146. /package/{utilities → dist/utilities}/createFolder.js +0 -0
  147. /package/{utilities → dist/utilities}/encryptionUtils.js +0 -0
  148. /package/{utilities → dist/utilities}/hasAbusiveWords.js +0 -0
  149. /package/{utilities → dist/utilities}/index.js +0 -0
  150. /package/{utilities → dist/utilities}/pngSvgCategories.js +0 -0
@@ -0,0 +1,61 @@
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);
@@ -0,0 +1,20 @@
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);
@@ -0,0 +1,87 @@
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);
@@ -0,0 +1,38 @@
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);
@@ -0,0 +1,26 @@
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);
@@ -0,0 +1,24 @@
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 ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./entity";
2
+ export * from "./middleware";
3
+ export * from "./resHandler";
4
+ export * from "./types";
5
+
6
+ export * from "./utilities";
@@ -0,0 +1,150 @@
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};
@@ -0,0 +1,3 @@
1
+ export * from "./authentication";
2
+ export * from "./role";
3
+ export * from "./schemaValidate";
@@ -0,0 +1,5 @@
1
+ export const ROLES = {
2
+ User: 'User',
3
+ Admin: 'Admin',
4
+ SuperAdmin: 'SuperAdmin'
5
+ }
@@ -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,66 @@
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
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./errorHandler";
2
+ export * from "./successHandler";
@@ -0,0 +1,11 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+
3
+ // Generic success handler middleware
4
+ export const successHandler = (
5
+ data: any,
6
+ req: Request,
7
+ res: Response,
8
+ next: NextFunction
9
+ ) => {
10
+ res.status(200).json(data);
11
+ };
@@ -0,0 +1,6 @@
1
+ import { Response } from "express";
2
+ import { IRequest } from "./IRequest";
3
+
4
+ export interface IController {
5
+ (req: IRequest, res: Response): void;
6
+ }
@@ -0,0 +1,8 @@
1
+ import { Request } from "express";
2
+
3
+ export interface IRequest extends Request {
4
+ user?: any,
5
+ token?: any,
6
+ role?: any,
7
+ file?:any
8
+ }
@@ -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 || error)
7
+ return callWithRetries(retryCount - 1, failedMessage, functionRef, ...args);
8
+ }
9
+ }
@@ -0,0 +1,11 @@
1
+ import fs from "fs";
2
+
3
+ export async function createFolder(folderPath: string) {
4
+ try {
5
+ if (!fs.existsSync(folderPath)) {
6
+ fs.mkdirSync(folderPath);
7
+ }
8
+ } catch (error: any) {
9
+ console.error(`Error: ${error.message}`);
10
+ }
11
+ }
@@ -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,5 @@
1
+ export * from "./callWithRetries";
2
+ export * from "./createFolder";
3
+ export * from "./encryptionUtils";
4
+ export * from "./pngSvgCategories";
5
+ export * from "./hasAbusiveWords";