@youreztickets/common 1.0.2 → 1.0.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/build/config/env.d.ts +2 -0
- package/build/config/env.d.ts.map +1 -0
- package/build/config/env.js +17 -0
- package/build/config/env.js.map +1 -0
- package/build/errors/bad-request-error.d.ts +9 -0
- package/build/errors/bad-request-error.d.ts.map +1 -0
- package/build/errors/bad-request-error.js +16 -0
- package/build/errors/bad-request-error.js.map +1 -0
- package/build/errors/custom-error.d.ts +9 -0
- package/build/errors/custom-error.d.ts.map +1 -0
- package/build/errors/custom-error.js +20 -0
- package/build/errors/custom-error.js.map +1 -0
- package/build/errors/database-connection-error.d.ts +10 -0
- package/build/errors/database-connection-error.d.ts.map +1 -0
- package/build/errors/database-connection-error.js +16 -0
- package/build/errors/database-connection-error.js.map +1 -0
- package/build/errors/not-authorized.d.ts +10 -0
- package/build/errors/not-authorized.d.ts.map +1 -0
- package/build/errors/not-authorized.js +16 -0
- package/build/errors/not-authorized.js.map +1 -0
- package/build/errors/not-found-error.d.ts +9 -0
- package/build/errors/not-found-error.d.ts.map +1 -0
- package/build/errors/not-found-error.js +16 -0
- package/build/errors/not-found-error.js.map +1 -0
- package/build/errors/request-validation-error.d.ts +12 -0
- package/build/errors/request-validation-error.d.ts.map +1 -0
- package/build/errors/request-validation-error.js +23 -0
- package/build/errors/request-validation-error.js.map +1 -0
- package/build/index.d.ts +11 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +27 -0
- package/build/index.js.map +1 -0
- package/build/middleware/current-user.d.ts +15 -0
- package/build/middleware/current-user.d.ts.map +1 -0
- package/build/middleware/current-user.js +21 -0
- package/build/middleware/current-user.js.map +1 -0
- package/build/middleware/error-handler.d.ts +3 -0
- package/build/middleware/error-handler.d.ts.map +1 -0
- package/build/middleware/error-handler.js +23 -0
- package/build/middleware/error-handler.js.map +1 -0
- package/build/middleware/require-auth.d.ts +3 -0
- package/build/middleware/require-auth.d.ts.map +1 -0
- package/build/middleware/require-auth.js +12 -0
- package/build/middleware/require-auth.js.map +1 -0
- package/build/middleware/validate-request.d.ts +3 -0
- package/build/middleware/validate-request.d.ts.map +1 -0
- package/build/middleware/validate-request.js +14 -0
- package/build/middleware/validate-request.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/config/env.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,MAAM,QAA4B,CAAC"}
|
|
@@ -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.jwtKey = void 0;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
+
dotenv_1.default.config();
|
|
9
|
+
function getEnvVariable(key, defaultValue) {
|
|
10
|
+
const value = process.env[key] || defaultValue;
|
|
11
|
+
if (!value) {
|
|
12
|
+
throw new Error(`${key} must be defined`);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
exports.jwtKey = getEnvVariable("JWT_KEY");
|
|
17
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/config/env.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,SAAS,cAAc,CAAC,GAAW,EAAE,YAAqB;IACxD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC;IAE/C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,kBAAkB,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAEY,QAAA,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bad-request-error.d.ts","sourceRoot":"","sources":["../../src/errors/bad-request-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,eAAgB,SAAQ,WAAW;IAC9C,UAAU,SAAO;gBAEL,OAAO,EAAE,MAAM;IAM3B,eAAe;;;CAGhB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BadRequestError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class BadRequestError extends custom_error_1.CustomError {
|
|
6
|
+
statusCode = 400;
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
10
|
+
}
|
|
11
|
+
serializeErrors() {
|
|
12
|
+
return [{ message: this.message }];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.BadRequestError = BadRequestError;
|
|
16
|
+
//# sourceMappingURL=bad-request-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bad-request-error.js","sourceRoot":"","sources":["../../src/errors/bad-request-error.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,eAAgB,SAAQ,0BAAW;IAC9C,UAAU,GAAG,GAAG,CAAC;IAEjB,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AAZD,0CAYC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-error.d.ts","sourceRoot":"","sources":["../../src/errors/custom-error.ts"],"names":[],"mappings":"AAIA,8BAAsB,WAAY,SAAQ,KAAK;IAG7C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM;IAa3B,QAAQ,CAAC,eAAe,IAAI;QAC1B,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,EAAE;CACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomError = void 0;
|
|
4
|
+
// We create an abstract class that extends the built-in Error class
|
|
5
|
+
// "abstract" means:
|
|
6
|
+
// - Cannot be instantiated -> new CustomError()
|
|
7
|
+
// - Used to set up requirements for subclasses
|
|
8
|
+
class CustomError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
// Call the parent Error constructor
|
|
11
|
+
// This sets the error message (err.message)
|
|
12
|
+
super(message);
|
|
13
|
+
// Fixes an issue with extending built-in classes in TypeScript
|
|
14
|
+
// Without this, instanceof checks might FAIL ❗
|
|
15
|
+
// (very important for: err instanceof CustomError)
|
|
16
|
+
Object.setPrototypeOf(this, CustomError.prototype);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CustomError = CustomError;
|
|
20
|
+
//# sourceMappingURL=custom-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-error.js","sourceRoot":"","sources":["../../src/errors/custom-error.ts"],"names":[],"mappings":";;;AAAA,oEAAoE;AACpE,oBAAoB;AACpB,gDAAgD;AAChD,+CAA+C;AAC/C,MAAsB,WAAY,SAAQ,KAAK;IAK7C,YAAY,OAAe;QACzB,oCAAoC;QACpC,4CAA4C;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,+DAA+D;QAC/D,+CAA+C;QAC/C,mDAAmD;QACnD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;CAQF;AAtBD,kCAsBC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CustomError } from "./custom-error";
|
|
2
|
+
export declare class DatabaseConnectionError extends CustomError {
|
|
3
|
+
statusCode: number;
|
|
4
|
+
constructor();
|
|
5
|
+
serializeErrors(): {
|
|
6
|
+
message: string;
|
|
7
|
+
field?: string;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=database-connection-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-connection-error.d.ts","sourceRoot":"","sources":["../../src/errors/database-connection-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,uBAAwB,SAAQ,WAAW;IACtD,UAAU,SAAO;;IAMjB,eAAe,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE;CAGzD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseConnectionError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class DatabaseConnectionError extends custom_error_1.CustomError {
|
|
6
|
+
statusCode = 500;
|
|
7
|
+
constructor() {
|
|
8
|
+
super("Database connection Error");
|
|
9
|
+
Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
|
|
10
|
+
}
|
|
11
|
+
serializeErrors() {
|
|
12
|
+
return [{ message: "Error connecting to database" }];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.DatabaseConnectionError = DatabaseConnectionError;
|
|
16
|
+
//# sourceMappingURL=database-connection-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-connection-error.js","sourceRoot":"","sources":["../../src/errors/database-connection-error.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,uBAAwB,SAAQ,0BAAW;IACtD,UAAU,GAAG,GAAG,CAAC;IACjB;QACE,KAAK,CAAC,2BAA2B,CAAC,CAAC;QACnC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAVD,0DAUC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CustomError } from "./custom-error";
|
|
2
|
+
export declare class NotAuthorizedError extends CustomError {
|
|
3
|
+
statusCode: number;
|
|
4
|
+
constructor();
|
|
5
|
+
serializeErrors(): {
|
|
6
|
+
message: string;
|
|
7
|
+
field?: string;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=not-authorized.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-authorized.d.ts","sourceRoot":"","sources":["../../src/errors/not-authorized.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,kBAAmB,SAAQ,WAAW;IACjD,UAAU,SAAO;;IAMjB,eAAe,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE;CAGzD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotAuthorizedError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class NotAuthorizedError extends custom_error_1.CustomError {
|
|
6
|
+
statusCode = 401;
|
|
7
|
+
constructor() {
|
|
8
|
+
super("Not authorized");
|
|
9
|
+
Object.setPrototypeOf(this, NotAuthorizedError.prototype);
|
|
10
|
+
}
|
|
11
|
+
serializeErrors() {
|
|
12
|
+
return [{ message: "Not authorized" }];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NotAuthorizedError = NotAuthorizedError;
|
|
16
|
+
//# sourceMappingURL=not-authorized.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-authorized.js","sourceRoot":"","sources":["../../src/errors/not-authorized.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,kBAAmB,SAAQ,0BAAW;IACjD,UAAU,GAAG,GAAG,CAAC;IACjB;QACE,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACzC,CAAC;CACF;AAVD,gDAUC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-found-error.d.ts","sourceRoot":"","sources":["../../src/errors/not-found-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,aAAc,SAAQ,WAAW;IAC5C,UAAU,SAAO;;IAOjB,eAAe;;;CAGhB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotFoundError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class NotFoundError extends custom_error_1.CustomError {
|
|
6
|
+
statusCode = 404;
|
|
7
|
+
constructor() {
|
|
8
|
+
super("Route not found");
|
|
9
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
10
|
+
}
|
|
11
|
+
serializeErrors() {
|
|
12
|
+
return [{ message: "Not found" }];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NotFoundError = NotFoundError;
|
|
16
|
+
//# sourceMappingURL=not-found-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-found-error.js","sourceRoot":"","sources":["../../src/errors/not-found-error.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,aAAc,SAAQ,0BAAW;IAC5C,UAAU,GAAG,GAAG,CAAC;IAEjB;QACE,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACzB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IACpC,CAAC;CACF;AAXD,sCAWC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ValidationError } from "express-validator";
|
|
2
|
+
import { CustomError } from "./custom-error";
|
|
3
|
+
export declare class RequestValidationError extends CustomError {
|
|
4
|
+
private errors;
|
|
5
|
+
statusCode: number;
|
|
6
|
+
constructor(errors: ValidationError[]);
|
|
7
|
+
serializeErrors(): {
|
|
8
|
+
message: any;
|
|
9
|
+
field: string;
|
|
10
|
+
}[];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=request-validation-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-validation-error.d.ts","sourceRoot":"","sources":["../../src/errors/request-validation-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,sBAAuB,SAAQ,WAAW;IAEzC,OAAO,CAAC,MAAM;IAD1B,UAAU,SAAO;gBACG,MAAM,EAAE,eAAe,EAAE;IAM7C,eAAe;;;;CAQhB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestValidationError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class RequestValidationError extends custom_error_1.CustomError {
|
|
6
|
+
errors;
|
|
7
|
+
statusCode = 400;
|
|
8
|
+
constructor(errors) {
|
|
9
|
+
super("Invalid request parameters");
|
|
10
|
+
this.errors = errors;
|
|
11
|
+
Object.setPrototypeOf(this, RequestValidationError.prototype);
|
|
12
|
+
}
|
|
13
|
+
serializeErrors() {
|
|
14
|
+
return this.errors
|
|
15
|
+
.filter((err) => err.type === "field")
|
|
16
|
+
.map((err) => ({
|
|
17
|
+
message: err.msg,
|
|
18
|
+
field: err.path,
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.RequestValidationError = RequestValidationError;
|
|
23
|
+
//# sourceMappingURL=request-validation-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-validation-error.js","sourceRoot":"","sources":["../../src/errors/request-validation-error.ts"],"names":[],"mappings":";;;AACA,iDAA6C;AAE7C,MAAa,sBAAuB,SAAQ,0BAAW;IAEjC;IADpB,UAAU,GAAG,GAAG,CAAC;IACjB,YAAoB,MAAyB;QAC3C,KAAK,CAAC,4BAA4B,CAAC,CAAC;QADlB,WAAM,GAAN,MAAM,CAAmB;QAG3C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,MAAM;aACf,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC;aACrC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACb,OAAO,EAAE,GAAG,CAAC,GAAG;YAChB,KAAK,EAAE,GAAG,CAAC,IAAI;SAChB,CAAC,CAAC,CAAC;IACR,CAAC;CACF;AAhBD,wDAgBC"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./errors/bad-request-error";
|
|
2
|
+
export * from "./errors/custom-error";
|
|
3
|
+
export * from "./errors/database-connection-error";
|
|
4
|
+
export * from "./errors/not-authorized";
|
|
5
|
+
export * from "./errors/not-found-error";
|
|
6
|
+
export * from "./errors/request-validation-error";
|
|
7
|
+
export * from "./middleware/current-user";
|
|
8
|
+
export * from "./middleware/error-handler";
|
|
9
|
+
export * from "./middleware/require-auth";
|
|
10
|
+
export * from "./middleware/validate-request";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAElD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./errors/bad-request-error"), exports);
|
|
18
|
+
__exportStar(require("./errors/custom-error"), exports);
|
|
19
|
+
__exportStar(require("./errors/database-connection-error"), exports);
|
|
20
|
+
__exportStar(require("./errors/not-authorized"), exports);
|
|
21
|
+
__exportStar(require("./errors/not-found-error"), exports);
|
|
22
|
+
__exportStar(require("./errors/request-validation-error"), exports);
|
|
23
|
+
__exportStar(require("./middleware/current-user"), exports);
|
|
24
|
+
__exportStar(require("./middleware/error-handler"), exports);
|
|
25
|
+
__exportStar(require("./middleware/require-auth"), exports);
|
|
26
|
+
__exportStar(require("./middleware/validate-request"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,wDAAsC;AACtC,qEAAmD;AACnD,0DAAwC;AACxC,2DAAyC;AACzC,oEAAkD;AAElD,4DAA0C;AAC1C,6DAA2C;AAC3C,4DAA0C;AAC1C,gEAA8C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 {};
|
|
15
|
+
//# sourceMappingURL=current-user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-user.d.ts","sourceRoot":"","sources":["../../src/middleware/current-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI1D,UAAU,WAAW;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,WAAW,CAAC,EAAE,WAAW,CAAC;SAC3B;KACF;CACF;AAED,eAAO,MAAM,WAAW,GACtB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,SAYnB,CAAC"}
|
|
@@ -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
|
+
exports.currentUser = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
const env_1 = require("../config/env");
|
|
9
|
+
const currentUser = (req, res, next) => {
|
|
10
|
+
if (!req.session?.jwt) {
|
|
11
|
+
return next();
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const payload = jsonwebtoken_1.default.verify(req.session.jwt, env_1.jwtKey);
|
|
15
|
+
req.currentUser = payload;
|
|
16
|
+
}
|
|
17
|
+
catch (error) { }
|
|
18
|
+
next();
|
|
19
|
+
};
|
|
20
|
+
exports.currentUser = currentUser;
|
|
21
|
+
//# sourceMappingURL=current-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-user.js","sourceRoot":"","sources":["../../src/middleware/current-user.ts"],"names":[],"mappings":";;;;;;AACA,gEAA+B;AAC/B,uCAAuC;AAehC,MAAM,WAAW,GAAG,CACzB,GAAY,EACZ,GAAa,EACb,IAAkB,EAClB,EAAE;IACF,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC;QACtB,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,sBAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,YAAM,CAAgB,CAAC;QACnE,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC,CAAA,CAAC;IAElB,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AAfW,QAAA,WAAW,eAetB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/middleware/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAG9C,eAAO,MAAM,YAAY,EAAE,mBAoB1B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorHandler = void 0;
|
|
4
|
+
const custom_error_1 = require("../errors/custom-error");
|
|
5
|
+
const errorHandler = (err, req, res, next) => {
|
|
6
|
+
if (err instanceof custom_error_1.CustomError) {
|
|
7
|
+
return res.status(err.statusCode).send({
|
|
8
|
+
errors: err.serializeErrors(),
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
// if (err instanceof RequestValidationError) {
|
|
12
|
+
// console.log("Handling this error as a request validation error");
|
|
13
|
+
// return res.status(400).send({ errors: formattedErrors });
|
|
14
|
+
// }
|
|
15
|
+
// if (err instanceof DatabaseConnectionError) {
|
|
16
|
+
// console.log("Handling this error as a db connection error");
|
|
17
|
+
// }
|
|
18
|
+
res.status(500).send({
|
|
19
|
+
errors: [{ message: "Something went wrong" }],
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
exports.errorHandler = errorHandler;
|
|
23
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/middleware/error-handler.ts"],"names":[],"mappings":";;;AACA,yDAAqD;AAE9C,MAAM,YAAY,GAAwB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IACvE,IAAI,GAAG,YAAY,0BAAW,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YACrC,MAAM,EAAE,GAAG,CAAC,eAAe,EAAE;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,+CAA+C;IAC/C,sEAAsE;IAEtE,8DAA8D;IAC9D,IAAI;IAEJ,gDAAgD;IAChD,iEAAiE;IACjE,IAAI;IAEJ,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QACnB,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC;KAC9C,CAAC,CAAC;AACL,CAAC,CAAC;AApBW,QAAA,YAAY,gBAoBvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require-auth.d.ts","sourceRoot":"","sources":["../../src/middleware/require-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG1D,eAAO,MAAM,WAAW,GACtB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,SAOnB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireAuth = void 0;
|
|
4
|
+
const not_authorized_1 = require("../errors/not-authorized");
|
|
5
|
+
const requireAuth = (req, res, next) => {
|
|
6
|
+
if (!req.currentUser) {
|
|
7
|
+
throw new not_authorized_1.NotAuthorizedError();
|
|
8
|
+
}
|
|
9
|
+
next();
|
|
10
|
+
};
|
|
11
|
+
exports.requireAuth = requireAuth;
|
|
12
|
+
//# sourceMappingURL=require-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require-auth.js","sourceRoot":"","sources":["../../src/middleware/require-auth.ts"],"names":[],"mappings":";;;AACA,6DAA8D;AAEvD,MAAM,WAAW,GAAG,CACzB,GAAY,EACZ,GAAa,EACb,IAAkB,EAClB,EAAE;IACF,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACrB,MAAM,IAAI,mCAAkB,EAAE,CAAC;IACjC,CAAC;IAED,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AAVW,QAAA,WAAW,eAUtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-request.d.ts","sourceRoot":"","sources":["../../src/middleware/validate-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI1D,eAAO,MAAM,eAAe,GAC1B,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,SAQnB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRequest = void 0;
|
|
4
|
+
const express_validator_1 = require("express-validator");
|
|
5
|
+
const request_validation_error_1 = require("../errors/request-validation-error");
|
|
6
|
+
const validateRequest = (req, res, next) => {
|
|
7
|
+
const errors = (0, express_validator_1.validationResult)(req);
|
|
8
|
+
if (!errors.isEmpty()) {
|
|
9
|
+
throw new request_validation_error_1.RequestValidationError(errors.array());
|
|
10
|
+
}
|
|
11
|
+
next();
|
|
12
|
+
};
|
|
13
|
+
exports.validateRequest = validateRequest;
|
|
14
|
+
//# sourceMappingURL=validate-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-request.js","sourceRoot":"","sources":["../../src/middleware/validate-request.ts"],"names":[],"mappings":";;;AACA,yDAAqD;AACrD,iFAA4E;AAErE,MAAM,eAAe,GAAG,CAC7B,GAAY,EACZ,GAAa,EACb,IAAkB,EAClB,EAAE;IACF,MAAM,MAAM,GAAG,IAAA,oCAAgB,EAAC,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACtB,MAAM,IAAI,iDAAsB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AAXW,QAAA,eAAe,mBAW1B"}
|