@armi-wave/common 1.2.0 → 1.5.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/build/enums/AccountType.d.ts +5 -0
- package/build/enums/AccountType.js +2 -0
- package/build/enums/PaidPlan.d.ts +3 -0
- package/build/enums/PaidPlan.js +2 -0
- package/build/enums/PostType.d.ts +7 -0
- package/build/enums/PostType.js +2 -0
- package/build/errors/bad-request-error.d.ts +9 -0
- package/build/errors/bad-request-error.js +18 -0
- package/build/errors/custom-error.d.ts +8 -0
- package/build/errors/custom-error.js +9 -0
- package/build/errors/database-connection-error.d.ts +9 -0
- package/build/errors/database-connection-error.js +22 -0
- package/build/errors/not-authorized-error.d.ts +8 -0
- package/build/errors/not-authorized-error.js +21 -0
- package/build/errors/not-found-error.d.ts +8 -0
- package/build/errors/not-found-error.js +21 -0
- package/build/errors/request-validation-error.d.ts +11 -0
- package/build/errors/request-validation-error.js +23 -0
- package/build/index.d.ts +15 -0
- package/build/index.js +42 -0
- package/build/middlewares/current-user.d.ts +14 -0
- package/build/middlewares/current-user.js +17 -0
- package/build/middlewares/error-handler.d.ts +2 -0
- package/build/middlewares/error-handler.js +17 -0
- package/build/middlewares/require-auth.d.ts +2 -0
- package/build/middlewares/require-auth.js +14 -0
- package/build/middlewares/validate-request.d.ts +2 -0
- package/build/middlewares/validate-request.js +16 -0
- package/build/models/Comment.d.ts +26 -0
- package/build/models/Comment.js +53 -0
- package/build/models/Post.d.ts +31 -0
- package/build/models/Post.js +61 -0
- package/build/models/User.d.ts +66 -0
- package/build/models/User.js +172 -0
- package/build/utils/password.d.ts +4 -0
- package/build/utils/password.js +31 -0
- package/package.json +15 -4
- package/src/index.ts +0 -3
- package/src/models/User.ts +0 -223
- package/src/utils/password.ts +0 -19
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const custom_error_1 = __importDefault(require("./custom-error"));
|
|
7
|
+
class BadRequestError extends custom_error_1.default {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.message = message;
|
|
11
|
+
this.statusCode = 400;
|
|
12
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
13
|
+
}
|
|
14
|
+
serializeErrors() {
|
|
15
|
+
return [{ message: this.message }];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = BadRequestError;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const custom_error_1 = __importDefault(require("./custom-error"));
|
|
7
|
+
class DatabaseConnectionError extends custom_error_1.default {
|
|
8
|
+
constructor() {
|
|
9
|
+
super('Error connecting to database');
|
|
10
|
+
this.statusCode = 500;
|
|
11
|
+
this.reason = 'Error connection to database';
|
|
12
|
+
Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
|
|
13
|
+
}
|
|
14
|
+
serializeErrors() {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
message: this.reason,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = DatabaseConnectionError;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const custom_error_1 = __importDefault(require("./custom-error"));
|
|
7
|
+
class NotAuthorizedError extends custom_error_1.default {
|
|
8
|
+
constructor() {
|
|
9
|
+
super('Not Authorized');
|
|
10
|
+
this.statusCode = 401;
|
|
11
|
+
Object.setPrototypeOf(this, NotAuthorizedError.prototype);
|
|
12
|
+
}
|
|
13
|
+
serializeErrors() {
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
message: 'Not Authorized',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = NotAuthorizedError;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const custom_error_1 = __importDefault(require("./custom-error"));
|
|
7
|
+
class NotFoundError extends custom_error_1.default {
|
|
8
|
+
constructor() {
|
|
9
|
+
super('Not Found');
|
|
10
|
+
this.statusCode = 404;
|
|
11
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
12
|
+
}
|
|
13
|
+
serializeErrors() {
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
message: 'Not Found',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = NotFoundError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ValidationError } from 'express-validator';
|
|
2
|
+
import CustomError from './custom-error';
|
|
3
|
+
export default class RequestValidationError extends CustomError {
|
|
4
|
+
errors: ValidationError[];
|
|
5
|
+
statusCode: number;
|
|
6
|
+
constructor(errors: ValidationError[]);
|
|
7
|
+
serializeErrors(): {
|
|
8
|
+
message: any;
|
|
9
|
+
field: string;
|
|
10
|
+
}[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const custom_error_1 = __importDefault(require("./custom-error"));
|
|
7
|
+
class RequestValidationError extends custom_error_1.default {
|
|
8
|
+
constructor(errors) {
|
|
9
|
+
super('Error with validation');
|
|
10
|
+
this.errors = errors;
|
|
11
|
+
this.statusCode = 400;
|
|
12
|
+
Object.setPrototypeOf(this, RequestValidationError.prototype);
|
|
13
|
+
}
|
|
14
|
+
serializeErrors() {
|
|
15
|
+
return this.errors.map((err) => {
|
|
16
|
+
return {
|
|
17
|
+
message: err.msg,
|
|
18
|
+
field: err.param,
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = RequestValidationError;
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import User from './models/User';
|
|
2
|
+
import Post from './models/Post';
|
|
3
|
+
import Comment from './models/Comment';
|
|
4
|
+
import BadRequestError from './errors/bad-request-error';
|
|
5
|
+
import DatabaseConnectionError from './errors/database-connection-error';
|
|
6
|
+
import CustomError from './errors/custom-error';
|
|
7
|
+
import NotAuthorizedError from './errors/not-authorized-error';
|
|
8
|
+
import NotFoundError from './errors/not-found-error';
|
|
9
|
+
import RequestValidationError from './errors/request-validation-error';
|
|
10
|
+
export { User, Post, Comment };
|
|
11
|
+
export { BadRequestError, DatabaseConnectionError, CustomError, NotAuthorizedError, NotFoundError, RequestValidationError, };
|
|
12
|
+
export * from './middlewares/current-user';
|
|
13
|
+
export * from './middlewares/error-handler';
|
|
14
|
+
export * from './middlewares/require-auth';
|
|
15
|
+
export * from './middlewares/validate-request';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.RequestValidationError = exports.NotFoundError = exports.NotAuthorizedError = exports.CustomError = exports.DatabaseConnectionError = exports.BadRequestError = exports.Comment = exports.Post = exports.User = void 0;
|
|
21
|
+
const User_1 = __importDefault(require("./models/User"));
|
|
22
|
+
exports.User = User_1.default;
|
|
23
|
+
const Post_1 = __importDefault(require("./models/Post"));
|
|
24
|
+
exports.Post = Post_1.default;
|
|
25
|
+
const Comment_1 = __importDefault(require("./models/Comment"));
|
|
26
|
+
exports.Comment = Comment_1.default;
|
|
27
|
+
const bad_request_error_1 = __importDefault(require("./errors/bad-request-error"));
|
|
28
|
+
exports.BadRequestError = bad_request_error_1.default;
|
|
29
|
+
const database_connection_error_1 = __importDefault(require("./errors/database-connection-error"));
|
|
30
|
+
exports.DatabaseConnectionError = database_connection_error_1.default;
|
|
31
|
+
const custom_error_1 = __importDefault(require("./errors/custom-error"));
|
|
32
|
+
exports.CustomError = custom_error_1.default;
|
|
33
|
+
const not_authorized_error_1 = __importDefault(require("./errors/not-authorized-error"));
|
|
34
|
+
exports.NotAuthorizedError = not_authorized_error_1.default;
|
|
35
|
+
const not_found_error_1 = __importDefault(require("./errors/not-found-error"));
|
|
36
|
+
exports.NotFoundError = not_found_error_1.default;
|
|
37
|
+
const request_validation_error_1 = __importDefault(require("./errors/request-validation-error"));
|
|
38
|
+
exports.RequestValidationError = request_validation_error_1.default;
|
|
39
|
+
__exportStar(require("./middlewares/current-user"), exports);
|
|
40
|
+
__exportStar(require("./middlewares/error-handler"), exports);
|
|
41
|
+
__exportStar(require("./middlewares/require-auth"), exports);
|
|
42
|
+
__exportStar(require("./middlewares/validate-request"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from 'express';
|
|
2
|
+
interface UserPayload {
|
|
3
|
+
id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
}
|
|
6
|
+
declare global {
|
|
7
|
+
namespace Express {
|
|
8
|
+
interface Request {
|
|
9
|
+
currentUser?: UserPayload;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.currentUser = void 0;
|
|
4
|
+
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
5
|
+
const currentUser = (req, res, next) => {
|
|
6
|
+
var _a;
|
|
7
|
+
if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
|
|
8
|
+
return next();
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const payload = (0, jsonwebtoken_1.verify)(req.session.jwt, process.env.JWT_KEY);
|
|
12
|
+
req.currentUser = payload;
|
|
13
|
+
}
|
|
14
|
+
catch (error) { }
|
|
15
|
+
next();
|
|
16
|
+
};
|
|
17
|
+
exports.currentUser = currentUser;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.errorHandler = void 0;
|
|
7
|
+
const custom_error_1 = __importDefault(require("../errors/custom-error"));
|
|
8
|
+
const errorHandler = (err, req, res, next) => {
|
|
9
|
+
if (err instanceof custom_error_1.default) {
|
|
10
|
+
return res.status(err.statusCode).send({ errors: err.serializeErrors() });
|
|
11
|
+
}
|
|
12
|
+
console.error(err);
|
|
13
|
+
res.status(400).send({
|
|
14
|
+
errors: [{ message: 'Something went wrong' }],
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.errorHandler = errorHandler;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.requireAuth = void 0;
|
|
7
|
+
const not_authorized_error_1 = __importDefault(require("../errors/not-authorized-error"));
|
|
8
|
+
const requireAuth = (req, res, next) => {
|
|
9
|
+
if (!req.currentUser) {
|
|
10
|
+
throw new not_authorized_error_1.default();
|
|
11
|
+
}
|
|
12
|
+
next();
|
|
13
|
+
};
|
|
14
|
+
exports.requireAuth = requireAuth;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateRequest = void 0;
|
|
7
|
+
const express_validator_1 = require("express-validator");
|
|
8
|
+
const request_validation_error_1 = __importDefault(require("../errors/request-validation-error"));
|
|
9
|
+
const validateRequest = (req, res, next) => {
|
|
10
|
+
const errors = (0, express_validator_1.validationResult)(req);
|
|
11
|
+
if (!errors.isEmpty()) {
|
|
12
|
+
throw new request_validation_error_1.default(errors.array());
|
|
13
|
+
}
|
|
14
|
+
next();
|
|
15
|
+
};
|
|
16
|
+
exports.validateRequest = validateRequest;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
interface CommentAttributes {
|
|
3
|
+
idPost: string;
|
|
4
|
+
username: string;
|
|
5
|
+
likes: number;
|
|
6
|
+
upVotes: number;
|
|
7
|
+
downVotes: number;
|
|
8
|
+
reportNr: number;
|
|
9
|
+
contentUrl: string;
|
|
10
|
+
text: string;
|
|
11
|
+
}
|
|
12
|
+
interface CommentModel extends mongoose.Model<CommentDocument> {
|
|
13
|
+
build(attrs: CommentAttributes): CommentDocument;
|
|
14
|
+
}
|
|
15
|
+
interface CommentDocument extends mongoose.Document {
|
|
16
|
+
idPost: string;
|
|
17
|
+
username: string;
|
|
18
|
+
likes: number;
|
|
19
|
+
upVotes: number;
|
|
20
|
+
downVotes: number;
|
|
21
|
+
reportNr: number;
|
|
22
|
+
contentUrl: string;
|
|
23
|
+
text: string;
|
|
24
|
+
}
|
|
25
|
+
declare const Comment: CommentModel;
|
|
26
|
+
export default Comment;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const commentSchema = new mongoose_1.default.Schema({
|
|
8
|
+
idPost: {
|
|
9
|
+
type: String,
|
|
10
|
+
required: true,
|
|
11
|
+
},
|
|
12
|
+
username: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
likes: {
|
|
17
|
+
type: Number,
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
upVotes: {
|
|
21
|
+
type: Number,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
downVotes: {
|
|
25
|
+
type: Number,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
reportNr: {
|
|
29
|
+
type: Number,
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
contentUrl: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
text: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
}, {
|
|
41
|
+
toJSON: {
|
|
42
|
+
transform(doc, ret) {
|
|
43
|
+
ret.id = ret._id;
|
|
44
|
+
delete ret.__v;
|
|
45
|
+
delete ret._id;
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
commentSchema.statics.build = (attrs) => {
|
|
50
|
+
return new Comment(attrs);
|
|
51
|
+
};
|
|
52
|
+
const Comment = mongoose_1.default.model('Comment', commentSchema);
|
|
53
|
+
exports.default = Comment;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { PostType } from '../enums/PostType';
|
|
3
|
+
interface PostAttributes {
|
|
4
|
+
idUser: string;
|
|
5
|
+
username: string;
|
|
6
|
+
likes: number;
|
|
7
|
+
upVotes: number;
|
|
8
|
+
downVotes: number;
|
|
9
|
+
saved: number;
|
|
10
|
+
postType: PostType;
|
|
11
|
+
reportNr: number;
|
|
12
|
+
contentUrl: string;
|
|
13
|
+
text: string;
|
|
14
|
+
}
|
|
15
|
+
interface PostModel extends mongoose.Model<PostDocument> {
|
|
16
|
+
build(attrs: PostAttributes): PostDocument;
|
|
17
|
+
}
|
|
18
|
+
interface PostDocument extends mongoose.Document {
|
|
19
|
+
idUser: string;
|
|
20
|
+
username: string;
|
|
21
|
+
likes: number;
|
|
22
|
+
upVotes: number;
|
|
23
|
+
downVotes: number;
|
|
24
|
+
saved: number;
|
|
25
|
+
postType: PostType;
|
|
26
|
+
reportNr: number;
|
|
27
|
+
contentUrl: string;
|
|
28
|
+
text: string;
|
|
29
|
+
}
|
|
30
|
+
declare const Post: PostModel;
|
|
31
|
+
export default Post;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const postSchema = new mongoose_1.default.Schema({
|
|
8
|
+
idUser: {
|
|
9
|
+
type: String,
|
|
10
|
+
required: true,
|
|
11
|
+
},
|
|
12
|
+
username: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
likes: {
|
|
17
|
+
type: Number,
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
upVotes: {
|
|
21
|
+
type: Number,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
downVotes: {
|
|
25
|
+
type: Number,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
saved: {
|
|
29
|
+
type: Number,
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
postType: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
reportNr: {
|
|
37
|
+
type: Number,
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
contentUrl: {
|
|
41
|
+
type: String,
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
text: {
|
|
45
|
+
type: String,
|
|
46
|
+
required: true,
|
|
47
|
+
},
|
|
48
|
+
}, {
|
|
49
|
+
toJSON: {
|
|
50
|
+
transform(doc, ret) {
|
|
51
|
+
ret.id = ret._id;
|
|
52
|
+
delete ret.__v;
|
|
53
|
+
delete ret._id;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
postSchema.statics.build = (attrs) => {
|
|
58
|
+
return new Post(attrs);
|
|
59
|
+
};
|
|
60
|
+
const Post = mongoose_1.default.model('Post', postSchema);
|
|
61
|
+
exports.default = Post;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { AccountType } from '../enums/AccountType';
|
|
3
|
+
import { PaidPlan } from '../enums/PaidPlan';
|
|
4
|
+
interface UserAttributes {
|
|
5
|
+
email: string;
|
|
6
|
+
username: string;
|
|
7
|
+
password: string;
|
|
8
|
+
name: string;
|
|
9
|
+
accountType: AccountType;
|
|
10
|
+
surname: string;
|
|
11
|
+
followers: number;
|
|
12
|
+
following: number;
|
|
13
|
+
phoneNumber: string;
|
|
14
|
+
verified: boolean;
|
|
15
|
+
paidPlan: PaidPlan;
|
|
16
|
+
savedPosts: string[];
|
|
17
|
+
likedPosts: string[];
|
|
18
|
+
upVotedPosts: string[];
|
|
19
|
+
likedComments: string[];
|
|
20
|
+
bannedAccounts: string[];
|
|
21
|
+
reportedPosts: string[];
|
|
22
|
+
validReportedPosts: string[];
|
|
23
|
+
totalLikes: number;
|
|
24
|
+
totalUpVotes: number;
|
|
25
|
+
totalDownVotes: number;
|
|
26
|
+
location: string;
|
|
27
|
+
height: number;
|
|
28
|
+
weight: number;
|
|
29
|
+
profession: string;
|
|
30
|
+
grossIncome: number;
|
|
31
|
+
netIncome: number;
|
|
32
|
+
}
|
|
33
|
+
interface UserModel extends mongoose.Model<UserDocument> {
|
|
34
|
+
build(attrs: UserAttributes): UserDocument;
|
|
35
|
+
}
|
|
36
|
+
interface UserDocument extends mongoose.Document {
|
|
37
|
+
email: string;
|
|
38
|
+
username: string;
|
|
39
|
+
password: string;
|
|
40
|
+
name: string;
|
|
41
|
+
accountType: AccountType;
|
|
42
|
+
surname: string;
|
|
43
|
+
followers: number;
|
|
44
|
+
following: number;
|
|
45
|
+
phoneNumber: string;
|
|
46
|
+
verified: boolean;
|
|
47
|
+
paidPlan: PaidPlan;
|
|
48
|
+
savedPosts: string[];
|
|
49
|
+
likedPosts: string[];
|
|
50
|
+
upVotedPosts: string[];
|
|
51
|
+
likedComments: string[];
|
|
52
|
+
bannedAccounts: string[];
|
|
53
|
+
reportedPosts: string[];
|
|
54
|
+
validReportedPosts: string[];
|
|
55
|
+
totalLikes: number;
|
|
56
|
+
totalUpVotes: number;
|
|
57
|
+
totalDownVotes: number;
|
|
58
|
+
location: string;
|
|
59
|
+
height: number;
|
|
60
|
+
weight: number;
|
|
61
|
+
profession: string;
|
|
62
|
+
grossIncome: number;
|
|
63
|
+
netIncome: number;
|
|
64
|
+
}
|
|
65
|
+
declare const User: UserModel;
|
|
66
|
+
export default User;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
16
|
+
const password_1 = __importDefault(require("../utils/password"));
|
|
17
|
+
const userSchema = new mongoose_1.default.Schema({
|
|
18
|
+
email: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
unique: true,
|
|
22
|
+
},
|
|
23
|
+
username: {
|
|
24
|
+
type: String,
|
|
25
|
+
required: true,
|
|
26
|
+
unique: true,
|
|
27
|
+
},
|
|
28
|
+
password: {
|
|
29
|
+
type: String,
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
name: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
accountType: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
surname: {
|
|
41
|
+
type: String,
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
followers: {
|
|
45
|
+
type: Number,
|
|
46
|
+
required: true,
|
|
47
|
+
},
|
|
48
|
+
following: {
|
|
49
|
+
type: Number,
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
phoneNumber: {
|
|
53
|
+
type: String,
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
verified: {
|
|
57
|
+
type: Boolean,
|
|
58
|
+
required: true,
|
|
59
|
+
},
|
|
60
|
+
paidPlan: {
|
|
61
|
+
type: String,
|
|
62
|
+
required: true,
|
|
63
|
+
},
|
|
64
|
+
savedPosts: {
|
|
65
|
+
type: Array,
|
|
66
|
+
required: true,
|
|
67
|
+
},
|
|
68
|
+
likedPosts: {
|
|
69
|
+
type: Array,
|
|
70
|
+
required: true,
|
|
71
|
+
},
|
|
72
|
+
upVotedPosts: {
|
|
73
|
+
type: Array,
|
|
74
|
+
required: true,
|
|
75
|
+
},
|
|
76
|
+
likedComments: {
|
|
77
|
+
type: Array,
|
|
78
|
+
required: true,
|
|
79
|
+
},
|
|
80
|
+
bannedAccounts: {
|
|
81
|
+
type: Array,
|
|
82
|
+
required: true,
|
|
83
|
+
},
|
|
84
|
+
reportedPosts: {
|
|
85
|
+
type: Array,
|
|
86
|
+
required: true,
|
|
87
|
+
},
|
|
88
|
+
validReportedPosts: {
|
|
89
|
+
type: Array,
|
|
90
|
+
required: true,
|
|
91
|
+
},
|
|
92
|
+
totalLikes: {
|
|
93
|
+
type: Number,
|
|
94
|
+
required: true,
|
|
95
|
+
},
|
|
96
|
+
totalUpVotes: {
|
|
97
|
+
type: Number,
|
|
98
|
+
required: true,
|
|
99
|
+
},
|
|
100
|
+
totalDownVotes: {
|
|
101
|
+
type: Number,
|
|
102
|
+
required: true,
|
|
103
|
+
},
|
|
104
|
+
location: {
|
|
105
|
+
type: String,
|
|
106
|
+
required: true,
|
|
107
|
+
},
|
|
108
|
+
height: {
|
|
109
|
+
type: Number,
|
|
110
|
+
required: true,
|
|
111
|
+
},
|
|
112
|
+
weight: {
|
|
113
|
+
type: Number,
|
|
114
|
+
required: true,
|
|
115
|
+
},
|
|
116
|
+
profession: {
|
|
117
|
+
type: String,
|
|
118
|
+
required: true,
|
|
119
|
+
},
|
|
120
|
+
grossIncome: {
|
|
121
|
+
type: Number,
|
|
122
|
+
required: true,
|
|
123
|
+
},
|
|
124
|
+
netIncome: {
|
|
125
|
+
type: Number,
|
|
126
|
+
required: true,
|
|
127
|
+
},
|
|
128
|
+
}, {
|
|
129
|
+
toJSON: {
|
|
130
|
+
transform(doc, ret) {
|
|
131
|
+
ret.id = ret._id;
|
|
132
|
+
delete ret.password;
|
|
133
|
+
delete ret.__v;
|
|
134
|
+
delete ret._id;
|
|
135
|
+
delete ret.followers;
|
|
136
|
+
delete ret.following;
|
|
137
|
+
delete ret.phoneNumber;
|
|
138
|
+
delete ret.verified;
|
|
139
|
+
delete ret.paidPlan;
|
|
140
|
+
delete ret.savedPosts;
|
|
141
|
+
delete ret.likedPosts;
|
|
142
|
+
delete ret.upVotedPosts;
|
|
143
|
+
delete ret.likedComments;
|
|
144
|
+
delete ret.bannedAccounts;
|
|
145
|
+
delete ret.reportedPosts;
|
|
146
|
+
delete ret.validReportedPosts;
|
|
147
|
+
delete ret.totalLikes;
|
|
148
|
+
delete ret.totalUpVotes;
|
|
149
|
+
delete ret.totalDownVotes;
|
|
150
|
+
delete ret.location;
|
|
151
|
+
delete ret.height;
|
|
152
|
+
delete ret.weight;
|
|
153
|
+
delete ret.profession;
|
|
154
|
+
delete ret.grossIncome;
|
|
155
|
+
delete ret.netIncome;
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
userSchema.pre('save', function (done) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
if (this.isModified('password')) {
|
|
162
|
+
const hashedPassword = yield password_1.default.toHash(this.get('password'));
|
|
163
|
+
this.set('password', hashedPassword);
|
|
164
|
+
}
|
|
165
|
+
done();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
userSchema.statics.build = (attrs) => {
|
|
169
|
+
return new User(attrs);
|
|
170
|
+
};
|
|
171
|
+
const User = mongoose_1.default.model('User', userSchema);
|
|
172
|
+
exports.default = User;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const crypto_1 = require("crypto");
|
|
13
|
+
const util_1 = require("util");
|
|
14
|
+
const scryptAsync = (0, util_1.promisify)(crypto_1.scrypt);
|
|
15
|
+
class Password {
|
|
16
|
+
static toHash(password) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const salt = (0, crypto_1.randomBytes)(16).toString('hex');
|
|
19
|
+
const buffer = (yield scryptAsync(password, salt, 64));
|
|
20
|
+
return `${buffer.toString('hex')}.${salt}`;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
static compare(storedPassword, suppliedPassword) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const [hashedPassword, salt] = storedPassword.split('.');
|
|
26
|
+
const buffer = (yield scryptAsync(suppliedPassword, salt, 64));
|
|
27
|
+
return buffer.toString('hex') === hashedPassword;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = Password;
|
package/package.json
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@armi-wave/common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "./
|
|
5
|
+
"main": "./build/index.js",
|
|
6
|
+
"types": "./build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build/**/*"
|
|
9
|
+
],
|
|
6
10
|
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"pub": "git add . && git commit -m \"Updates\" && npm version feature && npm run build && npm publish"
|
|
8
14
|
},
|
|
9
15
|
"author": "Armiron Kurbalaj",
|
|
10
|
-
"license": "ISC"
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"express": "^4.18.1",
|
|
19
|
+
"express-validator": "^6.14.2",
|
|
20
|
+
"jsonwebtoken": "^8.5.1"
|
|
21
|
+
}
|
|
11
22
|
}
|
package/src/index.ts
DELETED
package/src/models/User.ts
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import mongoose, { ObjectId } from 'mongoose';
|
|
2
|
-
import Password from '../utils/password';
|
|
3
|
-
|
|
4
|
-
interface UserAttributes {
|
|
5
|
-
email: string;
|
|
6
|
-
username: string;
|
|
7
|
-
password: string;
|
|
8
|
-
name: string;
|
|
9
|
-
surname: string;
|
|
10
|
-
followers: number;
|
|
11
|
-
following: number;
|
|
12
|
-
phoneNumber: string;
|
|
13
|
-
verified: boolean;
|
|
14
|
-
paidPlan: string;
|
|
15
|
-
savedPosts: ObjectId[];
|
|
16
|
-
likedPosts: ObjectId[];
|
|
17
|
-
upVotedPosts: ObjectId[];
|
|
18
|
-
likedComments: ObjectId[];
|
|
19
|
-
bannedAccounts: ObjectId[];
|
|
20
|
-
reportedPosts: ObjectId[];
|
|
21
|
-
validReportedPosts: ObjectId[];
|
|
22
|
-
totalLikes: number;
|
|
23
|
-
totalUpVotes: number;
|
|
24
|
-
totalDownVotes: number;
|
|
25
|
-
location: string;
|
|
26
|
-
height: number;
|
|
27
|
-
weight: number;
|
|
28
|
-
profession: string;
|
|
29
|
-
grossIncome: number;
|
|
30
|
-
netIncome: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface UserModel extends mongoose.Model<UserDocument> {
|
|
34
|
-
build(attrs: UserAttributes): UserDocument;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface UserDocument extends mongoose.Document {
|
|
38
|
-
email: string;
|
|
39
|
-
username: string;
|
|
40
|
-
password: string;
|
|
41
|
-
name: string;
|
|
42
|
-
surname: string;
|
|
43
|
-
followers: number;
|
|
44
|
-
following: number;
|
|
45
|
-
phoneNumber: string;
|
|
46
|
-
verified: boolean;
|
|
47
|
-
paidPlan: string;
|
|
48
|
-
savedPosts: ObjectId[];
|
|
49
|
-
likedPosts: ObjectId[];
|
|
50
|
-
upVotedPosts: ObjectId[];
|
|
51
|
-
likedComments: ObjectId[];
|
|
52
|
-
bannedAccounts: ObjectId[];
|
|
53
|
-
reportedPosts: ObjectId[];
|
|
54
|
-
validReportedPosts: ObjectId[];
|
|
55
|
-
totalLikes: number;
|
|
56
|
-
totalUpVotes: number;
|
|
57
|
-
totalDownVotes: number;
|
|
58
|
-
location: string;
|
|
59
|
-
height: number;
|
|
60
|
-
weight: number;
|
|
61
|
-
profession: string;
|
|
62
|
-
grossIncome: number;
|
|
63
|
-
netIncome: number;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const userSchema = new mongoose.Schema(
|
|
67
|
-
{
|
|
68
|
-
email: {
|
|
69
|
-
type: String,
|
|
70
|
-
required: true,
|
|
71
|
-
unique: true,
|
|
72
|
-
},
|
|
73
|
-
username: {
|
|
74
|
-
type: String,
|
|
75
|
-
required: true,
|
|
76
|
-
unique: true,
|
|
77
|
-
},
|
|
78
|
-
password: {
|
|
79
|
-
type: String,
|
|
80
|
-
required: true,
|
|
81
|
-
},
|
|
82
|
-
name: {
|
|
83
|
-
type: String,
|
|
84
|
-
required: true,
|
|
85
|
-
},
|
|
86
|
-
surname: {
|
|
87
|
-
type: String,
|
|
88
|
-
required: true,
|
|
89
|
-
},
|
|
90
|
-
followers: {
|
|
91
|
-
type: Number,
|
|
92
|
-
required: true,
|
|
93
|
-
},
|
|
94
|
-
following: {
|
|
95
|
-
type: Number,
|
|
96
|
-
required: true,
|
|
97
|
-
},
|
|
98
|
-
phoneNumber: {
|
|
99
|
-
type: String,
|
|
100
|
-
required: true,
|
|
101
|
-
},
|
|
102
|
-
verified: {
|
|
103
|
-
type: Boolean,
|
|
104
|
-
required: true,
|
|
105
|
-
},
|
|
106
|
-
paidPlan: {
|
|
107
|
-
type: String,
|
|
108
|
-
required: true,
|
|
109
|
-
},
|
|
110
|
-
savedPosts: {
|
|
111
|
-
type: Array,
|
|
112
|
-
required: true,
|
|
113
|
-
},
|
|
114
|
-
likedPosts: {
|
|
115
|
-
type: Array,
|
|
116
|
-
required: true,
|
|
117
|
-
},
|
|
118
|
-
upVotedPosts: {
|
|
119
|
-
type: Array,
|
|
120
|
-
required: true,
|
|
121
|
-
},
|
|
122
|
-
likedComments: {
|
|
123
|
-
type: Array,
|
|
124
|
-
required: true,
|
|
125
|
-
},
|
|
126
|
-
bannedAccounts: {
|
|
127
|
-
type: Array,
|
|
128
|
-
required: true,
|
|
129
|
-
},
|
|
130
|
-
reportedPosts: {
|
|
131
|
-
type: Array,
|
|
132
|
-
required: true,
|
|
133
|
-
},
|
|
134
|
-
validReportedPosts: {
|
|
135
|
-
type: Array,
|
|
136
|
-
required: true,
|
|
137
|
-
},
|
|
138
|
-
totalLikes: {
|
|
139
|
-
type: Number,
|
|
140
|
-
required: true,
|
|
141
|
-
},
|
|
142
|
-
totalUpVotes: {
|
|
143
|
-
type: Number,
|
|
144
|
-
required: true,
|
|
145
|
-
},
|
|
146
|
-
totalDownVotes: {
|
|
147
|
-
type: Number,
|
|
148
|
-
required: true,
|
|
149
|
-
},
|
|
150
|
-
location: {
|
|
151
|
-
type: String,
|
|
152
|
-
required: true,
|
|
153
|
-
},
|
|
154
|
-
height: {
|
|
155
|
-
type: Number,
|
|
156
|
-
required: true,
|
|
157
|
-
},
|
|
158
|
-
weight: {
|
|
159
|
-
type: Number,
|
|
160
|
-
required: true,
|
|
161
|
-
},
|
|
162
|
-
profession: {
|
|
163
|
-
type: String,
|
|
164
|
-
required: true,
|
|
165
|
-
},
|
|
166
|
-
grossIncome: {
|
|
167
|
-
type: Number,
|
|
168
|
-
required: true,
|
|
169
|
-
},
|
|
170
|
-
netIncome: {
|
|
171
|
-
type: Number,
|
|
172
|
-
required: true,
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
toJSON: {
|
|
177
|
-
transform(doc, ret) {
|
|
178
|
-
ret.id = ret._id;
|
|
179
|
-
delete ret.password;
|
|
180
|
-
delete ret.__v;
|
|
181
|
-
delete ret._id;
|
|
182
|
-
delete ret.followers;
|
|
183
|
-
delete ret.following;
|
|
184
|
-
delete ret.phoneNumber;
|
|
185
|
-
delete ret.verified;
|
|
186
|
-
delete ret.paidPlan;
|
|
187
|
-
delete ret.savedPosts;
|
|
188
|
-
delete ret.likedPosts;
|
|
189
|
-
delete ret.upVotedPosts;
|
|
190
|
-
delete ret.likedComments;
|
|
191
|
-
delete ret.bannedAccounts;
|
|
192
|
-
delete ret.reportedPosts;
|
|
193
|
-
delete ret.validReportedPosts;
|
|
194
|
-
delete ret.totalLikes;
|
|
195
|
-
delete ret.totalUpVotes;
|
|
196
|
-
delete ret.totalDownVotes;
|
|
197
|
-
delete ret.location;
|
|
198
|
-
delete ret.height;
|
|
199
|
-
delete ret.weight;
|
|
200
|
-
delete ret.profession;
|
|
201
|
-
delete ret.grossIncome;
|
|
202
|
-
delete ret.netIncome;
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
userSchema.pre('save', async function (done) {
|
|
209
|
-
if (this.isModified('password')) {
|
|
210
|
-
const hashedPassword = await Password.toHash(this.get('password'));
|
|
211
|
-
this.set('password', hashedPassword);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
done();
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
userSchema.statics.build = (attrs: UserAttributes) => {
|
|
218
|
-
return new User(attrs);
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const User = mongoose.model<UserDocument, UserModel>('User', userSchema);
|
|
222
|
-
|
|
223
|
-
export default User;
|
package/src/utils/password.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { scrypt, randomBytes } from 'crypto';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
|
-
|
|
4
|
-
const scryptAsync = promisify(scrypt);
|
|
5
|
-
|
|
6
|
-
export default class Password {
|
|
7
|
-
static async toHash(password: string) {
|
|
8
|
-
const salt = randomBytes(16).toString('hex');
|
|
9
|
-
const buffer = (await scryptAsync(password, salt, 64)) as Buffer;
|
|
10
|
-
|
|
11
|
-
return `${buffer.toString('hex')}.${salt}`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
static async compare(storedPassword: string, suppliedPassword: string) {
|
|
15
|
-
const [hashedPassword, salt] = storedPassword.split('.');
|
|
16
|
-
const buffer = (await scryptAsync(suppliedPassword, salt, 64)) as Buffer;
|
|
17
|
-
return buffer.toString('hex') === hashedPassword;
|
|
18
|
-
}
|
|
19
|
-
}
|