@vuvannghiawork/common 0.0.32 → 0.0.35
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/controllers/base-app.controller.d.ts +2 -0
- package/dist/controllers/base-app.controller.js +16 -0
- package/dist/controllers/base-app.controller.js.map +1 -1
- package/dist/events/base-event.d.ts +5 -0
- package/dist/events/base-event.js +3 -0
- package/dist/events/base-event.js.map +1 -0
- package/dist/events/base-listener.d.ts +13 -0
- package/dist/events/base-listener.js +34 -0
- package/dist/events/base-listener.js.map +1 -0
- package/dist/events/base-publisher.d.ts +13 -0
- package/dist/events/base-publisher.js +22 -0
- package/dist/events/base-publisher.js.map +1 -0
- package/dist/events/subjects.d.ts +4 -0
- package/dist/events/subjects.js +9 -0
- package/dist/events/subjects.js.map +1 -0
- package/dist/events/ticket-created-event.d.ts +10 -0
- package/dist/events/ticket-created-event.js +3 -0
- package/dist/events/ticket-created-event.js.map +1 -0
- package/dist/events/ticket-updated-event.d.ts +10 -0
- package/dist/events/ticket-updated-event.js +3 -0
- package/dist/events/ticket-updated-event.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/user-payload.interface.d.ts +1 -1
- package/dist/strategies/common-jwt.strategy.d.ts +2 -4
- package/dist/strategies/common-jwt.strategy.js +3 -0
- package/dist/strategies/common-jwt.strategy.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -1
|
@@ -8,14 +8,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.BaseAppController = void 0;
|
|
13
16
|
const common_1 = require("@nestjs/common");
|
|
14
17
|
const swagger_1 = require("@nestjs/swagger");
|
|
18
|
+
const current_user_decorator_1 = require("../decorators/current-user.decorator");
|
|
19
|
+
const require_auth_decorator_1 = require("../decorators/require-auth.decorator");
|
|
15
20
|
let BaseAppController = class BaseAppController {
|
|
16
21
|
getHello() {
|
|
17
22
|
return 'Hello World!';
|
|
18
23
|
}
|
|
24
|
+
getMe(user) {
|
|
25
|
+
return user;
|
|
26
|
+
}
|
|
19
27
|
getEnv() {
|
|
20
28
|
return process.env.ENVIRONMENT || 'ENVIRONMENT not set';
|
|
21
29
|
}
|
|
@@ -27,6 +35,14 @@ __decorate([
|
|
|
27
35
|
__metadata("design:paramtypes", []),
|
|
28
36
|
__metadata("design:returntype", String)
|
|
29
37
|
], BaseAppController.prototype, "getHello", null);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, common_1.Get)('me'),
|
|
40
|
+
(0, require_auth_decorator_1.RequireAuth)(),
|
|
41
|
+
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
|
42
|
+
__metadata("design:type", Function),
|
|
43
|
+
__metadata("design:paramtypes", [Object]),
|
|
44
|
+
__metadata("design:returntype", void 0)
|
|
45
|
+
], BaseAppController.prototype, "getMe", null);
|
|
30
46
|
__decorate([
|
|
31
47
|
(0, common_1.Get)('env'),
|
|
32
48
|
__metadata("design:type", Function),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-app.controller.js","sourceRoot":"","sources":["../../src/controllers/base-app.controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-app.controller.js","sourceRoot":"","sources":["../../src/controllers/base-app.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAiD;AACjD,6CAA0C;AAC1C,iFAAoE;AACpE,iFAAoE;AAK7D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAE5B,QAAQ;QACN,OAAO,cAAc,CAAC;IACxB,CAAC;IAGD,KAAK,CAAgB,IAAiB;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;QACJ,OAAO,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,qBAAqB,CAAC;IAC1D,CAAC;CACF,CAAA;AAdY,8CAAiB;AAE5B;IADC,IAAA,YAAG,GAAE;;;;iDAGL;AAGD;IAFC,IAAA,YAAG,EAAC,IAAI,CAAC;IACT,IAAA,oCAAW,GAAE;IACP,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;8CAEnB;AAED;IADC,IAAA,YAAG,EAAC,KAAK,CAAC;;;;+CAGV;4BAbU,iBAAiB;IAF7B,IAAA,iBAAO,EAAC,KAAK,CAAC;IACd,IAAA,mBAAU,GAAE;GACA,iBAAiB,CAc7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-event.js","sourceRoot":"","sources":["../../src/events/base-event.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Message, Stan } from 'node-nats-streaming';
|
|
2
|
+
import { BaseEvent } from './base-event';
|
|
3
|
+
export declare abstract class BaseListener<T extends BaseEvent> {
|
|
4
|
+
abstract subject: T['subject'];
|
|
5
|
+
abstract queueGroupName: string;
|
|
6
|
+
abstract onMessage(data: T['data'], msg: Message): void;
|
|
7
|
+
private client;
|
|
8
|
+
protected ackWait: number;
|
|
9
|
+
constructor(client: Stan);
|
|
10
|
+
subscriptionOptions(): import("node-nats-streaming").SubscriptionOptions;
|
|
11
|
+
listen(): void;
|
|
12
|
+
parseMessage(msg: Message): any;
|
|
13
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseListener = void 0;
|
|
4
|
+
class BaseListener {
|
|
5
|
+
client;
|
|
6
|
+
ackWait = 5 * 1000;
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
subscriptionOptions() {
|
|
11
|
+
return this.client
|
|
12
|
+
.subscriptionOptions()
|
|
13
|
+
.setDeliverAllAvailable()
|
|
14
|
+
.setManualAckMode(true)
|
|
15
|
+
.setAckWait(this.ackWait)
|
|
16
|
+
.setDurableName(this.queueGroupName);
|
|
17
|
+
}
|
|
18
|
+
listen() {
|
|
19
|
+
const subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
|
|
20
|
+
subscription.on('message', (msg) => {
|
|
21
|
+
console.log(`Message received: ${this.subject} / ${this.queueGroupName}`);
|
|
22
|
+
const parsedData = this.parseMessage(msg);
|
|
23
|
+
this.onMessage(parsedData, msg);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
parseMessage(msg) {
|
|
27
|
+
const data = msg.getData();
|
|
28
|
+
return typeof data === 'string'
|
|
29
|
+
? JSON.parse(data)
|
|
30
|
+
: JSON.parse(data.toString('utf8'));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.BaseListener = BaseListener;
|
|
34
|
+
//# sourceMappingURL=base-listener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-listener.js","sourceRoot":"","sources":["../../src/events/base-listener.ts"],"names":[],"mappings":";;;AAGA,MAAsB,YAAY;IAIxB,MAAM,CAAO;IACX,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC;IAE7B,YAAY,MAAY;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,CAAC,MAAM;aACf,mBAAmB,EAAE;aACrB,sBAAsB,EAAE;aACxB,gBAAgB,CAAC,IAAI,CAAC;aACtB,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;aACxB,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACzC,CAAC;IAED,MAAM;QACJ,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CACxC,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,mBAAmB,EAAE,CAC3B,CAAC;QAEF,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAY,EAAE,EAAE;YAC1C,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,CAAC,OAAO,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;YAE1E,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAC1C,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAC,GAAY;QACvB,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;QAC3B,OAAO,OAAO,IAAI,KAAK,QAAQ;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YAClB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACxC,CAAC;CACF;AAzCD,oCAyCC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Stan } from 'node-nats-streaming';
|
|
2
|
+
import { Subjects } from './subjects';
|
|
3
|
+
interface Event {
|
|
4
|
+
subject: Subjects;
|
|
5
|
+
data: any;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class Publisher<T extends Event> {
|
|
8
|
+
abstract subject: T['subject'];
|
|
9
|
+
private client;
|
|
10
|
+
constructor(client: Stan);
|
|
11
|
+
publish(data: T['data']): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Publisher = void 0;
|
|
4
|
+
class Publisher {
|
|
5
|
+
client;
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
publish(data) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
this.client.publish(this.subject, JSON.stringify(data), (err) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
return reject(err);
|
|
14
|
+
}
|
|
15
|
+
console.log('Event published to subject', this.subject);
|
|
16
|
+
resolve();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.Publisher = Publisher;
|
|
22
|
+
//# sourceMappingURL=base-publisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-publisher.js","sourceRoot":"","sources":["../../src/events/base-publisher.ts"],"names":[],"mappings":";;;AASA,MAAsB,SAAS;IAErB,MAAM,CAAO;IAErB,YAAY,MAAY;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,IAAe;QACrB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;gBAC9D,IAAI,GAAG,EAAE,CAAC;oBACR,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;gBACrB,CAAC;gBACD,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBACxD,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAnBD,8BAmBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subjects = void 0;
|
|
4
|
+
var Subjects;
|
|
5
|
+
(function (Subjects) {
|
|
6
|
+
Subjects["TicketCreated"] = "ticket:created";
|
|
7
|
+
Subjects["TicketUpdated"] = "ticket:updated";
|
|
8
|
+
})(Subjects || (exports.Subjects = Subjects = {}));
|
|
9
|
+
//# sourceMappingURL=subjects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subjects.js","sourceRoot":"","sources":["../../src/events/subjects.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,4CAAgC,CAAA;IAChC,4CAAgC,CAAA;AAClC,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket-created-event.js","sourceRoot":"","sources":["../../src/events/ticket-created-event.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket-updated-event.js","sourceRoot":"","sources":["../../src/events/ticket-updated-event.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ export * from './constants/swagger.constant';
|
|
|
3
3
|
export * from './controllers/base-app.controller';
|
|
4
4
|
export * from './decorators/current-user.decorator';
|
|
5
5
|
export * from './decorators/require-auth.decorator';
|
|
6
|
+
export * from './events/base-event';
|
|
7
|
+
export * from './events/base-listener';
|
|
8
|
+
export * from './events/base-publisher';
|
|
9
|
+
export * from './events/subjects';
|
|
10
|
+
export * from './events/ticket-created-event';
|
|
11
|
+
export * from './events/ticket-updated-event';
|
|
6
12
|
export * from './filters/error-handler.filter';
|
|
7
13
|
export * from './guards/jwt-auth.guard';
|
|
8
14
|
export * from './helpers/bootstrap.helper';
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,12 @@ __exportStar(require("./constants/swagger.constant"), exports);
|
|
|
19
19
|
__exportStar(require("./controllers/base-app.controller"), exports);
|
|
20
20
|
__exportStar(require("./decorators/current-user.decorator"), exports);
|
|
21
21
|
__exportStar(require("./decorators/require-auth.decorator"), exports);
|
|
22
|
+
__exportStar(require("./events/base-event"), exports);
|
|
23
|
+
__exportStar(require("./events/base-listener"), exports);
|
|
24
|
+
__exportStar(require("./events/base-publisher"), exports);
|
|
25
|
+
__exportStar(require("./events/subjects"), exports);
|
|
26
|
+
__exportStar(require("./events/ticket-created-event"), exports);
|
|
27
|
+
__exportStar(require("./events/ticket-updated-event"), exports);
|
|
22
28
|
__exportStar(require("./filters/error-handler.filter"), exports);
|
|
23
29
|
__exportStar(require("./guards/jwt-auth.guard"), exports);
|
|
24
30
|
__exportStar(require("./helpers/bootstrap.helper"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAIA,qEAAmD;AACnD,+DAA6C;AAC7C,oEAAkD;AAClD,sEAAoD;AACpD,sEAAoD;AACpD,iEAA+C;AAC/C,0DAAwC;AACxC,6DAA2C;AAC3C,2DAAyC;AACzC,qEAAmD;AACnD,sEAAoD;AACpD,kEAAgD;AAChD,6DAA2C;AAC3C,iEAA+C;AAC/C,mEAAiD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAIA,qEAAmD;AACnD,+DAA6C;AAC7C,oEAAkD;AAClD,sEAAoD;AACpD,sEAAoD;AACpD,sDAAoC;AACpC,yDAAuC;AACvC,0DAAwC;AACxC,oDAAkC;AAClC,gEAA8C;AAC9C,gEAA8C;AAC9C,iEAA+C;AAC/C,0DAAwC;AACxC,6DAA2C;AAC3C,2DAAyC;AACzC,qEAAmD;AACnD,sEAAoD;AACpD,kEAAgD;AAChD,6DAA2C;AAC3C,iEAA+C;AAC/C,mEAAiD"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { BaseJwtStrategy } from './base-jwt.strategy';
|
|
2
2
|
import { JwtPayload } from 'src/interfaces/jwt-payload.interface';
|
|
3
|
+
import { UserPayload } from 'src/interfaces/user-payload.interface';
|
|
3
4
|
export declare class CommonJwtStrategy extends BaseJwtStrategy {
|
|
4
5
|
constructor();
|
|
5
|
-
validate(payload: JwtPayload): Promise<
|
|
6
|
-
uuid: string;
|
|
7
|
-
email: string;
|
|
8
|
-
}>;
|
|
6
|
+
validate(payload: JwtPayload): Promise<UserPayload>;
|
|
9
7
|
}
|
|
@@ -20,6 +20,9 @@ let CommonJwtStrategy = class CommonJwtStrategy extends base_jwt_strategy_1.Base
|
|
|
20
20
|
super(process.env.JWT_SECRET_KEY);
|
|
21
21
|
}
|
|
22
22
|
async validate(payload) {
|
|
23
|
+
if (!payload.sub) {
|
|
24
|
+
throw new common_1.UnauthorizedException('Invalid token payload');
|
|
25
|
+
}
|
|
23
26
|
return {
|
|
24
27
|
uuid: payload.sub,
|
|
25
28
|
email: payload.email,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-jwt.strategy.js","sourceRoot":"","sources":["../../src/strategies/common-jwt.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"common-jwt.strategy.js","sourceRoot":"","sources":["../../src/strategies/common-jwt.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAmE;AACnE,2DAAsD;AAK/C,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,mCAAe;IACpD;QACE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACpC,CAAC;IACD,KAAK,CAAC,QAAQ,CAAC,OAAmB;QAChC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;YACjB,MAAM,IAAI,8BAAqB,CAAC,uBAAuB,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,GAAG;YACjB,KAAK,EAAE,OAAO,CAAC,KAAK;SAErB,CAAC;IACJ,CAAC;CACF,CAAA;AAlBY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;;GACA,iBAAiB,CAkB7B"}
|