@pixelplex/mail-service 0.1.21 → 0.2.0

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 (111) hide show
  1. package/.gitlab-ci.yml +1 -25
  2. package/LICENSE.md +1 -1
  3. package/README.md +76 -111
  4. package/dist/constants/index.d.ts +1 -0
  5. package/dist/constants/index.js +18 -0
  6. package/dist/constants/index.js.map +1 -0
  7. package/dist/constants/mail.constants.d.ts +10 -0
  8. package/dist/constants/mail.constants.js +16 -0
  9. package/dist/constants/mail.constants.js.map +1 -0
  10. package/dist/decorators/index.d.ts +2 -0
  11. package/dist/decorators/index.js +19 -0
  12. package/dist/decorators/index.js.map +1 -0
  13. package/dist/decorators/inject-gateways.decorator.d.ts +2 -0
  14. package/dist/decorators/inject-gateways.decorator.js +10 -0
  15. package/dist/decorators/inject-gateways.decorator.js.map +1 -0
  16. package/dist/decorators/inject-options.decorator.d.ts +3 -0
  17. package/dist/decorators/inject-options.decorator.js +14 -0
  18. package/dist/decorators/inject-options.decorator.js.map +1 -0
  19. package/dist/factories/gateway.factory.d.ts +4 -0
  20. package/dist/factories/gateway.factory.js +17 -0
  21. package/dist/factories/gateway.factory.js.map +1 -0
  22. package/dist/factories/index.d.ts +1 -0
  23. package/dist/factories/index.js +18 -0
  24. package/dist/factories/index.js.map +1 -0
  25. package/dist/gateways/console.gateway.d.ts +6 -0
  26. package/dist/{connect/app.module.js → gateways/console.gateway.js} +14 -13
  27. package/dist/gateways/console.gateway.js.map +1 -0
  28. package/dist/gateways/index.d.ts +3 -0
  29. package/dist/gateways/index.js +20 -0
  30. package/dist/gateways/index.js.map +1 -0
  31. package/dist/gateways/slack.gateway.d.ts +8 -0
  32. package/dist/gateways/slack.gateway.js +40 -0
  33. package/dist/gateways/slack.gateway.js.map +1 -0
  34. package/dist/gateways/smtp.gateway.d.ts +9 -0
  35. package/dist/gateways/smtp.gateway.js +43 -0
  36. package/dist/gateways/smtp.gateway.js.map +1 -0
  37. package/dist/index.d.ts +7 -3
  38. package/dist/index.js +21 -5
  39. package/dist/index.js.map +1 -1
  40. package/dist/interfaces/gateway.interface.d.ts +4 -0
  41. package/dist/interfaces/gateway.interface.js +3 -0
  42. package/dist/interfaces/gateway.interface.js.map +1 -0
  43. package/dist/interfaces/index.d.ts +1 -0
  44. package/dist/interfaces/index.js +18 -0
  45. package/dist/interfaces/index.js.map +1 -0
  46. package/dist/mail.module.d.ts +5 -0
  47. package/dist/mail.module.js +68 -0
  48. package/dist/mail.module.js.map +1 -0
  49. package/dist/services/index.d.ts +1 -0
  50. package/dist/services/index.js +18 -0
  51. package/dist/services/index.js.map +1 -0
  52. package/dist/services/mail-sender.service.d.ts +11 -0
  53. package/dist/services/mail-sender.service.js +84 -0
  54. package/dist/services/mail-sender.service.js.map +1 -0
  55. package/dist/tsconfig.build.tsbuildinfo +1 -8158
  56. package/dist/types/decorators.types.d.ts +2 -0
  57. package/dist/types/decorators.types.js +3 -0
  58. package/dist/types/decorators.types.js.map +1 -0
  59. package/dist/types/gateway.class.d.ts +4 -0
  60. package/dist/types/gateway.class.js +3 -0
  61. package/dist/types/gateway.class.js.map +1 -0
  62. package/dist/types/index.d.ts +6 -0
  63. package/dist/types/index.js +23 -0
  64. package/dist/types/index.js.map +1 -0
  65. package/dist/types/options.types.d.ts +13 -0
  66. package/dist/types/options.types.js +3 -0
  67. package/dist/types/options.types.js.map +1 -0
  68. package/dist/types/slack-options.types.d.ts +3 -0
  69. package/dist/types/slack-options.types.js +3 -0
  70. package/dist/types/slack-options.types.js.map +1 -0
  71. package/dist/types/smtp-options.types.d.ts +7 -0
  72. package/dist/types/smtp-options.types.js +3 -0
  73. package/dist/types/smtp-options.types.js.map +1 -0
  74. package/dist/types/templates.types.d.ts +10 -0
  75. package/dist/types/templates.types.js +3 -0
  76. package/dist/types/templates.types.js.map +1 -0
  77. package/dist/utils/connection.utils.d.ts +4 -0
  78. package/dist/utils/connection.utils.js +17 -0
  79. package/dist/utils/connection.utils.js.map +1 -0
  80. package/dist/utils/index.d.ts +2 -0
  81. package/dist/utils/index.js +19 -0
  82. package/dist/utils/index.js.map +1 -0
  83. package/dist/utils/types.utils.d.ts +1 -0
  84. package/dist/utils/types.utils.js +3 -0
  85. package/dist/utils/types.utils.js.map +1 -0
  86. package/package.json +29 -38
  87. package/tsconfig.json +4 -1
  88. package/.dockerignore +0 -5
  89. package/dist/connect/app.module.d.ts +0 -2
  90. package/dist/connect/app.module.js.map +0 -1
  91. package/dist/connect/app.service.d.ts +0 -20
  92. package/dist/connect/app.service.js +0 -61
  93. package/dist/connect/app.service.js.map +0 -1
  94. package/dist/connect/retry.d.ts +0 -2
  95. package/dist/connect/retry.js +0 -13
  96. package/dist/connect/retry.js.map +0 -1
  97. package/dist/connection.d.ts +0 -3
  98. package/dist/connection.js +0 -33
  99. package/dist/connection.js.map +0 -1
  100. package/dist/main.d.ts +0 -1
  101. package/dist/main.js +0 -23
  102. package/dist/main.js.map +0 -1
  103. package/dist/service/app.controller.d.ts +0 -9
  104. package/dist/service/app.controller.js +0 -59
  105. package/dist/service/app.controller.js.map +0 -1
  106. package/dist/service/app.module.d.ts +0 -2
  107. package/dist/service/app.module.js +0 -23
  108. package/dist/service/app.module.js.map +0 -1
  109. package/dist/service/sender.service.d.ts +0 -7
  110. package/dist/service/sender.service.js +0 -63
  111. package/dist/service/sender.service.js.map +0 -1
package/.gitlab-ci.yml CHANGED
@@ -1,32 +1,8 @@
1
1
  stages:
2
- - 🚦 test
3
2
  - 📦 package
4
- - 🚀 deploy
5
3
 
6
-
7
-
8
- ##############################
9
- # 📦 PACKAGE 📦 #
10
- ##############################
11
-
12
- 📦 image:
13
- stage: 📦 package
14
- tags:
15
- - pp-builder
16
- script:
17
- - docker login -u $DOCKERHUB_USER -p $DOCKERHUB_PASSWORD
18
- - docker pull pixelplex/mail-service:latest || true
19
- - docker build -t pixelplex/mail-service:$CI_COMMIT_REF_NAME
20
- -t pixelplex/mail-service:latest .
21
- - docker push pixelplex/mail-service:$CI_COMMIT_REF_NAME
22
- - docker push pixelplex/mail-service:latest
23
- - docker logout
24
- only:
25
- - tags
26
-
27
-
28
-
29
4
  📦 package:
5
+ image: node:18.16.0-alpine3.17
30
6
  stage: 📦 package
31
7
  tags:
32
8
  - docker
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Pixelplex LLC
3
+ Copyright (c) 2023 Pixelplex LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
package/README.md CHANGED
@@ -1,111 +1,73 @@
1
1
  # Mail Service
2
2
 
3
- Microservice for fast implementation of the functionality of sending email messages.
3
+ Library 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`.
6
- The service receive messages and sends them via email.
5
+ The sends messages them via email.
7
6
 
8
7
  ## How to use
9
8
 
10
- TL;DR
11
-
12
- 1. create `templates` folder
13
- 2. create template wrapper `templates/main.handlebars`
14
- 3. create template for mail `templates/welcome.subject.handlebars` and `templates/welcome.handlebars`
15
- 4. add mail service into your docker compose as below
16
- 5. add `MAIL_SERVICE` config in `config/default.json`
17
- 6. add `@pixelplex/mail-service` to your application
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`
20
- 9. ...
21
- 10. PROFIT
9
+ 1. create template for html, plain text and subject
10
+ 2. add `@pixelplex/mail-service` to your application
11
+ 3. Call `MailModule.register()` from `@pixelplex/mail-service`
12
+ with specified gateways (supported: smtp, console, slack) and option
13
+ 4. send a message by calling `this.mailSenderService.sendEmail('test@gmail.com', { html: htmlTemplatePath, plain: plainTextTemplatePath, subject: subjectTemplatePath }, {year: 20});` where `mailSenderService` is `MailSenderService`
22
14
 
23
15
  Didn't understand anything? Okay, let's see more details
24
16
 
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
-
37
17
  ### Prepare templates
38
18
 
39
19
  The service uses Handlebars as template engine. So all your email templates should be prepared as handlebars templates.
40
20
 
41
- For sending message your templates folder should include at least 3 files:
21
+ For sending message your templates folder should include this files:
42
22
 
43
- - `main.handlebars` - the wrapper of all emails. `<Html>`, `<head>`, `<body>` - all should be here
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
45
- - `{type}.subject.handlebars` - subject (title) of yur email
23
+ - `{name}.handlebars` - body of your email where `{name}` is just your template name for email. For example `welcome.handlebars` for the welcome use email
24
+ - `{name}.subject.handlebars` - subject (title) of your email
25
+ - `{name}.plain.handlebars` - subject (title) of your email
46
26
 
47
- For example our project will store files in `templates` folder.
27
+ Use provided naming convention
48
28
 
49
- ```
50
- ├── docker-compose.yml
51
- ├── templates
52
- │ ├── main.handlebars
53
- │ ├── welcome.subject.handlebars
54
- │ ├── welcome.handlebars
29
+ ```handlebars
30
+ # welcome.subject.handlebars Welcome, {{name}}! This is subject
55
31
  ```
56
32
 
57
33
  ```handlebars
58
- # main.handlebars
34
+ # welcome.handlebars
59
35
 
60
36
  <html>
61
37
  <head></head>
62
- <body>{{{body}}}</body>
38
+ <body>
39
+ <p>Welcome, {{name}}!</p>
40
+ <p>How are you?</p>
41
+ </body>
63
42
  </html>
64
43
  ```
65
44
 
66
45
  ```handlebars
67
- # welcome.subject.handlebars Welcome, {{name}}!
68
- ```
69
-
70
- ```handlebars
71
- # welcome.handlebars
46
+ # welcome.plain.handlebars
72
47
 
73
- <p>Welcome, {{name}}!</p>
74
- <p>How are you?</p>
48
+ <html>
49
+ <head></head>
50
+ <body>
51
+ <p>Welcome, {{name}}!</p>
52
+ <p>How are you?</p>
53
+ </body>
54
+ </html>
75
55
  ```
76
56
 
77
- ### Launch the service
78
-
79
- Then you need to run this service and connect it to RMQ. For example, you can use Docker Compose:
80
-
81
- ```yaml
82
- version: '3'
83
- services:
84
- rabbitmq:
85
- image: 'rabbitmq:3-management'
86
- ports:
87
- - '127.0.0.1:5672:5672'
88
- - '127.0.0.1:15672:15672'
89
-
90
- mail-service:
91
- image: 'pixelplex/mail-service:0.1.18'
92
- environment:
93
- - MAIL_SERVICE_RMQ_URL=amqp://rabbitmq:5672
94
- - MAIL_SERVICE_RMQ_QUEUE=test_queue
95
- - MAIL_SERVICE_SMTP_HOST=smtp.gmail.com
96
- - MAIL_SERVICE_SMTP_PORT=587
97
- - MAIL_SERVICE_SMTP_SENDER=postmail@pixelplex.io
98
- - MAIL_SERVICE_SMTP_USERNAME=postmail@pixelplex.io
99
- - MAIL_SERVICE_SMTP_PASSWORD=$MAIL_SERVICE_SMTP_PASSWORD
100
- - MAIL_SERVICE_SENTRY_DNS=$MAIL_SERVICE_SENTRY_DNS
101
- volumes:
102
- - ./templates:/app/templates # note that we attach our template folder as /app/templates
103
- ```
57
+ ## Configuration
104
58
 
105
- ### Trigger new message sending
59
+ | Name | Description | Example |
60
+ | -------------- | ---------------------------------------------------------------- | ------------------------- |
61
+ | gateways | Array of gateways to send email, supported: smpt, slack, console | `['slack']` |
62
+ | customGateways | Array of custom gateways classes | `[CustomGateway]` |
63
+ | smtp.host | Mail gateway host address | `smtp.gmail.com` |
64
+ | smtp.port | Mail gateway port number | `586` |
65
+ | smtp.username | Mail gateway username | `username` |
66
+ | smtp.password | Mail gateway password | `qh05780c2qcm034579` |
67
+ | smtp.sender | Mail sender address | `postmail@pixelplex.io` |
68
+ | slack.url | Hook URL in case you want to duplicate messages to Slack | `https://hooks.slack.com` |
106
69
 
107
- 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.
70
+ ### Trigger new message sending
109
71
 
110
72
  **1. Install npm package**
111
73
 
@@ -113,31 +75,7 @@ For it you should send a message to RMQ. But to simplify it you should use [@pix
113
75
  yarn add @pixelplex/mail-service
114
76
  ```
115
77
 
116
- **2. Configure you application** (we should use `config` package for the configuration). You config file should include next part:
117
-
118
- ```json
119
- {
120
- ...
121
- "MAIL_SERVICE": {
122
- "RMQ": {
123
- "URL": "amqp://localhost:5672",
124
- "QUEUE": "test_queue",
125
- "MESSAGE_TTL": 5000
126
- }
127
- },
128
- ...
129
- }
130
- ```
131
-
132
- Where:
133
-
134
- - `URL` - url to rabbit mq that will used for mail service
135
- - `QUEUE` - queue that will used in mail service to
136
- - `MESSAGE_TTL` - time after which the message, which was processed with an error, must return back in the queue and be processed again
137
-
138
- **! Be sure, that the configuration of the queue the same as in the mail service**
139
-
140
- **3. Import MailModule** in your module you'll send mail from:
78
+ **2. Import MailModule** in your module you'll send mail from:
141
79
 
142
80
  ```typescript
143
81
  import { Module } from '@nestjs/common';
@@ -146,31 +84,58 @@ import { AppService } from './app.service';
146
84
 
147
85
  @Module({
148
86
  controllers: [],
149
- imports: [MailModule],
87
+ imports: [
88
+ MailModule.forRoot({
89
+ gateways: ['slack', 'smtp', 'console'],
90
+ slack: { url: 'hooks.slack.com' },
91
+ smtp: {
92
+ username: 'postmail@pixelplex.io',
93
+ sender: 'postmail@pixelplex.io',
94
+ host: 'smtp.ethereal.com',
95
+ port: 678,
96
+ password: 'password',
97
+ },
98
+ }),
99
+ ],
150
100
  providers: [AppService],
151
101
  })
152
102
  export class AppModule {}
153
103
  ```
154
104
 
155
- **4. Call sendMail** to send your mail:
105
+ **3. Call sendEmail** to send your mail:
156
106
 
157
107
  ```typescript
158
108
  import { Injectable } from '@nestjs/common';
159
- import { MailService } from '@pixelplex/mail-service';
109
+ import { MailTCPService, MailRMQService } from '@pixelplex/mail-service';
110
+ import { MailSenderService } from './mail-sender.service';
160
111
 
161
112
  @Injectable()
162
113
  export class AppService {
163
- constructor(private mailService: MailService) {}
114
+ constructor(private mailSenderService: MailSenderService) {}
164
115
 
165
116
  async onModuleInit() {
166
- this.mailService.sendMail('test@gmail.com', 'welcome', { name: 'Афанасий' }, 20);
117
+ this.mailSenderService.sendEmail(
118
+ 'test@gmail.com',
119
+ { html: htmlTemplatePath, plain: plainTextTemplatePath, subject: subjectTemplatePath },
120
+ { year: 20 },
121
+ );
167
122
  }
168
123
  }
169
124
  ```
170
125
 
171
- In the example below we'll send email to `test@gmail.com` with type `welcome` (`welcome.handlebars` and `welcome.subject.handlebars` will used).
126
+ `{year: 20}` is the object with data which will used as payload data during processing your handlebars template.
172
127
 
173
- `{name: 'Афанасий'}` is the object with data which will used as payload data during processing your handlebars template.
128
+ ### Custom gateways
174
129
 
175
- 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.
176
- If you think your message should live until it is successfully sent use `0`.
130
+ To add custom gateways, provide class, that extends IGateway to customGateways options
131
+
132
+ ```typescript
133
+ @Injectable()
134
+ class CustomGateway implements IGateway {
135
+ async send(to: string, content: Content): Promise<void> {
136
+ console.log('this is custom gateway');
137
+ }
138
+ }
139
+
140
+ MailModule.forRoot({ customGateways: [CustomGateway] });
141
+ ```
@@ -0,0 +1 @@
1
+ export * from './mail.constants';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./mail.constants"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC"}
@@ -0,0 +1,10 @@
1
+ export declare enum MAIL_MODULE_CONSTANTS {
2
+ DEFAULT_CONNECTION = "default",
3
+ OPTIONS_TOKEN = "mailModuleOptionsToken",
4
+ GATEWAYS_TOKEN = "mailModuleGatewaysToken"
5
+ }
6
+ export declare enum GATEWAY {
7
+ SMTP = "smtp",
8
+ SLACK = "slack",
9
+ CONSOLE = "console"
10
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GATEWAY = exports.MAIL_MODULE_CONSTANTS = void 0;
4
+ var MAIL_MODULE_CONSTANTS;
5
+ (function (MAIL_MODULE_CONSTANTS) {
6
+ MAIL_MODULE_CONSTANTS["DEFAULT_CONNECTION"] = "default";
7
+ MAIL_MODULE_CONSTANTS["OPTIONS_TOKEN"] = "mailModuleOptionsToken";
8
+ MAIL_MODULE_CONSTANTS["GATEWAYS_TOKEN"] = "mailModuleGatewaysToken";
9
+ })(MAIL_MODULE_CONSTANTS || (exports.MAIL_MODULE_CONSTANTS = MAIL_MODULE_CONSTANTS = {}));
10
+ var GATEWAY;
11
+ (function (GATEWAY) {
12
+ GATEWAY["SMTP"] = "smtp";
13
+ GATEWAY["SLACK"] = "slack";
14
+ GATEWAY["CONSOLE"] = "console";
15
+ })(GATEWAY || (exports.GATEWAY = GATEWAY = {}));
16
+ //# sourceMappingURL=mail.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mail.constants.js","sourceRoot":"","sources":["../../src/constants/mail.constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,uDAA8B,CAAA;IAC9B,iEAAwC,CAAA;IACxC,mEAA0C,CAAA;AAC5C,CAAC,EAJW,qBAAqB,qCAArB,qBAAqB,QAIhC;AAED,IAAY,OAIX;AAJD,WAAY,OAAO;IACjB,wBAAa,CAAA;IACb,0BAAe,CAAA;IACf,8BAAmB,CAAA;AACrB,CAAC,EAJW,OAAO,uBAAP,OAAO,QAIlB"}
@@ -0,0 +1,2 @@
1
+ export * from './inject-gateways.decorator';
2
+ export * from './inject-options.decorator';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./inject-gateways.decorator"), exports);
18
+ __exportStar(require("./inject-options.decorator"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,6DAA2C"}
@@ -0,0 +1,2 @@
1
+ import { InjectDecorator } from '../types';
2
+ export declare const InjectGateways: (connection?: string) => InjectDecorator;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InjectGateways = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const utils_1 = require("../utils");
6
+ const InjectGateways = (connection) => {
7
+ return (0, common_1.Inject)((0, utils_1.getGatewaysToken)(connection));
8
+ };
9
+ exports.InjectGateways = InjectGateways;
10
+ //# sourceMappingURL=inject-gateways.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject-gateways.decorator.js","sourceRoot":"","sources":["../../src/decorators/inject-gateways.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAGxC,oCAA4C;AAErC,MAAM,cAAc,GAAG,CAAC,UAAmB,EAAmB,EAAE;IACrE,OAAO,IAAA,eAAM,EAAC,IAAA,wBAAgB,EAAC,UAAU,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB"}
@@ -0,0 +1,3 @@
1
+ import { Gateway, InjectDecorator } from '../types';
2
+ export declare const InjectMailOptions: (connection?: string) => InjectDecorator;
3
+ export declare const InjectGatewayOptions: (gateway: Gateway, connection?: string) => InjectDecorator;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InjectGatewayOptions = exports.InjectMailOptions = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const utils_1 = require("../utils");
6
+ const InjectMailOptions = (connection) => {
7
+ return (0, common_1.Inject)((0, utils_1.getMailOptionsToken)(connection));
8
+ };
9
+ exports.InjectMailOptions = InjectMailOptions;
10
+ const InjectGatewayOptions = (gateway, connection) => {
11
+ return (0, common_1.Inject)((0, utils_1.getGatewayOptionsToken)(gateway, connection));
12
+ };
13
+ exports.InjectGatewayOptions = InjectGatewayOptions;
14
+ //# sourceMappingURL=inject-options.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject-options.decorator.js","sourceRoot":"","sources":["../../src/decorators/inject-options.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAGxC,oCAAuE;AAEhE,MAAM,iBAAiB,GAAG,CAAC,UAAmB,EAAmB,EAAE;IACxE,OAAO,IAAA,eAAM,EAAC,IAAA,2BAAmB,EAAC,UAAU,CAAC,CAAC,CAAC;AACjD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,oBAAoB,GAAG,CAAC,OAAgB,EAAE,UAAmB,EAAmB,EAAE;IAC7F,OAAO,IAAA,eAAM,EAAC,IAAA,8BAAsB,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAC7D,CAAC,CAAC;AAFW,QAAA,oBAAoB,wBAE/B"}
@@ -0,0 +1,4 @@
1
+ import { Gateway, GatewayClass } from '../types';
2
+ export declare class GatewayFactory {
3
+ static getGateway(gateway: Gateway): GatewayClass;
4
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GatewayFactory = void 0;
4
+ const constants_1 = require("../constants");
5
+ const gateways_1 = require("../gateways");
6
+ class GatewayFactory {
7
+ static getGateway(gateway) {
8
+ const gateways = {
9
+ [constants_1.GATEWAY.SLACK]: gateways_1.SlackGateway,
10
+ [constants_1.GATEWAY.CONSOLE]: gateways_1.ConsoleGateway,
11
+ [constants_1.GATEWAY.SMTP]: gateways_1.SmtpGateway,
12
+ };
13
+ return gateways[gateway];
14
+ }
15
+ }
16
+ exports.GatewayFactory = GatewayFactory;
17
+ //# sourceMappingURL=gateway.factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.factory.js","sourceRoot":"","sources":["../../src/factories/gateway.factory.ts"],"names":[],"mappings":";;;AAAA,4CAAuC;AACvC,0CAAwE;AAGxE,MAAa,cAAc;IACzB,MAAM,CAAC,UAAU,CAAC,OAAgB;QAChC,MAAM,QAAQ,GAAG;YACf,CAAC,mBAAO,CAAC,KAAK,CAAC,EAAE,uBAAY;YAC7B,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE,yBAAc;YACjC,CAAC,mBAAO,CAAC,IAAI,CAAC,EAAE,sBAAW;SAC5B,CAAC;QAEF,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF;AAVD,wCAUC"}
@@ -0,0 +1 @@
1
+ export * from './gateway.factory';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./gateway.factory"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/factories/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC"}
@@ -0,0 +1,6 @@
1
+ import { IGateway } from '../interfaces';
2
+ import { Content } from '../types';
3
+ export declare class ConsoleGateway implements IGateway {
4
+ private readonly logger;
5
+ send(to: string, content: Content): Promise<void>;
6
+ }
@@ -6,18 +6,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.MailModule = void 0;
9
+ exports.ConsoleGateway = void 0;
10
10
  const common_1 = require("@nestjs/common");
11
- const app_service_1 = require("./app.service");
12
- let MailModule = class MailModule {
11
+ let ConsoleGateway = exports.ConsoleGateway = class ConsoleGateway {
12
+ constructor() {
13
+ this.logger = new common_1.Logger('Mail::ConsoleGateway');
14
+ }
15
+ async send(to, content) {
16
+ const text = `Message for ${to}: \n${content.plain}`;
17
+ this.logger.debug(text);
18
+ return Promise.resolve();
19
+ }
13
20
  };
14
- MailModule = __decorate([
15
- common_1.Module({
16
- imports: [],
17
- exports: [app_service_1.MailService],
18
- controllers: [],
19
- providers: [app_service_1.MailService],
20
- })
21
- ], MailModule);
22
- exports.MailModule = MailModule;
23
- //# sourceMappingURL=app.module.js.map
21
+ exports.ConsoleGateway = ConsoleGateway = __decorate([
22
+ (0, common_1.Injectable)()
23
+ ], ConsoleGateway);
24
+ //# sourceMappingURL=console.gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.gateway.js","sourceRoot":"","sources":["../../src/gateways/console.gateway.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAoD;AAM7C,IAAM,cAAc,4BAApB,MAAM,cAAc;IAApB;QACY,WAAM,GAAW,IAAI,eAAM,CAAC,sBAAsB,CAAC,CAAC;IAOvE,CAAC;IALC,KAAK,CAAC,IAAI,CAAC,EAAU,EAAE,OAAgB;QACrC,MAAM,IAAI,GAAG,eAAe,EAAE,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;yBARY,cAAc;IAD1B,IAAA,mBAAU,GAAE;GACA,cAAc,CAQ1B"}
@@ -0,0 +1,3 @@
1
+ export * from './console.gateway';
2
+ export * from './slack.gateway';
3
+ export * from './smtp.gateway';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./console.gateway"), exports);
18
+ __exportStar(require("./slack.gateway"), exports);
19
+ __exportStar(require("./smtp.gateway"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gateways/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,kDAAgC;AAChC,iDAA+B"}
@@ -0,0 +1,8 @@
1
+ import { IGateway } from '../interfaces';
2
+ import { Content, SlackOptions } from '../types';
3
+ export declare class SlackGateway implements IGateway {
4
+ private readonly slackOption;
5
+ private readonly logger;
6
+ constructor(slackOption: SlackOptions);
7
+ send(to: string, content: Content): Promise<void>;
8
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.SlackGateway = void 0;
19
+ const common_1 = require("@nestjs/common");
20
+ const axios_1 = __importDefault(require("axios"));
21
+ const constants_1 = require("../constants");
22
+ const decorators_1 = require("../decorators");
23
+ let SlackGateway = exports.SlackGateway = class SlackGateway {
24
+ constructor(slackOption) {
25
+ this.slackOption = slackOption;
26
+ this.logger = new common_1.Logger('Mail::SlackGateway');
27
+ }
28
+ async send(to, content) {
29
+ const text = `Message for ${to}: \n${content.plain}`;
30
+ const slackUrl = new URL(this.slackOption.url, 'https://hooks.slack.com');
31
+ await axios_1.default.post(slackUrl.href, { text });
32
+ this.logger.debug('Slack message sent');
33
+ }
34
+ };
35
+ exports.SlackGateway = SlackGateway = __decorate([
36
+ (0, common_1.Injectable)(),
37
+ __param(0, (0, decorators_1.InjectGatewayOptions)(constants_1.GATEWAY.SLACK)),
38
+ __metadata("design:paramtypes", [Object])
39
+ ], SlackGateway);
40
+ //# sourceMappingURL=slack.gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slack.gateway.js","sourceRoot":"","sources":["../../src/gateways/slack.gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,kDAA0B;AAE1B,4CAAuC;AACvC,8CAAqD;AAK9C,IAAM,YAAY,0BAAlB,MAAM,YAAY;IAGvB,YAAiD,WAA0C;QAAzB,gBAAW,GAAX,WAAW,CAAc;QAF1E,WAAM,GAAW,IAAI,eAAM,CAAC,oBAAoB,CAAC,CAAC;IAE2B,CAAC;IAE/F,KAAK,CAAC,IAAI,CAAC,EAAU,EAAE,OAAgB;QACrC,MAAM,IAAI,GAAG,eAAe,EAAE,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,yBAAyB,CAAC,CAAC;QAC1E,MAAM,eAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC1C,CAAC;CACF,CAAA;uBAXY,YAAY;IADxB,IAAA,mBAAU,GAAE;IAIE,WAAA,IAAA,iCAAoB,EAAC,mBAAO,CAAC,KAAK,CAAC,CAAA;;GAHrC,YAAY,CAWxB"}
@@ -0,0 +1,9 @@
1
+ import { IGateway } from '../interfaces';
2
+ import { Content, SmtpOptions } from '../types';
3
+ export declare class SmtpGateway implements IGateway {
4
+ private readonly smtpOptions;
5
+ private readonly logger;
6
+ private readonly transporter;
7
+ constructor(smtpOptions: SmtpOptions);
8
+ send(to: string, content: Content): Promise<void>;
9
+ }