cqrs-boilerplate-code 1.0.14 → 1.0.16
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/dist/index.d.ts +4 -4
- package/dist/index.js +4 -27
- package/dist/index.js.map +1 -1
- package/dist/middleware/auth-middleware/auth-middleware.factory.d.ts +2 -0
- package/dist/middleware/auth-middleware/auth-middleware.factory.js +8 -0
- package/dist/middleware/auth-middleware/auth-middleware.factory.js.map +1 -0
- package/dist/middleware/auth-middleware/auth.middleware.d.ts +13 -0
- package/dist/middleware/auth-middleware/auth.middleware.js +48 -0
- package/dist/middleware/auth-middleware/auth.middleware.js.map +1 -0
- package/dist/middleware/auth-middleware/index.d.ts +3 -0
- package/dist/middleware/auth-middleware/index.js +20 -0
- package/dist/middleware/auth-middleware/index.js.map +1 -0
- package/dist/middleware/auth-middleware/jwt-validator.d.ts +6 -0
- package/dist/middleware/auth-middleware/jwt-validator.js +51 -0
- package/dist/middleware/auth-middleware/jwt-validator.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export * from './common-infra/http/http-module.options';
|
|
|
25
25
|
export * from './common-infra/http/http.constant';
|
|
26
26
|
export * from './common-infra/http/http.module';
|
|
27
27
|
export * from './common-infra/http/https.service';
|
|
28
|
-
export *
|
|
29
|
-
export *
|
|
30
|
-
export *
|
|
31
|
-
export *
|
|
28
|
+
export * from './common-infra/socket.io/interfaces';
|
|
29
|
+
export * from './common-infra/socket.io/socket.gateway';
|
|
30
|
+
export * from './common-infra/socket.io/socket.module';
|
|
31
|
+
export * from './common-infra/socket.io/socket.options';
|
package/dist/index.js
CHANGED
|
@@ -10,33 +10,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
15
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
-
var ownKeys = function(o) {
|
|
23
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
-
var ar = [];
|
|
25
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
|
-
return ownKeys(o);
|
|
29
|
-
};
|
|
30
|
-
return function (mod) {
|
|
31
|
-
if (mod && mod.__esModule) return mod;
|
|
32
|
-
var result = {};
|
|
33
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
-
__setModuleDefault(result, mod);
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
})();
|
|
38
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports["socket-options"] = exports["socket-module"] = exports["socket-gateway"] = exports["socket-interface"] = void 0;
|
|
40
17
|
__exportStar(require("./core-common/constant/app.constant"), exports);
|
|
41
18
|
__exportStar(require("./core-common/error/custom-error/already-exists.error"), exports);
|
|
42
19
|
__exportStar(require("./core-common/error/custom-error/bad-request.error"), exports);
|
|
@@ -64,8 +41,8 @@ __exportStar(require("./common-infra/http/http-module.options"), exports);
|
|
|
64
41
|
__exportStar(require("./common-infra/http/http.constant"), exports);
|
|
65
42
|
__exportStar(require("./common-infra/http/http.module"), exports);
|
|
66
43
|
__exportStar(require("./common-infra/http/https.service"), exports);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
44
|
+
__exportStar(require("./common-infra/socket.io/interfaces"), exports);
|
|
45
|
+
__exportStar(require("./common-infra/socket.io/socket.gateway"), exports);
|
|
46
|
+
__exportStar(require("./common-infra/socket.io/socket.module"), exports);
|
|
47
|
+
__exportStar(require("./common-infra/socket.io/socket.options"), exports);
|
|
71
48
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,sEAAmD;AAGnD,wFAAqE;AACrE,qFAAkE;AAClE,kFAA+D;AAC/D,2FAAwE;AACxE,mFAAgE;AAChE,yFAAsE;AACtE,mFAAgE;AAChE,6FAA0E;AAC1E,sFAAmE;AACnE,0FAAuE;AACvE,oFAAiE;AACjE,oEAAiD;AAGjD,4FAAyE;AACzE,8FAA2E;AAC3E,oEAAiD;AAGjD,wEAAqD;AACrD,qEAAkD;AAClD,sEAAmD;AAGnD,qEAAkD;AAClD,yEAAsD;AACtD,sEAAmD;AACnD,mEAAgD;AAGhD,0EAAuD;AACvD,oEAAiD;AACjD,kEAA+C;AAC/C,oEAAiD;AAGjD,sEAAmD;AACnD,0EAAuD;AACvD,yEAAsD;AACtD,0EAAuD","sourcesContent":["\nexport * from './core-common/constant/app.constant'\n\n// Error Exports\nexport * from './core-common/error/custom-error/already-exists.error'\nexport * from './core-common/error/custom-error/bad-request.error'\nexport * from './core-common/error/custom-error/conflict.error'\nexport * from './core-common/error/custom-error/custom-validation-error'\nexport * from './core-common/error/custom-error/forbidden.error'\nexport * from './core-common/error/custom-error/internal-server.error'\nexport * from './core-common/error/custom-error/not-found.error'\nexport * from './core-common/error/custom-error/service-unavailable.error'\nexport * from './core-common/error/custom-error/unauthorized.error'\nexport * from './core-common/error/custom-error/unprocess-entity.error'\nexport * from './core-common/error/custom-error/validation.error'\nexport * from './core-common/error/generic.error'\n\n// Model Exports\nexport * from './core-common/response-model/generic-error-response.model'\nexport * from './core-common/response-model/generic-success-response.model'\nexport * from './core-common/result-model/result'\n\n// Logger Exports\nexport * from './core-common/logger/logger.interface'\nexport * from './core-common/logger/logger.module'\nexport * from './core-common/logger/logger.service'\n\n// Module Exports\nexport * from './common-infra/common-infra.module'\nexport * from './common-infra/database/typeorm.config'\nexport * from './core-common/constant/app.constant'\nexport * from './core-common/core-common.module'\n\n// HTTP Exports\nexport * from './common-infra/http/http-module.options'\nexport * from './common-infra/http/http.constant'\nexport * from './common-infra/http/http.module'\nexport * from './common-infra/http/https.service'\n\n// Socket.IO Exports\nexport * from './common-infra/socket.io/interfaces'\nexport * from './common-infra/socket.io/socket.gateway'\nexport * from './common-infra/socket.io/socket.module'\nexport * from './common-infra/socket.io/socket.options'\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAuthMiddleware = createAuthMiddleware;
|
|
4
|
+
const auth_middleware_1 = require("./auth.middleware");
|
|
5
|
+
function createAuthMiddleware(options) {
|
|
6
|
+
return new auth_middleware_1.AuthMiddleware(options);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=auth-middleware.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-middleware.factory.js","sourceRoot":"","sources":["../../../src/middleware/auth-middleware/auth-middleware.factory.ts"],"names":[],"mappings":";;AAEA,oDAEC;AAJD,uDAA0E;AAE1E,SAAgB,oBAAoB,CAAC,OAA8B;IAC/D,OAAO,IAAI,gCAAc,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { AuthMiddleware, AuthMiddlewareOptions } from \"./auth.middleware\";\n\nexport function createAuthMiddleware(options: AuthMiddlewareOptions) {\n return new AuthMiddleware(options);\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NestMiddleware } from "@nestjs/common";
|
|
2
|
+
import { Request, Response, NextFunction } from "express";
|
|
3
|
+
export interface AuthMiddlewareOptions {
|
|
4
|
+
headerName?: string;
|
|
5
|
+
validate?: (token: string, req: Request) => boolean | Promise<boolean>;
|
|
6
|
+
optional?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class AuthMiddleware implements NestMiddleware {
|
|
9
|
+
private readonly options;
|
|
10
|
+
constructor(options?: AuthMiddlewareOptions);
|
|
11
|
+
use(req: Request, _res: Response, next: NextFunction): Promise<void>;
|
|
12
|
+
private extractToken;
|
|
13
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthMiddleware = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
let AuthMiddleware = class AuthMiddleware {
|
|
15
|
+
options;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
async use(req, _res, next) {
|
|
20
|
+
const headerName = this.options.headerName ?? "authorization";
|
|
21
|
+
const authHeader = req.headers[headerName];
|
|
22
|
+
if (!authHeader) {
|
|
23
|
+
if (this.options.optional)
|
|
24
|
+
return next();
|
|
25
|
+
throw new common_1.UnauthorizedException("Authorization header missing");
|
|
26
|
+
}
|
|
27
|
+
const token = this.extractToken(authHeader);
|
|
28
|
+
if (this.options.validate) {
|
|
29
|
+
const isValid = await this.options.validate(token, req);
|
|
30
|
+
if (!isValid) {
|
|
31
|
+
throw new common_1.UnauthorizedException("Invalid authentication token");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
next();
|
|
35
|
+
}
|
|
36
|
+
extractToken(header) {
|
|
37
|
+
if (header.startsWith("Bearer ")) {
|
|
38
|
+
return header.slice(7);
|
|
39
|
+
}
|
|
40
|
+
return header;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.AuthMiddleware = AuthMiddleware;
|
|
44
|
+
exports.AuthMiddleware = AuthMiddleware = __decorate([
|
|
45
|
+
(0, common_1.Injectable)(),
|
|
46
|
+
__metadata("design:paramtypes", [Object])
|
|
47
|
+
], AuthMiddleware);
|
|
48
|
+
//# sourceMappingURL=auth.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.middleware.js","sourceRoot":"","sources":["../../../src/middleware/auth-middleware/auth.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAmF;AAU5E,IAAM,cAAc,GAApB,MAAM,cAAc;IACI;IAA7B,YAA6B,UAAiC,EAAE;QAAnC,YAAO,GAAP,OAAO,CAA4B;IAAG,CAAC;IAEpE,KAAK,CAAC,GAAG,CAAC,GAAY,EAAE,IAAc,EAAE,IAAkB;QACxD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,eAAe,CAAC;QAC9D,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,CAAuB,CAAC;QAEjE,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ;gBAAE,OAAO,IAAI,EAAE,CAAC;YACzC,MAAM,IAAI,8BAAqB,CAAC,8BAA8B,CAAC,CAAC;QAClE,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAE5C,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC1B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YAExD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,8BAAqB,CAAC,8BAA8B,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;QAED,IAAI,EAAE,CAAC;IACT,CAAC;IAEO,YAAY,CAAC,MAAc;QACjC,IAAI,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YACjC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AA/BY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;;GACA,cAAc,CA+B1B","sourcesContent":["import { Injectable, NestMiddleware, UnauthorizedException } from \"@nestjs/common\";\nimport { Request, Response, NextFunction } from \"express\";\n\nexport interface AuthMiddlewareOptions {\n headerName?: string;\n validate?: (token: string, req: Request) => boolean | Promise<boolean>;\n optional?: boolean;\n}\n\n@Injectable()\nexport class AuthMiddleware implements NestMiddleware {\n constructor(private readonly options: AuthMiddlewareOptions = {}) {}\n\n async use(req: Request, _res: Response, next: NextFunction): Promise<void> {\n const headerName = this.options.headerName ?? \"authorization\";\n const authHeader = req.headers[headerName] as string | undefined;\n\n if (!authHeader) {\n if (this.options.optional) return next();\n throw new UnauthorizedException(\"Authorization header missing\");\n }\n\n const token = this.extractToken(authHeader);\n\n if (this.options.validate) {\n const isValid = await this.options.validate(token, req);\n\n if (!isValid) {\n throw new UnauthorizedException(\"Invalid authentication token\");\n }\n }\n\n next();\n }\n\n private extractToken(header: string): string {\n if (header.startsWith(\"Bearer \")) {\n return header.slice(7);\n }\n return header;\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./auth.middleware"), exports);
|
|
18
|
+
__exportStar(require("./auth-middleware.factory"), exports);
|
|
19
|
+
__exportStar(require("./jwt-validator"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/middleware/auth-middleware/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,4DAA0C;AAC1C,kDAAgC","sourcesContent":["export * from \"./auth.middleware\";\nexport * from \"./auth-middleware.factory\";\nexport * from \"./jwt-validator\";"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.jwtValidator = jwtValidator;
|
|
37
|
+
const jwt = __importStar(require("jsonwebtoken"));
|
|
38
|
+
function jwtValidator(options) {
|
|
39
|
+
return (token) => {
|
|
40
|
+
try {
|
|
41
|
+
jwt.verify(token, options.secret, {
|
|
42
|
+
algorithms: options.algorithms,
|
|
43
|
+
});
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=jwt-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-validator.js","sourceRoot":"","sources":["../../../src/middleware/auth-middleware/jwt-validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,oCAWC;AAlBD,kDAAoC;AAOpC,SAAgB,YAAY,CAAC,OAA4B;IACrD,OAAO,CAAC,KAAa,EAAW,EAAE;QAClC,IAAI,CAAC;YACH,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE;gBAChC,UAAU,EAAE,OAAO,CAAC,UAAU;aAC/B,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import * as jwt from \"jsonwebtoken\";\n\nexport interface JwtValidatorOptions {\n secret: string;\n algorithms?: jwt.Algorithm[];\n}\n\nexport function jwtValidator(options: JwtValidatorOptions) {\n return (token: string): boolean => {\n try {\n jwt.verify(token, options.secret, {\n algorithms: options.algorithms,\n });\n return true;\n } catch {\n return false;\n }\n };\n}\n"]}
|