biz-slide-core 1.0.0
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/entity/image.entity.ts +34 -0
- package/entity/png-svg.entity.ts +36 -0
- package/entity/ppt-event.entity.ts +25 -0
- package/entity/ppt-slide.entity.ts +35 -0
- package/entity/ppt.entity.ts +60 -0
- package/entity/slide-layout.entity.ts +26 -0
- package/entity/slide.entity.ts +49 -0
- package/entity/socket.entity.ts +24 -0
- package/entity/template.entity.ts +26 -0
- package/entity/user.entity.ts +28 -0
- package/middleware/authentication.ts +64 -0
- package/middleware/role.ts +5 -0
- package/middleware/schemaValidate.ts +20 -0
- package/package.json +20 -0
- package/resHandler/errorHandler.ts +44 -0
- package/resHandler/index.ts +2 -0
- package/resHandler/successHandler.ts +11 -0
- package/tsconfig.json +109 -0
- package/types/IController.ts +6 -0
- package/types/IRequest.ts +8 -0
- package/utilities/aws-s3.ts +29 -0
- package/utilities/callWithRetries.ts +9 -0
- package/utilities/createFolder.ts +12 -0
- package/utilities/encryptionUtils.ts +26 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
import { Schema, model, Types } from "mongoose";
|
2
|
+
|
3
|
+
interface IImage {
|
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<IImage>(
|
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
|
+
const ImageModel = model<IImage>("image", ImageSchema);
|
33
|
+
|
34
|
+
export default ImageModel;
|
@@ -0,0 +1,36 @@
|
|
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
|
+
const PngSvgModel = model<IPngSvgSchema>("png-svg", PngSvgSchema);
|
35
|
+
|
36
|
+
export default PngSvgModel;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { Schema, model, Types, Document } from "mongoose";
|
2
|
+
|
3
|
+
|
4
|
+
export interface IPPTEventSchema extends Document {
|
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
|
+
const PPTSlideEventModel = model<IPPTEventSchema>("ppt-event", PPTEventSchema);
|
24
|
+
|
25
|
+
export default PPTSlideEventModel;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { Schema, model, Types, Document } from "mongoose";
|
2
|
+
|
3
|
+
|
4
|
+
export interface IPPTSlideSchema extends Document {
|
5
|
+
pptRef: Types.ObjectId;
|
6
|
+
slideRef: Types.ObjectId;
|
7
|
+
slideLayoutRef: Types.ObjectId;
|
8
|
+
title: string;
|
9
|
+
rawData: string;
|
10
|
+
images: string;
|
11
|
+
createdAt?: Date;
|
12
|
+
updatedAt?: Date;
|
13
|
+
deletedAt?: Date;
|
14
|
+
}
|
15
|
+
|
16
|
+
const PPTSlideSchema = new Schema<IPPTSlideSchema>(
|
17
|
+
{
|
18
|
+
createdAt: { type: Date, default: Date.now() },
|
19
|
+
updatedAt: { type: Date, default: Date.now() },
|
20
|
+
deletedAt: { type: Date, default: null },
|
21
|
+
pptRef: { type: Schema.Types.ObjectId, ref: 'ppt' },
|
22
|
+
slideRef: { type: Schema.Types.ObjectId, ref: 'slide' },
|
23
|
+
slideLayoutRef: { type: Schema.Types.ObjectId, ref: 'slide-layout' },
|
24
|
+
title: { type: String, default: null },
|
25
|
+
rawData: { type: String, default: "{}" },
|
26
|
+
images: { type: String, default: "{}" },
|
27
|
+
},
|
28
|
+
{
|
29
|
+
timestamps: true,
|
30
|
+
}
|
31
|
+
);
|
32
|
+
|
33
|
+
const PPTSlideModel = model<IPPTSlideSchema>("ppt-slide", PPTSlideSchema);
|
34
|
+
|
35
|
+
export default PPTSlideModel;
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { Schema, model, Types, Document } from "mongoose";
|
2
|
+
|
3
|
+
interface IPPTQuestions {
|
4
|
+
question: string;
|
5
|
+
answer: string;
|
6
|
+
}
|
7
|
+
|
8
|
+
const questionSchema = new Schema<IPPTQuestions>({
|
9
|
+
question: { type: String},
|
10
|
+
answer : { type : String }
|
11
|
+
}, {
|
12
|
+
timestamps: false,
|
13
|
+
_id: false
|
14
|
+
})
|
15
|
+
|
16
|
+
export interface IPPTQuestionSchema extends Document {
|
17
|
+
question: string;
|
18
|
+
answer: string;
|
19
|
+
}
|
20
|
+
|
21
|
+
export interface IPPTSchema extends Document {
|
22
|
+
systemGeneratedtopics: Array<string>;
|
23
|
+
colors: Array<string>;
|
24
|
+
slideRefs: Types.ObjectId[];
|
25
|
+
templateRef: Types.ObjectId;
|
26
|
+
template_type: string;
|
27
|
+
prompt: string;
|
28
|
+
userId: string;
|
29
|
+
questions: IPPTQuestions[];
|
30
|
+
isLocked?: boolean;
|
31
|
+
isCompleted?: boolean;
|
32
|
+
createdAt?: Date;
|
33
|
+
updatedAt?: Date;
|
34
|
+
deletedAt?: Date;
|
35
|
+
}
|
36
|
+
|
37
|
+
const PPTSchema = new Schema<IPPTSchema>(
|
38
|
+
{
|
39
|
+
createdAt: { type: Date, default: Date.now() },
|
40
|
+
updatedAt: { type: Date, default: Date.now() },
|
41
|
+
deletedAt: { type: Date, default: null },
|
42
|
+
isLocked: { type: Boolean, default: false },
|
43
|
+
isCompleted: { type: Boolean, default: false },
|
44
|
+
userId: { type: String, default: null },
|
45
|
+
template_type: { type: String, default: null },
|
46
|
+
systemGeneratedtopics: { type: [String], default: [], _id: false },
|
47
|
+
questions: [questionSchema],
|
48
|
+
colors: { type: [String], default: [], _id: false },
|
49
|
+
prompt: { type: String, default: null },
|
50
|
+
templateRef: { type: Schema.Types.ObjectId, ref: 'template' },
|
51
|
+
slideRefs: {type: [{ type: Schema.Types.ObjectId, ref: 'ppt-slide' }], default: [], _id: false}
|
52
|
+
},
|
53
|
+
{
|
54
|
+
timestamps: true,
|
55
|
+
}
|
56
|
+
);
|
57
|
+
|
58
|
+
const PPTModel = model<IPPTSchema>("ppt", PPTSchema);
|
59
|
+
|
60
|
+
export default PPTModel;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { Schema, model, Document, Types } from "mongoose";
|
2
|
+
|
3
|
+
export interface ISlideLayoutSchema extends Document {
|
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
|
+
const SlideLayoutModel = model<ISlideLayoutSchema>("slide-layout", SlideLayoutSchema);
|
25
|
+
|
26
|
+
export default SlideLayoutModel;
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { Schema, model, Document, 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 extends Document {
|
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
|
+
const SlideModel = model<ISlideSchema>("slide", SlideSchema);
|
48
|
+
|
49
|
+
export default SlideModel;
|
@@ -0,0 +1,24 @@
|
|
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
|
+
const SocketModel = model<ISocketSchema>("socket", SocketSchema);
|
23
|
+
|
24
|
+
export default SocketModel;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { Schema, model, Document } from "mongoose";
|
2
|
+
|
3
|
+
export interface ITemplateSchema extends Document {
|
4
|
+
name: string;
|
5
|
+
template_type: string;
|
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: String, default: "", required: true },
|
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
|
+
const TemplateModel = model<ITemplateSchema>("template", TemplateSchema);
|
25
|
+
|
26
|
+
export default TemplateModel;
|
@@ -0,0 +1,28 @@
|
|
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
|
+
const UserModel = model<IUser>("user", UserSchema);
|
27
|
+
|
28
|
+
export default UserModel;
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import { Response, NextFunction } from "express";
|
2
|
+
import { verifyUid } from "../utilities/encryptionUtils";
|
3
|
+
import IRequest from "../types/IRequest";
|
4
|
+
import UserModel from "../entity/user.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 = 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;
|
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
|
+
// token.value.customerid
|
54
|
+
|
55
|
+
req.user = {
|
56
|
+
userId: "123" //token.value.customerid
|
57
|
+
}
|
58
|
+
|
59
|
+
next();
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
export {authorize, authorizeWithSlideApp};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { NextFunction, Response } from "express";
|
2
|
+
import Joi from 'joi';
|
3
|
+
|
4
|
+
import IRequest from "../types/IRequest";
|
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
|
+
|
package/package.json
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"name": "biz-slide-core",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "",
|
5
|
+
"main": "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
|
+
"mongoose": "^8.0.3",
|
18
|
+
"typescript": "^5.3.3"
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
2
|
+
|
3
|
+
export class BadRequestError extends Error {
|
4
|
+
constructor(message: string) {
|
5
|
+
super(message);
|
6
|
+
this.name = 'BadRequestError';
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
10
|
+
export class NotFoundRequestError extends Error {
|
11
|
+
constructor(message: string) {
|
12
|
+
super(message);
|
13
|
+
this.name = 'NotFoundRequestError';
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
// Custom error handler middleware
|
20
|
+
export const errorHandler = (
|
21
|
+
err: Error,
|
22
|
+
req: Request,
|
23
|
+
res: Response,
|
24
|
+
next: NextFunction
|
25
|
+
) => {
|
26
|
+
console.error(err.stack); // Log the error for debugging
|
27
|
+
|
28
|
+
let statusCode = 500; // Default status code
|
29
|
+
let errorMessage = 'Internal Server Error'; // Default error message
|
30
|
+
|
31
|
+
if (err instanceof BadRequestError) {
|
32
|
+
statusCode = 400;
|
33
|
+
errorMessage = err.message;
|
34
|
+
} else if(err instanceof NotFoundRequestError) {
|
35
|
+
statusCode = 404;
|
36
|
+
errorMessage = err.message;
|
37
|
+
}
|
38
|
+
|
39
|
+
// Send an error response
|
40
|
+
res.status(statusCode).json({
|
41
|
+
message: errorMessage,
|
42
|
+
error: err.name // Optionally send the error name/type
|
43
|
+
});
|
44
|
+
};
|
package/tsconfig.json
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
4
|
+
|
5
|
+
/* Projects */
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
12
|
+
|
13
|
+
/* Language and Environment */
|
14
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
17
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
18
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
19
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
20
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
21
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
22
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
23
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
24
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
25
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
26
|
+
|
27
|
+
/* Modules */
|
28
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
29
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
30
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
31
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
32
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
33
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
34
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
35
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
36
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
37
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
38
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
39
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
40
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
41
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
42
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
43
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
44
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
45
|
+
|
46
|
+
/* JavaScript Support */
|
47
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
48
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
49
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
50
|
+
|
51
|
+
/* Emit */
|
52
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
53
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
54
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
55
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
56
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
57
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
58
|
+
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
59
|
+
// "removeComments": true, /* Disable emitting comments. */
|
60
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
61
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
62
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
63
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
64
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
65
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
66
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
67
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
68
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
69
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
70
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
71
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
72
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
73
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
74
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
75
|
+
|
76
|
+
/* Interop Constraints */
|
77
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
78
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
79
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
80
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
81
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
82
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
83
|
+
|
84
|
+
/* Type Checking */
|
85
|
+
"strict": true, /* Enable all strict type-checking options. */
|
86
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
87
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
88
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
89
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
90
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
91
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
92
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
93
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
94
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
95
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
96
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
97
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
98
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
99
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
100
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
101
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
102
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
103
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
104
|
+
|
105
|
+
/* Completeness */
|
106
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
107
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
108
|
+
}
|
109
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import fs from "fs";
|
2
|
+
|
3
|
+
export async function getPreSignedUrl(s3: any, bucketName: string, filepath: string): Promise<string> {
|
4
|
+
const params =
|
5
|
+
{
|
6
|
+
Bucket: bucketName,
|
7
|
+
Key: filepath,
|
8
|
+
Expires: 24 * 60 * 60
|
9
|
+
};
|
10
|
+
const url = await s3.getSignedUrl('getObject', params);
|
11
|
+
return url;
|
12
|
+
}
|
13
|
+
|
14
|
+
export async function uploadFileToS3(s3: any, bucketName: string, cloudPath: string, filepath: string) {
|
15
|
+
const fileContent = fs.createReadStream(filepath);
|
16
|
+
const params = {
|
17
|
+
Bucket: bucketName,
|
18
|
+
Key: cloudPath,
|
19
|
+
Body: fileContent,
|
20
|
+
};
|
21
|
+
|
22
|
+
try {
|
23
|
+
await s3.upload(params).promise();
|
24
|
+
console.log('File uploaded successfully');
|
25
|
+
} catch (error) {
|
26
|
+
console.log(error);
|
27
|
+
throw error;
|
28
|
+
}
|
29
|
+
}
|
@@ -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) {
|
5
|
+
if (retryCount <= 0) throw error;
|
6
|
+
console.log(failedMessage)
|
7
|
+
return callWithRetries(retryCount - 1, failedMessage, functionRef, ...args);
|
8
|
+
}
|
9
|
+
}
|
@@ -0,0 +1,12 @@
|
|
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
|
+
console.log(`Folder "${folderPath}" is ready.`);
|
9
|
+
} catch (error) {
|
10
|
+
console.error(`Error: ${error.message}`);
|
11
|
+
}
|
12
|
+
}
|
@@ -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];
|
12
|
+
jwt.verify(
|
13
|
+
jwtToken,
|
14
|
+
process.env.JWTSECRET || 'secret',
|
15
|
+
(err, decoded) => {
|
16
|
+
if (err) {
|
17
|
+
console.log(err)
|
18
|
+
resolve(null);
|
19
|
+
} else {
|
20
|
+
resolve(decoded);
|
21
|
+
}
|
22
|
+
},
|
23
|
+
);
|
24
|
+
});
|
25
|
+
|
26
|
+
export { signUid, verifyUid }
|