@feardread/fear 1.0.1
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/FEAR.js +459 -0
- package/FEARServer.js +280 -0
- package/controllers/agent.js +438 -0
- package/controllers/auth/index.js +345 -0
- package/controllers/auth/token.js +50 -0
- package/controllers/blog.js +105 -0
- package/controllers/brand.js +10 -0
- package/controllers/cart.js +425 -0
- package/controllers/category.js +9 -0
- package/controllers/coupon.js +63 -0
- package/controllers/crud/crud.js +508 -0
- package/controllers/crud/index.js +36 -0
- package/controllers/email.js +34 -0
- package/controllers/enquiry.js +65 -0
- package/controllers/events.js +9 -0
- package/controllers/order.js +125 -0
- package/controllers/payment.js +31 -0
- package/controllers/product.js +147 -0
- package/controllers/review.js +247 -0
- package/controllers/tag.js +10 -0
- package/controllers/task.js +10 -0
- package/controllers/upload.js +41 -0
- package/controllers/user.js +401 -0
- package/index.js +7 -0
- package/libs/agent/index.js +561 -0
- package/libs/agent/modules/ai/ai.js +285 -0
- package/libs/agent/modules/ai/chat.js +518 -0
- package/libs/agent/modules/ai/config.js +688 -0
- package/libs/agent/modules/ai/operations.js +787 -0
- package/libs/agent/modules/analyze/api.js +546 -0
- package/libs/agent/modules/analyze/dorks.js +395 -0
- package/libs/agent/modules/ccard/README.md +454 -0
- package/libs/agent/modules/ccard/audit.js +479 -0
- package/libs/agent/modules/ccard/checker.js +674 -0
- package/libs/agent/modules/ccard/payment-processors.json +16 -0
- package/libs/agent/modules/ccard/validator.js +629 -0
- package/libs/agent/modules/code/analyzer.js +303 -0
- package/libs/agent/modules/code/jquery.js +1093 -0
- package/libs/agent/modules/code/react.js +1536 -0
- package/libs/agent/modules/code/refactor.js +499 -0
- package/libs/agent/modules/crypto/exchange.js +564 -0
- package/libs/agent/modules/net/proxy.js +409 -0
- package/libs/agent/modules/security/cve.js +442 -0
- package/libs/agent/modules/security/monitor.js +360 -0
- package/libs/agent/modules/security/scanner.js +300 -0
- package/libs/agent/modules/security/vulnerability.js +506 -0
- package/libs/agent/modules/security/web.js +465 -0
- package/libs/agent/modules/utils/browser.js +492 -0
- package/libs/agent/modules/utils/colorizer.js +285 -0
- package/libs/agent/modules/utils/manager.js +478 -0
- package/libs/cloud/index.js +228 -0
- package/libs/config/db.js +21 -0
- package/libs/config/validator.js +82 -0
- package/libs/db/index.js +318 -0
- package/libs/emailer/imap.js +126 -0
- package/libs/emailer/info.js +41 -0
- package/libs/emailer/smtp.js +77 -0
- package/libs/handler/async.js +3 -0
- package/libs/handler/error.js +66 -0
- package/libs/handler/index.js +161 -0
- package/libs/logger/index.js +49 -0
- package/libs/logger/morgan.js +24 -0
- package/libs/passport/passport.js +109 -0
- package/libs/search/api.js +384 -0
- package/libs/search/features.js +219 -0
- package/libs/search/service.js +64 -0
- package/libs/swagger/config.js +18 -0
- package/libs/swagger/index.js +35 -0
- package/libs/validator/index.js +254 -0
- package/models/blog.js +31 -0
- package/models/brand.js +12 -0
- package/models/cart.js +14 -0
- package/models/category.js +11 -0
- package/models/coupon.js +9 -0
- package/models/customer.js +0 -0
- package/models/enquiry.js +29 -0
- package/models/events.js +13 -0
- package/models/order.js +94 -0
- package/models/product.js +32 -0
- package/models/review.js +14 -0
- package/models/tag.js +10 -0
- package/models/task.js +11 -0
- package/models/user.js +68 -0
- package/package.json +12 -0
- package/routes/agent.js +615 -0
- package/routes/auth.js +13 -0
- package/routes/blog.js +19 -0
- package/routes/brand.js +15 -0
- package/routes/cart.js +105 -0
- package/routes/category.js +16 -0
- package/routes/coupon.js +15 -0
- package/routes/enquiry.js +14 -0
- package/routes/events.js +16 -0
- package/routes/mail.js +170 -0
- package/routes/order.js +19 -0
- package/routes/product.js +22 -0
- package/routes/review.js +11 -0
- package/routes/task.js +12 -0
- package/routes/user.js +17 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
exports.AppError = class AppError extends Error {
|
|
4
|
+
constructor( message, statusCode ) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.statusCode = statusCode;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
Catch Errors Handler
|
|
12
|
+
|
|
13
|
+
With async/await, you need some way to catch errors
|
|
14
|
+
Instead of using try{} catch(e) {} in each controller, we wrap the function in
|
|
15
|
+
catchErrors(), catch any errors they throw, and pass it along to our express middleware with next()
|
|
16
|
+
*/
|
|
17
|
+
exports.tryCatch = (fn) => {
|
|
18
|
+
return function (req, res, next) {
|
|
19
|
+
const resp = fn(req, res, next);
|
|
20
|
+
if (resp instanceof Promise) {
|
|
21
|
+
return resp.catch(next);
|
|
22
|
+
}
|
|
23
|
+
return next(resp);
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
Not Found Error Handler
|
|
29
|
+
|
|
30
|
+
If we hit a route that is not found, we mark it as 404 and pass it along to the next error handler to display
|
|
31
|
+
*/
|
|
32
|
+
exports.notFound = (req, res, next) => {
|
|
33
|
+
res.status(404).json({
|
|
34
|
+
success: false,
|
|
35
|
+
message: "Api url doesn't exist ",
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
Development Error Handler
|
|
41
|
+
|
|
42
|
+
In development we show good error messages so if we hit a syntax error or any other previously un-handled error, we can show good info on what happened
|
|
43
|
+
*/
|
|
44
|
+
exports.development = (err, req, res, next) => {
|
|
45
|
+
err.stack = err.stack || "";
|
|
46
|
+
const errorDetails = {
|
|
47
|
+
message: err.message,
|
|
48
|
+
status: err.status,
|
|
49
|
+
stackHighlighted: err.stack.replace(
|
|
50
|
+
/[a-z_-\d]+.js:\d+:\d+/gi,
|
|
51
|
+
"<mark>$&</mark>"
|
|
52
|
+
),
|
|
53
|
+
};
|
|
54
|
+
console.log("Error Details = ", err);
|
|
55
|
+
res.status(500).json({ success: false, errorDetails });
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
Production Error Handler
|
|
60
|
+
|
|
61
|
+
No stacktraces are leaked to admin
|
|
62
|
+
*/
|
|
63
|
+
exports.production = (err, req, res, next) => {
|
|
64
|
+
res.status(500).json({ success: false, message: "Oops ! Error in Server" });
|
|
65
|
+
};
|
|
66
|
+
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Application Error class
|
|
3
|
+
* Extends the built-in Error class with HTTP status codes
|
|
4
|
+
*/
|
|
5
|
+
class AppError extends Error {
|
|
6
|
+
constructor(message, statusCode = 500) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = this.constructor.name;
|
|
9
|
+
this.statusCode = statusCode;
|
|
10
|
+
this.isOperational = true; // Distinguishes operational errors from programming errors
|
|
11
|
+
|
|
12
|
+
Error.captureStackTrace(this, this.constructor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Async Error Handler Wrapper
|
|
18
|
+
* Wraps async route handlers to automatically catch and forward errors
|
|
19
|
+
* @param {Function} asyncFn - The async function to wrap
|
|
20
|
+
* @returns {Function} Express middleware function
|
|
21
|
+
*/
|
|
22
|
+
const asyncHandler = (fn) => {
|
|
23
|
+
return (req, res, next) => {
|
|
24
|
+
Promise.resolve(fn(req, res, next)).catch(next);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 404 Not Found Handler
|
|
30
|
+
* Handles requests to non-existent routes
|
|
31
|
+
*/
|
|
32
|
+
const notFoundHandler = (req, res, next) => {
|
|
33
|
+
const error = new AppError(`Route ${req.originalUrl} not found`, 404);
|
|
34
|
+
next(error);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const successResponse = (res, obj) => {3
|
|
38
|
+
const strip = (text) => text.replace(/\x1b\[[0-9;]*m/g, '')
|
|
39
|
+
|
|
40
|
+
if (obj.output) {
|
|
41
|
+
obj.output = strip(obj.output);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return res.status(200).json(obj);
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Development Error Handler
|
|
49
|
+
* Provides detailed error information for debugging
|
|
50
|
+
*/
|
|
51
|
+
const developmentErrorHandler = (err, req, res, next) => {
|
|
52
|
+
const statusCode = err.statusCode || 500;
|
|
53
|
+
|
|
54
|
+
console.error('Error Details:', {
|
|
55
|
+
message: err.message,
|
|
56
|
+
stack: err.stack,
|
|
57
|
+
url: req.originalUrl,
|
|
58
|
+
method: req.method,
|
|
59
|
+
ip: req.ip,
|
|
60
|
+
userAgent: req.get('User-Agent')
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const response = {
|
|
64
|
+
success: false,
|
|
65
|
+
error: {
|
|
66
|
+
message: err.message,
|
|
67
|
+
statusCode,
|
|
68
|
+
stack: err.stack,
|
|
69
|
+
details: {
|
|
70
|
+
url: req.originalUrl,
|
|
71
|
+
method: req.method,
|
|
72
|
+
timestamp: new Date().toISOString()
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
res.status(statusCode).json(response);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Production Error Handler
|
|
82
|
+
* Provides sanitized error responses for production
|
|
83
|
+
*/
|
|
84
|
+
const productionErrorHandler = (err, req, res, next) => {
|
|
85
|
+
const statusCode = err.statusCode || 500;
|
|
86
|
+
|
|
87
|
+
// Log error details for monitoring (but don't expose to client)
|
|
88
|
+
console.error('Production Error:', {
|
|
89
|
+
message: err.message,
|
|
90
|
+
stack: err.stack,
|
|
91
|
+
url: req.originalUrl,
|
|
92
|
+
method: req.method,
|
|
93
|
+
ip: req.ip,
|
|
94
|
+
timestamp: new Date().toISOString()
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
let message = 'Internal Server Error';
|
|
98
|
+
|
|
99
|
+
// Only expose operational errors to clients
|
|
100
|
+
if (err.isOperational) {
|
|
101
|
+
message = err.message;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Handle specific error types
|
|
105
|
+
if (statusCode === 404) {
|
|
106
|
+
message = 'Resource not found';
|
|
107
|
+
} else if (statusCode === 401) {
|
|
108
|
+
message = 'Unauthorized access';
|
|
109
|
+
} else if (statusCode === 403) {
|
|
110
|
+
message = 'Forbidden';
|
|
111
|
+
} else if (statusCode === 400) {
|
|
112
|
+
message = err.message; // Usually safe to expose validation errors
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const response = {
|
|
116
|
+
success: false,
|
|
117
|
+
error: {
|
|
118
|
+
message,
|
|
119
|
+
statusCode
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
res.status(statusCode).json(response);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Global Error Handler
|
|
128
|
+
* Determines which error handler to use based on environment
|
|
129
|
+
*/
|
|
130
|
+
const globalErrorHandler = (err, req, res, next) => {
|
|
131
|
+
// Handle specific error types
|
|
132
|
+
if (err.name === 'ValidationError') {
|
|
133
|
+
err.statusCode = 400;
|
|
134
|
+
err.isOperational = true;
|
|
135
|
+
} else if (err.name === 'CastError') {
|
|
136
|
+
err.statusCode = 400;
|
|
137
|
+
err.message = 'Invalid ID format';
|
|
138
|
+
err.isOperational = true;
|
|
139
|
+
} else if (err.code === 11000) {
|
|
140
|
+
// MongoDB duplicate key error
|
|
141
|
+
err.statusCode = 400;
|
|
142
|
+
err.message = 'Duplicate field value';
|
|
143
|
+
err.isOperational = true;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (process.env.NODE_ENV === 'development') {
|
|
147
|
+
developmentErrorHandler(err, req, res, next);
|
|
148
|
+
} else {
|
|
149
|
+
productionErrorHandler(err, req, res, next);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
module.exports = {
|
|
154
|
+
error: () => new AppError,
|
|
155
|
+
success: successResponse,
|
|
156
|
+
global: globalErrorHandler,
|
|
157
|
+
production: productionErrorHandler,
|
|
158
|
+
development: developmentErrorHandler,
|
|
159
|
+
async: asyncHandler,
|
|
160
|
+
notFound: notFoundHandler
|
|
161
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const winston = require('winston');
|
|
2
|
+
const levels = {
|
|
3
|
+
error: 0,
|
|
4
|
+
warn: 1,
|
|
5
|
+
info: 2,
|
|
6
|
+
http: 3,
|
|
7
|
+
debug: 4,
|
|
8
|
+
}
|
|
9
|
+
const level = () => {
|
|
10
|
+
const env = process.env.NODE_ENV || 'development'
|
|
11
|
+
const isDevelopment = env === 'development'
|
|
12
|
+
return isDevelopment ? 'debug' : 'warn'
|
|
13
|
+
}
|
|
14
|
+
const colors = {
|
|
15
|
+
error: 'red',
|
|
16
|
+
warn: 'yellow',
|
|
17
|
+
info: 'green',
|
|
18
|
+
http: 'magenta',
|
|
19
|
+
debug: 'white',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
winston.addColors(colors)
|
|
23
|
+
|
|
24
|
+
const format = winston.format.combine(
|
|
25
|
+
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss:ms' }),
|
|
26
|
+
winston.format.colorize({ all: true }),
|
|
27
|
+
winston.format.printf(
|
|
28
|
+
(info) => `${info.timestamp} ${info.level}: ${info.message}`,
|
|
29
|
+
),
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const transports = [
|
|
34
|
+
new winston.transports.Console(),
|
|
35
|
+
// new winston.transports.File({
|
|
36
|
+
// filename: 'logs/error.log',
|
|
37
|
+
// level: 'error',
|
|
38
|
+
// }),
|
|
39
|
+
// new winston.transports.File({ filename: 'logs/all.log' }),
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const logger = winston.createLogger({
|
|
43
|
+
level: level(),
|
|
44
|
+
levels,
|
|
45
|
+
format,
|
|
46
|
+
transports,
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
module.exports = logger
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const morgan = require("morgan");
|
|
2
|
+
const logger = require("../logger");
|
|
3
|
+
|
|
4
|
+
const stream = {
|
|
5
|
+
write: (message) => logger.http(message),
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const skip = () => {
|
|
9
|
+
const env = process.env.NODE_ENV || "development";
|
|
10
|
+
return env !== "development";
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const middleware = morgan(
|
|
14
|
+
// Define message format string (this is the default one).
|
|
15
|
+
// The message format is made from tokens, and each token is
|
|
16
|
+
// defined inside the Morgan library.
|
|
17
|
+
// You can create your custom token to show what do you want from a request.
|
|
18
|
+
":remote-addr :method :url :status :res[content-length] - :response-time ms",
|
|
19
|
+
// Options: in this case, I overwrote the stream and the skip logic.
|
|
20
|
+
// See the methods above.
|
|
21
|
+
{ stream, skip }
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
module.exports = middleware;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// needed for local authentication
|
|
2
|
+
const passport = require("passport");
|
|
3
|
+
const LocalStrategy = require("passport-local").Strategy;
|
|
4
|
+
const FacebookStrategy = require("passport-facebook").Strategy;
|
|
5
|
+
const secret = require("../config/secret");
|
|
6
|
+
const User = require("../models/user");
|
|
7
|
+
const async = require("async");
|
|
8
|
+
const Cart = require("../models/cart");
|
|
9
|
+
|
|
10
|
+
// serialize and deserialize
|
|
11
|
+
passport.serializeUser((user, done) => {
|
|
12
|
+
done(null, user);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
passport.deserializeUser((id, done) => {
|
|
16
|
+
User.findById(id, (err, user) => {
|
|
17
|
+
done(err, user);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// custom function validate
|
|
22
|
+
exports.isAuthenticated = (req, res, next) => {
|
|
23
|
+
if (req.isAuthenticated()) {
|
|
24
|
+
return next();
|
|
25
|
+
}
|
|
26
|
+
res.redirect("/login");
|
|
27
|
+
};
|
|
28
|
+
// give the middleware a name, and create a new anonymous instance of LocalStrategy
|
|
29
|
+
passport.use(
|
|
30
|
+
"login",
|
|
31
|
+
new LocalStrategy(
|
|
32
|
+
{
|
|
33
|
+
usernameField: "email",
|
|
34
|
+
passwordField: "password",
|
|
35
|
+
passReqToCallback: true,
|
|
36
|
+
},
|
|
37
|
+
(req, email, password, done) => {
|
|
38
|
+
// find a specific email
|
|
39
|
+
User.findOne({ email: email }, (err, user) => {
|
|
40
|
+
// incase of an error return a callback
|
|
41
|
+
if (err) return done(err);
|
|
42
|
+
|
|
43
|
+
if (!user) {
|
|
44
|
+
return done(
|
|
45
|
+
null,
|
|
46
|
+
false,
|
|
47
|
+
req.flash("loginMessage", "No user with such credentials found")
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// compare user provided password and the database one
|
|
52
|
+
if (!user.comparePassword(password)) {
|
|
53
|
+
return done(
|
|
54
|
+
null,
|
|
55
|
+
false,
|
|
56
|
+
req.flash("loginMessage", "Oops! Wrong credentials")
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// return user object
|
|
61
|
+
return done(null, user);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
passport.use(
|
|
68
|
+
new FacebookStrategy(
|
|
69
|
+
secret.facebook,
|
|
70
|
+
(token, refreshToken, profile, done) => {
|
|
71
|
+
User.findOne({ facebook: profile.id }, (err, user) => {
|
|
72
|
+
if (err) return next(err);
|
|
73
|
+
|
|
74
|
+
if (user) {
|
|
75
|
+
return done(null, user);
|
|
76
|
+
} else {
|
|
77
|
+
async.waterfall([
|
|
78
|
+
(callback) => {
|
|
79
|
+
const newUser = new User();
|
|
80
|
+
newUser.email = profile._json.email;
|
|
81
|
+
newUser.facebook = profile.id;
|
|
82
|
+
newUser.tokens.push({ kind: "facebook", token: token });
|
|
83
|
+
newUser.profile.name = profile.displayName;
|
|
84
|
+
newUser.profile.picture =
|
|
85
|
+
"https://graph.facebook.com/" +
|
|
86
|
+
profile.id +
|
|
87
|
+
"/picture?type=large";
|
|
88
|
+
|
|
89
|
+
newUser.save((err) => {
|
|
90
|
+
if (err) return next(err);
|
|
91
|
+
callback(err, newUser._id);
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
(newUser) => {
|
|
95
|
+
const cart = new Cart();
|
|
96
|
+
|
|
97
|
+
cart.owner = newUser._id;
|
|
98
|
+
cart.save((err) => {
|
|
99
|
+
if (err) return done(err);
|
|
100
|
+
return done(err, newUser);
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
|