@pixelplex/mail-service 0.1.21 → 0.1.22

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 (35) hide show
  1. package/README.md +33 -7
  2. package/dist/connect/app.module.d.ts +2 -0
  3. package/dist/connect/app.module.js +14 -9
  4. package/dist/connect/app.module.js.map +1 -1
  5. package/dist/index.d.ts +3 -2
  6. package/dist/index.js +5 -3
  7. package/dist/index.js.map +1 -1
  8. package/dist/main.js +4 -3
  9. package/dist/main.js.map +1 -1
  10. package/dist/service/app.module.d.ts +2 -0
  11. package/dist/service/app.module.js +14 -8
  12. package/dist/service/app.module.js.map +1 -1
  13. package/dist/{service → transports/rmq}/app.controller.d.ts +2 -2
  14. package/dist/{service → transports/rmq}/app.controller.js +1 -1
  15. package/dist/transports/rmq/app.controller.js.map +1 -0
  16. package/dist/{connect → transports/rmq}/app.service.d.ts +0 -0
  17. package/dist/{connect → transports/rmq}/app.service.js +2 -2
  18. package/dist/transports/rmq/app.service.js.map +1 -0
  19. package/dist/{connection.d.ts → transports/rmq/connection.d.ts} +0 -0
  20. package/dist/{connection.js → transports/rmq/connection.js} +0 -0
  21. package/dist/transports/rmq/connection.js.map +1 -0
  22. package/dist/transports/tcp/app.controller.d.ts +8 -0
  23. package/dist/transports/tcp/app.controller.js +54 -0
  24. package/dist/transports/tcp/app.controller.js.map +1 -0
  25. package/dist/transports/tcp/app.service.d.ts +19 -0
  26. package/dist/transports/tcp/app.service.js +56 -0
  27. package/dist/transports/tcp/app.service.js.map +1 -0
  28. package/dist/transports/tcp/connection.d.ts +8 -0
  29. package/dist/transports/tcp/connection.js +13 -0
  30. package/dist/transports/tcp/connection.js.map +1 -0
  31. package/dist/tsconfig.build.tsbuildinfo +832 -779
  32. package/package.json +1 -1
  33. package/dist/connect/app.service.js.map +0 -1
  34. package/dist/connection.js.map +0 -1
  35. package/dist/service/app.controller.js.map +0 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Microservice for fast implementation of the functionality of sending email messages.
4
4
 
5
- The microservice runs using RabbitMQ - other NestJS services send messages to RabbitMQ using `client.emit`.
5
+ The microservice runs using RabbitMQ or TCP - other NestJS services send messages to RabbitMQ or connects by TCP protocol.
6
6
  The service receive messages and sends them via email.
7
7
 
8
8
  ## How to use
@@ -16,7 +16,7 @@ TL;DR
16
16
  5. add `MAIL_SERVICE` config in `config/default.json`
17
17
  6. add `@pixelplex/mail-service` to your application
18
18
  7. add `MailModule` from `@pixelplex/mail-service` to `import` in your module
19
- 8. send a message by calling `this.mailService.sendMail('test@gmail.com', 'welcome', { name: 'Афанасий' }, 20);` where `mailService` is `MailService` from `@pixelplex/mail-service`
19
+ 8. send a message by calling `this.mailService.sendMail('test@gmail.com', 'welcome', { name: 'Афанасий' }, 20);` where `mailService` is `MailRMQService` or `MailTCPService` from `@pixelplex/mail-service`
20
20
  9. ...
21
21
  10. PROFIT
22
22
 
@@ -92,6 +92,8 @@ services:
92
92
  environment:
93
93
  - MAIL_SERVICE_RMQ_URL=amqp://rabbitmq:5672
94
94
  - MAIL_SERVICE_RMQ_QUEUE=test_queue
95
+ - MAIL_SERVICE_TCP_PORT=3000
96
+ - MAIL_SERVICE_TCP_HOST=localhost
95
97
  - MAIL_SERVICE_SMTP_HOST=smtp.gmail.com
96
98
  - MAIL_SERVICE_SMTP_PORT=587
97
99
  - MAIL_SERVICE_SMTP_SENDER=postmail@pixelplex.io
@@ -105,7 +107,7 @@ services:
105
107
  ### Trigger new message sending
106
108
 
107
109
  Now you can return to your microservice (`api` module for example) and try to send new mail through Mail Service.
108
- For it you should send a message to RMQ. But to simplify it you should use [@pixelplex/mail-service](https://www.npmjs.com/package/@pixelplex/mail-service) package.
110
+ For it you should send a message to RMQ or use TCP connection. But to simplify it you should use [@pixelplex/mail-service](https://www.npmjs.com/package/@pixelplex/mail-service) package.
109
111
 
110
112
  **1. Install npm package**
111
113
 
@@ -115,6 +117,8 @@ yarn add @pixelplex/mail-service
115
117
 
116
118
  **2. Configure you application** (we should use `config` package for the configuration). You config file should include next part:
117
119
 
120
+ For RMQ microservices connection:
121
+
118
122
  ```json
119
123
  {
120
124
  ...
@@ -123,7 +127,8 @@ yarn add @pixelplex/mail-service
123
127
  "URL": "amqp://localhost:5672",
124
128
  "QUEUE": "test_queue",
125
129
  "MESSAGE_TTL": 5000
126
- }
130
+ },
131
+ "TRANSPORT": "rmq"
127
132
  },
128
133
  ...
129
134
  }
@@ -135,6 +140,27 @@ Where:
135
140
  - `QUEUE` - queue that will used in mail service to
136
141
  - `MESSAGE_TTL` - time after which the message, which was processed with an error, must return back in the queue and be processed again
137
142
 
143
+ For TCP microservices connection:
144
+
145
+ ```json
146
+ {
147
+ ...
148
+ "MAIL_SERVICE": {
149
+ "TCP": {
150
+ "HOST": "localhost",
151
+ "PORT": 3000
152
+ },
153
+ "TRANSPORT": "tcp"
154
+ },
155
+ ...
156
+ }
157
+ ```
158
+
159
+ Where:
160
+
161
+ - `HOST` - connection hostname
162
+ - `PORT` - connection port
163
+
138
164
  **! Be sure, that the configuration of the queue the same as in the mail service**
139
165
 
140
166
  **3. Import MailModule** in your module you'll send mail from:
@@ -146,7 +172,7 @@ import { AppService } from './app.service';
146
172
 
147
173
  @Module({
148
174
  controllers: [],
149
- imports: [MailModule],
175
+ imports: [MailModule.forRoot()],
150
176
  providers: [AppService],
151
177
  })
152
178
  export class AppModule {}
@@ -156,11 +182,11 @@ export class AppModule {}
156
182
 
157
183
  ```typescript
158
184
  import { Injectable } from '@nestjs/common';
159
- import { MailService } from '@pixelplex/mail-service';
185
+ import { MailTCPService, MailRMQService } from '@pixelplex/mail-service';
160
186
 
161
187
  @Injectable()
162
188
  export class AppService {
163
- constructor(private mailService: MailService) {}
189
+ constructor(private mailService: (MailRMQService or MailTCPService)) {}
164
190
 
165
191
  async onModuleInit() {
166
192
  this.mailService.sendMail('test@gmail.com', 'welcome', { name: 'Афанасий' }, 20);
@@ -1,2 +1,4 @@
1
+ import { DynamicModule } from '@nestjs/common';
1
2
  export declare class MailModule {
3
+ static forRoot(): Promise<DynamicModule>;
2
4
  }
@@ -5,19 +5,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var MailModule_1;
8
9
  Object.defineProperty(exports, "__esModule", { value: true });
9
10
  exports.MailModule = void 0;
10
11
  const common_1 = require("@nestjs/common");
11
- const app_service_1 = require("./app.service");
12
- let MailModule = class MailModule {
12
+ const config_1 = require("config");
13
+ let MailModule = MailModule_1 = class MailModule {
14
+ static async forRoot() {
15
+ const { MailService } = await Promise.resolve().then(() => require(`../transports/${config_1.MAIL_SERVICE.TRANSPORT}/app.service`));
16
+ return {
17
+ module: MailModule_1,
18
+ imports: [],
19
+ providers: [MailService],
20
+ exports: [MailService],
21
+ };
22
+ }
13
23
  };
14
- MailModule = __decorate([
15
- common_1.Module({
16
- imports: [],
17
- exports: [app_service_1.MailService],
18
- controllers: [],
19
- providers: [app_service_1.MailService],
20
- })
24
+ MailModule = MailModule_1 = __decorate([
25
+ common_1.Module({})
21
26
  ], MailModule);
22
27
  exports.MailModule = MailModule;
23
28
  //# sourceMappingURL=app.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../../src/connect/app.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+CAA4C;AAQ5C,IAAa,UAAU,GAAvB,MAAa,UAAU;CAAG,CAAA;AAAb,UAAU;IANtB,eAAM,CAAC;QACN,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,CAAC,yBAAW,CAAC;QACtB,WAAW,EAAE,EAAE;QACf,SAAS,EAAE,CAAC,yBAAW,CAAC;KACzB,CAAC;GACW,UAAU,CAAG;AAAb,gCAAU"}
1
+ {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../../src/connect/app.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AAEvD,mCAAsC;AAGtC,IAAa,UAAU,kBAAvB,MAAa,UAAU;IACrB,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,MAAM,EAAE,WAAW,EAAE,GAAG,2CAAa,iBAAiB,qBAAY,CAAC,SAAS,cAAc,EAAC,CAAC;QAC5F,OAAO;YACL,MAAM,EAAE,YAAU;YAClB,OAAO,EAAE,EAAE;YACX,SAAS,EAAE,CAAC,WAAW,CAAC;YACxB,OAAO,EAAE,CAAC,WAAW,CAAC;SACvB,CAAC;IACJ,CAAC;CACF,CAAA;AAVY,UAAU;IADtB,eAAM,CAAC,EAAE,CAAC;GACE,UAAU,CAUtB;AAVY,gCAAU"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { MailModule } from './connect/app.module';
2
- import { MailService } from './connect/app.service';
3
- export { MailModule, MailService };
2
+ import { MailService as MailRMQService } from './transports/rmq/app.service';
3
+ import { MailService as MailTCPService } from './transports/tcp/app.service';
4
+ export { MailModule, MailRMQService, MailTCPService };
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MailService = exports.MailModule = void 0;
3
+ exports.MailTCPService = exports.MailRMQService = exports.MailModule = void 0;
4
4
  const app_module_1 = require("./connect/app.module");
5
5
  Object.defineProperty(exports, "MailModule", { enumerable: true, get: function () { return app_module_1.MailModule; } });
6
- const app_service_1 = require("./connect/app.service");
7
- Object.defineProperty(exports, "MailService", { enumerable: true, get: function () { return app_service_1.MailService; } });
6
+ const app_service_1 = require("./transports/rmq/app.service");
7
+ Object.defineProperty(exports, "MailRMQService", { enumerable: true, get: function () { return app_service_1.MailService; } });
8
+ const app_service_2 = require("./transports/tcp/app.service");
9
+ Object.defineProperty(exports, "MailTCPService", { enumerable: true, get: function () { return app_service_2.MailService; } });
8
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAGzC,2FAHA,uBAAU,OAGA;AAFnB,uDAAoD;AAE/B,4FAFZ,yBAAW,OAEY"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAIzC,2FAJA,uBAAU,OAIA;AAHnB,8DAA6E;AAGxD,+FAHG,yBAAc,OAGH;AAFnC,8DAA6E;AAExC,+FAFb,yBAAc,OAEa"}
package/dist/main.js CHANGED
@@ -5,7 +5,6 @@ const common_1 = require("@nestjs/common");
5
5
  const Sentry = require("@sentry/node");
6
6
  const config_1 = require("config");
7
7
  const app_module_1 = require("./service/app.module");
8
- const connection_1 = require("./connection");
9
8
  const logger = new common_1.Logger('Mail::Application');
10
9
  if (config_1.SENTRY.ENABLED && config_1.SENTRY.DSN) {
11
10
  Sentry.init({
@@ -13,10 +12,12 @@ if (config_1.SENTRY.ENABLED && config_1.SENTRY.DSN) {
13
12
  });
14
13
  logger.log('Sentry is initialized');
15
14
  }
15
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
16
16
  async function bootstrap() {
17
- const app = await core_1.NestFactory.createMicroservice(app_module_1.AppModule, connection_1.generalClient);
17
+ const { generalClient } = await Promise.resolve().then(() => require(`./transports/${config_1.MAIL_SERVICE.TRANSPORT}/connection`));
18
+ const app = await core_1.NestFactory.createMicroservice(app_module_1.AppModule.forRoot(), generalClient);
18
19
  await app.listen(() => {
19
- logger.log('RMQ Connected. Service is started');
20
+ logger.log(`${config_1.MAIL_SERVICE.TRANSPORT.toLocaleUpperCase()} Connected. Service is started`);
20
21
  });
21
22
  }
22
23
  bootstrap();
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"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,CAAC,OAAO,EAAE,EAAE,aAAa,CAAC,CAAC;IAC1G,MAAM,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE;QACpB,MAAM,CAAC,GAAG,CAAC,GAAG,qBAAY,CAAC,SAAS,CAAC,iBAAiB,EAAE,gCAAgC,CAAC,CAAC;IAC5F,CAAC,CAAC,CAAC;AACL,CAAC;AACD,SAAS,EAAE,CAAC"}
@@ -1,2 +1,4 @@
1
+ import { DynamicModule } from '@nestjs/common';
1
2
  export declare class AppModule {
3
+ static forRoot(): Promise<DynamicModule>;
2
4
  }
@@ -5,19 +5,25 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var AppModule_1;
8
9
  Object.defineProperty(exports, "__esModule", { value: true });
9
10
  exports.AppModule = void 0;
10
11
  const common_1 = require("@nestjs/common");
11
- const app_controller_1 = require("./app.controller");
12
+ const config_1 = require("config");
12
13
  const sender_service_1 = require("./sender.service");
13
- let AppModule = class AppModule {
14
+ let AppModule = AppModule_1 = class AppModule {
15
+ static async forRoot() {
16
+ const { AppController } = await Promise.resolve().then(() => require(`../transports/${config_1.MAIL_SERVICE.TRANSPORT}/app.controller`));
17
+ return {
18
+ module: AppModule_1,
19
+ imports: [],
20
+ controllers: [AppController],
21
+ providers: [sender_service_1.SenderService],
22
+ };
23
+ }
14
24
  };
15
- AppModule = __decorate([
16
- common_1.Module({
17
- imports: [],
18
- controllers: [app_controller_1.AppController],
19
- providers: [sender_service_1.SenderService],
20
- })
25
+ AppModule = AppModule_1 = __decorate([
26
+ common_1.Module({})
21
27
  ], AppModule);
22
28
  exports.AppModule = AppModule;
23
29
  //# sourceMappingURL=app.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../../src/service/app.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,qDAAiD;AACjD,qDAAiD;AAOjD,IAAa,SAAS,GAAtB,MAAa,SAAS;CAAG,CAAA;AAAZ,SAAS;IALrB,eAAM,CAAC;QACN,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,CAAC,8BAAa,CAAC;QAC5B,SAAS,EAAE,CAAC,8BAAa,CAAC;KAC3B,CAAC;GACW,SAAS,CAAG;AAAZ,8BAAS"}
1
+ {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../../src/service/app.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,mCAAsC;AACtC,qDAAiD;AAGjD,IAAa,SAAS,iBAAtB,MAAa,SAAS;IACpB,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,MAAM,EAAE,aAAa,EAAE,GAAG,2CAAa,iBAAiB,qBAAY,CAAC,SAAS,iBAAiB,EAAC,CAAC;QACjG,OAAO;YACL,MAAM,EAAE,WAAS;YACjB,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,CAAC,aAAa,CAAC;YAC5B,SAAS,EAAE,CAAC,8BAAa,CAAC;SAC3B,CAAC;IACJ,CAAC;CACF,CAAA;AAVY,SAAS;IADrB,eAAM,CAAC,EAAE,CAAC;GACE,SAAS,CAUrB;AAVY,8BAAS"}
@@ -1,6 +1,6 @@
1
1
  import { RmqContext } from '@nestjs/microservices';
2
- import { MailMessage } from '../mail';
3
- import { SenderService } from './sender.service';
2
+ import { MailMessage } from '../../mail';
3
+ import { SenderService } from '../../service/sender.service';
4
4
  export declare class AppController {
5
5
  private readonly senderService;
6
6
  private logger;
@@ -16,7 +16,7 @@ exports.AppController = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
17
  const microservices_1 = require("@nestjs/microservices");
18
18
  const Sentry = require("@sentry/node");
19
- const sender_service_1 = require("./sender.service");
19
+ const sender_service_1 = require("../../service/sender.service");
20
20
  let AppController = class AppController {
21
21
  constructor(senderService) {
22
22
  this.senderService = senderService;
@@ -0,0 +1 @@
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"}
@@ -13,8 +13,8 @@ exports.MailService = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const microservices_1 = require("@nestjs/microservices");
15
15
  const rxjs_1 = require("rxjs");
16
- const connection_1 = require("../connection");
17
- const retry_1 = require("./retry");
16
+ const retry_1 = require("../../connect/retry");
17
+ const connection_1 = require("./connection");
18
18
  let MailService = class MailService {
19
19
  constructor() {
20
20
  this.logger = new common_1.Logger('Mail::MailService');
@@ -0,0 +1 @@
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,CA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ACb,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"}
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,54 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,56 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,8 @@
1
+ import { Transport } from '@nestjs/microservices';
2
+ export declare const generalClient: {
3
+ transport: Transport;
4
+ options: {
5
+ host: string;
6
+ port: number;
7
+ };
8
+ };
@@ -0,0 +1,13 @@
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
@@ -0,0 +1 @@
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"}