@triproject/nestjs-core 1.0.5
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/LICENSE +15 -0
- package/README.md +140 -0
- package/dist/bootstrap.d.ts +2 -0
- package/dist/bootstrap.js +43 -0
- package/dist/config.d.ts +46 -0
- package/dist/config.js +50 -0
- package/dist/controllers/controller.d.ts +8 -0
- package/dist/controllers/controller.js +56 -0
- package/dist/drivers/cache/cache.d.ts +18 -0
- package/dist/drivers/cache/cache.driver.d.ts +2 -0
- package/dist/drivers/cache/cache.driver.js +22 -0
- package/dist/drivers/cache/cache.js +92 -0
- package/dist/drivers/cache/index.d.ts +3 -0
- package/dist/drivers/cache/index.js +19 -0
- package/dist/drivers/cache/redis.d.ts +10 -0
- package/dist/drivers/cache/redis.js +52 -0
- package/dist/drivers/db/db.helper.d.ts +55 -0
- package/dist/drivers/db/db.helper.js +217 -0
- package/dist/drivers/db/db.module.d.ts +2 -0
- package/dist/drivers/db/db.module.js +44 -0
- package/dist/drivers/db/db.service.d.ts +10 -0
- package/dist/drivers/db/db.service.js +49 -0
- package/dist/drivers/db/index.d.ts +5 -0
- package/dist/drivers/db/index.js +21 -0
- package/dist/drivers/db/migration.d.ts +42 -0
- package/dist/drivers/db/migration.js +81 -0
- package/dist/drivers/db/repository.d.ts +41 -0
- package/dist/drivers/db/repository.js +255 -0
- package/dist/drivers/encryptions/encryption.d.ts +8 -0
- package/dist/drivers/encryptions/encryption.js +50 -0
- package/dist/drivers/encryptions/encryption.module.d.ts +2 -0
- package/dist/drivers/encryptions/encryption.module.js +24 -0
- package/dist/drivers/encryptions/index.d.ts +3 -0
- package/dist/drivers/encryptions/index.js +19 -0
- package/dist/drivers/encryptions/jwt.d.ts +6 -0
- package/dist/drivers/encryptions/jwt.js +46 -0
- package/dist/drivers/encryptions/password-hash.d.ts +11 -0
- package/dist/drivers/encryptions/password-hash.js +38 -0
- package/dist/drivers/encryptions/snap.signature.d.ts +32 -0
- package/dist/drivers/encryptions/snap.signature.js +110 -0
- package/dist/drivers/logger/app.logger.d.ts +23 -0
- package/dist/drivers/logger/app.logger.js +183 -0
- package/dist/drivers/logger/index.d.ts +2 -0
- package/dist/drivers/logger/index.js +18 -0
- package/dist/drivers/logger/slack.logger.d.ts +4 -0
- package/dist/drivers/logger/slack.logger.js +24 -0
- package/dist/drivers/mail/index.d.ts +6 -0
- package/dist/drivers/mail/index.js +22 -0
- package/dist/drivers/mail/mail-template.d.ts +8 -0
- package/dist/drivers/mail/mail-template.js +74 -0
- package/dist/drivers/mail/mail.config.d.ts +18 -0
- package/dist/drivers/mail/mail.config.js +4 -0
- package/dist/drivers/mail/mail.d.ts +23 -0
- package/dist/drivers/mail/mail.js +98 -0
- package/dist/drivers/mail/mail.module.d.ts +2 -0
- package/dist/drivers/mail/mail.module.js +26 -0
- package/dist/drivers/mail/mail.queue.d.ts +9 -0
- package/dist/drivers/mail/mail.queue.js +37 -0
- package/dist/drivers/mail/mailer.d.ts +13 -0
- package/dist/drivers/mail/mailer.js +62 -0
- package/dist/drivers/notifications/index.d.ts +5 -0
- package/dist/drivers/notifications/index.js +21 -0
- package/dist/drivers/notifications/notification.config.d.ts +8 -0
- package/dist/drivers/notifications/notification.config.js +4 -0
- package/dist/drivers/notifications/notification.module.d.ts +2 -0
- package/dist/drivers/notifications/notification.module.js +25 -0
- package/dist/drivers/notifications/notification.queue.d.ts +9 -0
- package/dist/drivers/notifications/notification.queue.js +37 -0
- package/dist/drivers/notifications/push-notification.d.ts +10 -0
- package/dist/drivers/notifications/push-notification.js +75 -0
- package/dist/drivers/notifications/slack.d.ts +15 -0
- package/dist/drivers/notifications/slack.js +95 -0
- package/dist/drivers/queues/app.queue.d.ts +11 -0
- package/dist/drivers/queues/app.queue.js +66 -0
- package/dist/drivers/queues/index.d.ts +2 -0
- package/dist/drivers/queues/index.js +18 -0
- package/dist/drivers/queues/queue.module.d.ts +2 -0
- package/dist/drivers/queues/queue.module.js +41 -0
- package/dist/helpers/exception.helper.d.ts +35 -0
- package/dist/helpers/exception.helper.js +71 -0
- package/dist/helpers/http.helper.d.ts +23 -0
- package/dist/helpers/http.helper.js +134 -0
- package/dist/helpers/swagger.helper.d.ts +20 -0
- package/dist/helpers/swagger.helper.js +287 -0
- package/dist/helpers/totp.helper.d.ts +16 -0
- package/dist/helpers/totp.helper.js +30 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +24 -0
- package/dist/middlewares/log.middleware.d.ts +9 -0
- package/dist/middlewares/log.middleware.js +59 -0
- package/package.json +145 -0
|
@@ -0,0 +1,21 @@
|
|
|
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("./notification.config"), exports);
|
|
18
|
+
__exportStar(require("./notification.module"), exports);
|
|
19
|
+
__exportStar(require("./notification.queue"), exports);
|
|
20
|
+
__exportStar(require("./push-notification"), exports);
|
|
21
|
+
__exportStar(require("./slack"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.NotificationDriverModule = void 0;
|
|
10
|
+
const bull_1 = require("@nestjs/bull");
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const notification_config_1 = require("./notification.config");
|
|
13
|
+
const notification_queue_1 = require("./notification.queue");
|
|
14
|
+
const push_notification_1 = require("./push-notification");
|
|
15
|
+
let NotificationDriverModule = class NotificationDriverModule {
|
|
16
|
+
};
|
|
17
|
+
exports.NotificationDriverModule = NotificationDriverModule;
|
|
18
|
+
exports.NotificationDriverModule = NotificationDriverModule = __decorate([
|
|
19
|
+
(0, common_1.Global)(),
|
|
20
|
+
(0, common_1.Module)({
|
|
21
|
+
providers: [push_notification_1.PushNotification, notification_queue_1.NotificationQueue],
|
|
22
|
+
imports: [bull_1.BullModule.registerQueue({ name: notification_config_1.notificationQueue })],
|
|
23
|
+
exports: [push_notification_1.PushNotification],
|
|
24
|
+
})
|
|
25
|
+
], NotificationDriverModule);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Job } from 'bull';
|
|
2
|
+
import { AppQueue } from '../queues/app.queue';
|
|
3
|
+
import { SendNotificationDto } from './notification.config';
|
|
4
|
+
import { PushNotification } from './push-notification';
|
|
5
|
+
export declare class NotificationQueue extends AppQueue {
|
|
6
|
+
private pushNotification;
|
|
7
|
+
constructor(pushNotification: PushNotification);
|
|
8
|
+
sendNotification({ data }: Job<SendNotificationDto>): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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.NotificationQueue = void 0;
|
|
13
|
+
const bull_1 = require("@nestjs/bull");
|
|
14
|
+
const app_queue_1 = require("../queues/app.queue");
|
|
15
|
+
const notification_config_1 = require("./notification.config");
|
|
16
|
+
const push_notification_1 = require("./push-notification");
|
|
17
|
+
let NotificationQueue = class NotificationQueue extends app_queue_1.AppQueue {
|
|
18
|
+
pushNotification;
|
|
19
|
+
constructor(pushNotification) {
|
|
20
|
+
super();
|
|
21
|
+
this.pushNotification = pushNotification;
|
|
22
|
+
}
|
|
23
|
+
async sendNotification({ data }) {
|
|
24
|
+
await this.pushNotification.send(data, false);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.NotificationQueue = NotificationQueue;
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, bull_1.Process)({ name: notification_config_1.notificationQueue, concurrency: 4 }),
|
|
30
|
+
__metadata("design:type", Function),
|
|
31
|
+
__metadata("design:paramtypes", [Object]),
|
|
32
|
+
__metadata("design:returntype", Promise)
|
|
33
|
+
], NotificationQueue.prototype, "sendNotification", null);
|
|
34
|
+
exports.NotificationQueue = NotificationQueue = __decorate([
|
|
35
|
+
(0, bull_1.Processor)(notification_config_1.notificationQueue),
|
|
36
|
+
__metadata("design:paramtypes", [push_notification_1.PushNotification])
|
|
37
|
+
], NotificationQueue);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Queue } from 'bullmq';
|
|
2
|
+
import { SendNotificationDto } from './notification.config';
|
|
3
|
+
export declare class PushNotification {
|
|
4
|
+
private notificationQueue;
|
|
5
|
+
private APP_ID;
|
|
6
|
+
private client;
|
|
7
|
+
constructor(notificationQueue: Queue);
|
|
8
|
+
send(params: SendNotificationDto, shouldQueue?: boolean): Promise<import("axios").AxiosResponse<any, any, {}> | import("bullmq").Job<any, any, string>>;
|
|
9
|
+
broadcast(params: Omit<SendNotificationDto, 'userId' | 'type'>, shouldQueue?: boolean): Promise<import("axios").AxiosResponse<any, any, {}> | import("bullmq").Job<any, any, string>>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.PushNotification = void 0;
|
|
19
|
+
const bull_1 = require("@nestjs/bull");
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const helpers_1 = require("@triproject/helpers");
|
|
22
|
+
const axios_1 = __importDefault(require("axios"));
|
|
23
|
+
const bullmq_1 = require("bullmq");
|
|
24
|
+
const config_1 = require("../../config");
|
|
25
|
+
const notification_config_1 = require("./notification.config");
|
|
26
|
+
let PushNotification = class PushNotification {
|
|
27
|
+
notificationQueue;
|
|
28
|
+
APP_ID;
|
|
29
|
+
client;
|
|
30
|
+
constructor(notificationQueue) {
|
|
31
|
+
this.notificationQueue = notificationQueue;
|
|
32
|
+
this.APP_ID = config_1.ONESIGNAL_APP_ID;
|
|
33
|
+
this.client = axios_1.default.create({
|
|
34
|
+
baseURL: 'https://api.onesignal.com',
|
|
35
|
+
timeout: 100,
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
38
|
+
Authorization: `Key ${config_1.ONESIGNAL_REST_API_KEY}`,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async send(params, shouldQueue = true) {
|
|
43
|
+
if (shouldQueue) {
|
|
44
|
+
return this.notificationQueue.add(notification_config_1.notificationQueue, params, {
|
|
45
|
+
jobId: (0, helpers_1.generateId)(),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const { userId, type, title, message, data } = params;
|
|
49
|
+
return await this.client.post('notifications', {
|
|
50
|
+
app_id: this.APP_ID,
|
|
51
|
+
target_channel: 'push',
|
|
52
|
+
name: type,
|
|
53
|
+
headings: { en: title },
|
|
54
|
+
contents: { en: message },
|
|
55
|
+
data,
|
|
56
|
+
included_segments: [userId].filter((d) => d),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
broadcast(params, shouldQueue = true) {
|
|
60
|
+
const { title, message, data } = params;
|
|
61
|
+
return this.send({
|
|
62
|
+
userId: 'All',
|
|
63
|
+
type: 'broadcast',
|
|
64
|
+
title,
|
|
65
|
+
message,
|
|
66
|
+
data,
|
|
67
|
+
}, shouldQueue);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.PushNotification = PushNotification;
|
|
71
|
+
exports.PushNotification = PushNotification = __decorate([
|
|
72
|
+
(0, common_1.Injectable)(),
|
|
73
|
+
__param(0, (0, bull_1.InjectQueue)(notification_config_1.notificationQueue)),
|
|
74
|
+
__metadata("design:paramtypes", [bullmq_1.Queue])
|
|
75
|
+
], PushNotification);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AppLogger } from '../logger/app.logger';
|
|
2
|
+
interface SlackConfig {
|
|
3
|
+
webhookUrl: string;
|
|
4
|
+
logger?: AppLogger | Console;
|
|
5
|
+
}
|
|
6
|
+
export declare class Slack {
|
|
7
|
+
private logger;
|
|
8
|
+
private client;
|
|
9
|
+
private status;
|
|
10
|
+
constructor(config: SlackConfig);
|
|
11
|
+
private _toggleBlocked;
|
|
12
|
+
private _format;
|
|
13
|
+
send(...messages: any): Promise<void | import("axios").AxiosResponse<any, any, {}>>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
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.Slack = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
class Slack {
|
|
9
|
+
logger = console;
|
|
10
|
+
client;
|
|
11
|
+
status = {
|
|
12
|
+
blocked: false,
|
|
13
|
+
lastUpdateAt: new Date(),
|
|
14
|
+
};
|
|
15
|
+
constructor(config) {
|
|
16
|
+
if (config.logger)
|
|
17
|
+
this.logger = config.logger;
|
|
18
|
+
if (config.webhookUrl.startsWith('https')) {
|
|
19
|
+
this.client = axios_1.default.create({
|
|
20
|
+
baseURL: config.webhookUrl,
|
|
21
|
+
timeout: 500,
|
|
22
|
+
headers: { 'Content-Type': 'application/json' },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
_toggleBlocked() {
|
|
27
|
+
this.status = {
|
|
28
|
+
blocked: !this.status.blocked,
|
|
29
|
+
lastUpdateAt: new Date(),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
_format(...messages) {
|
|
33
|
+
const blocks = [];
|
|
34
|
+
if (messages.length === 0)
|
|
35
|
+
return blocks;
|
|
36
|
+
if (messages.length > 0 && typeof messages[0] === 'string') {
|
|
37
|
+
blocks.push({
|
|
38
|
+
type: 'header',
|
|
39
|
+
text: { type: 'plain_text', text: messages[0] },
|
|
40
|
+
});
|
|
41
|
+
return blocks;
|
|
42
|
+
}
|
|
43
|
+
for (const msg of messages) {
|
|
44
|
+
if (!msg)
|
|
45
|
+
continue;
|
|
46
|
+
if (msg instanceof Error) {
|
|
47
|
+
blocks.push({
|
|
48
|
+
type: 'section',
|
|
49
|
+
text: {
|
|
50
|
+
type: 'mrkdwn',
|
|
51
|
+
text: '<font color="red">```**' +
|
|
52
|
+
msg.name +
|
|
53
|
+
'**: ' +
|
|
54
|
+
msg.message +
|
|
55
|
+
'\n ' +
|
|
56
|
+
msg?.stack?.split('\n').join('\n ') +
|
|
57
|
+
'</font>```',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else if (typeof msg === 'object') {
|
|
62
|
+
blocks.push({
|
|
63
|
+
type: 'section',
|
|
64
|
+
text: { type: 'mrkdwn', text: '```json' + JSON.stringify(msg, null, 2) + '```' },
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
blocks.push({
|
|
69
|
+
type: 'section',
|
|
70
|
+
text: { type: 'plain_text', text: msg?.toString() },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return blocks;
|
|
75
|
+
}
|
|
76
|
+
async send(...messages) {
|
|
77
|
+
if (!this.client)
|
|
78
|
+
return;
|
|
79
|
+
if (this.status.blocked && new Date().getTime() - this.status.lastUpdateAt.getTime() < 60_000 * 60 * 3)
|
|
80
|
+
return;
|
|
81
|
+
return await this.client
|
|
82
|
+
.post('', { blocks: this._format(...messages) })
|
|
83
|
+
.then((data) => {
|
|
84
|
+
if (this.status.blocked)
|
|
85
|
+
this._toggleBlocked();
|
|
86
|
+
return data;
|
|
87
|
+
})
|
|
88
|
+
.catch((error) => {
|
|
89
|
+
this?.logger.error('Failed to send slack notification', error);
|
|
90
|
+
if (!this.status.blocked)
|
|
91
|
+
this._toggleBlocked();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.Slack = Slack;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Job } from 'bull';
|
|
2
|
+
import { AppLogger } from '../logger/app.logger';
|
|
3
|
+
export declare class AppQueue {
|
|
4
|
+
protected logger: AppLogger;
|
|
5
|
+
constructor();
|
|
6
|
+
onProgress(job: Job): void;
|
|
7
|
+
onCompleted(job: Job): void;
|
|
8
|
+
onStalled(job: Job): void;
|
|
9
|
+
onError(job: Job): void;
|
|
10
|
+
onFailed(job: Job, error: unknown): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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.AppQueue = void 0;
|
|
13
|
+
const bull_1 = require("@nestjs/bull");
|
|
14
|
+
const app_logger_1 = require("../logger/app.logger");
|
|
15
|
+
class AppQueue {
|
|
16
|
+
logger = new app_logger_1.AppLogger(this.constructor.name);
|
|
17
|
+
constructor() {
|
|
18
|
+
this.logger.log(this.constructor.name + ' is ready');
|
|
19
|
+
}
|
|
20
|
+
onProgress(job) {
|
|
21
|
+
this.logger.log(`Job ${job.id} in ${job.name} is active`, job.data);
|
|
22
|
+
}
|
|
23
|
+
onCompleted(job) {
|
|
24
|
+
this.logger.log(`Job ${job.id} in ${job.name} is completed`, job.data);
|
|
25
|
+
}
|
|
26
|
+
onStalled(job) {
|
|
27
|
+
this.logger.error(`Job ${job.id} in ${job.name} is stalled`, job.data);
|
|
28
|
+
}
|
|
29
|
+
onError(job) {
|
|
30
|
+
this.logger.error(`Job ${job.id} in ${job.name} is error`, job.data);
|
|
31
|
+
}
|
|
32
|
+
onFailed(job, error) {
|
|
33
|
+
this.logger.error(`Job ${job.id} in ${job.name} is failed`, job.data, error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.AppQueue = AppQueue;
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, bull_1.OnQueueProgress)(),
|
|
39
|
+
__metadata("design:type", Function),
|
|
40
|
+
__metadata("design:paramtypes", [Object]),
|
|
41
|
+
__metadata("design:returntype", void 0)
|
|
42
|
+
], AppQueue.prototype, "onProgress", null);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, bull_1.OnQueueCompleted)(),
|
|
45
|
+
__metadata("design:type", Function),
|
|
46
|
+
__metadata("design:paramtypes", [Object]),
|
|
47
|
+
__metadata("design:returntype", void 0)
|
|
48
|
+
], AppQueue.prototype, "onCompleted", null);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, bull_1.OnQueueStalled)(),
|
|
51
|
+
__metadata("design:type", Function),
|
|
52
|
+
__metadata("design:paramtypes", [Object]),
|
|
53
|
+
__metadata("design:returntype", void 0)
|
|
54
|
+
], AppQueue.prototype, "onStalled", null);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, bull_1.OnQueueError)(),
|
|
57
|
+
__metadata("design:type", Function),
|
|
58
|
+
__metadata("design:paramtypes", [Object]),
|
|
59
|
+
__metadata("design:returntype", void 0)
|
|
60
|
+
], AppQueue.prototype, "onError", null);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, bull_1.OnQueueFailed)(),
|
|
63
|
+
__metadata("design:type", Function),
|
|
64
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
65
|
+
__metadata("design:returntype", void 0)
|
|
66
|
+
], AppQueue.prototype, "onFailed", null);
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./app.queue"), exports);
|
|
18
|
+
__exportStar(require("./queue.module"), exports);
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.QueueModule = void 0;
|
|
10
|
+
const bullmq_1 = require("@nestjs/bullmq");
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const config_1 = require("../../config");
|
|
13
|
+
let QueueModule = class QueueModule {
|
|
14
|
+
};
|
|
15
|
+
exports.QueueModule = QueueModule;
|
|
16
|
+
exports.QueueModule = QueueModule = __decorate([
|
|
17
|
+
(0, common_1.Global)(),
|
|
18
|
+
(0, common_1.Module)({
|
|
19
|
+
imports: [
|
|
20
|
+
bullmq_1.BullModule.forRootAsync({
|
|
21
|
+
useFactory: async () => ({
|
|
22
|
+
prefix: config_1.APP_KEY + ':JOBS:',
|
|
23
|
+
defaultJobOptions: {
|
|
24
|
+
delay: 0,
|
|
25
|
+
removeOnComplete: true,
|
|
26
|
+
removeOnFail: false,
|
|
27
|
+
backoff: { type: 'exponential', delay: 10 },
|
|
28
|
+
attempts: 2,
|
|
29
|
+
},
|
|
30
|
+
connection: {
|
|
31
|
+
host: config_1.REDIS_HOST,
|
|
32
|
+
port: config_1.REDIS_PORT,
|
|
33
|
+
db: config_1.REDIS_DB,
|
|
34
|
+
password: config_1.REDIS_PASSWORD,
|
|
35
|
+
tls: config_1.REDIS_TLS ? { ca: '' } : undefined,
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
], QueueModule);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BadGatewayException, BadRequestException, ConflictException, ForbiddenException, GatewayTimeoutException, InternalServerErrorException, NotFoundException, ServiceUnavailableException, UnauthorizedException, UnprocessableEntityException } from '@nestjs/common';
|
|
2
|
+
type BadRequestParams<T = any> = Partial<Record<keyof T, string>>;
|
|
3
|
+
export declare class AppBadRequestException<T> extends BadRequestException {
|
|
4
|
+
constructor(err: BadRequestParams<T>);
|
|
5
|
+
constructor(err: string);
|
|
6
|
+
has(str: string): boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class AppUnprocessableEntityException extends UnprocessableEntityException {
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class AppNotFoundException extends NotFoundException {
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class AppForbiddenException extends ForbiddenException {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class AppUnauthorizedException extends UnauthorizedException {
|
|
18
|
+
constructor(message?: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class AppConflictException extends ConflictException {
|
|
21
|
+
constructor(message?: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class AppBadGatewayException extends BadGatewayException {
|
|
24
|
+
constructor(message?: string);
|
|
25
|
+
}
|
|
26
|
+
export declare class AppGatewayTimeoutException extends GatewayTimeoutException {
|
|
27
|
+
constructor(message?: string);
|
|
28
|
+
}
|
|
29
|
+
export declare class AppInternalServerErrorException extends InternalServerErrorException {
|
|
30
|
+
constructor(message?: string);
|
|
31
|
+
}
|
|
32
|
+
export declare class AppServiceUnavailableException extends ServiceUnavailableException {
|
|
33
|
+
constructor(message?: string);
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppServiceUnavailableException = exports.AppInternalServerErrorException = exports.AppGatewayTimeoutException = exports.AppBadGatewayException = exports.AppConflictException = exports.AppUnauthorizedException = exports.AppForbiddenException = exports.AppNotFoundException = exports.AppUnprocessableEntityException = exports.AppBadRequestException = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class AppBadRequestException extends common_1.BadRequestException {
|
|
6
|
+
constructor(err) {
|
|
7
|
+
const errors = typeof err === 'string'
|
|
8
|
+
? { error: err }
|
|
9
|
+
: Object.entries(err).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
10
|
+
super({ statusCode: 400, message: 'Bad request', errors });
|
|
11
|
+
this.message = (typeof err === 'string' ? [err] : Object.values(err).flat()).join(', ');
|
|
12
|
+
}
|
|
13
|
+
has(str) {
|
|
14
|
+
return this.message.includes(str);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.AppBadRequestException = AppBadRequestException;
|
|
18
|
+
class AppUnprocessableEntityException extends common_1.UnprocessableEntityException {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super({ statusCode: 422, message: message || 'Unprocessable entity' });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.AppUnprocessableEntityException = AppUnprocessableEntityException;
|
|
24
|
+
class AppNotFoundException extends common_1.NotFoundException {
|
|
25
|
+
constructor(message) {
|
|
26
|
+
super({ statusCode: 404, message: message || 'Not found' });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.AppNotFoundException = AppNotFoundException;
|
|
30
|
+
class AppForbiddenException extends common_1.ForbiddenException {
|
|
31
|
+
constructor(message) {
|
|
32
|
+
super({ statusCode: 403, message: message || 'Forbidden' });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.AppForbiddenException = AppForbiddenException;
|
|
36
|
+
class AppUnauthorizedException extends common_1.UnauthorizedException {
|
|
37
|
+
constructor(message) {
|
|
38
|
+
super({ statusCode: 401, message: message || 'Unauthorized' });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.AppUnauthorizedException = AppUnauthorizedException;
|
|
42
|
+
class AppConflictException extends common_1.ConflictException {
|
|
43
|
+
constructor(message) {
|
|
44
|
+
super({ statusCode: 409, message: message || 'Conflict' });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.AppConflictException = AppConflictException;
|
|
48
|
+
class AppBadGatewayException extends common_1.BadGatewayException {
|
|
49
|
+
constructor(message) {
|
|
50
|
+
super({ statusCode: 502, message: message || 'Bad gateway' });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.AppBadGatewayException = AppBadGatewayException;
|
|
54
|
+
class AppGatewayTimeoutException extends common_1.GatewayTimeoutException {
|
|
55
|
+
constructor(message) {
|
|
56
|
+
super({ statusCode: 504, message: message || 'Gateway timeout' });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.AppGatewayTimeoutException = AppGatewayTimeoutException;
|
|
60
|
+
class AppInternalServerErrorException extends common_1.InternalServerErrorException {
|
|
61
|
+
constructor(message) {
|
|
62
|
+
super({ statusCode: 500, message: message || 'Internal server error' });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.AppInternalServerErrorException = AppInternalServerErrorException;
|
|
66
|
+
class AppServiceUnavailableException extends common_1.ServiceUnavailableException {
|
|
67
|
+
constructor(message) {
|
|
68
|
+
super({ statusCode: 503, message: message || 'Service unavailable' });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.AppServiceUnavailableException = AppServiceUnavailableException;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ArgumentsHost, CallHandler, ExceptionFilter, ExecutionContext, HttpException, HttpStatus, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
export declare function CatchError(err: string): (target: any, key: string, descriptor: PropertyDescriptor) => void;
|
|
5
|
+
export declare class HttpExceptionFilter implements ExceptionFilter {
|
|
6
|
+
catch(exception: HttpException, host: ArgumentsHost): void;
|
|
7
|
+
}
|
|
8
|
+
type ResponseData<T> = {
|
|
9
|
+
statusCode: number;
|
|
10
|
+
message: string;
|
|
11
|
+
data: T;
|
|
12
|
+
};
|
|
13
|
+
export declare class TransformResponseInterceptor<T> implements NestInterceptor<T, ResponseData<T>> {
|
|
14
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<Response<T>>;
|
|
15
|
+
}
|
|
16
|
+
export declare class ResponseInterceptor<T> implements NestInterceptor<T, ResponseData<T>> {
|
|
17
|
+
private readonly message;
|
|
18
|
+
private readonly status;
|
|
19
|
+
constructor(message?: string, status?: HttpStatus);
|
|
20
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<Response<T>>;
|
|
21
|
+
}
|
|
22
|
+
export declare const HandleResponse: (message: string, status?: HttpStatus) => MethodDecorator & ClassDecorator;
|
|
23
|
+
export {};
|