biz-slide-core 1.1.6 → 1.1.7

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.
Files changed (60) hide show
  1. package/dist/package-lock.json +1770 -0
  2. package/dist/package.json +23 -0
  3. package/{utilities → dist/utilities}/index.js +1 -0
  4. package/dist/utilities/pngSvgCategories.js +170 -0
  5. package/package.json +1 -1
  6. package/src/entity/image.entity.ts +32 -0
  7. package/src/entity/index.ts +11 -0
  8. package/src/entity/png-svg.entity.ts +34 -0
  9. package/src/entity/ppt-event.entity.ts +23 -0
  10. package/src/entity/ppt-slide.entity.ts +31 -0
  11. package/src/entity/ppt.entity.ts +42 -0
  12. package/src/entity/slide-layout.entity.ts +24 -0
  13. package/src/entity/slide.entity.ts +47 -0
  14. package/src/entity/socket.entity.ts +22 -0
  15. package/src/entity/template-type.entity.ts +53 -0
  16. package/src/entity/template.entity.ts +24 -0
  17. package/src/entity/user.entity.ts +26 -0
  18. package/src/index.ts +5 -0
  19. package/src/middleware/authentication.ts +62 -0
  20. package/src/middleware/index.ts +3 -0
  21. package/src/middleware/role.ts +5 -0
  22. package/src/middleware/schemaValidate.ts +20 -0
  23. package/src/resHandler/errorHandler.ts +44 -0
  24. package/src/resHandler/index.ts +2 -0
  25. package/src/resHandler/successHandler.ts +11 -0
  26. package/src/types/IController.ts +6 -0
  27. package/src/types/IRequest.ts +8 -0
  28. package/src/types/index.ts +11 -0
  29. package/src/utilities/callWithRetries.ts +9 -0
  30. package/src/utilities/createFolder.ts +12 -0
  31. package/src/utilities/encryptionUtils.ts +26 -0
  32. package/src/utilities/index.ts +5 -0
  33. package/src/utilities/pngSvgCategories.ts +167 -0
  34. package/tsconfig.json +11 -0
  35. /package/{entity → dist/entity}/image.entity.js +0 -0
  36. /package/{entity → dist/entity}/index.js +0 -0
  37. /package/{entity → dist/entity}/png-svg.entity.js +0 -0
  38. /package/{entity → dist/entity}/ppt-event.entity.js +0 -0
  39. /package/{entity → dist/entity}/ppt-slide.entity.js +0 -0
  40. /package/{entity → dist/entity}/ppt.entity.js +0 -0
  41. /package/{entity → dist/entity}/slide-layout.entity.js +0 -0
  42. /package/{entity → dist/entity}/slide.entity.js +0 -0
  43. /package/{entity → dist/entity}/socket.entity.js +0 -0
  44. /package/{entity → dist/entity}/template-type.entity.js +0 -0
  45. /package/{entity → dist/entity}/template.entity.js +0 -0
  46. /package/{entity → dist/entity}/user.entity.js +0 -0
  47. /package/{index.js → dist/index.js} +0 -0
  48. /package/{middleware → dist/middleware}/authentication.js +0 -0
  49. /package/{middleware → dist/middleware}/index.js +0 -0
  50. /package/{middleware → dist/middleware}/role.js +0 -0
  51. /package/{middleware → dist/middleware}/schemaValidate.js +0 -0
  52. /package/{resHandler → dist/resHandler}/errorHandler.js +0 -0
  53. /package/{resHandler → dist/resHandler}/index.js +0 -0
  54. /package/{resHandler → dist/resHandler}/successHandler.js +0 -0
  55. /package/{types → dist/types}/IController.js +0 -0
  56. /package/{types → dist/types}/IRequest.js +0 -0
  57. /package/{types → dist/types}/index.js +0 -0
  58. /package/{utilities → dist/utilities}/callWithRetries.js +0 -0
  59. /package/{utilities → dist/utilities}/createFolder.js +0 -0
  60. /package/{utilities → dist/utilities}/encryptionUtils.js +0 -0
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "biz-slide-core",
3
+ "version": "1.1.7",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "express": "^4.18.2",
15
+ "joi": "^17.11.0",
16
+ "jsonwebtoken": "^9.0.2",
17
+ "typescript": "^5.3.3"
18
+ },
19
+ "devDependencies": {
20
+ "@types/express": "^4.17.21",
21
+ "@types/jsonwebtoken": "^9.0.5"
22
+ }
23
+ }
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./callWithRetries"), exports);
18
18
  __exportStar(require("./createFolder"), exports);
19
19
  __exportStar(require("./encryptionUtils"), exports);
20
+ __exportStar(require("./pngSvgCategories"), exports);
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pngSvgCategories = void 0;
4
+ exports.pngSvgCategories = {
5
+ "Logo": {
6
+ "Outline": {
7
+ "alias": ""
8
+ },
9
+ "Monogram": {
10
+ "alias": ""
11
+ },
12
+ "Wordmark": {
13
+ "alias": ""
14
+ },
15
+ "Emblem": {
16
+ "alias": ""
17
+ },
18
+ "Abstract Logo": {
19
+ "alias": ""
20
+ },
21
+ "Mascot": {
22
+ "alias": ""
23
+ }
24
+ },
25
+ "Icons": {
26
+ "Outline": {
27
+ "alias": ""
28
+ },
29
+ "Pictogram": {
30
+ "alias": ""
31
+ },
32
+ "Broken Line": {
33
+ "alias": ""
34
+ },
35
+ "Gradient Line": {
36
+ "alias": ""
37
+ },
38
+ "Gradient Shape": {
39
+ "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."
40
+ },
41
+ "Doodle": {
42
+ "alias": ""
43
+ },
44
+ "Flat": {
45
+ "alias": ""
46
+ },
47
+ "Minimalistic": {
48
+ "alias": ""
49
+ },
50
+ "Isometric": {
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
+ "3D Icons": {
54
+ "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."
55
+ }
56
+ },
57
+ "Illustrations": {
58
+ "Hand Drawn": {
59
+ "alias": ""
60
+ },
61
+ "Glow": {
62
+ "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. "
63
+ },
64
+ "Pixel Art": {
65
+ "alias": ""
66
+ },
67
+ "Watercolour": {
68
+ "alias": ""
69
+ },
70
+ "Psychedelic": {
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
+ "80's": {
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
+ "Digital Art": {
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
+ "Abstract": {
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
+ "Realistic": {
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
+ "Comic Style": {
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
+ "Fantasy": {
89
+ "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. "
90
+ },
91
+ "Anime": {
92
+ "alias": ""
93
+ },
94
+ "Minimalist": {
95
+ "alias": ""
96
+ },
97
+ "Pencil Sketch": {
98
+ "alias": ""
99
+ },
100
+ },
101
+ "3D illustration": {
102
+ "Wireframe": {
103
+ "alias": ""
104
+ },
105
+ "Low Poly": {
106
+ "alias": ""
107
+ },
108
+ "Cartoon 3D": {
109
+ "alias": ""
110
+ },
111
+ "Plastic 3D": {
112
+ "alias": ""
113
+ },
114
+ "3D render": {
115
+ "alias": ""
116
+ },
117
+ },
118
+ "Photorealism": {
119
+ "Photorealistic Painting": {
120
+ "alias": ""
121
+ },
122
+ "Photorealistic Drawing": {
123
+ "alias": ""
124
+ },
125
+ "Hyperealism": {
126
+ "alias": ""
127
+ },
128
+ "Photorealism": {
129
+ "alias": ""
130
+ },
131
+ },
132
+ "Vector Art": {
133
+ "Line Art": {
134
+ "alias": ""
135
+ },
136
+ "Cartoon": {
137
+ "alias": ""
138
+ },
139
+ "Vector Kawai": {
140
+ "alias": ""
141
+ },
142
+ "Linocut": {
143
+ "alias": ""
144
+ },
145
+ "Engraving": {
146
+ "alias": ""
147
+ },
148
+ "Doodle Line Art": {
149
+ "alias": ""
150
+ },
151
+ "Geometric": {
152
+ "alias": ""
153
+ },
154
+ "Abstract": {
155
+ "alias": ""
156
+ },
157
+ "Vintage": {
158
+ "alias": ""
159
+ },
160
+ "Minimalist": {
161
+ "alias": ""
162
+ },
163
+ "Stylized": {
164
+ "alias": ""
165
+ },
166
+ "Flat Design": {
167
+ "alias": ""
168
+ },
169
+ }
170
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "biz-slide-core",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,32 @@
1
+ import { Schema, model, Types } from "mongoose";
2
+
3
+ export interface IImageSchema {
4
+ focusPoint: { x: number, y: number };
5
+ url: string;
6
+ radius: string;
7
+ keywords: [string] | null;
8
+ title: string;
9
+ userId: Types.ObjectId;
10
+ createdAt: Date;
11
+ updatedAt: Date;
12
+ deletedAt: Date;
13
+ }
14
+
15
+ const ImageSchema = new Schema<IImageSchema>(
16
+ {
17
+ focusPoint: { x: Number, y: Number },
18
+ url: { type: String, required: true },
19
+ radius: { type: String, required: true },
20
+ keywords: { type: [String], default: [] },
21
+ title: { type: String, required: true },
22
+ userId: { type: Schema.Types.ObjectId, ref: "user" },
23
+ createdAt: { type: Date, default: Date.now() },
24
+ updatedAt: { type: Date, default: Date.now() },
25
+ deletedAt: { type: Date, default: null },
26
+ },
27
+ {
28
+ timestamps: true,
29
+ }
30
+ );
31
+
32
+ export const ImageModel = model<IImageSchema>("image", ImageSchema);
@@ -0,0 +1,11 @@
1
+ export * from "./image.entity";
2
+ export * from "./png-svg.entity";
3
+ export * from "./ppt-event.entity";
4
+ export * from "./ppt-slide.entity";
5
+ export * from "./ppt.entity";
6
+ export * from "./slide-layout.entity";
7
+ export * from "./slide.entity";
8
+ export * from "./socket.entity";
9
+ export * from "./template.entity";
10
+ export * from "./template-type.entity";
11
+ export * from "./user.entity";
@@ -0,0 +1,34 @@
1
+ import { Schema, model } from "mongoose";
2
+
3
+ export interface IPngSvgSchema {
4
+ title: string;
5
+ styleCategory: string;
6
+ styleSubCategory: string;
7
+ colors: Array<string>;
8
+ userId: string;
9
+ isLocked?: boolean;
10
+ isCompleted?: boolean;
11
+ createdAt?: Date;
12
+ updatedAt?: Date;
13
+ deletedAt?: Date;
14
+ }
15
+
16
+ const PngSvgSchema = new Schema<IPngSvgSchema>(
17
+ {
18
+ createdAt: { type: Date, default: Date.now() },
19
+ updatedAt: { type: Date, default: Date.now() },
20
+ deletedAt: { type: Date, default: null },
21
+ isLocked: { type: Boolean, default: false },
22
+ isCompleted: { type: Boolean, default: false },
23
+ userId: { type: String, default: null },
24
+ title: { type: String, default: null },
25
+ styleCategory: { type: String, default: null },
26
+ styleSubCategory: { type: String, default: null },
27
+ colors: { type: [{ type: String, default: null }], default: null, _id: false }
28
+ },
29
+ {
30
+ timestamps: true,
31
+ }
32
+ );
33
+
34
+ export const PngSvgModel = model<IPngSvgSchema>("png-svg", PngSvgSchema);
@@ -0,0 +1,23 @@
1
+ import { Schema, model, Types } from "mongoose";
2
+
3
+
4
+ export interface IPPTEventSchema {
5
+ pptRef: Types.ObjectId;
6
+ message: string;
7
+ createdAt?: Date;
8
+ updatedAt?: Date;
9
+ }
10
+
11
+ const PPTEventSchema = new Schema<IPPTEventSchema>(
12
+ {
13
+ createdAt: { type: Date, default: Date.now() },
14
+ updatedAt: { type: Date, default: Date.now() },
15
+ pptRef: { type: Schema.Types.ObjectId, ref: 'ppt' },
16
+ message: { type: String, default: null }
17
+ },
18
+ {
19
+ timestamps: true,
20
+ }
21
+ );
22
+
23
+ export const PPTSlideEventModel = model<IPPTEventSchema>("ppt-event", PPTEventSchema);
@@ -0,0 +1,31 @@
1
+ import { Schema, model, Types } from "mongoose";
2
+ export interface IPPTSlideSchema {
3
+ pptRef: Types.ObjectId;
4
+ slideRef: Types.ObjectId;
5
+ slideLayoutRef: Types.ObjectId;
6
+ title: string;
7
+ rawData: string;
8
+ images: string;
9
+ createdAt?: Date;
10
+ updatedAt?: Date;
11
+ deletedAt?: Date;
12
+ }
13
+
14
+ const PPTSlideSchema = new Schema<IPPTSlideSchema>(
15
+ {
16
+ createdAt: { type: Date, default: Date.now() },
17
+ updatedAt: { type: Date, default: Date.now() },
18
+ deletedAt: { type: Date, default: null },
19
+ pptRef: { type: Schema.Types.ObjectId, ref: 'ppt' },
20
+ slideRef: { type: Schema.Types.ObjectId, ref: 'slide' },
21
+ slideLayoutRef: { type: Schema.Types.ObjectId, ref: 'slide-layout' },
22
+ title: { type: String, default: null },
23
+ rawData: { type: String, default: "{}" },
24
+ images: { type: String, default: "{}" },
25
+ },
26
+ {
27
+ timestamps: true,
28
+ }
29
+ );
30
+
31
+ export const PPTSlideModel = model<IPPTSlideSchema>("ppt-slide", PPTSlideSchema);
@@ -0,0 +1,42 @@
1
+ import { Schema, model, Types } from "mongoose";
2
+
3
+ export interface IPPTSchema {
4
+ systemGeneratedtopics: Array<string>;
5
+ colors: Array<string>;
6
+ slideRefs: Types.ObjectId[];
7
+ templateRef: Types.ObjectId;
8
+ template_type: string;
9
+ prompt: string;
10
+ userId: string;
11
+ questions: Array<string>;
12
+ isLocked?: boolean;
13
+ fileCreated?: boolean;
14
+ isCompleted?: boolean;
15
+ createdAt?: Date;
16
+ updatedAt?: Date;
17
+ deletedAt?: Date;
18
+ }
19
+
20
+ const PPTSchema = new Schema<IPPTSchema>(
21
+ {
22
+ createdAt: { type: Date, default: Date.now() },
23
+ updatedAt: { type: Date, default: Date.now() },
24
+ deletedAt: { type: Date, default: null },
25
+ isLocked: { type: Boolean, default: false },
26
+ isCompleted: { type: Boolean, default: false },
27
+ fileCreated: { type: Boolean, default: false },
28
+ userId: { type: String, default: null },
29
+ template_type: { type: String, default: null },
30
+ systemGeneratedtopics: { type: [String], default: [], _id: false },
31
+ questions: { type: [String], default: [], _id: false },
32
+ colors: { type: [String], default: [], _id: false },
33
+ prompt: { type: String, default: null },
34
+ templateRef: { type: Schema.Types.ObjectId, ref: 'template' },
35
+ slideRefs: {type: [{ type: Schema.Types.ObjectId, ref: 'ppt-slide' }], default: [], _id: false}
36
+ },
37
+ {
38
+ timestamps: true,
39
+ }
40
+ );
41
+
42
+ export const PPTModel = model<IPPTSchema>("ppt", PPTSchema);
@@ -0,0 +1,24 @@
1
+ import { Schema, model, Types } from "mongoose";
2
+
3
+ export interface ISlideLayoutSchema {
4
+ name: string;
5
+ templateId: Types.ObjectId;
6
+ createdAt: Date;
7
+ updatedAt: Date;
8
+ deletedAt: Date;
9
+ }
10
+
11
+ const SlideLayoutSchema = new Schema<ISlideLayoutSchema>(
12
+ {
13
+ name: { type: String, default: "", required: true },
14
+ templateId: { type: Schema.Types.ObjectId, ref: "template" },
15
+ createdAt: { type: Date, default: Date.now() },
16
+ updatedAt: { type: Date, default: Date.now() },
17
+ deletedAt: { type: Date, default: null },
18
+ },
19
+ {
20
+ timestamps: true,
21
+ }
22
+ );
23
+
24
+ export const SlideLayoutModel = model<ISlideLayoutSchema>("slide-layout", SlideLayoutSchema);
@@ -0,0 +1,47 @@
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
+ }
29
+
30
+ const SlideSchema = new Schema<ISlideSchema>(
31
+ {
32
+ name: { type: String, default: "", required: true },
33
+ postfix: { type: String, default: "" },
34
+ rules: { type: String, default: "" },
35
+ layers: [layerSchema],
36
+ slideLayoutId: { type: Schema.Types.ObjectId, ref: "slide-layout" },
37
+ templateId: { type: Schema.Types.ObjectId, ref: "template" },
38
+ createdAt: { type: Date, default: Date.now() },
39
+ updatedAt: { type: Date, default: Date.now() },
40
+ deletedAt: { type: Date, default: null },
41
+ },
42
+ {
43
+ timestamps: true,
44
+ }
45
+ );
46
+
47
+ export const SlideModel = model<ISlideSchema>("slide", SlideSchema);
@@ -0,0 +1,22 @@
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
+ createdAt: { type: Date, default: Date.now() },
13
+ updatedAt: { type: Date, default: Date.now() },
14
+ userId: { type: String, default: null },
15
+ socketIds: { type: [String], default: [] }
16
+ },
17
+ {
18
+ timestamps: true,
19
+ }
20
+ );
21
+
22
+ export const SocketModel = model<ISocketSchema>("socket", SocketSchema);
@@ -0,0 +1,53 @@
1
+ import { Schema, model } from "mongoose";
2
+
3
+ interface IQuestionSchema {
4
+ question: string;
5
+ systemMessage: string;
6
+ }
7
+
8
+ export interface ITemplateLayout {
9
+ title: string;
10
+ layoutType: string;
11
+ }
12
+ export interface ITemplateTypeSchema{
13
+ name: string;
14
+ questions: Array<IQuestionSchema>;
15
+ predefineSystemMessage: string;
16
+ layouts: Array<ITemplateLayout>;
17
+ createdAt: Date;
18
+ updatedAt: Date;
19
+ deletedAt: Date;
20
+ }
21
+
22
+ const questionSchema = new Schema<IQuestionSchema>({
23
+ question: { type: String },
24
+ systemMessage: { type: String },
25
+ }, {
26
+ timestamps: false,
27
+ _id: false
28
+ })
29
+
30
+ const layoutsSchema = new Schema<ITemplateLayout>({
31
+ title: { type: String },
32
+ layoutType: { type: String },
33
+ }, {
34
+ timestamps: false,
35
+ _id: false
36
+ })
37
+
38
+ const TemplateTypeSchema = new Schema<ITemplateTypeSchema>(
39
+ {
40
+ name: { type: String, default: "", required: true },
41
+ questions: [questionSchema],
42
+ predefineSystemMessage: {type: String, default: ""},
43
+ layouts: [layoutsSchema],
44
+ createdAt: { type: Date, default: Date.now() },
45
+ updatedAt: { type: Date, default: Date.now() },
46
+ deletedAt: { type: Date, default: null },
47
+ },
48
+ {
49
+ timestamps: true,
50
+ }
51
+ );
52
+
53
+ export const TemplateTypeModel = model<ITemplateTypeSchema>("template-type", TemplateTypeSchema);
@@ -0,0 +1,24 @@
1
+ import { Schema, model, Types } from "mongoose";
2
+
3
+ export interface ITemplateSchema{
4
+ name: string;
5
+ template_type: Types.ObjectId;
6
+ createdAt: Date,
7
+ updatedAt: Date,
8
+ deletedAt: Date
9
+ }
10
+
11
+ const TemplateSchema = new Schema<ITemplateSchema>(
12
+ {
13
+ name: { type: String, default: "", required: true },
14
+ template_type: { type: Schema.Types.ObjectId, ref: "template-type" },
15
+ createdAt: { type: Date, default: Date.now() },
16
+ updatedAt: { type: Date, default: Date.now() },
17
+ deletedAt: { type: Date, default: null },
18
+ },
19
+ {
20
+ timestamps: true,
21
+ }
22
+ );
23
+
24
+ export const TemplateModel = model<ITemplateSchema>("template", TemplateSchema);
@@ -0,0 +1,26 @@
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
+ createdAt: { type: Date, default: Date.now()},
18
+ updatedAt: { type: Date, default: Date.now()},
19
+ deletedAt: { type: Date, default: null},
20
+ },
21
+ {
22
+ timestamps: true,
23
+ }
24
+ );
25
+
26
+ export const UserModel = model<IUser>("user", UserSchema);
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./entity";
2
+ export * from "./middleware";
3
+ export * from "./resHandler";
4
+ export * from "./types";
5
+ export * from "./utilities";
@@ -0,0 +1,62 @@
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
+ req.user = {
54
+ userId: token.value.email || token.value.customer_id
55
+ }
56
+
57
+ next();
58
+ }
59
+ }
60
+ }
61
+
62
+ export {authorize, authorizeWithSlideApp};
@@ -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
+ }