cqrs-boilerplate-code 1.0.13 → 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/common-infra/socket.io/interfaces.d.ts +4 -0
- package/dist/common-infra/socket.io/interfaces.js +3 -0
- package/dist/common-infra/socket.io/interfaces.js.map +1 -0
- package/dist/common-infra/socket.io/socket.gateway.d.ts +9 -0
- package/dist/common-infra/socket.io/socket.gateway.js +52 -0
- package/dist/common-infra/socket.io/socket.gateway.js.map +1 -0
- package/dist/common-infra/socket.io/socket.module.d.ts +5 -0
- package/dist/common-infra/socket.io/socket.module.js +35 -0
- package/dist/common-infra/socket.io/socket.module.js.map +1 -0
- package/dist/common-infra/socket.io/socket.options.d.ts +6 -0
- package/dist/common-infra/socket.io/socket.options.js +3 -0
- package/dist/common-infra/socket.io/socket.options.js.map +1 -0
- package/dist/index.d.ts +16 -12
- package/dist/index.js +16 -12
- 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 +4 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/common-infra/socket.io/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["export interface SocketMessage<T = any> {\n event: string;\n payload: T;\n}"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Server, Socket } from 'socket.io';
|
|
2
|
+
export declare class BaseSocketGateway {
|
|
3
|
+
protected server: Server;
|
|
4
|
+
handleConnection(client: Socket): void;
|
|
5
|
+
handleDisconnect(client: Socket): void;
|
|
6
|
+
onMessage(payload: any, client: Socket): void;
|
|
7
|
+
protected emitToClient(client: Socket, event: string, data: any): void;
|
|
8
|
+
protected broadcast(event: string, data: any): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BaseSocketGateway = void 0;
|
|
16
|
+
const websockets_1 = require("@nestjs/websockets");
|
|
17
|
+
const socket_io_1 = require("socket.io");
|
|
18
|
+
let BaseSocketGateway = class BaseSocketGateway {
|
|
19
|
+
server;
|
|
20
|
+
handleConnection(client) {
|
|
21
|
+
console.log('[Socket Connected]', client.id);
|
|
22
|
+
}
|
|
23
|
+
handleDisconnect(client) {
|
|
24
|
+
console.log('[Socket Disconnected]', client.id);
|
|
25
|
+
}
|
|
26
|
+
onMessage(payload, client) {
|
|
27
|
+
client.emit('messageResponse', payload);
|
|
28
|
+
}
|
|
29
|
+
emitToClient(client, event, data) {
|
|
30
|
+
client.emit(event, data);
|
|
31
|
+
}
|
|
32
|
+
broadcast(event, data) {
|
|
33
|
+
this.server.emit(event, data);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.BaseSocketGateway = BaseSocketGateway;
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, websockets_1.WebSocketServer)(),
|
|
39
|
+
__metadata("design:type", socket_io_1.Server)
|
|
40
|
+
], BaseSocketGateway.prototype, "server", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, websockets_1.SubscribeMessage)('message'),
|
|
43
|
+
__param(0, (0, websockets_1.MessageBody)()),
|
|
44
|
+
__param(1, (0, websockets_1.ConnectedSocket)()),
|
|
45
|
+
__metadata("design:type", Function),
|
|
46
|
+
__metadata("design:paramtypes", [Object, socket_io_1.Socket]),
|
|
47
|
+
__metadata("design:returntype", void 0)
|
|
48
|
+
], BaseSocketGateway.prototype, "onMessage", null);
|
|
49
|
+
exports.BaseSocketGateway = BaseSocketGateway = __decorate([
|
|
50
|
+
(0, websockets_1.WebSocketGateway)()
|
|
51
|
+
], BaseSocketGateway);
|
|
52
|
+
//# sourceMappingURL=socket.gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.gateway.js","sourceRoot":"","sources":["../../../src/common-infra/socket.io/socket.gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mDAM4B;AAC5B,yCAA2C;AAGpC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAEhB,MAAM,CAAS;IAEzB,gBAAgB,CAAC,MAAc;QAC3B,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,gBAAgB,CAAC,MAAc;QAC3B,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;IAGD,SAAS,CACU,OAAY,EACR,MAAc;QAEjC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAES,YAAY,CAClB,MAAc,EACd,KAAa,EACb,IAAS;QAET,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;IAES,SAAS,CACf,KAAa,EACb,IAAS;QAET,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;CACJ,CAAA;AAlCY,8CAAiB;AAEhB;IADT,IAAA,4BAAe,GAAE;8BACA,kBAAM;iDAAC;AAWzB;IADC,IAAA,6BAAgB,EAAC,SAAS,CAAC;IAEvB,WAAA,IAAA,wBAAW,GAAE,CAAA;IACb,WAAA,IAAA,4BAAe,GAAE,CAAA;;6CAAS,kBAAM;;kDAGpC;4BAlBQ,iBAAiB;IAD7B,IAAA,6BAAgB,GAAE;GACN,iBAAiB,CAkC7B","sourcesContent":["import {\n WebSocketGateway,\n WebSocketServer,\n SubscribeMessage,\n MessageBody,\n ConnectedSocket,\n} from '@nestjs/websockets';\nimport { Server, Socket } from 'socket.io';\n\n@WebSocketGateway()\nexport class BaseSocketGateway {\n @WebSocketServer()\n protected server: Server;\n\n handleConnection(client: Socket) {\n console.log('[Socket Connected]', client.id);\n }\n\n handleDisconnect(client: Socket) {\n console.log('[Socket Disconnected]', client.id);\n }\n\n @SubscribeMessage('message')\n onMessage(\n @MessageBody() payload: any,\n @ConnectedSocket() client: Socket,\n ) {\n client.emit('messageResponse', payload);\n }\n\n protected emitToClient(\n client: Socket,\n event: string,\n data: any,\n ) {\n client.emit(event, data);\n }\n\n protected broadcast(\n event: string,\n data: any,\n ) {\n this.server.emit(event, data);\n }\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 SocketModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SocketModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const websockets_1 = require("@nestjs/websockets");
|
|
13
|
+
const socket_gateway_1 = require("./socket.gateway");
|
|
14
|
+
let SocketModule = SocketModule_1 = class SocketModule {
|
|
15
|
+
static register(options = {}) {
|
|
16
|
+
let Gateway = class Gateway extends socket_gateway_1.BaseSocketGateway {
|
|
17
|
+
};
|
|
18
|
+
Gateway = __decorate([
|
|
19
|
+
(0, websockets_1.WebSocketGateway)({
|
|
20
|
+
cors: options.cors ?? { origin: '*' },
|
|
21
|
+
namespace: options.namespace,
|
|
22
|
+
})
|
|
23
|
+
], Gateway);
|
|
24
|
+
return {
|
|
25
|
+
module: SocketModule_1,
|
|
26
|
+
providers: [Gateway],
|
|
27
|
+
exports: [Gateway],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.SocketModule = SocketModule;
|
|
32
|
+
exports.SocketModule = SocketModule = SocketModule_1 = __decorate([
|
|
33
|
+
(0, common_1.Module)({})
|
|
34
|
+
], SocketModule);
|
|
35
|
+
//# sourceMappingURL=socket.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.module.js","sourceRoot":"","sources":["../../../src/common-infra/socket.io/socket.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,mDAAsD;AACtD,qDAAqD;AAI9C,IAAM,YAAY,oBAAlB,MAAM,YAAY;IACd,AAAP,MAAM,CAAC,QAAQ,CAAC,UAA+B,EAAE;QAK7C,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,kCAAiB;SAAG,CAAA;QAApC,OAAO;YAJZ,IAAA,6BAAgB,EAAC;gBACd,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE;gBACrC,SAAS,EAAE,OAAO,CAAC,SAAS;aAC/B,CAAC;WACI,OAAO,CAA6B;QAC1C,OAAO;YACH,MAAM,EAAE,cAAY;YACpB,SAAS,EAAE,CAAC,OAAO,CAAC;YACpB,OAAO,EAAE,CAAC,OAAO,CAAC;SACrB,CAAC;IACN,CAAC;CACJ,CAAA;AAbY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,YAAY,CAaxB","sourcesContent":["import { DynamicModule, Module } from '@nestjs/common';\nimport { WebSocketGateway } from '@nestjs/websockets';\nimport { BaseSocketGateway } from './socket.gateway';\nimport { SocketModuleOptions } from './socket.options';\n\n@Module({})\nexport class SocketModule {\n static register(options: SocketModuleOptions = {}): DynamicModule {\n @WebSocketGateway({\n cors: options.cors ?? { origin: '*' },\n namespace: options.namespace,\n })\n class Gateway extends BaseSocketGateway {}\n return {\n module: SocketModule,\n providers: [Gateway],\n exports: [Gateway],\n };\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.options.js","sourceRoot":"","sources":["../../../src/common-infra/socket.io/socket.options.ts"],"names":[],"mappings":"","sourcesContent":["export interface SocketModuleOptions {\n cors?: {\n origin: string | string[];\n };\n namespace?: string;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
export * from './core-common/constant/app.constant';
|
|
2
2
|
export * from './core-common/error/custom-error/already-exists.error';
|
|
3
|
-
export * from './core-common/error/custom-error/not-found.error';
|
|
4
|
-
export * from './core-common/error/custom-error/validation.error';
|
|
5
|
-
export * from './core-common/error/custom-error/internal-server.error';
|
|
6
|
-
export * from './core-common/error/custom-error/unauthorized.error';
|
|
7
|
-
export * from './core-common/error/custom-error/service-unavailable.error';
|
|
8
|
-
export * from './core-common/error/generic.error';
|
|
9
3
|
export * from './core-common/error/custom-error/bad-request.error';
|
|
4
|
+
export * from './core-common/error/custom-error/conflict.error';
|
|
10
5
|
export * from './core-common/error/custom-error/custom-validation-error';
|
|
11
6
|
export * from './core-common/error/custom-error/forbidden.error';
|
|
7
|
+
export * from './core-common/error/custom-error/internal-server.error';
|
|
8
|
+
export * from './core-common/error/custom-error/not-found.error';
|
|
9
|
+
export * from './core-common/error/custom-error/service-unavailable.error';
|
|
10
|
+
export * from './core-common/error/custom-error/unauthorized.error';
|
|
12
11
|
export * from './core-common/error/custom-error/unprocess-entity.error';
|
|
13
|
-
export * from './core-common/error/custom-error/
|
|
14
|
-
export * from './core-common/
|
|
12
|
+
export * from './core-common/error/custom-error/validation.error';
|
|
13
|
+
export * from './core-common/error/generic.error';
|
|
15
14
|
export * from './core-common/response-model/generic-error-response.model';
|
|
16
15
|
export * from './core-common/response-model/generic-success-response.model';
|
|
16
|
+
export * from './core-common/result-model/result';
|
|
17
17
|
export * from './core-common/logger/logger.interface';
|
|
18
18
|
export * from './core-common/logger/logger.module';
|
|
19
19
|
export * from './core-common/logger/logger.service';
|
|
20
|
-
export * from './core-common/core-common.module';
|
|
21
|
-
export * from './core-common/constant/app.constant';
|
|
22
20
|
export * from './common-infra/common-infra.module';
|
|
23
21
|
export * from './common-infra/database/typeorm.config';
|
|
22
|
+
export * from './core-common/constant/app.constant';
|
|
23
|
+
export * from './core-common/core-common.module';
|
|
24
|
+
export * from './common-infra/http/http-module.options';
|
|
25
|
+
export * from './common-infra/http/http.constant';
|
|
24
26
|
export * from './common-infra/http/http.module';
|
|
25
27
|
export * from './common-infra/http/https.service';
|
|
26
|
-
export * from './common-infra/
|
|
27
|
-
export * from './common-infra/
|
|
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
|
@@ -16,29 +16,33 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./core-common/constant/app.constant"), exports);
|
|
18
18
|
__exportStar(require("./core-common/error/custom-error/already-exists.error"), exports);
|
|
19
|
-
__exportStar(require("./core-common/error/custom-error/not-found.error"), exports);
|
|
20
|
-
__exportStar(require("./core-common/error/custom-error/validation.error"), exports);
|
|
21
|
-
__exportStar(require("./core-common/error/custom-error/internal-server.error"), exports);
|
|
22
|
-
__exportStar(require("./core-common/error/custom-error/unauthorized.error"), exports);
|
|
23
|
-
__exportStar(require("./core-common/error/custom-error/service-unavailable.error"), exports);
|
|
24
|
-
__exportStar(require("./core-common/error/generic.error"), exports);
|
|
25
19
|
__exportStar(require("./core-common/error/custom-error/bad-request.error"), exports);
|
|
20
|
+
__exportStar(require("./core-common/error/custom-error/conflict.error"), exports);
|
|
26
21
|
__exportStar(require("./core-common/error/custom-error/custom-validation-error"), exports);
|
|
27
22
|
__exportStar(require("./core-common/error/custom-error/forbidden.error"), exports);
|
|
23
|
+
__exportStar(require("./core-common/error/custom-error/internal-server.error"), exports);
|
|
24
|
+
__exportStar(require("./core-common/error/custom-error/not-found.error"), exports);
|
|
25
|
+
__exportStar(require("./core-common/error/custom-error/service-unavailable.error"), exports);
|
|
26
|
+
__exportStar(require("./core-common/error/custom-error/unauthorized.error"), exports);
|
|
28
27
|
__exportStar(require("./core-common/error/custom-error/unprocess-entity.error"), exports);
|
|
29
|
-
__exportStar(require("./core-common/error/custom-error/
|
|
30
|
-
__exportStar(require("./core-common/
|
|
28
|
+
__exportStar(require("./core-common/error/custom-error/validation.error"), exports);
|
|
29
|
+
__exportStar(require("./core-common/error/generic.error"), exports);
|
|
31
30
|
__exportStar(require("./core-common/response-model/generic-error-response.model"), exports);
|
|
32
31
|
__exportStar(require("./core-common/response-model/generic-success-response.model"), exports);
|
|
32
|
+
__exportStar(require("./core-common/result-model/result"), exports);
|
|
33
33
|
__exportStar(require("./core-common/logger/logger.interface"), exports);
|
|
34
34
|
__exportStar(require("./core-common/logger/logger.module"), exports);
|
|
35
35
|
__exportStar(require("./core-common/logger/logger.service"), exports);
|
|
36
|
-
__exportStar(require("./core-common/core-common.module"), exports);
|
|
37
|
-
__exportStar(require("./core-common/constant/app.constant"), exports);
|
|
38
36
|
__exportStar(require("./common-infra/common-infra.module"), exports);
|
|
39
37
|
__exportStar(require("./common-infra/database/typeorm.config"), exports);
|
|
38
|
+
__exportStar(require("./core-common/constant/app.constant"), exports);
|
|
39
|
+
__exportStar(require("./core-common/core-common.module"), exports);
|
|
40
|
+
__exportStar(require("./common-infra/http/http-module.options"), exports);
|
|
41
|
+
__exportStar(require("./common-infra/http/http.constant"), exports);
|
|
40
42
|
__exportStar(require("./common-infra/http/http.module"), exports);
|
|
41
43
|
__exportStar(require("./common-infra/http/https.service"), exports);
|
|
42
|
-
__exportStar(require("./common-infra/
|
|
43
|
-
__exportStar(require("./common-infra/
|
|
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);
|
|
44
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":";;;;;;;;;;;;;;;;AACA,sEAAmD;AAGnD,wFAAqE;AACrE,mFAAgE;AAChE,
|
|
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"]}
|