@pixelplex/mail-service 0.1.19 → 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 (39) hide show
  1. package/.husky/pre-commit +9 -0
  2. package/README.md +55 -21
  3. package/dist/connect/app.module.d.ts +2 -0
  4. package/dist/connect/app.module.js +14 -9
  5. package/dist/connect/app.module.js.map +1 -1
  6. package/dist/connect/retry.js.map +1 -1
  7. package/dist/index.d.ts +3 -2
  8. package/dist/index.js +5 -3
  9. package/dist/index.js.map +1 -1
  10. package/dist/main.js +4 -3
  11. package/dist/main.js.map +1 -1
  12. package/dist/service/app.module.d.ts +2 -0
  13. package/dist/service/app.module.js +14 -8
  14. package/dist/service/app.module.js.map +1 -1
  15. package/dist/service/sender.service.js +17 -8
  16. package/dist/service/sender.service.js.map +1 -1
  17. package/dist/{service → transports/rmq}/app.controller.d.ts +2 -2
  18. package/dist/{service → transports/rmq}/app.controller.js +1 -1
  19. package/dist/transports/rmq/app.controller.js.map +1 -0
  20. package/dist/{connect → transports/rmq}/app.service.d.ts +0 -0
  21. package/dist/{connect → transports/rmq}/app.service.js +5 -3
  22. package/dist/transports/rmq/app.service.js.map +1 -0
  23. package/dist/{connection.d.ts → transports/rmq/connection.d.ts} +0 -0
  24. package/dist/{connection.js → transports/rmq/connection.js} +0 -0
  25. package/dist/transports/rmq/connection.js.map +1 -0
  26. package/dist/transports/tcp/app.controller.d.ts +8 -0
  27. package/dist/transports/tcp/app.controller.js +54 -0
  28. package/dist/transports/tcp/app.controller.js.map +1 -0
  29. package/dist/transports/tcp/app.service.d.ts +19 -0
  30. package/dist/transports/tcp/app.service.js +56 -0
  31. package/dist/transports/tcp/app.service.js.map +1 -0
  32. package/dist/transports/tcp/connection.d.ts +8 -0
  33. package/dist/transports/tcp/connection.js +13 -0
  34. package/dist/transports/tcp/connection.js.map +1 -0
  35. package/dist/tsconfig.build.tsbuildinfo +840 -782
  36. package/package.json +18 -16
  37. package/dist/connect/app.service.js.map +0 -1
  38. package/dist/connection.js.map +0 -1
  39. package/dist/service/app.controller.js.map +0 -1
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ if [[ "$NO_LINT" ]]; then
5
+ exit 0
6
+ fi
7
+
8
+ npx pretty-quick --staged
9
+ yarn lint
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,12 +16,24 @@ 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
 
23
23
  Didn't understand anything? Okay, let's see more details
24
24
 
25
+ ### Local development
26
+
27
+ To use the package locally, pass the follow config:
28
+
29
+ ```text
30
+ - MAIL_SERVICE_SMTP_HOST=smtp.ethereal.email
31
+ - MAIL_SERVICE_SMTP_PORT=587
32
+ - MAIL_SERVICE_SMTP_SENDER=postmail@pixelplex.io
33
+ - MAIL_SERVICE_SMTP_USERNAME=
34
+ - MAIL_SERVICE_SMTP_PASSWORD=
35
+ ```
36
+
25
37
  ### Prepare templates
26
38
 
27
39
  The service uses Handlebars as template engine. So all your email templates should be prepared as handlebars templates.
@@ -32,7 +44,7 @@ For sending message your templates folder should include at least 3 files:
32
44
  - `{type}.handlebars` - body of your email where `{type}` is just your unique key for a unique type of email. For example `welcome.handlebars` for the welcome use email
33
45
  - `{type}.subject.handlebars` - subject (title) of yur email
34
46
 
35
- For example our project will store files in `templates` folder.
47
+ For example our project will store files in `templates` folder.
36
48
 
37
49
  ```
38
50
  ├── docker-compose.yml
@@ -52,9 +64,7 @@ For example our project will store files in `templates` folder.
52
64
  ```
53
65
 
54
66
  ```handlebars
55
- # welcome.subject.handlebars
56
-
57
- Welcome, {{name}}!
67
+ # welcome.subject.handlebars Welcome, {{name}}!
58
68
  ```
59
69
 
60
70
  ```handlebars
@@ -69,19 +79,21 @@ Welcome, {{name}}!
69
79
  Then you need to run this service and connect it to RMQ. For example, you can use Docker Compose:
70
80
 
71
81
  ```yaml
72
- version: "3"
82
+ version: '3'
73
83
  services:
74
84
  rabbitmq:
75
- image: "rabbitmq:3-management"
85
+ image: 'rabbitmq:3-management'
76
86
  ports:
77
- - "127.0.0.1:5672:5672"
78
- - "127.0.0.1:15672:15672"
87
+ - '127.0.0.1:5672:5672'
88
+ - '127.0.0.1:15672:15672'
79
89
 
80
90
  mail-service:
81
- image: "pixelplex/mail-service:0.1.18"
91
+ image: 'pixelplex/mail-service:0.1.18'
82
92
  environment:
83
93
  - MAIL_SERVICE_RMQ_URL=amqp://rabbitmq:5672
84
94
  - MAIL_SERVICE_RMQ_QUEUE=test_queue
95
+ - MAIL_SERVICE_TCP_PORT=3000
96
+ - MAIL_SERVICE_TCP_HOST=localhost
85
97
  - MAIL_SERVICE_SMTP_HOST=smtp.gmail.com
86
98
  - MAIL_SERVICE_SMTP_PORT=587
87
99
  - MAIL_SERVICE_SMTP_SENDER=postmail@pixelplex.io
@@ -89,13 +101,13 @@ services:
89
101
  - MAIL_SERVICE_SMTP_PASSWORD=$MAIL_SERVICE_SMTP_PASSWORD
90
102
  - MAIL_SERVICE_SENTRY_DNS=$MAIL_SERVICE_SENTRY_DNS
91
103
  volumes:
92
- - ./templates:/app/templates # note that we attach our template folder as /app/templates
93
- ```
104
+ - ./templates:/app/templates # note that we attach our template folder as /app/templates
105
+ ```
94
106
 
95
107
  ### Trigger new message sending
96
108
 
97
109
  Now you can return to your microservice (`api` module for example) and try to send new mail through Mail Service.
98
- 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.
99
111
 
100
112
  **1. Install npm package**
101
113
 
@@ -105,6 +117,8 @@ yarn add @pixelplex/mail-service
105
117
 
106
118
  **2. Configure you application** (we should use `config` package for the configuration). You config file should include next part:
107
119
 
120
+ For RMQ microservices connection:
121
+
108
122
  ```json
109
123
  {
110
124
  ...
@@ -113,7 +127,8 @@ yarn add @pixelplex/mail-service
113
127
  "URL": "amqp://localhost:5672",
114
128
  "QUEUE": "test_queue",
115
129
  "MESSAGE_TTL": 5000
116
- }
130
+ },
131
+ "TRANSPORT": "rmq"
117
132
  },
118
133
  ...
119
134
  }
@@ -125,6 +140,27 @@ Where:
125
140
  - `QUEUE` - queue that will used in mail service to
126
141
  - `MESSAGE_TTL` - time after which the message, which was processed with an error, must return back in the queue and be processed again
127
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
+
128
164
  **! Be sure, that the configuration of the queue the same as in the mail service**
129
165
 
130
166
  **3. Import MailModule** in your module you'll send mail from:
@@ -136,7 +172,7 @@ import { AppService } from './app.service';
136
172
 
137
173
  @Module({
138
174
  controllers: [],
139
- imports: [MailModule],
175
+ imports: [MailModule.forRoot()],
140
176
  providers: [AppService],
141
177
  })
142
178
  export class AppModule {}
@@ -146,17 +182,15 @@ export class AppModule {}
146
182
 
147
183
  ```typescript
148
184
  import { Injectable } from '@nestjs/common';
149
- import { MailService } from '@pixelplex/mail-service';
185
+ import { MailTCPService, MailRMQService } from '@pixelplex/mail-service';
150
186
 
151
187
  @Injectable()
152
188
  export class AppService {
153
-
154
- constructor(private mailService: MailService) {}
189
+ constructor(private mailService: (MailRMQService or MailTCPService)) {}
155
190
 
156
191
  async onModuleInit() {
157
192
  this.mailService.sendMail('test@gmail.com', 'welcome', { name: 'Афанасий' }, 20);
158
193
  }
159
-
160
194
  }
161
195
  ```
162
196
 
@@ -164,5 +198,5 @@ In the example below we'll send email to `test@gmail.com` with type `welcome` (`
164
198
 
165
199
  `{name: 'Афанасий'}` is the object with data which will used as payload data during processing your handlebars template.
166
200
 
167
- The last argument, `20`, is the number of seconds after which the message will be rejected from the queue if, but only if it was processed with an error.
201
+ The last argument, `20`, is the number of seconds after which the message will be rejected from the queue if, but only if it was processed with an error.
168
202
  If you think your message should live until it is successfully sent use `0`.
@@ -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"}
@@ -1 +1 @@
1
- {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/connect/retry.ts"],"names":[],"mappings":";;AACA,8CAAwD;AAExD,SAAwB,KAAK,CAC3B,aAAa,GAAG,EAAE,EAClB,UAAU,GAAG,KAAK;IAElB,OAAO,CAAI,MAAqB,EAAE,EAAE,CAClC,MAAM,CAAC,IAAI,CACT,qBAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CACd,CAAC,CAAC,IAAI,CACJ,gBAAI,CAAC,CAAC,GAAW,EAAE,KAAY,EAAE,EAAE;QACjC,IAAI,GAAG,GAAG,CAAC,IAAI,aAAa,EAAE;YAC5B,MAAM,KAAK,CAAC;SACb;QACD,OAAO,GAAG,GAAG,CAAC,CAAC;IACjB,CAAC,EAAE,CAAC,CAAC,EACL,iBAAK,CAAC,UAAU,CAAC,CAClB,CACF,CACF,CAAC;AACN,CAAC;AAlBD,wBAkBC"}
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/connect/retry.ts"],"names":[],"mappings":";;AACA,8CAAwD;AAExD,SAAwB,KAAK,CAAC,aAAa,GAAG,EAAE,EAAE,UAAU,GAAG,KAAK;IAClE,OAAO,CAAI,MAAqB,EAAE,EAAE,CAClC,MAAM,CAAC,IAAI,CACT,qBAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CACd,CAAC,CAAC,IAAI,CACJ,gBAAI,CAAC,CAAC,GAAW,EAAE,KAAY,EAAE,EAAE;QACjC,IAAI,GAAG,GAAG,CAAC,IAAI,aAAa,EAAE;YAC5B,MAAM,KAAK,CAAC;SACb;QACD,OAAO,GAAG,GAAG,CAAC,CAAC;IACjB,CAAC,EAAE,CAAC,CAAC,EACL,iBAAK,CAAC,UAAU,CAAC,CAClB,CACF,CACF,CAAC;AACN,CAAC;AAfD,wBAeC"}
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;AAIhD,2FAJO,uBAAU,OAIP;AAHZ,uDAAoD;AAIlD,4FAJO,yBAAW,OAIP"}
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"],"names":[],"mappings":";;AAAA,uCAA2C;AAE3C,2CAAwC;AACxC,uCAAuC;AACvC,mCAAgC;AAChC,qDAAiD;AACjD,6CAA6C;AAE7C,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,mBAAmB,CAAC,CAAC;AAE/C,IAAI,eAAM,CAAC,OAAO,IAAI,eAAM,CAAC,GAAG,EAAE;IAChC,MAAM,CAAC,IAAI,CAAC;QACV,GAAG,EAAE,eAAM,CAAC,GAAG;KAChB,CAAC,CAAC;IACH,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;CACrC;AAED,KAAK,UAAU,SAAS;IACtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,kBAAkB,CAAsB,sBAAS,EAAE,0BAAa,CAAC,CAAC;IAChG,MAAM,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE;QACpB,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AACD,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAE3C,2CAAwC;AACxC,uCAAuC;AACvC,mCAA8C;AAC9C,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,mBAAmB,CAAC,CAAC;AAE/C,IAAI,eAAM,CAAC,OAAO,IAAI,eAAM,CAAC,GAAG,EAAE;IAChC,MAAM,CAAC,IAAI,CAAC;QACV,GAAG,EAAE,eAAM,CAAC,GAAG;KAChB,CAAC,CAAC;IACH,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;CACrC;AAED,4EAA4E;AAC5E,KAAK,UAAU,SAAS;IACtB,MAAM,EAAE,aAAa,EAAE,GAAG,2CAAa,gBAAgB,qBAAY,CAAC,SAAS,aAAa,EAAC,CAAC;IAC5F,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,kBAAkB,CAAsB,sBAAS,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,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SenderService = void 0;
4
+ const fs = require("fs");
4
5
  const common_1 = require("@nestjs/common");
5
6
  const config_1 = require("config");
6
- const fs = require("fs");
7
7
  const Handlebars = require("handlebars");
8
8
  const nodemailer_1 = require("nodemailer");
9
9
  const hbs = require("nodemailer-express-handlebars");
@@ -21,16 +21,22 @@ class SenderService {
21
21
  await this.connect();
22
22
  }
23
23
  async connect() {
24
- if (!config_1.MAIL_SERVICE.SMTP.PASSWORD) {
25
- throw new Error('[NodemailerConnector Error] Password wasn\'t provided. ' +
26
- 'You should provide the password in ENV Variable or in local.json config file');
24
+ const isEthereal = config_1.MAIL_SERVICE.SMTP.HOST === 'smtp.ethereal.email';
25
+ if (!config_1.MAIL_SERVICE.SMTP.PASSWORD && !isEthereal) {
26
+ throw new Error(`[NodemailerConnector Error] Password wasn\'t provided.
27
+ You should provide the password in ENV Variable or in local.json config file`);
28
+ }
29
+ let testAccount;
30
+ if (isEthereal) {
31
+ this.logger.warn('Run in ethereal.email mode');
32
+ testAccount = await nodemailer_1.createTestAccount();
27
33
  }
28
34
  this.transporter = nodemailer_1.createTransport({
29
35
  host: config_1.MAIL_SERVICE.SMTP.HOST,
30
36
  port: config_1.MAIL_SERVICE.SMTP.PORT,
31
37
  auth: {
32
- user: config_1.MAIL_SERVICE.SMTP.USERNAME,
33
- pass: config_1.MAIL_SERVICE.SMTP.PASSWORD,
38
+ user: config_1.MAIL_SERVICE.SMTP.USERNAME || testAccount.user,
39
+ pass: config_1.MAIL_SERVICE.SMTP.PASSWORD || testAccount.pass,
34
40
  },
35
41
  });
36
42
  this.transporter.use('compile', hbs(hbsOptions));
@@ -42,12 +48,15 @@ class SenderService {
42
48
  const info = await this.transporter.sendMail({
43
49
  from: config_1.MAIL_SERVICE.SMTP.SENDER,
44
50
  to,
45
- html: subjectTpl(context),
51
+ subject: subjectTpl(context),
46
52
  template,
47
53
  context,
48
- subject: context['subject'] || subjectTpl(context),
49
54
  });
50
55
  this.logger.debug(`Message sent: ${info.messageId}, ${info.response}`);
56
+ const isEthereal = config_1.MAIL_SERVICE.SMTP.HOST === 'smtp.ethereal.email';
57
+ if (isEthereal) {
58
+ this.logger.debug(`Preview URL: ${nodemailer_1.getTestMessageUrl(info)}`);
59
+ }
51
60
  }
52
61
  }
53
62
  exports.SenderService = SenderService;
@@ -1 +1 @@
1
- {"version":3,"file":"sender.service.js","sourceRoot":"","sources":["../../src/service/sender.service.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,mCAAsC;AACtC,yBAAyB;AACzB,yCAAyC;AACzC,2CAA0D;AAC1D,qDAAqD;AAErD,MAAM,UAAU,GAAG;IACjB,UAAU,EAAE;QACV,UAAU,EAAE,YAAY;KACzB;IACD,QAAQ,EAAE,YAAY;CACvB,CAAC;AAEF,MAAa,aAAa;IAA1B;QAGmB,WAAM,GAAW,IAAI,eAAM,CAAC,qBAAqB,CAAC,CAAC;IAoCtE,CAAC;IAlCC,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,qBAAY,CAAC,IAAI,CAAC,QAAQ,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,yDAAyD;gBACvE,8EAA8E,CAAC,CAAC;SACnF;QACD,IAAI,CAAC,WAAW,GAAG,4BAAe,CAAC;YACjC,IAAI,EAAE,qBAAY,CAAC,IAAI,CAAC,IAAI;YAC5B,IAAI,EAAE,qBAAY,CAAC,IAAI,CAAC,IAAI;YAC5B,IAAI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CAAC,mBAAmB,EAAE,oBAAoB,QAAQ,GAAG,CAAC,CAAC;QACxE,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,YAAY,CAAC,aAAa,QAAQ,qBAAqB,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC9G,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;YAC3C,IAAI,EAAE,qBAAY,CAAC,IAAI,CAAC,MAAM;YAC9B,EAAE;YACF,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;YAC5B,QAAQ;YACR,OAAO;SACR,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACvE,MAAM,UAAU,GAAG,qBAAY,CAAC,IAAI,CAAC,IAAI,KAAK,qBAAqB,CAAC;QACpE,IAAI,UAAU,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,8BAAiB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SAC9D;IACH,CAAC;CACF;AAlDD,sCAkDC"}
@@ -1,6 +1,6 @@
1
1
  import { RmqContext } from '@nestjs/microservices';
2
- import { SenderService } from './sender.service';
3
- import { MailMessage } from '../mail';
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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AAE,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 retry_1 = require("./retry");
17
- const connection_1 = require("../connection");
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');
@@ -23,7 +23,9 @@ let MailService = class MailService {
23
23
  await rxjs_1.defer(async () => {
24
24
  await this.client.connect();
25
25
  await this.clientRecovery.connect();
26
- }).pipe(retry_1.default(10, 5000)).toPromise();
26
+ })
27
+ .pipe(retry_1.default(10, 5000))
28
+ .toPromise();
27
29
  this.logger.log('RMQ Connected');
28
30
  }
29
31
  /**
@@ -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,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"}
@@ -0,0 +1 @@
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"}
@@ -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"}