@things-factory/integration-email 8.0.0-beta.0 → 8.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-email",
3
- "version": "8.0.0-beta.0",
3
+ "version": "8.0.0-beta.2",
4
4
  "main": "dist-server/index.js",
5
5
  "things-factory": true,
6
6
  "author": "heartyoh <heartyoh@hatiolab.com>",
@@ -22,12 +22,12 @@
22
22
  "clean": "npm run clean:server"
23
23
  },
24
24
  "dependencies": {
25
- "@things-factory/integration-base": "^8.0.0-beta.0",
25
+ "@things-factory/integration-base": "^8.0.0-beta.2",
26
26
  "nodemailer": "^6.9.13",
27
27
  "ses": "^1.5.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/nodemailer": "^6.4.14"
31
31
  },
32
- "gitHead": "add6fb8224b2cb19cbea47bed6a5ecb0424c9a28"
32
+ "gitHead": "f03431a09435511b2595515658f9cb8f78ba4ebb"
33
33
  }
@@ -1,88 +0,0 @@
1
- import { Connection, ConnectionManager, Connector } from '@things-factory/integration-base'
2
-
3
- export class EmailConnector implements Connector {
4
- async ready(connectionConfigs) {
5
- await Promise.all(connectionConfigs.map(this.connect.bind(this)))
6
-
7
- ConnectionManager.logger.info('email connections are ready')
8
- }
9
-
10
- checkConnectionInstance(domain, connectionName): boolean {
11
- try {
12
- const connection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)
13
-
14
- return !!(connection?.client?.connectionState !== 'online')
15
- } catch (e) {
16
- return false
17
- }
18
- }
19
-
20
- async connect(connection) {
21
- var {
22
- endpoint,
23
- params: { user, pass }
24
- } = connection
25
-
26
- try {
27
- const parsed = new URL(endpoint)
28
-
29
- const protocol = parsed.protocol.replace(':', '').toLowerCase()
30
- const host = parsed.hostname
31
- const port = parsed.port || protocol == 'smtp' ? 587 : protocol == 'smtps' ? 465 : undefined
32
-
33
- if (protocol !== 'smtp' && protocol !== 'smtps') {
34
- throw 'protocol should be "smtp" or "smtps" in the endpoint'
35
- }
36
-
37
- if (!host) {
38
- throw 'hostname should be provided in the endpoint'
39
- }
40
-
41
- ConnectionManager.addConnectionInstance(connection, {
42
- secure: protocol == 'smtps',
43
- host,
44
- port,
45
- user,
46
- pass,
47
- close: () => {}
48
- })
49
-
50
- ConnectionManager.logger.info(`Email(SMTP) connection(${connection.name}:${connection.endpoint}) is connected`)
51
- } catch (ex) {
52
- ConnectionManager.logger.info(`Email(SMTP) connection(${connection.name}:${connection.endpoint}) failed to connect`)
53
- throw ex
54
- }
55
- }
56
-
57
- async disconnect(connection: Connection) {
58
- var client = ConnectionManager.removeConnectionInstance(connection)
59
- client.close()
60
-
61
- ConnectionManager.logger.info(`email connection(${connection.name}) is disconnected`)
62
- }
63
-
64
- get parameterSpec() {
65
- return [
66
- {
67
- type: 'string',
68
- name: 'user',
69
- label: 'email.user'
70
- },
71
- {
72
- type: 'string',
73
- name: 'pass',
74
- label: 'email.pass'
75
- }
76
- ]
77
- }
78
-
79
- get taskPrefixes() {
80
- return ['email']
81
- }
82
-
83
- get help() {
84
- return 'integration/connector/email-connector'
85
- }
86
- }
87
-
88
- ConnectionManager.registerConnector('email-connector', new EmailConnector())
@@ -1 +0,0 @@
1
- import './email'
@@ -1,2 +0,0 @@
1
- import './connector'
2
- import './task'
@@ -1,108 +0,0 @@
1
- import * as nodemailer from 'nodemailer'
2
- import 'ses'
3
- import { ConnectionManager, TaskRegistry } from '@things-factory/integration-base'
4
-
5
- const debug = require('debug')('things-factory:email-send')
6
-
7
- async function emailSend(step, { logger, domain, data, lng, variables }) {
8
- const {
9
- connection,
10
- params: { from, to, subject, contents, html }
11
- } = step
12
-
13
- const client = ConnectionManager.getConnectionInstanceByName(domain, connection)
14
- if (!client) {
15
- debug(`no connection : ${connection}`)
16
- throw new Error(`no connection : ${connection}`)
17
- }
18
-
19
- const { host, port = 587 /* SSL은 465 TLS는 587 */, secure = false /* SSL은 true TLS는 false */, user, pass } = client
20
-
21
- const transporter = nodemailer.createTransport({
22
- host,
23
- port,
24
- secure,
25
- auth: {
26
- user,
27
- pass
28
- }
29
- })
30
-
31
- const compartment = new Compartment({
32
- domain,
33
- user,
34
- lng,
35
- data,
36
- variables,
37
- console
38
- })
39
-
40
- let evalFrom, evalTo, evalSubject, evalContents, evalHtml
41
- try {
42
- evalFrom = compartment.evaluate('`' + from + '`')
43
- evalTo = compartment.evaluate('`' + to + '`')
44
- evalSubject = compartment.evaluate('`' + subject + '`')
45
- evalContents = compartment.evaluate('`' + contents + '`')
46
- evalHtml = compartment.evaluate('`' + html + '`')
47
- } catch (err) {
48
- throw new Error(`Failed to evaluate template: ${err.message}`)
49
- }
50
-
51
- const info = await transporter.sendMail({
52
- from: evalFrom,
53
- to: evalTo,
54
- subject: evalSubject,
55
- text: evalContents,
56
- html: evalHtml
57
- })
58
-
59
- return {
60
- data: info
61
- }
62
- }
63
-
64
- emailSend.parameterSpec = [
65
- {
66
- type: 'string',
67
- name: 'from',
68
- label: 'email.from'
69
- },
70
- {
71
- type: 'string',
72
- name: 'to',
73
- label: 'email.to'
74
- },
75
- {
76
- type: 'string',
77
- name: 'subject',
78
- label: 'email.subject'
79
- },
80
- {
81
- type: 'textarea',
82
- name: 'contents',
83
- label: 'email.contents',
84
- property: {
85
- language: 'text',
86
- showLineNumbers: true
87
- },
88
- styles: {
89
- flex: '1'
90
- }
91
- },
92
- {
93
- type: 'textarea',
94
- name: 'html',
95
- label: 'email.html',
96
- property: {
97
- language: 'text',
98
- showLineNumbers: true
99
- },
100
- styles: {
101
- flex: '1'
102
- }
103
- }
104
- ]
105
-
106
- emailSend.help = 'integration/task/email-send'
107
-
108
- TaskRegistry.registerTaskHandler('email-send', emailSend)
@@ -1 +0,0 @@
1
- import './email-send'
package/server/index.ts DELETED
@@ -1 +0,0 @@
1
- import './engine'