@pixelplex/mail-service 0.1.22 → 0.2.1
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/.gitlab-ci.yml +1 -25
- package/LICENSE.md +1 -1
- package/README.md +83 -137
- package/audit-ci.json +4 -0
- package/commitlint.config.js +27 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +18 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/mail.constants.d.ts +11 -0
- package/dist/constants/mail.constants.js +17 -0
- package/dist/constants/mail.constants.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +19 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/inject-gateways.decorator.d.ts +2 -0
- package/dist/decorators/inject-gateways.decorator.js +10 -0
- package/dist/decorators/inject-gateways.decorator.js.map +1 -0
- package/dist/decorators/inject-options.decorator.d.ts +3 -0
- package/dist/decorators/inject-options.decorator.js +14 -0
- package/dist/decorators/inject-options.decorator.js.map +1 -0
- package/dist/factories/gateway.factory.d.ts +4 -0
- package/dist/factories/gateway.factory.js +18 -0
- package/dist/factories/gateway.factory.js.map +1 -0
- package/dist/factories/index.d.ts +1 -0
- package/dist/factories/index.js +18 -0
- package/dist/factories/index.js.map +1 -0
- package/dist/gateways/console.gateway.d.ts +6 -0
- package/dist/{connect/app.module.js → gateways/console.gateway.js} +13 -17
- package/dist/gateways/console.gateway.js.map +1 -0
- package/dist/gateways/index.d.ts +4 -0
- package/dist/gateways/index.js +21 -0
- package/dist/gateways/index.js.map +1 -0
- package/dist/gateways/sendgrid.gateway.d.ts +8 -0
- package/dist/gateways/sendgrid.gateway.js +45 -0
- package/dist/gateways/sendgrid.gateway.js.map +1 -0
- package/dist/gateways/slack.gateway.d.ts +8 -0
- package/dist/gateways/slack.gateway.js +40 -0
- package/dist/gateways/slack.gateway.js.map +1 -0
- package/dist/gateways/smtp.gateway.d.ts +9 -0
- package/dist/gateways/smtp.gateway.js +43 -0
- package/dist/gateways/smtp.gateway.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +21 -7
- package/dist/index.js.map +1 -1
- package/dist/interfaces/gateway.interface.d.ts +4 -0
- package/dist/interfaces/gateway.interface.js +3 -0
- package/dist/interfaces/gateway.interface.js.map +1 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.js +18 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/mail.module.d.ts +5 -0
- package/dist/mail.module.js +68 -0
- package/dist/mail.module.js.map +1 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +18 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/mail-sender.service.d.ts +11 -0
- package/dist/services/mail-sender.service.js +91 -0
- package/dist/services/mail-sender.service.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -8211
- package/dist/types/decorators.types.d.ts +2 -0
- package/dist/types/decorators.types.js +3 -0
- package/dist/types/decorators.types.js.map +1 -0
- package/dist/types/gateway.class.d.ts +4 -0
- package/dist/types/gateway.class.js +3 -0
- package/dist/types/gateway.class.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +24 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/options.types.d.ts +16 -0
- package/dist/types/options.types.js +3 -0
- package/dist/types/options.types.js.map +1 -0
- package/dist/types/sendgrid-options.types.d.ts +4 -0
- package/dist/types/sendgrid-options.types.js +3 -0
- package/dist/types/sendgrid-options.types.js.map +1 -0
- package/dist/types/slack-options.types.d.ts +3 -0
- package/dist/types/slack-options.types.js +3 -0
- package/dist/types/slack-options.types.js.map +1 -0
- package/dist/types/smtp-options.types.d.ts +7 -0
- package/dist/types/smtp-options.types.js +3 -0
- package/dist/types/smtp-options.types.js.map +1 -0
- package/dist/types/templates.types.d.ts +12 -0
- package/dist/types/templates.types.js +3 -0
- package/dist/types/templates.types.js.map +1 -0
- package/dist/utils/connection.utils.d.ts +4 -0
- package/dist/utils/connection.utils.js +17 -0
- package/dist/utils/connection.utils.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/object.utils.d.ts +1 -0
- package/dist/utils/object.utils.js +8 -0
- package/dist/utils/object.utils.js.map +1 -0
- package/dist/utils/types.utils.d.ts +1 -0
- package/dist/utils/types.utils.js +3 -0
- package/dist/utils/types.utils.js.map +1 -0
- package/package.json +51 -45
- package/tsconfig.json +4 -1
- package/.dockerignore +0 -5
- package/.husky/pre-commit +0 -9
- package/dist/connect/app.module.d.ts +0 -4
- package/dist/connect/app.module.js.map +0 -1
- package/dist/connect/retry.d.ts +0 -2
- package/dist/connect/retry.js +0 -13
- package/dist/connect/retry.js.map +0 -1
- package/dist/main.d.ts +0 -1
- package/dist/main.js +0 -24
- package/dist/main.js.map +0 -1
- package/dist/service/app.module.d.ts +0 -4
- package/dist/service/app.module.js +0 -29
- package/dist/service/app.module.js.map +0 -1
- package/dist/service/sender.service.d.ts +0 -7
- package/dist/service/sender.service.js +0 -63
- package/dist/service/sender.service.js.map +0 -1
- package/dist/transports/rmq/app.controller.d.ts +0 -9
- package/dist/transports/rmq/app.controller.js +0 -59
- package/dist/transports/rmq/app.controller.js.map +0 -1
- package/dist/transports/rmq/app.service.d.ts +0 -20
- package/dist/transports/rmq/app.service.js +0 -61
- package/dist/transports/rmq/app.service.js.map +0 -1
- package/dist/transports/rmq/connection.d.ts +0 -3
- package/dist/transports/rmq/connection.js +0 -33
- package/dist/transports/rmq/connection.js.map +0 -1
- package/dist/transports/tcp/app.controller.d.ts +0 -8
- package/dist/transports/tcp/app.controller.js +0 -54
- package/dist/transports/tcp/app.controller.js.map +0 -1
- package/dist/transports/tcp/app.service.d.ts +0 -19
- package/dist/transports/tcp/app.service.js +0 -56
- package/dist/transports/tcp/app.service.js.map +0 -1
- package/dist/transports/tcp/connection.d.ts +0 -8
- package/dist/transports/tcp/connection.js +0 -13
- package/dist/transports/tcp/connection.js.map +0 -1
|
@@ -1,59 +0,0 @@
|
|
|
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.AppController = void 0;
|
|
16
|
-
const common_1 = require("@nestjs/common");
|
|
17
|
-
const microservices_1 = require("@nestjs/microservices");
|
|
18
|
-
const Sentry = require("@sentry/node");
|
|
19
|
-
const sender_service_1 = require("../../service/sender.service");
|
|
20
|
-
let AppController = class AppController {
|
|
21
|
-
constructor(senderService) {
|
|
22
|
-
this.senderService = senderService;
|
|
23
|
-
this.logger = new common_1.Logger('Mail::AppController');
|
|
24
|
-
}
|
|
25
|
-
async getHello(data, context) {
|
|
26
|
-
const channel = context.getChannelRef();
|
|
27
|
-
const originalMsg = context.getMessage();
|
|
28
|
-
try {
|
|
29
|
-
await this.senderService.sendMail(data.to, data.type, data.payload);
|
|
30
|
-
channel.ack(originalMsg);
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
if (data.ttl > 0 && (new Date().getTime() - data.timestamp) / 1000 > data.ttl) {
|
|
34
|
-
this.logger.warn(`message to "${data.to}" with template "${data.type}" was market as processed due to exceeding ttl`);
|
|
35
|
-
channel.ack(originalMsg);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
Sentry.captureException(e, {
|
|
39
|
-
extra: data,
|
|
40
|
-
});
|
|
41
|
-
this.logger.error('send email error');
|
|
42
|
-
this.logger.error(e);
|
|
43
|
-
channel.nack(originalMsg, false, false);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
__decorate([
|
|
48
|
-
microservices_1.EventPattern('new_mail'),
|
|
49
|
-
__param(0, microservices_1.Payload()), __param(1, microservices_1.Ctx()),
|
|
50
|
-
__metadata("design:type", Function),
|
|
51
|
-
__metadata("design:paramtypes", [Object, microservices_1.RmqContext]),
|
|
52
|
-
__metadata("design:returntype", Promise)
|
|
53
|
-
], AppController.prototype, "getHello", null);
|
|
54
|
-
AppController = __decorate([
|
|
55
|
-
common_1.Controller(),
|
|
56
|
-
__metadata("design:paramtypes", [sender_service_1.SenderService])
|
|
57
|
-
], AppController);
|
|
58
|
-
exports.AppController = AppController;
|
|
59
|
-
//# sourceMappingURL=app.controller.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app.controller.js","sourceRoot":"","sources":["../../../src/transports/rmq/app.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,yDAA+E;AAC/E,uCAAuC;AAEvC,iEAA6D;AAG7D,IAAa,aAAa,GAA1B,MAAa,aAAa;IAExB,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QADjD,WAAM,GAAG,IAAI,eAAM,CAAC,qBAAqB,CAAC,CAAC;IACS,CAAC;IAG7D,KAAK,CAAC,QAAQ,CAAY,IAAiB,EAAS,OAAmB;QACrE,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QACxC,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QACzC,IAAI;YACF,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACpE,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;SAC1B;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE;gBAC7E,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,eAAe,IAAI,CAAC,EAAE,oBAAoB,IAAI,CAAC,IAAI,gDAAgD,CACpG,CAAC;gBACF,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBACzB,OAAO;aACR;YACD,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE;gBACzB,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;SACzC;IACH,CAAC;CACF,CAAA;AAtBC;IADC,4BAAY,CAAC,UAAU,CAAC;IACT,WAAA,uBAAO,EAAE,CAAA,EAAqB,WAAA,mBAAG,EAAE,CAAA;;6CAAU,0BAAU;;6CAqBtE;AA1BU,aAAa;IADzB,mBAAU,EAAE;qCAGiC,8BAAa;GAF9C,aAAa,CA2BzB;AA3BY,sCAAa"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { OnApplicationBootstrap } from '@nestjs/common';
|
|
2
|
-
import { ClientProxy } from '@nestjs/microservices';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
export declare class MailService implements OnApplicationBootstrap {
|
|
5
|
-
private logger;
|
|
6
|
-
client: ClientProxy;
|
|
7
|
-
clientRecovery: ClientProxy;
|
|
8
|
-
onApplicationBootstrap(): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* @param to - email to send the message to
|
|
11
|
-
* @param type - the type of message to send. files `{type}.handlebars` and `{type}.subject.handlebars` will used
|
|
12
|
-
* @param payload - object with payload to build you mail
|
|
13
|
-
* @param ttl - the number of seconds after which the message will be rejected from the queue if,
|
|
14
|
-
* but only if it was processed with an error. Set 0 if you think your message should live until
|
|
15
|
-
* it is successfully sent.
|
|
16
|
-
*/
|
|
17
|
-
sendMail<TResult = any>(to: string, type: string, payload?: {
|
|
18
|
-
[key: string]: unknown;
|
|
19
|
-
}, ttl?: number): Observable<TResult>;
|
|
20
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
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.MailService = void 0;
|
|
13
|
-
const common_1 = require("@nestjs/common");
|
|
14
|
-
const microservices_1 = require("@nestjs/microservices");
|
|
15
|
-
const rxjs_1 = require("rxjs");
|
|
16
|
-
const retry_1 = require("../../connect/retry");
|
|
17
|
-
const connection_1 = require("./connection");
|
|
18
|
-
let MailService = class MailService {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.logger = new common_1.Logger('Mail::MailService');
|
|
21
|
-
}
|
|
22
|
-
async onApplicationBootstrap() {
|
|
23
|
-
await rxjs_1.defer(async () => {
|
|
24
|
-
await this.client.connect();
|
|
25
|
-
await this.clientRecovery.connect();
|
|
26
|
-
})
|
|
27
|
-
.pipe(retry_1.default(10, 5000))
|
|
28
|
-
.toPromise();
|
|
29
|
-
this.logger.log('RMQ Connected');
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @param to - email to send the message to
|
|
33
|
-
* @param type - the type of message to send. files `{type}.handlebars` and `{type}.subject.handlebars` will used
|
|
34
|
-
* @param payload - object with payload to build you mail
|
|
35
|
-
* @param ttl - the number of seconds after which the message will be rejected from the queue if,
|
|
36
|
-
* but only if it was processed with an error. Set 0 if you think your message should live until
|
|
37
|
-
* it is successfully sent.
|
|
38
|
-
*/
|
|
39
|
-
sendMail(to, type, payload, ttl = 0) {
|
|
40
|
-
return this.client.emit('new_mail', {
|
|
41
|
-
type,
|
|
42
|
-
payload,
|
|
43
|
-
to,
|
|
44
|
-
timestamp: new Date().getTime(),
|
|
45
|
-
ttl,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
__decorate([
|
|
50
|
-
microservices_1.Client(connection_1.generalClient),
|
|
51
|
-
__metadata("design:type", microservices_1.ClientProxy)
|
|
52
|
-
], MailService.prototype, "client", void 0);
|
|
53
|
-
__decorate([
|
|
54
|
-
microservices_1.Client(connection_1.dlClient),
|
|
55
|
-
__metadata("design:type", microservices_1.ClientProxy)
|
|
56
|
-
], MailService.prototype, "clientRecovery", void 0);
|
|
57
|
-
MailService = __decorate([
|
|
58
|
-
common_1.Injectable()
|
|
59
|
-
], MailService);
|
|
60
|
-
exports.MailService = MailService;
|
|
61
|
-
//# sourceMappingURL=app.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app.service.js","sourceRoot":"","sources":["../../../src/transports/rmq/app.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4E;AAC5E,yDAA4D;AAC5D,+BAAyC;AAEzC,+CAAwC;AACxC,6CAAuD;AAGvD,IAAa,WAAW,GAAxB,MAAa,WAAW;IAAxB;QACU,WAAM,GAAW,IAAI,eAAM,CAAC,mBAAmB,CAAC,CAAC;IAwC3D,CAAC;IAhCC,KAAK,CAAC,sBAAsB;QAC1B,MAAM,YAAK,CAAC,KAAK,IAAI,EAAE;YACrB,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QACtC,CAAC,CAAC;aACC,IAAI,CAAC,eAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;aACrB,SAAS,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;OAOG;IACH,QAAQ,CACN,EAAU,EACV,IAAY,EACZ,OAAoC,EACpC,MAAc,CAAC;QAEf,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAuB,UAAU,EAAE;YACxD,IAAI;YACJ,OAAO;YACP,EAAE;YACF,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC/B,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AArCC;IADC,sBAAM,CAAC,0BAAa,CAAC;8BACd,2BAAW;2CAAC;AAGpB;IADC,sBAAM,CAAC,qBAAQ,CAAC;8BACD,2BAAW;mDAAC;AAPjB,WAAW;IADvB,mBAAU,EAAE;GACA,WAAW,CAyCvB;AAzCY,kCAAW"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dlClient = exports.generalClient = void 0;
|
|
4
|
-
const microservices_1 = require("@nestjs/microservices");
|
|
5
|
-
const config_1 = require("config");
|
|
6
|
-
exports.generalClient = {
|
|
7
|
-
transport: microservices_1.Transport.RMQ,
|
|
8
|
-
options: {
|
|
9
|
-
urls: [config_1.MAIL_SERVICE.RMQ.URL],
|
|
10
|
-
noAck: false,
|
|
11
|
-
queueOptions: {
|
|
12
|
-
durable: true,
|
|
13
|
-
deadLetterExchange: '',
|
|
14
|
-
deadLetterRoutingKey: `DL_${config_1.MAIL_SERVICE.RMQ.QUEUE}`,
|
|
15
|
-
},
|
|
16
|
-
queue: config_1.MAIL_SERVICE.RMQ.QUEUE,
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
exports.dlClient = {
|
|
20
|
-
transport: microservices_1.Transport.RMQ,
|
|
21
|
-
options: {
|
|
22
|
-
urls: [config_1.MAIL_SERVICE.RMQ.URL],
|
|
23
|
-
noAck: false,
|
|
24
|
-
queueOptions: {
|
|
25
|
-
durable: true,
|
|
26
|
-
deadLetterExchange: '',
|
|
27
|
-
deadLetterRoutingKey: config_1.MAIL_SERVICE.RMQ.QUEUE,
|
|
28
|
-
messageTtl: config_1.MAIL_SERVICE.RMQ.MESSAGE_TTL,
|
|
29
|
-
},
|
|
30
|
-
queue: `DL_${config_1.MAIL_SERVICE.RMQ.QUEUE}`,
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/transports/rmq/connection.ts"],"names":[],"mappings":";;;AAAA,yDAA8D;AAC9D,mCAAsC;AAEzB,QAAA,aAAa,GAAe;IACvC,SAAS,EAAE,yBAAS,CAAC,GAAG;IACxB,OAAO,EAAE;QACP,IAAI,EAAE,CAAC,qBAAY,CAAC,GAAG,CAAC,GAAG,CAAC;QAC5B,KAAK,EAAE,KAAK;QACZ,YAAY,EAAE;YACZ,OAAO,EAAE,IAAI;YACb,kBAAkB,EAAE,EAAE;YACtB,oBAAoB,EAAE,MAAM,qBAAY,CAAC,GAAG,CAAC,KAAK,EAAE;SACrD;QACD,KAAK,EAAE,qBAAY,CAAC,GAAG,CAAC,KAAK;KAC9B;CACF,CAAC;AAEW,QAAA,QAAQ,GAAe;IAClC,SAAS,EAAE,yBAAS,CAAC,GAAG;IACxB,OAAO,EAAE;QACP,IAAI,EAAE,CAAC,qBAAY,CAAC,GAAG,CAAC,GAAG,CAAC;QAC5B,KAAK,EAAE,KAAK;QACZ,YAAY,EAAE;YACZ,OAAO,EAAE,IAAI;YACb,kBAAkB,EAAE,EAAE;YACtB,oBAAoB,EAAE,qBAAY,CAAC,GAAG,CAAC,KAAK;YAC5C,UAAU,EAAE,qBAAY,CAAC,GAAG,CAAC,WAAW;SACzC;QACD,KAAK,EAAE,MAAM,qBAAY,CAAC,GAAG,CAAC,KAAK,EAAE;KACtC;CACF,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SenderService } from '../../service/sender.service';
|
|
2
|
-
import { MailMessage } from '../../mail';
|
|
3
|
-
export declare class AppController {
|
|
4
|
-
private readonly senderService;
|
|
5
|
-
private logger;
|
|
6
|
-
constructor(senderService: SenderService);
|
|
7
|
-
getHello(data: MailMessage): Promise<void>;
|
|
8
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
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.AppController = void 0;
|
|
16
|
-
const common_1 = require("@nestjs/common");
|
|
17
|
-
const microservices_1 = require("@nestjs/microservices");
|
|
18
|
-
const Sentry = require("@sentry/node");
|
|
19
|
-
const sender_service_1 = require("../../service/sender.service");
|
|
20
|
-
let AppController = class AppController {
|
|
21
|
-
constructor(senderService) {
|
|
22
|
-
this.senderService = senderService;
|
|
23
|
-
this.logger = new common_1.Logger('Mail::AppController');
|
|
24
|
-
}
|
|
25
|
-
async getHello(data) {
|
|
26
|
-
try {
|
|
27
|
-
await this.senderService.sendMail(data.to, data.type, data.payload);
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
if (data.ttl > 0 && (new Date().getTime() - data.timestamp) / 1000 > data.ttl) {
|
|
31
|
-
this.logger.warn(`message to "${data.to}" with template "${data.type}" was market as processed due to exceeding ttl`);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
Sentry.captureException(e, {
|
|
35
|
-
extra: data,
|
|
36
|
-
});
|
|
37
|
-
this.logger.error('send email error');
|
|
38
|
-
this.logger.error(e);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
__decorate([
|
|
43
|
-
microservices_1.EventPattern('new_mail'),
|
|
44
|
-
__param(0, microservices_1.Payload()),
|
|
45
|
-
__metadata("design:type", Function),
|
|
46
|
-
__metadata("design:paramtypes", [Object]),
|
|
47
|
-
__metadata("design:returntype", Promise)
|
|
48
|
-
], AppController.prototype, "getHello", null);
|
|
49
|
-
AppController = __decorate([
|
|
50
|
-
common_1.Controller(),
|
|
51
|
-
__metadata("design:paramtypes", [sender_service_1.SenderService])
|
|
52
|
-
], AppController);
|
|
53
|
-
exports.AppController = AppController;
|
|
54
|
-
//# sourceMappingURL=app.controller.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app.controller.js","sourceRoot":"","sources":["../../../src/transports/tcp/app.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,yDAA8D;AAC9D,uCAAuC;AACvC,iEAA6D;AAI7D,IAAa,aAAa,GAA1B,MAAa,aAAa;IAExB,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QADjD,WAAM,GAAG,IAAI,eAAM,CAAC,qBAAqB,CAAC,CAAC;IACS,CAAC;IAG7D,KAAK,CAAC,QAAQ,CAAY,IAAiB;QACzC,IAAI;YACF,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;SACrE;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE;gBAC7E,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,eAAe,IAAI,CAAC,EAAE,oBAAoB,IAAI,CAAC,IAAI,gDAAgD,CACpG,CAAC;gBACF,OAAO;aACR;YACD,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE;gBACzB,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACtB;IACH,CAAC;CACF,CAAA;AAjBC;IADC,4BAAY,CAAC,UAAU,CAAC;IACT,WAAA,uBAAO,EAAE,CAAA;;;;6CAgBxB;AArBU,aAAa;IADzB,mBAAU,EAAE;qCAGiC,8BAAa;GAF9C,aAAa,CAsBzB;AAtBY,sCAAa"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { OnApplicationBootstrap } from '@nestjs/common';
|
|
2
|
-
import { ClientProxy } from '@nestjs/microservices';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
export declare class MailService implements OnApplicationBootstrap {
|
|
5
|
-
private logger;
|
|
6
|
-
client: ClientProxy;
|
|
7
|
-
onApplicationBootstrap(): Promise<void>;
|
|
8
|
-
/**
|
|
9
|
-
* @param to - email to send the message to
|
|
10
|
-
* @param type - the type of message to send. files `{type}.handlebars` and `{type}.subject.handlebars` will used
|
|
11
|
-
* @param payload - object with payload to build you mail
|
|
12
|
-
* @param ttl - the number of seconds after which the message will be rejected from the queue if,
|
|
13
|
-
* but only if it was processed with an error. Set 0 if you think your message should live until
|
|
14
|
-
* it is successfully sent.
|
|
15
|
-
*/
|
|
16
|
-
sendMail<TResult = any>(to: string, type: string, payload?: {
|
|
17
|
-
[key: string]: unknown;
|
|
18
|
-
}, ttl?: number): Observable<TResult>;
|
|
19
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
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.MailService = void 0;
|
|
13
|
-
const common_1 = require("@nestjs/common");
|
|
14
|
-
const microservices_1 = require("@nestjs/microservices");
|
|
15
|
-
const rxjs_1 = require("rxjs");
|
|
16
|
-
const retry_1 = require("../../connect/retry");
|
|
17
|
-
const connection_1 = require("./connection");
|
|
18
|
-
let MailService = class MailService {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.logger = new common_1.Logger('Mail::MailService');
|
|
21
|
-
}
|
|
22
|
-
async onApplicationBootstrap() {
|
|
23
|
-
await rxjs_1.defer(async () => {
|
|
24
|
-
await this.client.connect();
|
|
25
|
-
})
|
|
26
|
-
.pipe(retry_1.default(10, 5000))
|
|
27
|
-
.toPromise();
|
|
28
|
-
this.logger.log('TCP Connected');
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @param to - email to send the message to
|
|
32
|
-
* @param type - the type of message to send. files `{type}.handlebars` and `{type}.subject.handlebars` will used
|
|
33
|
-
* @param payload - object with payload to build you mail
|
|
34
|
-
* @param ttl - the number of seconds after which the message will be rejected from the queue if,
|
|
35
|
-
* but only if it was processed with an error. Set 0 if you think your message should live until
|
|
36
|
-
* it is successfully sent.
|
|
37
|
-
*/
|
|
38
|
-
sendMail(to, type, payload, ttl = 0) {
|
|
39
|
-
return this.client.emit('new_mail', {
|
|
40
|
-
type,
|
|
41
|
-
payload,
|
|
42
|
-
to,
|
|
43
|
-
timestamp: new Date().getTime(),
|
|
44
|
-
ttl,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
__decorate([
|
|
49
|
-
microservices_1.Client(connection_1.generalClient),
|
|
50
|
-
__metadata("design:type", microservices_1.ClientProxy)
|
|
51
|
-
], MailService.prototype, "client", void 0);
|
|
52
|
-
MailService = __decorate([
|
|
53
|
-
common_1.Injectable()
|
|
54
|
-
], MailService);
|
|
55
|
-
exports.MailService = MailService;
|
|
56
|
-
//# sourceMappingURL=app.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app.service.js","sourceRoot":"","sources":["../../../src/transports/tcp/app.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4E;AAC5E,yDAA4D;AAC5D,+BAAyC;AAEzC,+CAAwC;AACxC,6CAA6C;AAG7C,IAAa,WAAW,GAAxB,MAAa,WAAW;IAAxB;QACU,WAAM,GAAW,IAAI,eAAM,CAAC,mBAAmB,CAAC,CAAC;IAoC3D,CAAC;IA/BC,KAAK,CAAC,sBAAsB;QAC1B,MAAM,YAAK,CAAC,KAAK,IAAI,EAAE;YACrB,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC,CAAC;aACC,IAAI,CAAC,eAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;aACrB,SAAS,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;OAOG;IACH,QAAQ,CACN,EAAU,EACV,IAAY,EACZ,OAAoC,EACpC,MAAc,CAAC;QAEf,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAuB,UAAU,EAAE;YACxD,IAAI;YACJ,OAAO;YACP,EAAE;YACF,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC/B,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAjCC;IADC,sBAAM,CAAC,0BAAoB,CAAC;8BACrB,2BAAW;2CAAC;AAJT,WAAW;IADvB,mBAAU,EAAE;GACA,WAAW,CAqCvB;AArCY,kCAAW"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generalClient = void 0;
|
|
4
|
-
const microservices_1 = require("@nestjs/microservices");
|
|
5
|
-
const config_1 = require("config");
|
|
6
|
-
exports.generalClient = {
|
|
7
|
-
transport: microservices_1.Transport.TCP,
|
|
8
|
-
options: {
|
|
9
|
-
host: config_1.MAIL_SERVICE.TCP.HOST,
|
|
10
|
-
port: config_1.MAIL_SERVICE.TCP.PORT,
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/transports/tcp/connection.ts"],"names":[],"mappings":";;;AAAA,yDAAkD;AAClD,mCAAsC;AAEzB,QAAA,aAAa,GAAG;IAC3B,SAAS,EAAE,yBAAS,CAAC,GAAG;IACxB,OAAO,EAAE;QACP,IAAI,EAAE,qBAAY,CAAC,GAAG,CAAC,IAAI;QAC3B,IAAI,EAAE,qBAAY,CAAC,GAAG,CAAC,IAAI;KAC5B;CACF,CAAC"}
|