@pixelplex/mail-service 0.1.22 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/.gitlab-ci.yml +1 -25
  2. package/LICENSE.md +1 -1
  3. package/README.md +83 -137
  4. package/audit-ci.json +4 -0
  5. package/commitlint.config.js +27 -0
  6. package/dist/constants/index.d.ts +1 -0
  7. package/dist/constants/index.js +18 -0
  8. package/dist/constants/index.js.map +1 -0
  9. package/dist/constants/mail.constants.d.ts +11 -0
  10. package/dist/constants/mail.constants.js +17 -0
  11. package/dist/constants/mail.constants.js.map +1 -0
  12. package/dist/decorators/index.d.ts +2 -0
  13. package/dist/decorators/index.js +19 -0
  14. package/dist/decorators/index.js.map +1 -0
  15. package/dist/decorators/inject-gateways.decorator.d.ts +2 -0
  16. package/dist/decorators/inject-gateways.decorator.js +10 -0
  17. package/dist/decorators/inject-gateways.decorator.js.map +1 -0
  18. package/dist/decorators/inject-options.decorator.d.ts +3 -0
  19. package/dist/decorators/inject-options.decorator.js +14 -0
  20. package/dist/decorators/inject-options.decorator.js.map +1 -0
  21. package/dist/factories/gateway.factory.d.ts +4 -0
  22. package/dist/factories/gateway.factory.js +18 -0
  23. package/dist/factories/gateway.factory.js.map +1 -0
  24. package/dist/factories/index.d.ts +1 -0
  25. package/dist/factories/index.js +18 -0
  26. package/dist/factories/index.js.map +1 -0
  27. package/dist/gateways/console.gateway.d.ts +6 -0
  28. package/dist/{connect/app.module.js → gateways/console.gateway.js} +13 -17
  29. package/dist/gateways/console.gateway.js.map +1 -0
  30. package/dist/gateways/index.d.ts +4 -0
  31. package/dist/gateways/index.js +21 -0
  32. package/dist/gateways/index.js.map +1 -0
  33. package/dist/gateways/sendgrid.gateway.d.ts +8 -0
  34. package/dist/gateways/sendgrid.gateway.js +45 -0
  35. package/dist/gateways/sendgrid.gateway.js.map +1 -0
  36. package/dist/gateways/slack.gateway.d.ts +8 -0
  37. package/dist/gateways/slack.gateway.js +40 -0
  38. package/dist/gateways/slack.gateway.js.map +1 -0
  39. package/dist/gateways/smtp.gateway.d.ts +9 -0
  40. package/dist/gateways/smtp.gateway.js +43 -0
  41. package/dist/gateways/smtp.gateway.js.map +1 -0
  42. package/dist/index.d.ts +7 -4
  43. package/dist/index.js +21 -7
  44. package/dist/index.js.map +1 -1
  45. package/dist/interfaces/gateway.interface.d.ts +4 -0
  46. package/dist/interfaces/gateway.interface.js +3 -0
  47. package/dist/interfaces/gateway.interface.js.map +1 -0
  48. package/dist/interfaces/index.d.ts +1 -0
  49. package/dist/interfaces/index.js +18 -0
  50. package/dist/interfaces/index.js.map +1 -0
  51. package/dist/mail.module.d.ts +5 -0
  52. package/dist/mail.module.js +68 -0
  53. package/dist/mail.module.js.map +1 -0
  54. package/dist/services/index.d.ts +1 -0
  55. package/dist/services/index.js +18 -0
  56. package/dist/services/index.js.map +1 -0
  57. package/dist/services/mail-sender.service.d.ts +11 -0
  58. package/dist/services/mail-sender.service.js +91 -0
  59. package/dist/services/mail-sender.service.js.map +1 -0
  60. package/dist/tsconfig.build.tsbuildinfo +1 -8211
  61. package/dist/types/decorators.types.d.ts +2 -0
  62. package/dist/types/decorators.types.js +3 -0
  63. package/dist/types/decorators.types.js.map +1 -0
  64. package/dist/types/gateway.class.d.ts +4 -0
  65. package/dist/types/gateway.class.js +3 -0
  66. package/dist/types/gateway.class.js.map +1 -0
  67. package/dist/types/index.d.ts +7 -0
  68. package/dist/types/index.js +24 -0
  69. package/dist/types/index.js.map +1 -0
  70. package/dist/types/options.types.d.ts +16 -0
  71. package/dist/types/options.types.js +3 -0
  72. package/dist/types/options.types.js.map +1 -0
  73. package/dist/types/sendgrid-options.types.d.ts +4 -0
  74. package/dist/types/sendgrid-options.types.js +3 -0
  75. package/dist/types/sendgrid-options.types.js.map +1 -0
  76. package/dist/types/slack-options.types.d.ts +3 -0
  77. package/dist/types/slack-options.types.js +3 -0
  78. package/dist/types/slack-options.types.js.map +1 -0
  79. package/dist/types/smtp-options.types.d.ts +7 -0
  80. package/dist/types/smtp-options.types.js +3 -0
  81. package/dist/types/smtp-options.types.js.map +1 -0
  82. package/dist/types/templates.types.d.ts +12 -0
  83. package/dist/types/templates.types.js +3 -0
  84. package/dist/types/templates.types.js.map +1 -0
  85. package/dist/utils/connection.utils.d.ts +4 -0
  86. package/dist/utils/connection.utils.js +17 -0
  87. package/dist/utils/connection.utils.js.map +1 -0
  88. package/dist/utils/index.d.ts +3 -0
  89. package/dist/utils/index.js +20 -0
  90. package/dist/utils/index.js.map +1 -0
  91. package/dist/utils/object.utils.d.ts +1 -0
  92. package/dist/utils/object.utils.js +8 -0
  93. package/dist/utils/object.utils.js.map +1 -0
  94. package/dist/utils/types.utils.d.ts +1 -0
  95. package/dist/utils/types.utils.js +3 -0
  96. package/dist/utils/types.utils.js.map +1 -0
  97. package/package.json +51 -45
  98. package/tsconfig.json +4 -1
  99. package/.dockerignore +0 -5
  100. package/.husky/pre-commit +0 -9
  101. package/dist/connect/app.module.d.ts +0 -4
  102. package/dist/connect/app.module.js.map +0 -1
  103. package/dist/connect/retry.d.ts +0 -2
  104. package/dist/connect/retry.js +0 -13
  105. package/dist/connect/retry.js.map +0 -1
  106. package/dist/main.d.ts +0 -1
  107. package/dist/main.js +0 -24
  108. package/dist/main.js.map +0 -1
  109. package/dist/service/app.module.d.ts +0 -4
  110. package/dist/service/app.module.js +0 -29
  111. package/dist/service/app.module.js.map +0 -1
  112. package/dist/service/sender.service.d.ts +0 -7
  113. package/dist/service/sender.service.js +0 -63
  114. package/dist/service/sender.service.js.map +0 -1
  115. package/dist/transports/rmq/app.controller.d.ts +0 -9
  116. package/dist/transports/rmq/app.controller.js +0 -59
  117. package/dist/transports/rmq/app.controller.js.map +0 -1
  118. package/dist/transports/rmq/app.service.d.ts +0 -20
  119. package/dist/transports/rmq/app.service.js +0 -61
  120. package/dist/transports/rmq/app.service.js.map +0 -1
  121. package/dist/transports/rmq/connection.d.ts +0 -3
  122. package/dist/transports/rmq/connection.js +0 -33
  123. package/dist/transports/rmq/connection.js.map +0 -1
  124. package/dist/transports/tcp/app.controller.d.ts +0 -8
  125. package/dist/transports/tcp/app.controller.js +0 -54
  126. package/dist/transports/tcp/app.controller.js.map +0 -1
  127. package/dist/transports/tcp/app.service.d.ts +0 -19
  128. package/dist/transports/tcp/app.service.js +0 -56
  129. package/dist/transports/tcp/app.service.js.map +0 -1
  130. package/dist/transports/tcp/connection.d.ts +0 -8
  131. package/dist/transports/tcp/connection.js +0 -13
  132. package/dist/transports/tcp/connection.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,113 +1,79 @@
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 or TCP - other NestJS services send messages to RabbitMQ or connects by TCP protocol.
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
9
+ 1. create template for html, plain text and subject
10
+ 2. add `@pixelplex/mail-service` to your application
11
+ 3. Call `MailModule.forRoot` from `@pixelplex/mail-service`
12
+ with specified gateways and options
13
+ 4. send a message by calling `this.mailSenderService.sendEmail('test@gmail.com', { htmlPath: htmlTemplatePath, plainPath: plainTextTemplatePath, subjectPath: subjectTemplatePath }, {year: 20});` where `mailSenderService` is `MailSenderService`
11
14
 
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 `MailRMQService` or `MailTCPService` from `@pixelplex/mail-service`
20
- 9. ...
21
- 10. PROFIT
15
+ Currently supported gateways:
22
16
 
23
- Didn't understand anything? Okay, let's see more details
24
-
25
- ### Local development
26
-
27
- To use the package locally, pass the follow config:
17
+ - slack
18
+ - console
19
+ - smtp
20
+ - sendgrid
28
21
 
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
- ```
22
+ Didn't understand anything? Okay, let's see more details
36
23
 
37
24
  ### Prepare templates
38
25
 
39
26
  The service uses Handlebars as template engine. So all your email templates should be prepared as handlebars templates.
40
27
 
41
- For sending message your templates folder should include at least 3 files:
28
+ For sending message your templates folder should include this files:
42
29
 
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
30
+ - `{name}.handlebars` - body of your email where `{name}` is just your template name for email. For example `welcome.handlebars` for the welcome use email
31
+ - `{name}.subject.handlebars` - subject (title) of your email. You can use subject field to specify subject directly. It will override subjectPath
32
+ - `{name}.plain.handlebars` - subject (title) of your email. You can use plain field to specify plain directly. It will override plainPath
46
33
 
47
- For example our project will store files in `templates` folder.
48
-
49
- ```
50
- ├── docker-compose.yml
51
- ├── templates
52
- │ ├── main.handlebars
53
- │ ├── welcome.subject.handlebars
54
- │ ├── welcome.handlebars
34
+ ```handlebars
35
+ # welcome.subject.handlebars Welcome, {{name}}! This is subject
55
36
  ```
56
37
 
57
38
  ```handlebars
58
- # main.handlebars
39
+ # welcome.handlebars
59
40
 
60
41
  <html>
61
42
  <head></head>
62
- <body>{{{body}}}</body>
43
+ <body>
44
+ <p>Welcome, {{name}}!</p>
45
+ <p>How are you?</p>
46
+ </body>
63
47
  </html>
64
48
  ```
65
49
 
66
50
  ```handlebars
67
- # welcome.subject.handlebars Welcome, {{name}}!
68
- ```
51
+ # welcome.plain.handlebars
69
52
 
70
- ```handlebars
71
- # welcome.handlebars
72
-
73
- <p>Welcome, {{name}}!</p>
74
- <p>How are you?</p>
53
+ <html>
54
+ <head></head>
55
+ <body>
56
+ <p>Welcome, {{name}}!</p>
57
+ <p>How are you?</p>
58
+ </body>
59
+ </html>
75
60
  ```
76
61
 
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_TCP_PORT=3000
96
- - MAIL_SERVICE_TCP_HOST=localhost
97
- - MAIL_SERVICE_SMTP_HOST=smtp.gmail.com
98
- - MAIL_SERVICE_SMTP_PORT=587
99
- - MAIL_SERVICE_SMTP_SENDER=postmail@pixelplex.io
100
- - MAIL_SERVICE_SMTP_USERNAME=postmail@pixelplex.io
101
- - MAIL_SERVICE_SMTP_PASSWORD=$MAIL_SERVICE_SMTP_PASSWORD
102
- - MAIL_SERVICE_SENTRY_DNS=$MAIL_SERVICE_SENTRY_DNS
103
- volumes:
104
- - ./templates:/app/templates # note that we attach our template folder as /app/templates
105
- ```
62
+ ## Configuration
106
63
 
107
- ### Trigger new message sending
64
+ | Name | Description | Example |
65
+ | --------------- | -------------------------------------------------------- | ------------------------- |
66
+ | gateways | Array of gateways to send email | `['slack']` |
67
+ | customGateways | Array of custom gateways classes | `[CustomGateway]` |
68
+ | smtp.host | Mail gateway host address | `smtp.gmail.com` |
69
+ | smtp.port | Mail gateway port number | `586` |
70
+ | smtp.username | Mail gateway username | `username` |
71
+ | smtp.password | Mail gateway password | `qh05780c2qcm034579` |
72
+ | \*.sender | Mail sender address | `postmail@pixelplex.io` |
73
+ | slack.url | Hook URL in case you want to duplicate messages to Slack | `https://hooks.slack.com` |
74
+ | sendgrid.apiKey | Sendgrid api key | `oiqur9823uiofhaoafoe` |
108
75
 
109
- Now you can return to your microservice (`api` module for example) and try to send new mail through Mail Service.
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.
76
+ ### Trigger new message sending
111
77
 
112
78
  **1. Install npm package**
113
79
 
@@ -115,55 +81,7 @@ For it you should send a message to RMQ or use TCP connection. But to simplify i
115
81
  yarn add @pixelplex/mail-service
116
82
  ```
117
83
 
118
- **2. Configure you application** (we should use `config` package for the configuration). You config file should include next part:
119
-
120
- For RMQ microservices connection:
121
-
122
- ```json
123
- {
124
- ...
125
- "MAIL_SERVICE": {
126
- "RMQ": {
127
- "URL": "amqp://localhost:5672",
128
- "QUEUE": "test_queue",
129
- "MESSAGE_TTL": 5000
130
- },
131
- "TRANSPORT": "rmq"
132
- },
133
- ...
134
- }
135
- ```
136
-
137
- Where:
138
-
139
- - `URL` - url to rabbit mq that will used for mail service
140
- - `QUEUE` - queue that will used in mail service to
141
- - `MESSAGE_TTL` - time after which the message, which was processed with an error, must return back in the queue and be processed again
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
-
164
- **! Be sure, that the configuration of the queue the same as in the mail service**
165
-
166
- **3. Import MailModule** in your module you'll send mail from:
84
+ **2. Import MailModule** in your module you'll send mail from:
167
85
 
168
86
  ```typescript
169
87
  import { Module } from '@nestjs/common';
@@ -172,31 +90,59 @@ import { AppService } from './app.service';
172
90
 
173
91
  @Module({
174
92
  controllers: [],
175
- imports: [MailModule.forRoot()],
93
+ imports: [
94
+ MailModule.forRoot({
95
+ gateways: ['slack', 'smtp', 'console'],
96
+ slack: { url: 'hooks.slack.com' },
97
+ smtp: {
98
+ username: 'postmail@pixelplex.io',
99
+ sender: 'postmail@pixelplex.io',
100
+ host: 'smtp.ethereal.com',
101
+ port: 678,
102
+ password: 'password',
103
+ },
104
+ }),
105
+ ],
176
106
  providers: [AppService],
177
107
  })
178
108
  export class AppModule {}
179
109
  ```
180
110
 
181
- **4. Call sendMail** to send your mail:
111
+ **3. Call sendEmail** to send your mail:
182
112
 
183
113
  ```typescript
184
114
  import { Injectable } from '@nestjs/common';
185
- import { MailTCPService, MailRMQService } from '@pixelplex/mail-service';
115
+ import { MailSenderService } from '@pixelplex/mail-service';
186
116
 
187
117
  @Injectable()
188
118
  export class AppService {
189
- constructor(private mailService: (MailRMQService or MailTCPService)) {}
119
+ constructor(private mailSenderService: MailSenderService) {}
190
120
 
191
121
  async onModuleInit() {
192
- this.mailService.sendMail('test@gmail.com', 'welcome', { name: 'Афанасий' }, 20);
122
+ this.mailSenderService.sendEmail(
123
+ 'test@gmail.com',
124
+ // additionaly you can use plain: plainText, subject: subjectText to specify plain or subject directly
125
+ // if so, plainPath or subjectPath will be ignored
126
+ { htmlPath: htmlTemplatePath, plainPath: plainTextTemplatePath, subjectPath: subjectTemplatePath },
127
+ { year: 20 },
128
+ );
193
129
  }
194
130
  }
195
131
  ```
196
132
 
197
- In the example below we'll send email to `test@gmail.com` with type `welcome` (`welcome.handlebars` and `welcome.subject.handlebars` will used).
133
+ `{year: 20}` is the object with data which will used as payload data during processing your handlebars template.
134
+
135
+ ### Custom gateways
198
136
 
199
- `{name: 'Афанасий'}` is the object with data which will used as payload data during processing your handlebars template.
137
+ To add custom gateways, provide class, that extends IGateway to customGateways options
138
+
139
+ ```typescript
140
+ @Injectable()
141
+ class CustomGateway implements IGateway {
142
+ async send(to: string, content: Content): Promise<void> {
143
+ console.log('this is custom gateway');
144
+ }
145
+ }
200
146
 
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.
202
- If you think your message should live until it is successfully sent use `0`.
147
+ MailModule.forRoot({ customGateways: [CustomGateway] });
148
+ ```
package/audit-ci.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "high": true,
3
+ "allowlist": ["dicer"]
4
+ }
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ rules: {
4
+ 'body-leading-blank': [2, 'always'],
5
+ 'footer-leading-blank': [2, 'always'],
6
+ 'jira-issue-in-scope': [2, 'always'],
7
+ },
8
+ plugins: [
9
+ {
10
+ rules: {
11
+ 'jira-issue-in-scope': ({ scope }) => {
12
+ return [
13
+ scope && scope.match(/\b([A-Z]{1,10}-\d+(, ?[A-Z]{1,10}-\d+)*|HOTFIX|VERSION)\b/),
14
+ 'scope should contain a JIRA issue number. Something like this - "KEY-20", "KEY-20, KEY-21", "HOTFIX" or "VERSION"',
15
+ ];
16
+ },
17
+ },
18
+ },
19
+ ],
20
+ prompt: {
21
+ questions: {
22
+ scope: {
23
+ description: 'What is the scope of this change (JIRA issue number like KEY-20)',
24
+ },
25
+ },
26
+ },
27
+ };
@@ -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,11 @@
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
+ SENDGRID = "sendgrid"
11
+ }
@@ -0,0 +1,17 @@
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["SENDGRID"] = "sendgrid";
16
+ })(GATEWAY || (exports.GATEWAY = GATEWAY = {}));
17
+ //# 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,OAKX;AALD,WAAY,OAAO;IACjB,wBAAa,CAAA;IACb,0BAAe,CAAA;IACf,8BAAmB,CAAA;IACnB,gCAAqB,CAAA;AACvB,CAAC,EALW,OAAO,uBAAP,OAAO,QAKlB"}
@@ -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,18 @@
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
+ [constants_1.GATEWAY.SENDGRID]: gateways_1.SendgridGateway,
13
+ };
14
+ return gateways[gateway];
15
+ }
16
+ }
17
+ exports.GatewayFactory = GatewayFactory;
18
+ //# 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,0CAAyF;AAGzF,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;YAC3B,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE,0BAAe;SACpC,CAAC;QAEF,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF;AAXD,wCAWC"}
@@ -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
+ }
@@ -5,24 +5,20 @@ 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;
9
8
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.MailModule = void 0;
9
+ exports.ConsoleGateway = void 0;
11
10
  const common_1 = require("@nestjs/common");
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
- };
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();
22
19
  }
23
20
  };
24
- MailModule = MailModule_1 = __decorate([
25
- common_1.Module({})
26
- ], MailModule);
27
- exports.MailModule = MailModule;
28
- //# 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,4 @@
1
+ export * from './console.gateway';
2
+ export * from './sendgrid.gateway';
3
+ export * from './slack.gateway';
4
+ export * from './smtp.gateway';
@@ -0,0 +1,21 @@
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("./sendgrid.gateway"), exports);
19
+ __exportStar(require("./slack.gateway"), exports);
20
+ __exportStar(require("./smtp.gateway"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gateways/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,qDAAmC;AACnC,kDAAgC;AAChC,iDAA+B"}
@@ -0,0 +1,8 @@
1
+ import { IGateway } from '../interfaces';
2
+ import { Content, SendgridOptions } from '../types';
3
+ export declare class SendgridGateway implements IGateway {
4
+ private readonly sendgridOptions;
5
+ private readonly logger;
6
+ constructor(sendgridOptions: SendgridOptions);
7
+ send(to: string, content: Content): Promise<void>;
8
+ }