@triproject/nestjs-core 1.0.6 → 1.0.13

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.
Files changed (54) hide show
  1. package/.swcrc +24 -0
  2. package/dist/bootstrap.js +1 -43
  3. package/dist/config.js +1 -50
  4. package/dist/controllers/controller.js +1 -56
  5. package/dist/drivers/cache/cache.d.ts +1 -1
  6. package/dist/drivers/cache/cache.driver.js +1 -22
  7. package/dist/drivers/cache/cache.js +1 -92
  8. package/dist/drivers/cache/index.js +1 -19
  9. package/dist/drivers/cache/redis.js +1 -52
  10. package/dist/drivers/db/db.helper.js +1 -217
  11. package/dist/drivers/db/db.module.js +1 -44
  12. package/dist/drivers/db/db.service.js +1 -49
  13. package/dist/drivers/db/index.js +1 -21
  14. package/dist/drivers/db/migration.d.ts +133 -5
  15. package/dist/drivers/db/migration.js +1 -81
  16. package/dist/drivers/db/repository.js +1 -255
  17. package/dist/drivers/encryptions/encryption.js +1 -50
  18. package/dist/drivers/encryptions/encryption.module.js +1 -24
  19. package/dist/drivers/encryptions/index.js +1 -19
  20. package/dist/drivers/encryptions/jwt.js +1 -46
  21. package/dist/drivers/encryptions/password-hash.js +1 -38
  22. package/dist/drivers/encryptions/snap.signature.js +1 -110
  23. package/dist/drivers/logger/app.logger.js +2 -183
  24. package/dist/drivers/logger/cloudwatch.d.ts +18 -0
  25. package/dist/drivers/logger/cloudwatch.js +1 -0
  26. package/dist/drivers/logger/cloudwatch.logger.d.ts +1 -0
  27. package/dist/drivers/logger/cloudwatch.logger.js +1 -0
  28. package/dist/drivers/logger/index.js +1 -18
  29. package/dist/drivers/logger/slack.logger.js +1 -24
  30. package/dist/drivers/mail/index.js +1 -22
  31. package/dist/drivers/mail/mail-template.js +8 -41
  32. package/dist/drivers/mail/mail.config.js +1 -4
  33. package/dist/drivers/mail/mail.js +13 -73
  34. package/dist/drivers/mail/mail.module.js +1 -26
  35. package/dist/drivers/mail/mail.queue.js +1 -37
  36. package/dist/drivers/mail/mailer.js +1 -62
  37. package/dist/drivers/notifications/index.js +1 -21
  38. package/dist/drivers/notifications/notification.config.js +1 -4
  39. package/dist/drivers/notifications/notification.module.js +1 -25
  40. package/dist/drivers/notifications/notification.queue.js +1 -37
  41. package/dist/drivers/notifications/push-notification.js +1 -75
  42. package/dist/drivers/notifications/slack.js +1 -95
  43. package/dist/drivers/queues/app.queue.js +1 -66
  44. package/dist/drivers/queues/index.js +1 -18
  45. package/dist/drivers/queues/queue.module.js +1 -41
  46. package/dist/helpers/exception.helper.js +1 -71
  47. package/dist/helpers/http.helper.js +1 -134
  48. package/dist/helpers/swagger.helper.js +1 -287
  49. package/dist/helpers/totp.helper.js +1 -30
  50. package/dist/index.d.ts +1 -0
  51. package/dist/index.js +1 -24
  52. package/dist/middlewares/log.middleware.js +1 -59
  53. package/dist/types.d.js +1 -0
  54. package/package.json +27 -14
@@ -1,45 +1,18 @@
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.MailTemplate = void 0;
10
- const common_1 = require("@nestjs/common");
11
- const config_1 = require("../../config");
12
- let MailTemplate = class MailTemplate {
13
- // @ts-ignore
14
- THEME_COLOR = '#3968FE';
15
- MAX_WIDTH = '530px';
16
- logo() {
17
- return `<div style="padding:1em 1.3em 0 1.3em;">
18
- <a href="${config_1.LANDING_PAGE_URL}" title="${config_1.APP_NAME}" style="underline:none;color:${this.THEME_COLOR};text-decoration:none;">
19
- ${config_1.APP_LOGO_URL
20
- ? `<img src="${config_1.APP_LOGO_URL}" alt="${config_1.APP_NAME}" width="100" />`
21
- : `<b style="font-size:1.5em;letter-spacing:0.1em;line-height:1.6;">${config_1.APP_NAME}</b>`}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"MailTemplate",{enumerable:!0,get:function(){return MailTemplate}});let _common=require("@nestjs/common"),_config=require("../../config");let MailTemplate=class MailTemplate{THEME_COLOR="#3968FE";MAX_WIDTH="530px";logo(){return`<div style="padding:1em 1.3em 0 1.3em;">
2
+ <a href="${_config.LANDING_PAGE_URL}" title="${_config.APP_NAME}" style="underline:none;color:${this.THEME_COLOR};text-decoration:none;">
3
+ ${_config.APP_LOGO_URL?`<img src="${_config.APP_LOGO_URL}" alt="${_config.APP_NAME}" width="100" />`:`<b style="font-size:1.5em;letter-spacing:0.1em;line-height:1.6;">${_config.APP_NAME}</b>`}
22
4
  </a>
23
- </div>`;
24
- }
25
- header() {
26
- return `<div style="
5
+ </div>`}header(){return`<div style="
27
6
  width:100%;
28
7
  max-width:${this.MAX_WIDTH};margin:1.5em auto 0;
29
8
  position:relative;
30
9
  font-size:14px;padding:0.5em 0;">
31
10
  ${this.logo()}
32
- </div>`;
33
- }
34
- get FOOTER() {
35
- return `<div style="font-size:12px;color:#868686;text-align:center;padding:0 1.5em">
11
+ </div>`}get FOOTER(){return`<div style="font-size:12px;color:#868686;text-align:center;padding:0 1.5em">
36
12
  <div style="border-top:1px solid #eee;padding:1.5em 0 2em;text-align:center">
37
- ${new Date().getFullYear()} &copy; ${config_1.APP_NAME}
13
+ ${new Date().getFullYear()} &copy; ${_config.APP_NAME}
38
14
  </div>
39
- </div>`;
40
- }
41
- html(content) {
42
- return `<!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
15
+ </div>`}html(content){return`<!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
43
16
  <html>
44
17
  <head>
45
18
  <meta http-equiv="Content-Type" CONTENT="text/html charset=UTF-8" />
@@ -65,10 +38,4 @@ let MailTemplate = class MailTemplate {
65
38
  </tr>
66
39
  </tbody>
67
40
  </table>
68
- </html>`.replace(/ +/g, ' ');
69
- }
70
- };
71
- exports.MailTemplate = MailTemplate;
72
- exports.MailTemplate = MailTemplate = __decorate([
73
- (0, common_1.Injectable)()
74
- ], MailTemplate);
41
+ </html>`.replace(/ +/g," ")}};MailTemplate=function(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r}([(0,_common.Injectable)()],MailTemplate);
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mailerQueue = void 0;
4
- exports.mailerQueue = 'MAILER:QUEUE';
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"mailerQueue",{enumerable:!0,get:function(){return mailerQueue}});let mailerQueue="MAILER:QUEUE";
@@ -1,45 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Mail = void 0;
4
- class Mail {
5
- CONTENT = '';
6
- caption(content) {
7
- this.CONTENT += `<div style="margin:0 0 1.5em 0;">${content.replace(/((http:|https:)[^\s]+[\w])/g, '<a href="$1" target="_blank" style="color:#3D96FF;font-weight:500">$1</a>')}</div>`;
8
- return this;
9
- }
10
- p(content, style = '') {
11
- this.CONTENT += `<p style="
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Mail",{enumerable:!0,get:function(){return Mail}});let Mail=class Mail{CONTENT="";caption(content){return this.CONTENT+=`<div style="margin:0 0 1.5em 0;">${content.replace(/((http:|https:)[^\s]+[\w])/g,'<a href="$1" target="_blank" style="color:#3D96FF;font-weight:500">$1</a>')}</div>`,this}p(content,style=""){return this.CONTENT+=`<p style="
12
2
  font-family: sans-serif;
13
3
  font-weight: 400;
14
4
  font-size: 1.2em;
15
5
  margin: 1.25em 0;
16
- ${style}">${content.replace(/((http:|https:)[^\s]+[\w])/g, '<a href="$1" target="_blank" style="color:#3D96FF;font-weight:500">$1</a>')}</p>`;
17
- return this;
18
- }
19
- ln(content) {
20
- this.CONTENT += `${content}\n`;
21
- return this;
22
- }
23
- a(title, href) {
24
- this.CONTENT += `<a href="${href ?? title}" title="${title}" style="color:#3D96FF;font-weight:500">${title}</a>`;
25
- return this;
26
- }
27
- otp(code) {
28
- this.CONTENT += `<p style="padding:1em 2em;text-align:center;font-weight:bold;font-size:30px;background-color:#eee;letter-spacing: 0.2em;border-radius:5px;">
6
+ ${style}">${content.replace(/((http:|https:)[^\s]+[\w])/g,'<a href="$1" target="_blank" style="color:#3D96FF;font-weight:500">$1</a>')}</p>`,this}ln(content){return this.CONTENT+=`${content}
7
+ `,this}a(title,href){return this.CONTENT+=`<a href="${href??title}" title="${title}" style="color:#3D96FF;font-weight:500">${title}</a>`,this}otp(code){return this.CONTENT+=`<p style="padding:1em 2em;text-align:center;font-weight:bold;font-size:30px;background-color:#eee;letter-spacing: 0.2em;border-radius:5px;">
29
8
  ${code}
30
- </p>`;
31
- return this;
32
- }
33
- title(title, style = '') {
34
- this.CONTENT += `<h1 style="
9
+ </p>`,this}title(title,style=""){return this.CONTENT+=`<h1 style="
35
10
  font-family: sans-serif;
36
11
  font-weight: 600;
37
12
  font-size: 18px;
38
- ${style}">${title}</h1>`;
39
- return this;
40
- }
41
- action(title, href) {
42
- this.CONTENT += `<p style="margin: 2em 0"><a href="${href}" title="${title}" style="
13
+ ${style}">${title}</h1>`,this}action(title,href){return this.CONTENT+=`<p style="margin: 2em 0"><a href="${href}" title="${title}" style="
43
14
  display:block;
44
15
  background: #3968FE;
45
16
  color: white;
@@ -50,49 +21,18 @@ class Mail {
50
21
  font-weight: bold;
51
22
  text-decoration: none;
52
23
  font-family: sans-serif;">
53
- ${title}</a></p>`;
54
- return this;
55
- }
56
- listDetail(list, title = '') {
57
- const parsedList = list
58
- .map((li) => {
59
- return `<div style="margin-bottom:8px;display:flex;justify-CONTENT:space-between;${li?.style ?? ''}">
24
+ ${title}</a></p>`,this}listDetail(list,title=""){let parsedList=list.map(li=>`<div style="margin-bottom:8px;display:flex;justify-CONTENT:space-between;${li?.style??""}">
60
25
  <div style="margin-right:0.75em">${li.name}</div>
61
26
  <div style="text-align:right;font-weight:bold">${li.value}</div>
62
- </div>`;
63
- })
64
- .join(' ');
65
- this.CONTENT += `<p style="text-align:center;">
66
- ${title &&
67
- `<div style="background-color:#F6F6F6;padding:8px 10px;border-radius:5px;font-weight:bold;margin-bottom:1em">${title}</div>`}
68
- <div style="margin-top:5px;font-size:95%;${title ? 'padding: 0 0.75em' : ''}">
27
+ </div>`).join(" ");return this.CONTENT+=`<p style="text-align:center;">
28
+ ${title&&`<div style="background-color:#F6F6F6;padding:8px 10px;border-radius:5px;font-weight:bold;margin-bottom:1em">${title}</div>`}
29
+ <div style="margin-top:5px;font-size:95%;${title?"padding: 0 0.75em":""}">
69
30
  ${parsedList}
70
31
  </div>
71
- </p>`;
72
- return this;
73
- }
74
- list(list, type = 'bulleted') {
75
- const listStyleType = type === 'numbered' ? 'decimal' : 'disc';
76
- const parsedList = list
77
- .map((li) => {
78
- return `<li style="margin-bottom:8px;">
32
+ </p>`,this}list(list,type="bulleted"){let parsedList=list.map(li=>`<li style="margin-bottom:8px;">
79
33
  <span>${li}</span>
80
- </li>`;
81
- })
82
- .join('');
83
- this.CONTENT += `<p style="text-align:center;">
84
- <ul style="list-style-type:${listStyleType}; padding-left: 20px; margin-top:5px; font-size:100%;">
34
+ </li>`).join("");return this.CONTENT+=`<p style="text-align:center;">
35
+ <ul style="list-style-type:${"numbered"===type?"decimal":"disc"}; padding-left: 20px; margin-top:5px; font-size:100%;">
85
36
  ${parsedList}
86
37
  </ul>
87
- </p>`;
88
- return this;
89
- }
90
- hr() {
91
- this.CONTENT += `<hr style="margin: 2em 0">`;
92
- return this;
93
- }
94
- toString() {
95
- return this.CONTENT;
96
- }
97
- }
98
- exports.Mail = Mail;
38
+ </p>`,this}hr(){return this.CONTENT+='<hr style="margin: 2em 0">',this}toString(){return this.CONTENT}};
@@ -1,26 +1 @@
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.MailModule = void 0;
10
- const bull_1 = require("@nestjs/bull");
11
- const common_1 = require("@nestjs/common");
12
- const mail_template_1 = require("./mail-template");
13
- const mail_config_1 = require("./mail.config");
14
- const mail_queue_1 = require("./mail.queue");
15
- const mailer_1 = require("./mailer");
16
- let MailModule = class MailModule {
17
- };
18
- exports.MailModule = MailModule;
19
- exports.MailModule = MailModule = __decorate([
20
- (0, common_1.Global)(),
21
- (0, common_1.Module)({
22
- providers: [mailer_1.Mailer, mail_template_1.MailTemplate, mail_queue_1.MailQueue],
23
- exports: [mailer_1.Mailer, mail_template_1.MailTemplate],
24
- imports: [bull_1.BullModule.registerQueue({ name: mail_config_1.mailerQueue })],
25
- })
26
- ], MailModule);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"MailModule",{enumerable:!0,get:function(){return MailModule}});let _bull=require("@nestjs/bull"),_common=require("@nestjs/common"),_mailtemplate=require("./mail-template"),_mailconfig=require("./mail.config"),_mailqueue=require("./mail.queue"),_mailer=require("./mailer");let MailModule=class MailModule{};MailModule=function(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r}([(0,_common.Global)(),(0,_common.Module)({providers:[_mailer.Mailer,_mailtemplate.MailTemplate,_mailqueue.MailQueue],exports:[_mailer.Mailer,_mailtemplate.MailTemplate],imports:[_bull.BullModule.registerQueue({name:_mailconfig.mailerQueue})]})],MailModule);
@@ -1,37 +1 @@
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.MailQueue = void 0;
13
- const bull_1 = require("@nestjs/bull");
14
- const app_queue_1 = require("../queues/app.queue");
15
- const mail_config_1 = require("./mail.config");
16
- const mailer_1 = require("./mailer");
17
- let MailQueue = class MailQueue extends app_queue_1.AppQueue {
18
- mailer;
19
- constructor(mailer) {
20
- super();
21
- this.mailer = mailer;
22
- }
23
- async addLog({ data }) {
24
- await this.mailer.send(data, false);
25
- }
26
- };
27
- exports.MailQueue = MailQueue;
28
- __decorate([
29
- (0, bull_1.Process)({ name: mail_config_1.mailerQueue, concurrency: 4 }),
30
- __metadata("design:type", Function),
31
- __metadata("design:paramtypes", [Object]),
32
- __metadata("design:returntype", Promise)
33
- ], MailQueue.prototype, "addLog", null);
34
- exports.MailQueue = MailQueue = __decorate([
35
- (0, bull_1.Processor)(mail_config_1.mailerQueue),
36
- __metadata("design:paramtypes", [mailer_1.Mailer])
37
- ], MailQueue);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"MailQueue",{enumerable:!0,get:function(){return MailQueue}});let _bull=require("@nestjs/bull"),_bull1=require("bull"),_appqueue=require("../queues/app.queue"),_mailconfig=require("./mail.config"),_mailer=require("./mailer");function _ts_decorate(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r}function _ts_metadata(k,v){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(k,v)}let MailQueue=class MailQueue extends _appqueue.AppQueue{mailer;constructor(mailer){super(),this.mailer=mailer}async addLog({data}){await this.mailer.send(data,!1)}};_ts_decorate([(0,_bull.Process)({name:_mailconfig.mailerQueue,concurrency:4}),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[void 0===_bull1.Job?Object:_bull1.Job]),_ts_metadata("design:returntype",Promise)],MailQueue.prototype,"addLog",null),MailQueue=_ts_decorate([(0,_bull.Processor)(_mailconfig.mailerQueue),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[void 0===_mailer.Mailer?Object:_mailer.Mailer])],MailQueue);
@@ -1,62 +1 @@
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.Mailer = void 0;
16
- const bull_1 = require("@nestjs/bull");
17
- const common_1 = require("@nestjs/common");
18
- const helpers_1 = require("@triproject/helpers");
19
- const nodemailer_1 = require("nodemailer");
20
- const config_1 = require("../../config");
21
- const mail_template_1 = require("./mail-template");
22
- const mail_config_1 = require("./mail.config");
23
- let Mailer = class Mailer {
24
- mailTemplate;
25
- mailerQueue;
26
- EMAIL_FROM;
27
- mailer;
28
- constructor(mailTemplate, mailerQueue) {
29
- this.mailTemplate = mailTemplate;
30
- this.mailerQueue = mailerQueue;
31
- this.EMAIL_FROM = config_1.MAIL_FROM_EMAIL;
32
- this.mailer = (0, nodemailer_1.createTransport)({
33
- host: config_1.MAIL_HOST,
34
- port: config_1.MAIL_PORT,
35
- auth: { user: config_1.MAIL_USERNAME, pass: config_1.MAIL_PASSWORD },
36
- });
37
- }
38
- async _queue(params) {
39
- const data = {
40
- from: this.EMAIL_FROM,
41
- to: `${params.name} <${params.email}>`,
42
- cc: params.cc,
43
- bcc: params.bcc,
44
- subject: params.subject,
45
- html: this.mailTemplate.html(params.mail.toString()),
46
- };
47
- await this.mailerQueue.add(mail_config_1.mailerQueue, data, {
48
- jobId: (0, helpers_1.generateId)(),
49
- });
50
- }
51
- async send(params, shouldQueue = true) {
52
- if (shouldQueue)
53
- return await this._queue(params);
54
- return await this.mailer.sendMail(params);
55
- }
56
- };
57
- exports.Mailer = Mailer;
58
- exports.Mailer = Mailer = __decorate([
59
- (0, common_1.Injectable)(),
60
- __param(1, (0, bull_1.InjectQueue)(mail_config_1.mailerQueue)),
61
- __metadata("design:paramtypes", [mail_template_1.MailTemplate, Object])
62
- ], Mailer);
1
+ "use strict";var decorator;Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Mailer",{enumerable:!0,get:function(){return Mailer}});let _bull=require("@nestjs/bull"),_common=require("@nestjs/common"),_helpers=require("@triproject/helpers"),_bull1=require("bull"),_nodemailer=require("nodemailer"),_config=require("../../config"),_mailtemplate=require("./mail-template"),_mailconfig=require("./mail.config");function _ts_metadata(k,v){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(k,v)}let Mailer=class Mailer{mailTemplate;mailerQueue;EMAIL_FROM;mailer;constructor(mailTemplate,mailerQueue){this.mailTemplate=mailTemplate,this.mailerQueue=mailerQueue,this.EMAIL_FROM=_config.MAIL_FROM_EMAIL,this.mailer=(0,_nodemailer.createTransport)({host:_config.MAIL_HOST,port:_config.MAIL_PORT,auth:{user:_config.MAIL_USERNAME,pass:_config.MAIL_PASSWORD}})}async _queue(params){let data={from:this.EMAIL_FROM,to:`${params.name} <${params.email}>`,cc:params.cc,bcc:params.bcc,subject:params.subject,html:this.mailTemplate.html(params.mail.toString())};await this.mailerQueue.add(_mailconfig.mailerQueue,data,{jobId:(0,_helpers.generateId)()})}async send(params,shouldQueue=!0){return shouldQueue?await this._queue(params):await this.mailer.sendMail(params)}};Mailer=function(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r}([(0,_common.Injectable)(),(decorator=(0,_bull.InjectQueue)(_mailconfig.mailerQueue),function(target,key){decorator(target,key,1)}),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[void 0===_mailtemplate.MailTemplate?Object:_mailtemplate.MailTemplate,void 0===_bull1.Queue?Object:_bull1.Queue])],Mailer);
@@ -1,21 +1 @@
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);
1
+ "use strict";function _export_star(from,to){return Object.keys(from).forEach(function(k){"default"===k||Object.prototype.hasOwnProperty.call(to,k)||Object.defineProperty(to,k,{enumerable:!0,get:function(){return from[k]}})}),from}Object.defineProperty(exports,"__esModule",{value:!0}),_export_star(require("./notification.config"),exports),_export_star(require("./notification.module"),exports),_export_star(require("./notification.queue"),exports),_export_star(require("./push-notification"),exports),_export_star(require("./slack"),exports);
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.notificationQueue = void 0;
4
- exports.notificationQueue = 'NOTIFICATION:QUEUE';
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"notificationQueue",{enumerable:!0,get:function(){return notificationQueue}});let notificationQueue="NOTIFICATION:QUEUE";
@@ -1,25 +1 @@
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);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"NotificationDriverModule",{enumerable:!0,get:function(){return NotificationDriverModule}});let _bull=require("@nestjs/bull"),_common=require("@nestjs/common"),_notificationconfig=require("./notification.config"),_notificationqueue=require("./notification.queue"),_pushnotification=require("./push-notification");let NotificationDriverModule=class NotificationDriverModule{};NotificationDriverModule=function(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r}([(0,_common.Global)(),(0,_common.Module)({providers:[_pushnotification.PushNotification,_notificationqueue.NotificationQueue],imports:[_bull.BullModule.registerQueue({name:_notificationconfig.notificationQueue})],exports:[_pushnotification.PushNotification]})],NotificationDriverModule);
@@ -1,37 +1 @@
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);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"NotificationQueue",{enumerable:!0,get:function(){return NotificationQueue}});let _bull=require("@nestjs/bull"),_bull1=require("bull"),_appqueue=require("../queues/app.queue"),_notificationconfig=require("./notification.config"),_pushnotification=require("./push-notification");function _ts_decorate(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r}function _ts_metadata(k,v){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(k,v)}let NotificationQueue=class NotificationQueue extends _appqueue.AppQueue{pushNotification;constructor(pushNotification){super(),this.pushNotification=pushNotification}async sendNotification({data}){await this.pushNotification.send(data,!1)}};_ts_decorate([(0,_bull.Process)({name:_notificationconfig.notificationQueue,concurrency:4}),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[void 0===_bull1.Job?Object:_bull1.Job]),_ts_metadata("design:returntype",Promise)],NotificationQueue.prototype,"sendNotification",null),NotificationQueue=_ts_decorate([(0,_bull.Processor)(_notificationconfig.notificationQueue),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[void 0===_pushnotification.PushNotification?Object:_pushnotification.PushNotification])],NotificationQueue);
@@ -1,75 +1 @@
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);
1
+ "use strict";var decorator,obj;Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"PushNotification",{enumerable:!0,get:function(){return PushNotification}});let _bull=require("@nestjs/bull"),_common=require("@nestjs/common"),_helpers=require("@triproject/helpers"),_axios=(obj=require("axios"))&&obj.__esModule?obj:{default:obj},_bullmq=require("bullmq"),_config=require("../../config"),_notificationconfig=require("./notification.config");function _ts_metadata(k,v){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(k,v)}let PushNotification=class PushNotification{notificationQueue;APP_ID;client;constructor(notificationQueue){this.notificationQueue=notificationQueue,this.APP_ID=_config.ONESIGNAL_APP_ID,this.client=_axios.default.create({baseURL:"https://api.onesignal.com",timeout:100,headers:{"Content-Type":"application/json; charset=utf-8",Authorization:`Key ${_config.ONESIGNAL_REST_API_KEY}`}})}async send(params,shouldQueue=!0){if(shouldQueue)return this.notificationQueue.add(_notificationconfig.notificationQueue,params,{jobId:(0,_helpers.generateId)()});let{userId,type,title,message,data}=params;return await this.client.post("notifications",{app_id:this.APP_ID,target_channel:"push",name:type,headings:{en:title},contents:{en:message},data,included_segments:[userId].filter(d=>d)})}broadcast(params,shouldQueue=!0){let{title,message,data}=params;return this.send({userId:"All",type:"broadcast",title,message,data},shouldQueue)}};PushNotification=function(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r}([(0,_common.Injectable)(),(decorator=(0,_bull.InjectQueue)(_notificationconfig.notificationQueue),function(target,key){decorator(target,key,0)}),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[void 0===_bullmq.Queue?Object:_bullmq.Queue])],PushNotification);
@@ -1,95 +1 @@
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;
1
+ "use strict";var obj;Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Slack",{enumerable:!0,get:function(){return Slack}});let _axios=(obj=require("axios"))&&obj.__esModule?obj:{default:obj};let Slack=class Slack{logger=console;client;status={blocked:!1,lastUpdateAt:new Date};constructor(config){config.logger&&(this.logger=config.logger),config.webhookUrl.startsWith("https")&&(this.client=_axios.default.create({baseURL:config.webhookUrl,timeout:500,headers:{"Content-Type":"application/json"}}))}_toggleBlocked(){this.status={blocked:!this.status.blocked,lastUpdateAt:new Date}}_format(...messages){let blocks=[];if(0===messages.length)return blocks;if(messages.length>0&&"string"==typeof messages[0])return blocks.push({type:"header",text:{type:"plain_text",text:messages[0]}}),blocks;for(let msg of messages)msg&&(msg instanceof Error?blocks.push({type:"section",text:{type:"mrkdwn",text:'<font color="red">```**'+msg.name+"**: "+msg.message+"\n "+msg?.stack?.split("\n").join("\n ")+"</font>```"}}):"object"==typeof msg?blocks.push({type:"section",text:{type:"mrkdwn",text:"```json"+JSON.stringify(msg,null,2)+"```"}}):blocks.push({type:"section",text:{type:"plain_text",text:msg?.toString()}}));return blocks}async send(...messages){if(this.client&&!(this.status.blocked&&new Date().getTime()-this.status.lastUpdateAt.getTime()<108e5))return await this.client.post("",{blocks:this._format(...messages)}).then(data=>(this.status.blocked&&this._toggleBlocked(),data)).catch(error=>{this?.logger.error("Failed to send slack notification",error),this.status.blocked||this._toggleBlocked()})}};