nexus-backend 1.1.1 → 1.1.3
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/README.md +522 -349
- package/dist/index.d.mts +2 -22
- package/dist/index.d.ts +2 -22
- package/dist/index.js +7 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +35 -35
package/dist/index.d.mts
CHANGED
|
@@ -33,33 +33,13 @@ interface MongoConfig {
|
|
|
33
33
|
|
|
34
34
|
declare const connectMongoDb: (config: MongoConfig) => Promise<boolean>;
|
|
35
35
|
|
|
36
|
-
declare class
|
|
36
|
+
declare class NexusError extends Error {
|
|
37
37
|
statusCode: number;
|
|
38
38
|
isOperational: boolean;
|
|
39
39
|
errors?: any;
|
|
40
40
|
constructor(message: string, statusCode?: number, errors?: any, isOperational?: boolean);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
declare class BadRequestError extends ApiError {
|
|
44
|
-
constructor(message?: string, errors?: any);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
declare class UnauthorizedError extends ApiError {
|
|
48
|
-
constructor(message?: string, errors?: any);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
declare class ForbiddenError extends ApiError {
|
|
52
|
-
constructor(message?: string, errors?: any);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
declare class NotFoundError extends ApiError {
|
|
56
|
-
constructor(message?: string, errors?: any);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
declare class ValidationError extends ApiError {
|
|
60
|
-
constructor(message?: string, errors?: any);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
43
|
declare const errorHandler: [
|
|
64
44
|
(req: Request, res: Response, next: NextFunction) => void,
|
|
65
45
|
(err: any, req: Request, res: Response, next: NextFunction) => void
|
|
@@ -118,4 +98,4 @@ declare const uploader: {
|
|
|
118
98
|
getNexusDownloadUrl: (fileId: string) => Promise<string>;
|
|
119
99
|
};
|
|
120
100
|
|
|
121
|
-
export {
|
|
101
|
+
export { Cache, type EmailOptions, type ErrorResponse, Mailer, type MailerConfig, type MongoConfig, NexusError, type SuccessResponse, cacheMemory, connectMongoDb, errorHandler as errorMiddleware, errorResponse, random, requiredEnv, successResponse, uploader };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,33 +33,13 @@ interface MongoConfig {
|
|
|
33
33
|
|
|
34
34
|
declare const connectMongoDb: (config: MongoConfig) => Promise<boolean>;
|
|
35
35
|
|
|
36
|
-
declare class
|
|
36
|
+
declare class NexusError extends Error {
|
|
37
37
|
statusCode: number;
|
|
38
38
|
isOperational: boolean;
|
|
39
39
|
errors?: any;
|
|
40
40
|
constructor(message: string, statusCode?: number, errors?: any, isOperational?: boolean);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
declare class BadRequestError extends ApiError {
|
|
44
|
-
constructor(message?: string, errors?: any);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
declare class UnauthorizedError extends ApiError {
|
|
48
|
-
constructor(message?: string, errors?: any);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
declare class ForbiddenError extends ApiError {
|
|
52
|
-
constructor(message?: string, errors?: any);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
declare class NotFoundError extends ApiError {
|
|
56
|
-
constructor(message?: string, errors?: any);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
declare class ValidationError extends ApiError {
|
|
60
|
-
constructor(message?: string, errors?: any);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
43
|
declare const errorHandler: [
|
|
64
44
|
(req: Request, res: Response, next: NextFunction) => void,
|
|
65
45
|
(err: any, req: Request, res: Response, next: NextFunction) => void
|
|
@@ -118,4 +98,4 @@ declare const uploader: {
|
|
|
118
98
|
getNexusDownloadUrl: (fileId: string) => Promise<string>;
|
|
119
99
|
};
|
|
120
100
|
|
|
121
|
-
export {
|
|
101
|
+
export { Cache, type EmailOptions, type ErrorResponse, Mailer, type MailerConfig, type MongoConfig, NexusError, type SuccessResponse, cacheMemory, connectMongoDb, errorHandler as errorMiddleware, errorResponse, random, requiredEnv, successResponse, uploader };
|
package/dist/index.js
CHANGED
|
@@ -10315,14 +10315,9 @@ var require_form_data = __commonJS({
|
|
|
10315
10315
|
// src/index.ts
|
|
10316
10316
|
var index_exports = {};
|
|
10317
10317
|
__export(index_exports, {
|
|
10318
|
-
ApiError: () => ApiError,
|
|
10319
|
-
BadRequestError: () => BadRequestError,
|
|
10320
10318
|
Cache: () => Cache,
|
|
10321
|
-
ForbiddenError: () => ForbiddenError,
|
|
10322
10319
|
Mailer: () => mailer_default,
|
|
10323
|
-
|
|
10324
|
-
UnauthorizedError: () => UnauthorizedError,
|
|
10325
|
-
ValidationError: () => ValidationError,
|
|
10320
|
+
NexusError: () => NexusError,
|
|
10326
10321
|
cacheMemory: () => cacheMemory_default,
|
|
10327
10322
|
connectMongoDb: () => connectMongoDb,
|
|
10328
10323
|
errorMiddleware: () => errorHandler_default,
|
|
@@ -10374,8 +10369,8 @@ var connectMongoDb = async (config) => {
|
|
|
10374
10369
|
}
|
|
10375
10370
|
};
|
|
10376
10371
|
|
|
10377
|
-
// src/errors/
|
|
10378
|
-
var
|
|
10372
|
+
// src/errors/nexusError.ts
|
|
10373
|
+
var NexusError = class extends Error {
|
|
10379
10374
|
constructor(message, statusCode = 500, errors, isOperational = true) {
|
|
10380
10375
|
super(message);
|
|
10381
10376
|
this.statusCode = statusCode;
|
|
@@ -10385,44 +10380,9 @@ var ApiError = class extends Error {
|
|
|
10385
10380
|
}
|
|
10386
10381
|
};
|
|
10387
10382
|
|
|
10388
|
-
// src/errors/BadRequestError.ts
|
|
10389
|
-
var BadRequestError = class extends ApiError {
|
|
10390
|
-
constructor(message = "Bad Request", errors) {
|
|
10391
|
-
super(message, 400, errors);
|
|
10392
|
-
}
|
|
10393
|
-
};
|
|
10394
|
-
|
|
10395
|
-
// src/errors/UnauthorisedError.ts
|
|
10396
|
-
var UnauthorizedError = class extends ApiError {
|
|
10397
|
-
constructor(message = "Unauthorized", errors) {
|
|
10398
|
-
super(message, 401, errors);
|
|
10399
|
-
}
|
|
10400
|
-
};
|
|
10401
|
-
|
|
10402
|
-
// src/errors/ForbiddenError.ts
|
|
10403
|
-
var ForbiddenError = class extends ApiError {
|
|
10404
|
-
constructor(message = "Forbidden", errors) {
|
|
10405
|
-
super(message, 403, errors);
|
|
10406
|
-
}
|
|
10407
|
-
};
|
|
10408
|
-
|
|
10409
|
-
// src/errors/NotFoundError.ts
|
|
10410
|
-
var NotFoundError = class extends ApiError {
|
|
10411
|
-
constructor(message = "Resource Not Found", errors) {
|
|
10412
|
-
super(message, 404, errors);
|
|
10413
|
-
}
|
|
10414
|
-
};
|
|
10415
|
-
|
|
10416
|
-
// src/errors/ValidationError.ts
|
|
10417
|
-
var ValidationError = class extends ApiError {
|
|
10418
|
-
constructor(message = "Validation Failed", errors) {
|
|
10419
|
-
super(message, 422, errors);
|
|
10420
|
-
}
|
|
10421
|
-
};
|
|
10422
|
-
|
|
10423
10383
|
// src/handlers/errorHandler.ts
|
|
10424
10384
|
var routeNotFoundHandler = (req, _, next) => {
|
|
10425
|
-
next(new
|
|
10385
|
+
next(new NexusError(`Route ${req.originalUrl} not found`, 404));
|
|
10426
10386
|
};
|
|
10427
10387
|
var globalErrorHandler = (err, req, res, next) => {
|
|
10428
10388
|
console.error("Error:", err);
|
|
@@ -10430,7 +10390,7 @@ var globalErrorHandler = (err, req, res, next) => {
|
|
|
10430
10390
|
let message = "Internal Server Error";
|
|
10431
10391
|
let errors = void 0;
|
|
10432
10392
|
let stack = void 0;
|
|
10433
|
-
if (err instanceof
|
|
10393
|
+
if (err instanceof NexusError) {
|
|
10434
10394
|
statusCode = err.statusCode;
|
|
10435
10395
|
message = err.message;
|
|
10436
10396
|
errors = err.errors;
|
|
@@ -10572,7 +10532,7 @@ var Mailer = class {
|
|
|
10572
10532
|
from: `${this.config.brandName} <${this.config.fromEmail}>`,
|
|
10573
10533
|
to: [to],
|
|
10574
10534
|
subject,
|
|
10575
|
-
|
|
10535
|
+
html: body
|
|
10576
10536
|
// or 'text: body' depending on your needs
|
|
10577
10537
|
});
|
|
10578
10538
|
console.log("SMTP Response:", response);
|
|
@@ -10668,14 +10628,9 @@ var uploader = {
|
|
|
10668
10628
|
var nexusCloud_default = uploader;
|
|
10669
10629
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10670
10630
|
0 && (module.exports = {
|
|
10671
|
-
ApiError,
|
|
10672
|
-
BadRequestError,
|
|
10673
10631
|
Cache,
|
|
10674
|
-
ForbiddenError,
|
|
10675
10632
|
Mailer,
|
|
10676
|
-
|
|
10677
|
-
UnauthorizedError,
|
|
10678
|
-
ValidationError,
|
|
10633
|
+
NexusError,
|
|
10679
10634
|
cacheMemory,
|
|
10680
10635
|
connectMongoDb,
|
|
10681
10636
|
errorMiddleware,
|