@nocobase/plugin-workflow-mailer 2.2.19 → 2.2.21
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/dist/externalVersion.js +6 -6
- package/dist/node_modules/joi/package.json +1 -1
- package/dist/node_modules/nodemailer/dist/cjs/addressparser/index.d.ts +59 -0
- package/dist/node_modules/nodemailer/dist/cjs/addressparser/index.js +790 -0
- package/dist/node_modules/nodemailer/dist/cjs/base64/index.d.ts +36 -0
- package/dist/node_modules/nodemailer/dist/cjs/base64/index.js +119 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/index.d.ts +52 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/index.js +228 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/message-parser.d.ts +48 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/message-parser.js +180 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.d.ts +36 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.js +148 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/sign.d.ts +52 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/sign.js +165 -0
- package/dist/node_modules/nodemailer/dist/cjs/errors.d.ts +96 -0
- package/dist/node_modules/nodemailer/dist/cjs/errors.js +70 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/cookies.d.ts +107 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/cookies.js +282 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/index.js +384 -0
- package/dist/node_modules/nodemailer/dist/cjs/json-transport/index.d.ts +64 -0
- package/dist/node_modules/nodemailer/dist/cjs/json-transport/index.js +99 -0
- package/dist/node_modules/nodemailer/dist/cjs/mail-composer/index.d.ts +174 -0
- package/dist/node_modules/nodemailer/dist/cjs/mail-composer/index.js +613 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/index.d.ts +237 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/index.js +415 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/mail-message.d.ts +97 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/mail-message.js +342 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +161 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +787 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.d.ts +2 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.js +2103 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/index.d.ts +333 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/index.js +1493 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/last-newline.d.ts +5 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/last-newline.js +32 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-unix.d.ts +9 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-unix.js +40 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-windows.d.ts +10 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-windows.js +47 -0
- package/dist/node_modules/nodemailer/dist/cjs/nodemailer.d.ts +124 -0
- package/dist/node_modules/nodemailer/dist/cjs/nodemailer.js +1 -0
- package/dist/node_modules/nodemailer/dist/cjs/package-info.d.ts +3 -0
- package/dist/node_modules/nodemailer/dist/cjs/package-info.js +7 -0
- package/dist/node_modules/nodemailer/dist/cjs/package.json +3 -0
- package/dist/node_modules/nodemailer/dist/cjs/punycode/index.d.ts +73 -0
- package/dist/node_modules/nodemailer/{lib → dist/cjs}/punycode/index.js +62 -111
- package/dist/node_modules/nodemailer/dist/cjs/qp/index.d.ts +32 -0
- package/dist/node_modules/nodemailer/dist/cjs/qp/index.js +207 -0
- package/dist/node_modules/nodemailer/dist/cjs/sendmail-transport/index.d.ts +69 -0
- package/dist/node_modules/nodemailer/dist/cjs/sendmail-transport/index.js +210 -0
- package/dist/node_modules/nodemailer/dist/cjs/ses-transport/index.d.ts +112 -0
- package/dist/node_modules/nodemailer/dist/cjs/ses-transport/index.js +252 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/index.d.ts +260 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/index.js +680 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/objects.d.ts +23 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/objects.js +43 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/url.d.ts +21 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/url.js +255 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.d.ts +15 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.js +108 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.d.ts +47 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.js +189 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/index.d.ts +416 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +1837 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +133 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +569 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.d.ts +62 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +257 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-transport/index.d.ts +156 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-transport/index.js +371 -0
- package/dist/node_modules/nodemailer/dist/cjs/stream-transport/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/cjs/stream-transport/index.js +146 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/index.d.ts +35 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/index.js +41 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/services.d.ts +2 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/services.js +674 -0
- package/dist/node_modules/nodemailer/dist/cjs/xoauth2/index.d.ts +201 -0
- package/dist/node_modules/nodemailer/dist/cjs/xoauth2/index.js +426 -0
- package/dist/node_modules/nodemailer/dist/esm/addressparser/index.d.ts +59 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/addressparser/index.js +361 -131
- package/dist/node_modules/nodemailer/dist/esm/base64/index.d.ts +36 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/base64/index.js +31 -56
- package/dist/node_modules/nodemailer/dist/esm/dkim/index.d.ts +52 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/dkim/index.js +49 -78
- package/dist/node_modules/nodemailer/dist/esm/dkim/message-parser.d.ts +48 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/dkim/message-parser.js +64 -42
- package/dist/node_modules/nodemailer/dist/esm/dkim/relaxed-body.d.ts +36 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/relaxed-body.js +141 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/sign.d.ts +52 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/dkim/sign.js +50 -46
- package/dist/node_modules/nodemailer/dist/esm/errors.d.ts +96 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/errors.js +26 -18
- package/dist/node_modules/nodemailer/dist/esm/fetch/cookies.d.ts +107 -0
- package/dist/node_modules/nodemailer/dist/esm/fetch/cookies.js +242 -0
- package/dist/node_modules/nodemailer/dist/esm/fetch/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/fetch/index.js +80 -147
- package/dist/node_modules/nodemailer/dist/esm/json-transport/index.d.ts +64 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/json-transport/index.js +19 -39
- package/dist/node_modules/nodemailer/dist/esm/mail-composer/index.d.ts +174 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mail-composer/index.js +199 -265
- package/dist/node_modules/nodemailer/dist/esm/mailer/index.d.ts +237 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/index.js +128 -234
- package/dist/node_modules/nodemailer/dist/esm/mailer/mail-message.d.ts +97 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/mail-message.js +62 -114
- package/dist/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +161 -0
- package/dist/node_modules/nodemailer/dist/esm/mime-funcs/index.js +738 -0
- package/dist/node_modules/nodemailer/dist/esm/mime-funcs/mime-types.d.ts +2 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-funcs/mime-types.js +29 -42
- package/dist/node_modules/nodemailer/dist/esm/mime-node/index.d.ts +333 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/index.js +259 -372
- package/dist/node_modules/nodemailer/dist/esm/mime-node/last-newline.d.ts +5 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/last-newline.js +4 -10
- package/dist/node_modules/nodemailer/dist/esm/mime-node/le-unix.d.ts +9 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/le-unix.js +6 -11
- package/dist/node_modules/nodemailer/dist/esm/mime-node/le-windows.d.ts +10 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/le-windows.js +6 -13
- package/dist/node_modules/nodemailer/dist/esm/nodemailer.d.ts +124 -0
- package/dist/node_modules/nodemailer/dist/esm/nodemailer.js +166 -0
- package/dist/node_modules/nodemailer/dist/esm/package-info.d.ts +3 -0
- package/dist/node_modules/nodemailer/dist/esm/package-info.js +4 -0
- package/dist/node_modules/nodemailer/dist/esm/package.json +3 -0
- package/dist/node_modules/nodemailer/dist/esm/punycode/index.d.ts +73 -0
- package/dist/node_modules/nodemailer/dist/esm/punycode/index.js +405 -0
- package/dist/node_modules/nodemailer/dist/esm/qp/index.d.ts +32 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/qp/index.js +38 -67
- package/dist/node_modules/nodemailer/dist/esm/sendmail-transport/index.d.ts +69 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/sendmail-transport/index.js +51 -101
- package/dist/node_modules/nodemailer/dist/esm/ses-transport/index.d.ts +112 -0
- package/dist/node_modules/nodemailer/dist/esm/ses-transport/index.js +212 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/index.d.ts +260 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/shared/index.js +156 -272
- package/dist/node_modules/nodemailer/dist/esm/shared/objects.d.ts +23 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/shared/objects.js +13 -17
- package/dist/node_modules/nodemailer/dist/esm/shared/url.d.ts +21 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/url.js +214 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.d.ts +15 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.js +103 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.d.ts +47 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-connection/http-proxy-client.js +49 -74
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/index.d.ts +416 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-connection/index.js +574 -794
- package/dist/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +133 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-pool/index.js +172 -284
- package/dist/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.d.ts +62 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-pool/pool-resource.js +57 -97
- package/dist/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +156 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-transport/index.js +81 -179
- package/dist/node_modules/nodemailer/dist/esm/stream-transport/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/stream-transport/index.js +36 -74
- package/dist/node_modules/nodemailer/dist/esm/well-known/index.d.ts +35 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/well-known/index.js +5 -16
- package/dist/node_modules/nodemailer/dist/esm/well-known/services.d.ts +2 -0
- package/dist/node_modules/nodemailer/dist/esm/well-known/services.js +671 -0
- package/dist/node_modules/nodemailer/dist/esm/xoauth2/index.d.ts +201 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/xoauth2/index.js +125 -187
- package/dist/node_modules/nodemailer/{lib → dist}/well-known/services.json +9 -2
- package/dist/node_modules/nodemailer/package.json +1 -1
- package/package.json +3 -3
- package/dist/node_modules/nodemailer/.gitattributes +0 -6
- package/dist/node_modules/nodemailer/.ncurc.js +0 -9
- package/dist/node_modules/nodemailer/.prettierignore +0 -8
- package/dist/node_modules/nodemailer/.prettierrc +0 -12
- package/dist/node_modules/nodemailer/.prettierrc.js +0 -10
- package/dist/node_modules/nodemailer/.release-please-config.json +0 -9
- package/dist/node_modules/nodemailer/eslint.config.js +0 -88
- package/dist/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
- package/dist/node_modules/nodemailer/lib/fetch/cookies.js +0 -276
- package/dist/node_modules/nodemailer/lib/mime-funcs/index.js +0 -671
- package/dist/node_modules/nodemailer/lib/nodemailer.js +0 -1
- package/dist/node_modules/nodemailer/lib/ses-transport/index.js +0 -266
- package/dist/node_modules/nodemailer/lib/shared/url.js +0 -151
- package/dist/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -105
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const errors = require('../errors');
|
|
12
|
-
const { isProtoKey } = require('../shared/objects');
|
|
13
|
-
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import https from 'node:https';
|
|
3
|
+
import * as urllib from '../shared/url.js';
|
|
4
|
+
import zlib from 'node:zlib';
|
|
5
|
+
import { PassThrough } from 'node:stream';
|
|
6
|
+
import Cookies from './cookies.js';
|
|
7
|
+
import * as packageData from '../package-info.js';
|
|
8
|
+
import net from 'node:net';
|
|
9
|
+
import * as errors from '../errors.js';
|
|
10
|
+
import { isProtoKey } from '../shared/objects.js';
|
|
14
11
|
const MAX_REDIRECTS = 5;
|
|
15
|
-
|
|
12
|
+
// a stalled server would otherwise hold the request, and whatever waits on it, open forever
|
|
13
|
+
const DEFAULT_TIMEOUT = 60 * 1000;
|
|
14
|
+
// the body is usually buffered in memory by the caller, so an unbounded download is refused
|
|
15
|
+
const DEFAULT_MAX_BYTES = 64 * 1024 * 1024;
|
|
16
16
|
// Only genuine TLS settings are taken from options.tls. That object reaches us straight
|
|
17
17
|
// from a user supplied attachment (content.tls), so keys like host, port, path, socketPath
|
|
18
18
|
// or lookup would otherwise repoint the request at a destination that never went through
|
|
@@ -43,7 +43,6 @@ const TLS_OPTION_KEYS = [
|
|
|
43
43
|
'sessionIdContext',
|
|
44
44
|
'sigalgs'
|
|
45
45
|
];
|
|
46
|
-
|
|
47
46
|
/**
|
|
48
47
|
* Resolves a URL only if it is one this module is willing to request.
|
|
49
48
|
*
|
|
@@ -52,41 +51,30 @@ const TLS_OPTION_KEYS = [
|
|
|
52
51
|
* or from a redirect Location header. An uncaught throw here takes the process down,
|
|
53
52
|
* so a URL that does not parse is reported the same way as one with a scheme we refuse.
|
|
54
53
|
*
|
|
55
|
-
* @param
|
|
56
|
-
* @returns
|
|
54
|
+
* @param url URL to parse
|
|
55
|
+
* @returns Parsed URL, or false if it is not a usable http(s) URL
|
|
57
56
|
*/
|
|
58
57
|
function parseFetchUrl(url) {
|
|
59
58
|
let parsed;
|
|
60
59
|
try {
|
|
61
60
|
parsed = urllib.parse(url);
|
|
62
|
-
}
|
|
61
|
+
}
|
|
62
|
+
catch (_err) {
|
|
63
63
|
return false;
|
|
64
64
|
}
|
|
65
|
-
|
|
66
65
|
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
67
66
|
return false;
|
|
68
67
|
}
|
|
69
|
-
|
|
70
68
|
return parsed;
|
|
71
69
|
}
|
|
72
|
-
|
|
73
|
-
module.exports = function (url, options) {
|
|
74
|
-
return nmfetch(url, options);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
module.exports.Cookies = Cookies;
|
|
78
|
-
|
|
79
70
|
function nmfetch(url, options) {
|
|
80
71
|
options = options || {};
|
|
81
|
-
|
|
82
72
|
options.fetchRes = options.fetchRes || new PassThrough();
|
|
83
73
|
options.cookies = options.cookies || new Cookies();
|
|
84
74
|
options.redirects = options.redirects || 0;
|
|
85
75
|
options.maxRedirects = isNaN(options.maxRedirects) ? MAX_REDIRECTS : options.maxRedirects;
|
|
86
|
-
|
|
87
76
|
const fetchRes = options.fetchRes;
|
|
88
77
|
const parsed = parseFetchUrl(url);
|
|
89
|
-
|
|
90
78
|
if (!parsed) {
|
|
91
79
|
// Only http(s) URLs can be fetched. Any other scheme (file:, gopher:, a
|
|
92
80
|
// protocol-relative redirect target etc.) would otherwise be silently served over
|
|
@@ -107,26 +95,21 @@ function nmfetch(url, options) {
|
|
|
107
95
|
});
|
|
108
96
|
return fetchRes;
|
|
109
97
|
}
|
|
110
|
-
|
|
111
98
|
if (options.cookie) {
|
|
112
99
|
[].concat(options.cookie || []).forEach(cookie => {
|
|
113
100
|
options.cookies.set(cookie, url);
|
|
114
101
|
});
|
|
115
102
|
options.cookie = false;
|
|
116
103
|
}
|
|
117
|
-
|
|
118
104
|
let method = (options.method || '').toString().trim().toUpperCase() || 'GET';
|
|
119
105
|
let finished = false;
|
|
120
106
|
let cookies;
|
|
121
107
|
let body;
|
|
122
|
-
|
|
123
108
|
const handler = parsed.protocol === 'https:' ? https : http;
|
|
124
|
-
|
|
125
109
|
const headers = {
|
|
126
110
|
'accept-encoding': 'gzip,deflate',
|
|
127
111
|
'user-agent': 'nodemailer/' + packageData.version
|
|
128
112
|
};
|
|
129
|
-
|
|
130
113
|
Object.keys(options.headers || {}).forEach(key => {
|
|
131
114
|
// options.headers is the caller's httpHeaders, straight off an attachment
|
|
132
115
|
if (isProtoKey(key.toLowerCase().trim())) {
|
|
@@ -134,29 +117,24 @@ function nmfetch(url, options) {
|
|
|
134
117
|
}
|
|
135
118
|
headers[key.toLowerCase().trim()] = options.headers[key];
|
|
136
119
|
});
|
|
137
|
-
|
|
138
120
|
if (options.userAgent) {
|
|
139
121
|
headers['user-agent'] = options.userAgent;
|
|
140
122
|
}
|
|
141
|
-
|
|
142
123
|
if (parsed.auth) {
|
|
143
124
|
headers.Authorization = 'Basic ' + Buffer.from(parsed.auth).toString('base64');
|
|
144
125
|
}
|
|
145
|
-
|
|
146
126
|
if ((cookies = options.cookies.get(url))) {
|
|
147
127
|
headers.cookie = cookies;
|
|
148
128
|
}
|
|
149
|
-
|
|
150
129
|
if (options.body) {
|
|
151
130
|
if (options.contentType !== false) {
|
|
152
131
|
headers['Content-Type'] = options.contentType || 'application/x-www-form-urlencoded';
|
|
153
132
|
}
|
|
154
|
-
|
|
155
133
|
if (typeof options.body.pipe === 'function') {
|
|
156
134
|
// it's a stream
|
|
157
135
|
headers['Transfer-Encoding'] = 'chunked';
|
|
158
136
|
body = options.body;
|
|
159
|
-
body.on('error', err => {
|
|
137
|
+
body.on('error', (err) => {
|
|
160
138
|
if (finished) {
|
|
161
139
|
return;
|
|
162
140
|
}
|
|
@@ -165,41 +143,41 @@ function nmfetch(url, options) {
|
|
|
165
143
|
err.sourceUrl = url;
|
|
166
144
|
fetchRes.emit('error', err);
|
|
167
145
|
});
|
|
168
|
-
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
169
148
|
if (options.body instanceof Buffer) {
|
|
170
149
|
body = options.body;
|
|
171
|
-
}
|
|
150
|
+
}
|
|
151
|
+
else if (typeof options.body === 'object') {
|
|
172
152
|
try {
|
|
173
153
|
// encodeURIComponent can fail on invalid input (partial emoji etc.)
|
|
174
|
-
body = Buffer.from(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
154
|
+
body = Buffer.from(Object.keys(options.body)
|
|
155
|
+
.map(key => {
|
|
156
|
+
const value = options.body[key].toString().trim();
|
|
157
|
+
return encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
|
158
|
+
})
|
|
159
|
+
.join('&'));
|
|
160
|
+
}
|
|
161
|
+
catch (E) {
|
|
162
|
+
// the caller attaches its error listener once nmfetch has returned, so
|
|
163
|
+
// the error is emitted on the next tick and the stream is handed back
|
|
164
|
+
// the way every other failure is reported
|
|
186
165
|
finished = true;
|
|
187
166
|
E.code = errors.EFETCH;
|
|
188
167
|
E.sourceUrl = url;
|
|
189
|
-
fetchRes.emit('error', E);
|
|
190
|
-
return;
|
|
168
|
+
setImmediate(() => fetchRes.emit('error', E));
|
|
169
|
+
return fetchRes;
|
|
191
170
|
}
|
|
192
|
-
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
193
173
|
body = Buffer.from(options.body.toString().trim());
|
|
194
174
|
}
|
|
195
|
-
|
|
196
175
|
headers['Content-Type'] = options.contentType || 'application/x-www-form-urlencoded';
|
|
197
176
|
headers['Content-Length'] = body.length;
|
|
198
177
|
}
|
|
199
178
|
// if method is not provided, use POST instead of GET
|
|
200
179
|
method = (options.method || '').toString().trim().toUpperCase() || 'POST';
|
|
201
180
|
}
|
|
202
|
-
|
|
203
181
|
let req;
|
|
204
182
|
const reqOptions = {
|
|
205
183
|
method,
|
|
@@ -213,7 +191,6 @@ function nmfetch(url, options) {
|
|
|
213
191
|
rejectUnauthorized: true,
|
|
214
192
|
agent: false
|
|
215
193
|
};
|
|
216
|
-
|
|
217
194
|
if (options.tls) {
|
|
218
195
|
// see TLS_OPTION_KEYS
|
|
219
196
|
Object.keys(options.tls).forEach(key => {
|
|
@@ -222,20 +199,17 @@ function nmfetch(url, options) {
|
|
|
222
199
|
}
|
|
223
200
|
});
|
|
224
201
|
}
|
|
225
|
-
|
|
226
|
-
if (
|
|
227
|
-
parsed.protocol === 'https:' &&
|
|
202
|
+
if (parsed.protocol === 'https:' &&
|
|
228
203
|
parsed.hostname &&
|
|
229
204
|
parsed.hostname !== reqOptions.host &&
|
|
230
205
|
!net.isIP(parsed.hostname) &&
|
|
231
|
-
!reqOptions.servername
|
|
232
|
-
) {
|
|
206
|
+
!reqOptions.servername) {
|
|
233
207
|
reqOptions.servername = parsed.hostname;
|
|
234
208
|
}
|
|
235
|
-
|
|
236
209
|
try {
|
|
237
210
|
req = handler.request(reqOptions);
|
|
238
|
-
}
|
|
211
|
+
}
|
|
212
|
+
catch (E) {
|
|
239
213
|
finished = true;
|
|
240
214
|
setImmediate(() => {
|
|
241
215
|
E.code = errors.EFETCH;
|
|
@@ -244,91 +218,64 @@ function nmfetch(url, options) {
|
|
|
244
218
|
});
|
|
245
219
|
return fetchRes;
|
|
246
220
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
req.setTimeout(options.timeout, () => {
|
|
250
|
-
if (finished) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
finished = true;
|
|
254
|
-
req.abort();
|
|
255
|
-
const err = new Error('Request Timeout');
|
|
256
|
-
err.code = errors.EFETCH;
|
|
257
|
-
err.sourceUrl = url;
|
|
258
|
-
fetchRes.emit('error', err);
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
req.on('error', err => {
|
|
221
|
+
// reports the first failure of this request on fetchRes and releases the request
|
|
222
|
+
const fail = (err, sourceUrl = url) => {
|
|
263
223
|
if (finished) {
|
|
264
224
|
return;
|
|
265
225
|
}
|
|
266
226
|
finished = true;
|
|
267
227
|
err.code = errors.EFETCH;
|
|
268
|
-
err.sourceUrl =
|
|
228
|
+
err.sourceUrl = sourceUrl;
|
|
269
229
|
fetchRes.emit('error', err);
|
|
270
|
-
|
|
271
|
-
|
|
230
|
+
req.abort();
|
|
231
|
+
};
|
|
232
|
+
const timeout = typeof options.timeout === 'number' && options.timeout >= 0 ? options.timeout : DEFAULT_TIMEOUT;
|
|
233
|
+
if (timeout) {
|
|
234
|
+
req.setTimeout(timeout, () => fail(new Error('Request Timeout')));
|
|
235
|
+
}
|
|
236
|
+
req.on('error', (err) => fail(err));
|
|
272
237
|
req.on('response', res => {
|
|
273
238
|
let inflate;
|
|
274
|
-
|
|
275
239
|
if (finished) {
|
|
276
240
|
return;
|
|
277
241
|
}
|
|
278
|
-
|
|
279
242
|
switch (res.headers['content-encoding']) {
|
|
280
243
|
case 'gzip':
|
|
281
244
|
case 'deflate':
|
|
282
245
|
inflate = zlib.createUnzip();
|
|
283
246
|
break;
|
|
284
247
|
}
|
|
285
|
-
|
|
286
248
|
if (res.headers['set-cookie']) {
|
|
287
249
|
[].concat(res.headers['set-cookie'] || []).forEach(cookie => {
|
|
288
250
|
options.cookies.set(cookie, url);
|
|
289
251
|
});
|
|
290
252
|
}
|
|
291
|
-
|
|
292
253
|
if ([301, 302, 303, 307, 308].includes(res.statusCode) && res.headers.location) {
|
|
293
254
|
// redirect
|
|
294
255
|
options.redirects++;
|
|
295
256
|
if (options.redirects > options.maxRedirects) {
|
|
296
|
-
|
|
297
|
-
const err = new Error('Maximum redirect count exceeded');
|
|
298
|
-
err.code = errors.EFETCH;
|
|
299
|
-
err.sourceUrl = url;
|
|
300
|
-
fetchRes.emit('error', err);
|
|
301
|
-
req.abort();
|
|
302
|
-
return;
|
|
257
|
+
return fail(new Error('Maximum redirect count exceeded'));
|
|
303
258
|
}
|
|
304
259
|
// redirect does not include POST body
|
|
305
260
|
options.method = 'GET';
|
|
306
261
|
options.body = false;
|
|
307
|
-
|
|
308
262
|
let redirectUrl;
|
|
309
263
|
try {
|
|
310
264
|
redirectUrl = urllib.resolve(url, res.headers.location);
|
|
311
|
-
}
|
|
265
|
+
}
|
|
266
|
+
catch (_err) {
|
|
312
267
|
// the legacy resolver throws on a Location the WHATWG parser also refused,
|
|
313
268
|
// so fall through to the check below with what the server actually sent
|
|
314
269
|
redirectUrl = res.headers.location;
|
|
315
270
|
}
|
|
316
271
|
const redirectParsed = parseFetchUrl(redirectUrl);
|
|
317
|
-
|
|
318
272
|
if (!redirectParsed) {
|
|
319
273
|
// Refuse the redirect target here rather than leaving it to the recursive
|
|
320
274
|
// call: that call gets its own `finished` flag and no handle on this
|
|
321
275
|
// request, so this one would stay open and could emit a second error on
|
|
322
276
|
// the shared fetchRes once it times out. Callers listen with req.once().
|
|
323
|
-
|
|
324
|
-
const err = new Error('Unsupported protocol for URL ' + redirectUrl);
|
|
325
|
-
err.code = errors.EFETCH;
|
|
326
|
-
err.sourceUrl = redirectUrl;
|
|
327
|
-
fetchRes.emit('error', err);
|
|
328
|
-
req.abort();
|
|
329
|
-
return;
|
|
277
|
+
return fail(new Error('Unsupported protocol for URL ' + redirectUrl), redirectUrl);
|
|
330
278
|
}
|
|
331
|
-
|
|
332
279
|
// Do not forward credentials when the redirect leaves the original
|
|
333
280
|
// security context: a different host, or a downgrade from https to
|
|
334
281
|
// http (which would otherwise put them on the wire in cleartext).
|
|
@@ -344,51 +291,38 @@ function nmfetch(url, options) {
|
|
|
344
291
|
}
|
|
345
292
|
});
|
|
346
293
|
}
|
|
347
|
-
|
|
294
|
+
// this request is done with, release it so its socket and timeout do not
|
|
295
|
+
// outlive it and report a late error on the shared fetchRes
|
|
296
|
+
finished = true;
|
|
297
|
+
res.resume();
|
|
298
|
+
req.abort();
|
|
348
299
|
return nmfetch(redirectUrl, options);
|
|
349
300
|
}
|
|
350
|
-
|
|
351
301
|
fetchRes.statusCode = res.statusCode;
|
|
352
302
|
fetchRes.headers = res.headers;
|
|
353
|
-
|
|
354
303
|
if (res.statusCode >= 300 && !options.allowErrorResponse) {
|
|
355
|
-
|
|
356
|
-
const err = new Error('Invalid status code ' + res.statusCode);
|
|
357
|
-
err.code = errors.EFETCH;
|
|
358
|
-
err.sourceUrl = url;
|
|
359
|
-
fetchRes.emit('error', err);
|
|
360
|
-
req.abort();
|
|
361
|
-
return;
|
|
304
|
+
return fail(new Error('Invalid status code ' + res.statusCode));
|
|
362
305
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
306
|
+
res.on('error', (err) => fail(err));
|
|
307
|
+
const maxBytes = typeof options.maxBytes === 'number' && options.maxBytes > 0 ? options.maxBytes : DEFAULT_MAX_BYTES;
|
|
308
|
+
const source = inflate || res;
|
|
309
|
+
let received = 0;
|
|
310
|
+
source.on('data', (chunk) => {
|
|
311
|
+
received += chunk.length;
|
|
312
|
+
if (received <= maxBytes || finished) {
|
|
366
313
|
return;
|
|
367
314
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
err.sourceUrl = url;
|
|
371
|
-
fetchRes.emit('error', err);
|
|
372
|
-
req.abort();
|
|
315
|
+
source.unpipe(fetchRes);
|
|
316
|
+
fail(new Error('Response size exceeds the allowed ' + maxBytes + ' bytes'));
|
|
373
317
|
});
|
|
374
|
-
|
|
375
318
|
if (inflate) {
|
|
376
319
|
res.pipe(inflate).pipe(fetchRes);
|
|
377
|
-
inflate.on('error', err =>
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
finished = true;
|
|
382
|
-
err.code = errors.EFETCH;
|
|
383
|
-
err.sourceUrl = url;
|
|
384
|
-
fetchRes.emit('error', err);
|
|
385
|
-
req.abort();
|
|
386
|
-
});
|
|
387
|
-
} else {
|
|
320
|
+
inflate.on('error', (err) => fail(err));
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
388
323
|
res.pipe(fetchRes);
|
|
389
324
|
}
|
|
390
325
|
});
|
|
391
|
-
|
|
392
326
|
setImmediate(() => {
|
|
393
327
|
if (body) {
|
|
394
328
|
try {
|
|
@@ -396,16 +330,15 @@ function nmfetch(url, options) {
|
|
|
396
330
|
return body.pipe(req);
|
|
397
331
|
}
|
|
398
332
|
req.write(body);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
err
|
|
402
|
-
err.sourceUrl = url;
|
|
403
|
-
fetchRes.emit('error', err);
|
|
404
|
-
return;
|
|
333
|
+
}
|
|
334
|
+
catch (err) {
|
|
335
|
+
return fail(err);
|
|
405
336
|
}
|
|
406
337
|
}
|
|
407
338
|
req.end();
|
|
408
339
|
});
|
|
409
|
-
|
|
410
340
|
return fetchRes;
|
|
411
341
|
}
|
|
342
|
+
nmfetch.Cookies = Cookies;
|
|
343
|
+
nmfetch.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
|
|
344
|
+
export default nmfetch;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Logger } from '../shared/index.js';
|
|
2
|
+
import type { MimeNodeEnvelope } from '../mime-node/index.js';
|
|
3
|
+
import type MailMessage from '../mailer/mail-message.js';
|
|
4
|
+
import type { default as Mail, SentMessageInfo, SendMailOptions, TransportOptions } from '../mailer/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Options for the JSON transport
|
|
7
|
+
*/
|
|
8
|
+
export interface JSONTransportOptions extends TransportOptions {
|
|
9
|
+
/** Selects this transport in createTransport */
|
|
10
|
+
jsonTransport?: boolean | undefined;
|
|
11
|
+
/** If true, the message is returned as an object instead of a JSON string */
|
|
12
|
+
skipEncoding?: boolean | undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The value the JSON transport hands to the send callback. M is the type of the message
|
|
16
|
+
* field: a JSON string by default, the message object itself when skipEncoding is set
|
|
17
|
+
*/
|
|
18
|
+
export interface JSONSentMessageInfo<M = string> extends SentMessageInfo {
|
|
19
|
+
/** The envelope the message was generated with */
|
|
20
|
+
envelope: MimeNodeEnvelope;
|
|
21
|
+
/** Message-ID value of the message */
|
|
22
|
+
messageId: string;
|
|
23
|
+
/** The normalized message as a JSON string, or as the object itself when skipEncoding is set */
|
|
24
|
+
message: M;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The value the JSON transport hands to the send callback when skipEncoding is set: the
|
|
28
|
+
* message field holds the message object. Typed loosely so that a transporter created with
|
|
29
|
+
* skipEncoding still fits a variable declared with the plain result type
|
|
30
|
+
*/
|
|
31
|
+
export type JSONSentMessageObjectInfo = JSONSentMessageInfo<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Generates a Transport object to generate JSON output
|
|
34
|
+
*
|
|
35
|
+
* @constructor
|
|
36
|
+
* @param optional config parameter
|
|
37
|
+
*/
|
|
38
|
+
declare class JSONTransport {
|
|
39
|
+
mailer: Mail<JSONSentMessageInfo>;
|
|
40
|
+
options: JSONTransportOptions;
|
|
41
|
+
name: string;
|
|
42
|
+
version: string;
|
|
43
|
+
logger: Logger;
|
|
44
|
+
constructor(options?: JSONTransportOptions);
|
|
45
|
+
/**
|
|
46
|
+
* <p>Compiles a mailcomposer message and forwards it to handler that sends it.</p>
|
|
47
|
+
*
|
|
48
|
+
* @param mail MailComposer object
|
|
49
|
+
* @param done Callback function to run when the sending is completed
|
|
50
|
+
*/
|
|
51
|
+
send(mail: MailMessage<JSONSentMessageInfo>, done: (err: Error | null, info?: JSONSentMessageInfo) => void): void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Type aliases in the layout of @types/nodemailer, so `JSONTransport.Options` style references keep working
|
|
55
|
+
*/
|
|
56
|
+
declare namespace JSONTransport {
|
|
57
|
+
type Options = JSONTransportOptions;
|
|
58
|
+
type MailOptions = SendMailOptions;
|
|
59
|
+
type SentMessageInfo = JSONSentMessageInfo;
|
|
60
|
+
type SentMessageObjectInfo = JSONSentMessageObjectInfo;
|
|
61
|
+
}
|
|
62
|
+
/** The same aliases as module level exports, for `import * as JSONTransport` and `import JSONTransport = require()` */
|
|
63
|
+
export type { JSONTransportOptions as Options, SendMailOptions as MailOptions, JSONSentMessageInfo as SentMessageInfo, JSONSentMessageObjectInfo as SentMessageObjectInfo };
|
|
64
|
+
export default JSONTransport;
|
|
@@ -1,74 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const packageData = require('../../package.json');
|
|
4
|
-
const shared = require('../shared');
|
|
5
|
-
|
|
1
|
+
import * as packageData from '../package-info.js';
|
|
2
|
+
import * as shared from '../shared/index.js';
|
|
6
3
|
/**
|
|
7
4
|
* Generates a Transport object to generate JSON output
|
|
8
5
|
*
|
|
9
6
|
* @constructor
|
|
10
|
-
* @param
|
|
7
|
+
* @param optional config parameter
|
|
11
8
|
*/
|
|
12
9
|
class JSONTransport {
|
|
13
10
|
constructor(options) {
|
|
14
11
|
options = options || {};
|
|
15
|
-
|
|
16
12
|
this.options = options;
|
|
17
|
-
|
|
18
13
|
this.name = 'JSONTransport';
|
|
19
14
|
this.version = packageData.version;
|
|
20
|
-
|
|
21
15
|
this.logger = shared.getLogger(this.options, {
|
|
22
16
|
component: this.options.component || 'json-transport'
|
|
23
17
|
});
|
|
24
18
|
}
|
|
25
|
-
|
|
26
19
|
/**
|
|
27
20
|
* <p>Compiles a mailcomposer message and forwards it to handler that sends it.</p>
|
|
28
21
|
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
22
|
+
* @param mail MailComposer object
|
|
23
|
+
* @param done Callback function to run when the sending is completed
|
|
31
24
|
*/
|
|
32
25
|
send(mail, done) {
|
|
33
|
-
// Sendmail strips this header line by itself
|
|
26
|
+
// Sendmail strips this header line by itself. send() runs after the message was
|
|
27
|
+
// compiled, so mail.message is set
|
|
34
28
|
mail.message.keepBcc = true;
|
|
35
|
-
|
|
36
29
|
const envelope = mail.message.getEnvelope();
|
|
37
30
|
const messageId = mail.message.messageId();
|
|
38
|
-
|
|
39
31
|
const recipients = [].concat(envelope.to || []);
|
|
40
32
|
if (recipients.length > 3) {
|
|
41
33
|
recipients.push('...and ' + recipients.splice(2).length + ' more');
|
|
42
34
|
}
|
|
43
|
-
this.logger.info(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
'Composing JSON structure of %s to <%s>',
|
|
49
|
-
messageId,
|
|
50
|
-
recipients.join(', ')
|
|
51
|
-
);
|
|
52
|
-
|
|
35
|
+
this.logger.info({
|
|
36
|
+
tnx: 'send',
|
|
37
|
+
messageId
|
|
38
|
+
}, 'Composing JSON structure of %s to <%s>', messageId, recipients.join(', '));
|
|
53
39
|
setImmediate(() => {
|
|
54
40
|
mail.normalize((err, data) => {
|
|
55
41
|
if (err) {
|
|
56
|
-
this.logger.error(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
'Failed building JSON structure for %s. %s',
|
|
63
|
-
messageId,
|
|
64
|
-
err.message
|
|
65
|
-
);
|
|
42
|
+
this.logger.error({
|
|
43
|
+
err,
|
|
44
|
+
tnx: 'send',
|
|
45
|
+
messageId
|
|
46
|
+
}, 'Failed building JSON structure for %s. %s', messageId, err.message);
|
|
66
47
|
return done(err);
|
|
67
48
|
}
|
|
68
|
-
|
|
69
49
|
delete data.envelope;
|
|
70
50
|
delete data.normalizedHeaders;
|
|
71
|
-
|
|
51
|
+
// the message field is the object itself with skipEncoding, the
|
|
52
|
+
// createTransport overload for that option types the result accordingly
|
|
72
53
|
return done(null, {
|
|
73
54
|
envelope,
|
|
74
55
|
messageId,
|
|
@@ -78,5 +59,4 @@ class JSONTransport {
|
|
|
78
59
|
});
|
|
79
60
|
}
|
|
80
61
|
}
|
|
81
|
-
|
|
82
|
-
module.exports = JSONTransport;
|
|
62
|
+
export default JSONTransport;
|