@nocobase/plugin-workflow-mailer 2.2.20 → 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,61 +1,46 @@
|
|
|
1
1
|
/* eslint no-console: 0 */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const dns = require('dns');
|
|
12
|
-
const net = require('net');
|
|
13
|
-
const os = require('os');
|
|
14
|
-
|
|
2
|
+
import * as urllib from './url.js';
|
|
3
|
+
import util from 'node:util';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import nmfetch from '../fetch/index.js';
|
|
6
|
+
import * as errors from '../errors.js';
|
|
7
|
+
import { isProtoKey, copyOwnKeys } from './objects.js';
|
|
8
|
+
import dns from 'node:dns';
|
|
9
|
+
import net from 'node:net';
|
|
10
|
+
import os from 'node:os';
|
|
15
11
|
// re-exported for the callers that already depend on this module, see ./objects
|
|
16
|
-
|
|
17
|
-
module.exports.copyOwnKeys = objects.copyOwnKeys;
|
|
18
|
-
|
|
12
|
+
export { isProtoKey, copyOwnKeys };
|
|
19
13
|
const DNS_TTL = 5 * 60 * 1000;
|
|
20
14
|
const CACHE_CLEANUP_INTERVAL = 30 * 1000; // Minimum 30 seconds between cleanups
|
|
21
15
|
const MAX_CACHE_SIZE = 1000; // Maximum number of entries in cache
|
|
22
|
-
|
|
23
16
|
let lastCacheCleanup = 0;
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
/** @internal */
|
|
18
|
+
export const _lastCacheCleanup = () => lastCacheCleanup;
|
|
19
|
+
/** @internal */
|
|
20
|
+
export const _resetCacheCleanup = () => {
|
|
26
21
|
lastCacheCleanup = 0;
|
|
27
22
|
};
|
|
28
|
-
|
|
29
|
-
let networkInterfaces;
|
|
23
|
+
export let networkInterfaces;
|
|
30
24
|
try {
|
|
31
25
|
networkInterfaces = os.networkInterfaces();
|
|
32
|
-
}
|
|
26
|
+
}
|
|
27
|
+
catch (_err) {
|
|
33
28
|
// fails on some systems
|
|
34
29
|
}
|
|
35
|
-
|
|
36
|
-
module.exports.networkInterfaces = networkInterfaces;
|
|
37
|
-
|
|
38
30
|
const isFamilySupported = (family, allowInternal) => {
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
41
|
-
// hope for the best
|
|
31
|
+
const addresses = Object.values(networkInterfaces || {}).flat();
|
|
32
|
+
if (!addresses.length) {
|
|
33
|
+
// hope for the best. Runtimes without an interface table (Cloudflare
|
|
34
|
+
// Workers) report an empty object rather than throwing
|
|
42
35
|
return true;
|
|
43
36
|
}
|
|
44
|
-
|
|
45
|
-
return Object.keys(ifaces)
|
|
46
|
-
.map(key => ifaces[key])
|
|
47
|
-
.reduce((acc, val) => acc.concat(val), [])
|
|
48
|
-
.filter(i => !i.internal || allowInternal)
|
|
49
|
-
.some(i => i.family === 'IPv' + family || i.family === family);
|
|
37
|
+
return addresses.filter(i => !i.internal || allowInternal).some(i => i.family === 'IPv' + family || i.family === family);
|
|
50
38
|
};
|
|
51
|
-
|
|
52
39
|
const resolve = (family, hostname, options, callback) => {
|
|
53
40
|
options = options || {};
|
|
54
|
-
|
|
55
41
|
if (!isFamilySupported(family, options.allowInternalNetworkInterfaces)) {
|
|
56
42
|
return callback(null, []);
|
|
57
43
|
}
|
|
58
|
-
|
|
59
44
|
const dnsResolver = dns.Resolver ? new dns.Resolver(options) : dns;
|
|
60
45
|
dnsResolver['resolve' + family](hostname, (err, addresses) => {
|
|
61
46
|
if (err) {
|
|
@@ -74,67 +59,54 @@ const resolve = (family, hostname, options, callback) => {
|
|
|
74
59
|
return callback(null, Array.isArray(addresses) ? addresses : [].concat(addresses || []));
|
|
75
60
|
});
|
|
76
61
|
};
|
|
77
|
-
|
|
78
|
-
const dnsCache = (module.exports.dnsCache = new Map());
|
|
79
|
-
|
|
62
|
+
export const dnsCache = new Map();
|
|
80
63
|
const formatDNSValue = (value, extra) => {
|
|
81
64
|
if (!value) {
|
|
82
65
|
return Object.assign({}, extra || {});
|
|
83
66
|
}
|
|
84
|
-
|
|
85
67
|
const addresses = value.addresses || [];
|
|
86
|
-
|
|
87
68
|
// Select a random address from available addresses, or null if none
|
|
88
69
|
const host = addresses.length > 0 ? addresses[Math.floor(Math.random() * addresses.length)] : null;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// Include all addresses for connection fallback support
|
|
95
|
-
_addresses: addresses
|
|
96
|
-
},
|
|
97
|
-
extra || {}
|
|
98
|
-
);
|
|
70
|
+
return Object.assign({
|
|
71
|
+
host,
|
|
72
|
+
// Include all addresses for connection fallback support
|
|
73
|
+
_addresses: addresses
|
|
74
|
+
}, extra || {});
|
|
99
75
|
};
|
|
100
|
-
|
|
101
|
-
module.exports.resolveHostname = (options, callback) => {
|
|
76
|
+
export const resolveHostname = (options, callback) => {
|
|
102
77
|
options = options || {};
|
|
103
|
-
|
|
104
78
|
if (!options.host && options.servername) {
|
|
105
79
|
options.host = options.servername;
|
|
106
80
|
}
|
|
107
|
-
|
|
108
81
|
if (!options.host || net.isIP(options.host)) {
|
|
109
82
|
// nothing to do here
|
|
110
83
|
const value = {
|
|
111
|
-
addresses: [options.host]
|
|
112
|
-
servername: options.servername || false
|
|
84
|
+
addresses: [options.host]
|
|
113
85
|
};
|
|
114
|
-
return callback(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
})
|
|
119
|
-
);
|
|
86
|
+
return callback(null, formatDNSValue(value, {
|
|
87
|
+
servername: options.servername || false,
|
|
88
|
+
cached: false
|
|
89
|
+
}));
|
|
120
90
|
}
|
|
121
|
-
|
|
91
|
+
const host = options.host;
|
|
92
|
+
// The TLS server name belongs to the connection asking, not to the host it resolves. The
|
|
93
|
+
// cache is shared by every transport of the process and keyed by host alone, so a server
|
|
94
|
+
// name stored in it would be the one of whichever transport resolved the host first, and a
|
|
95
|
+
// later transport with its own tls.servername would present and verify that name instead
|
|
96
|
+
const servername = options.servername || host;
|
|
122
97
|
let cached;
|
|
123
98
|
if (dnsCache.has(options.host)) {
|
|
124
99
|
cached = dnsCache.get(options.host);
|
|
125
|
-
|
|
126
100
|
// Lazy cleanup with time throttling
|
|
127
101
|
const now = Date.now();
|
|
128
102
|
if (now - lastCacheCleanup > CACHE_CLEANUP_INTERVAL) {
|
|
129
103
|
lastCacheCleanup = now;
|
|
130
|
-
|
|
131
104
|
// Clean up expired entries
|
|
132
105
|
for (const [host, entry] of dnsCache.entries()) {
|
|
133
106
|
if (entry.expires && entry.expires < now) {
|
|
134
107
|
dnsCache.delete(host);
|
|
135
108
|
}
|
|
136
109
|
}
|
|
137
|
-
|
|
138
110
|
// If cache is still too large, remove oldest entries
|
|
139
111
|
if (dnsCache.size > MAX_CACHE_SIZE) {
|
|
140
112
|
const toDelete = Math.floor(MAX_CACHE_SIZE * 0.1); // Remove 10% of entries
|
|
@@ -142,149 +114,117 @@ module.exports.resolveHostname = (options, callback) => {
|
|
|
142
114
|
keys.forEach(key => dnsCache.delete(key));
|
|
143
115
|
}
|
|
144
116
|
}
|
|
145
|
-
|
|
146
117
|
if (!cached.expires || cached.expires >= now) {
|
|
147
|
-
return callback(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
})
|
|
152
|
-
);
|
|
118
|
+
return callback(null, formatDNSValue(cached.value, {
|
|
119
|
+
servername,
|
|
120
|
+
cached: true
|
|
121
|
+
}));
|
|
153
122
|
}
|
|
154
123
|
}
|
|
155
|
-
|
|
156
124
|
// Resolve both IPv4 and IPv6 addresses for fallback support
|
|
157
125
|
let ipv4Addresses = [];
|
|
158
126
|
let ipv6Addresses = [];
|
|
159
127
|
let ipv4Error = null;
|
|
160
128
|
let ipv6Error = null;
|
|
161
|
-
|
|
162
129
|
resolve(4, options.host, options, (err, addresses) => {
|
|
163
130
|
if (err) {
|
|
164
131
|
ipv4Error = err;
|
|
165
|
-
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
166
134
|
ipv4Addresses = addresses || [];
|
|
167
135
|
}
|
|
168
|
-
|
|
169
|
-
resolve(6, options.host, options, (err, addresses) => {
|
|
136
|
+
resolve(6, host, options, (err, addresses) => {
|
|
170
137
|
if (err) {
|
|
171
138
|
ipv6Error = err;
|
|
172
|
-
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
173
141
|
ipv6Addresses = addresses || [];
|
|
174
142
|
}
|
|
175
|
-
|
|
176
143
|
// Combine addresses: IPv4 first, then IPv6
|
|
177
144
|
const allAddresses = ipv4Addresses.concat(ipv6Addresses);
|
|
178
|
-
|
|
179
145
|
if (allAddresses.length) {
|
|
180
146
|
const value = {
|
|
181
|
-
addresses: allAddresses
|
|
182
|
-
servername: options.servername || options.host
|
|
147
|
+
addresses: allAddresses
|
|
183
148
|
};
|
|
184
|
-
|
|
185
|
-
dnsCache.set(options.host, {
|
|
149
|
+
dnsCache.set(host, {
|
|
186
150
|
value,
|
|
187
151
|
expires: Date.now() + (options.dnsTtl || DNS_TTL)
|
|
188
152
|
});
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
cached: false
|
|
194
|
-
})
|
|
195
|
-
);
|
|
153
|
+
return callback(null, formatDNSValue(value, {
|
|
154
|
+
servername,
|
|
155
|
+
cached: false
|
|
156
|
+
}));
|
|
196
157
|
}
|
|
197
|
-
|
|
198
158
|
// No addresses from resolve4/resolve6, try dns.lookup as fallback
|
|
199
159
|
if (ipv4Error && ipv6Error) {
|
|
200
160
|
// Both resolvers had errors
|
|
201
161
|
if (cached) {
|
|
202
|
-
dnsCache.set(
|
|
162
|
+
dnsCache.set(host, {
|
|
203
163
|
value: cached.value,
|
|
204
164
|
expires: Date.now() + (options.dnsTtl || DNS_TTL)
|
|
205
165
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
error: ipv4Error
|
|
212
|
-
})
|
|
213
|
-
);
|
|
166
|
+
return callback(null, formatDNSValue(cached.value, {
|
|
167
|
+
servername,
|
|
168
|
+
cached: true,
|
|
169
|
+
error: ipv4Error
|
|
170
|
+
}));
|
|
214
171
|
}
|
|
215
172
|
}
|
|
216
|
-
|
|
217
173
|
try {
|
|
218
|
-
dns.lookup(
|
|
174
|
+
dns.lookup(host, { all: true }, (err, addresses) => {
|
|
219
175
|
if (err) {
|
|
220
176
|
if (cached) {
|
|
221
|
-
dnsCache.set(
|
|
177
|
+
dnsCache.set(host, {
|
|
222
178
|
value: cached.value,
|
|
223
179
|
expires: Date.now() + (options.dnsTtl || DNS_TTL)
|
|
224
180
|
});
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
error: err
|
|
231
|
-
})
|
|
232
|
-
);
|
|
181
|
+
return callback(null, formatDNSValue(cached.value, {
|
|
182
|
+
servername,
|
|
183
|
+
cached: true,
|
|
184
|
+
error: err
|
|
185
|
+
}));
|
|
233
186
|
}
|
|
234
187
|
return callback(err);
|
|
235
188
|
}
|
|
236
|
-
|
|
237
189
|
// Get all supported addresses from dns.lookup
|
|
238
190
|
const supportedAddresses = addresses
|
|
239
191
|
? addresses.filter(addr => isFamilySupported(addr.family)).map(addr => addr.address)
|
|
240
192
|
: [];
|
|
241
|
-
|
|
242
193
|
if (addresses && addresses.length && !supportedAddresses.length) {
|
|
243
194
|
// there are addresses but none can be used
|
|
244
195
|
console.warn(`Failed to resolve IPv${addresses[0].family} addresses with current network`);
|
|
245
196
|
}
|
|
246
|
-
|
|
247
197
|
if (!supportedAddresses.length && cached) {
|
|
248
198
|
// nothing was found, fallback to cached value
|
|
249
|
-
return callback(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
})
|
|
254
|
-
);
|
|
199
|
+
return callback(null, formatDNSValue(cached.value, {
|
|
200
|
+
servername,
|
|
201
|
+
cached: true
|
|
202
|
+
}));
|
|
255
203
|
}
|
|
256
|
-
|
|
257
204
|
const value = {
|
|
258
|
-
addresses: supportedAddresses.length ? supportedAddresses : [
|
|
259
|
-
servername: options.servername || options.host
|
|
205
|
+
addresses: supportedAddresses.length ? supportedAddresses : [host]
|
|
260
206
|
};
|
|
261
|
-
|
|
262
|
-
dnsCache.set(options.host, {
|
|
207
|
+
dnsCache.set(host, {
|
|
263
208
|
value,
|
|
264
209
|
expires: Date.now() + (options.dnsTtl || DNS_TTL)
|
|
265
210
|
});
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
cached: false
|
|
271
|
-
})
|
|
272
|
-
);
|
|
211
|
+
return callback(null, formatDNSValue(value, {
|
|
212
|
+
servername,
|
|
213
|
+
cached: false
|
|
214
|
+
}));
|
|
273
215
|
});
|
|
274
|
-
}
|
|
216
|
+
}
|
|
217
|
+
catch (lookupErr) {
|
|
275
218
|
if (cached) {
|
|
276
|
-
dnsCache.set(
|
|
219
|
+
dnsCache.set(host, {
|
|
277
220
|
value: cached.value,
|
|
278
221
|
expires: Date.now() + (options.dnsTtl || DNS_TTL)
|
|
279
222
|
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
error: lookupErr
|
|
286
|
-
})
|
|
287
|
-
);
|
|
223
|
+
return callback(null, formatDNSValue(cached.value, {
|
|
224
|
+
servername,
|
|
225
|
+
cached: true,
|
|
226
|
+
error: lookupErr
|
|
227
|
+
}));
|
|
288
228
|
}
|
|
289
229
|
return callback(ipv4Error || ipv6Error || lookupErr);
|
|
290
230
|
}
|
|
@@ -294,14 +234,13 @@ module.exports.resolveHostname = (options, callback) => {
|
|
|
294
234
|
/**
|
|
295
235
|
* Parses connection url to a structured configuration object
|
|
296
236
|
*
|
|
297
|
-
* @param
|
|
298
|
-
* @return
|
|
237
|
+
* @param str Connection url
|
|
238
|
+
* @return Configuration object
|
|
299
239
|
*/
|
|
300
|
-
|
|
240
|
+
export const parseConnectionUrl = (str) => {
|
|
301
241
|
str = str || '';
|
|
302
242
|
const options = {};
|
|
303
243
|
const url = urllib.parse(str, true);
|
|
304
|
-
|
|
305
244
|
switch (url.protocol) {
|
|
306
245
|
case 'smtp:':
|
|
307
246
|
options.secure = false;
|
|
@@ -313,32 +252,25 @@ module.exports.parseConnectionUrl = str => {
|
|
|
313
252
|
options.direct = true;
|
|
314
253
|
break;
|
|
315
254
|
}
|
|
316
|
-
|
|
317
255
|
if (!isNaN(url.port) && Number(url.port)) {
|
|
318
256
|
options.port = Number(url.port);
|
|
319
257
|
}
|
|
320
|
-
|
|
321
258
|
if (url.hostname) {
|
|
322
259
|
options.host = url.hostname;
|
|
323
260
|
}
|
|
324
|
-
|
|
325
|
-
if (url.auth) {
|
|
326
|
-
const auth = url.auth.split(':');
|
|
261
|
+
if (url.username || url.password) {
|
|
327
262
|
options.auth = {
|
|
328
|
-
user:
|
|
329
|
-
pass:
|
|
263
|
+
user: url.username || '',
|
|
264
|
+
pass: url.password || ''
|
|
330
265
|
};
|
|
331
266
|
}
|
|
332
|
-
|
|
333
267
|
Object.keys(url.query || {}).forEach(key => {
|
|
334
268
|
let obj = options;
|
|
335
269
|
let lKey = key;
|
|
336
270
|
let value = url.query[key];
|
|
337
|
-
|
|
338
271
|
if (!isNaN(value)) {
|
|
339
272
|
value = Number(value);
|
|
340
273
|
}
|
|
341
|
-
|
|
342
274
|
switch (value) {
|
|
343
275
|
case 'true':
|
|
344
276
|
value = true;
|
|
@@ -347,7 +279,6 @@ module.exports.parseConnectionUrl = str => {
|
|
|
347
279
|
value = false;
|
|
348
280
|
break;
|
|
349
281
|
}
|
|
350
|
-
|
|
351
282
|
// tls is nested object
|
|
352
283
|
if (key.indexOf('tls.') === 0) {
|
|
353
284
|
lKey = key.substr(4);
|
|
@@ -355,50 +286,45 @@ module.exports.parseConnectionUrl = str => {
|
|
|
355
286
|
options.tls = {};
|
|
356
287
|
}
|
|
357
288
|
obj = options.tls;
|
|
358
|
-
}
|
|
289
|
+
}
|
|
290
|
+
else if (key.indexOf('.') >= 0) {
|
|
359
291
|
// ignore nested properties besides tls
|
|
360
292
|
return;
|
|
361
293
|
}
|
|
362
|
-
|
|
363
294
|
// `in` already keeps "__proto__" out, but only as a side effect of it being an
|
|
364
295
|
// Object.prototype member. Say it, so the protection survives a change to the check
|
|
365
296
|
if (!isProtoKey(lKey) && !(lKey in obj)) {
|
|
366
297
|
obj[lKey] = value;
|
|
367
298
|
}
|
|
368
299
|
});
|
|
369
|
-
|
|
370
300
|
return options;
|
|
371
301
|
};
|
|
372
|
-
|
|
373
|
-
|
|
302
|
+
/** @internal */
|
|
303
|
+
export const _logFunc = (logger, level, defaults, data, message, ...args) => {
|
|
374
304
|
const entry = Object.assign({}, defaults || {}, data || {});
|
|
375
305
|
delete entry.level;
|
|
376
|
-
|
|
377
306
|
let logLevel = level;
|
|
378
307
|
if (typeof logger[logLevel] !== 'function') {
|
|
379
308
|
// Provided logger does not implement this level. Fall back to a
|
|
380
309
|
// lower-severity handler instead of throwing.
|
|
381
310
|
logLevel = ['info', 'debug', 'log', 'trace', 'warn', 'error'].find(name => typeof logger[name] === 'function');
|
|
382
311
|
}
|
|
383
|
-
|
|
384
312
|
if (logLevel) {
|
|
385
313
|
logger[logLevel](entry, message, ...args);
|
|
386
314
|
}
|
|
387
315
|
};
|
|
388
|
-
|
|
389
316
|
/**
|
|
390
317
|
* Returns a bunyan-compatible logger interface. Uses either provided logger or
|
|
391
318
|
* creates a default console logger
|
|
392
319
|
*
|
|
393
|
-
* @param
|
|
394
|
-
* @
|
|
320
|
+
* @param [options] Options object that might include 'logger' value
|
|
321
|
+
* @param [defaults] Fields merged into every log entry, overridden by the fields of the entry itself
|
|
322
|
+
* @return bunyan compatible logger
|
|
395
323
|
*/
|
|
396
|
-
|
|
324
|
+
export const getLogger = (options, defaults) => {
|
|
397
325
|
options = options || {};
|
|
398
|
-
|
|
399
326
|
const response = {};
|
|
400
327
|
const levels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];
|
|
401
|
-
|
|
402
328
|
if (!options.logger) {
|
|
403
329
|
// use vanity logger
|
|
404
330
|
levels.forEach(level => {
|
|
@@ -406,58 +332,49 @@ module.exports.getLogger = (options, defaults) => {
|
|
|
406
332
|
});
|
|
407
333
|
return response;
|
|
408
334
|
}
|
|
409
|
-
|
|
410
335
|
const logger = options.logger === true ? createDefaultLogger(levels) : options.logger;
|
|
411
|
-
|
|
412
336
|
levels.forEach(level => {
|
|
413
|
-
response[level] = (
|
|
414
|
-
|
|
337
|
+
response[level] = (...args) => {
|
|
338
|
+
// the bunyan forms: a data object first, or the message alone
|
|
339
|
+
const data = typeof args[0] === 'string' ? undefined : args.shift();
|
|
340
|
+
_logFunc(logger, level, defaults, data, ...args);
|
|
415
341
|
};
|
|
416
342
|
});
|
|
417
|
-
|
|
418
343
|
return response;
|
|
419
344
|
};
|
|
420
|
-
|
|
421
345
|
/**
|
|
422
346
|
* Wrapper for creating a callback that either resolves or rejects a promise
|
|
423
347
|
* based on input
|
|
424
348
|
*
|
|
425
|
-
* @param
|
|
426
|
-
* @param
|
|
349
|
+
* @param resolve Function to run if callback is called
|
|
350
|
+
* @param reject Function to run if callback ends with an error
|
|
427
351
|
*/
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
module.exports.parseDataURI = uri => {
|
|
352
|
+
export const callbackPromise = (resolve, reject) => function (...args) {
|
|
353
|
+
const err = args.shift();
|
|
354
|
+
if (err) {
|
|
355
|
+
reject(err);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
resolve(...args);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
export const parseDataURI = (uri) => {
|
|
440
362
|
if (typeof uri !== 'string') {
|
|
441
363
|
return null;
|
|
442
364
|
}
|
|
443
|
-
|
|
444
365
|
// Early return for non-data URIs to avoid unnecessary processing
|
|
445
366
|
if (!uri.startsWith('data:')) {
|
|
446
367
|
return null;
|
|
447
368
|
}
|
|
448
|
-
|
|
449
369
|
// Find the first comma safely - this prevents ReDoS
|
|
450
370
|
const commaPos = uri.indexOf(',');
|
|
451
371
|
if (commaPos === -1) {
|
|
452
372
|
return null;
|
|
453
373
|
}
|
|
454
|
-
|
|
455
374
|
const data = uri.substring(commaPos + 1);
|
|
456
375
|
const metaStr = uri.substring('data:'.length, commaPos);
|
|
457
|
-
|
|
458
376
|
let encoding;
|
|
459
377
|
const metaEntries = metaStr.split(';');
|
|
460
|
-
|
|
461
378
|
if (metaEntries.length > 0) {
|
|
462
379
|
const lastEntry = metaEntries[metaEntries.length - 1].toLowerCase().trim();
|
|
463
380
|
// Only recognize valid encoding types to prevent manipulation
|
|
@@ -466,10 +383,8 @@ module.exports.parseDataURI = uri => {
|
|
|
466
383
|
metaEntries.pop();
|
|
467
384
|
}
|
|
468
385
|
}
|
|
469
|
-
|
|
470
386
|
const contentType = metaEntries.length > 0 ? metaEntries.shift() : 'application/octet-stream';
|
|
471
387
|
const params = {};
|
|
472
|
-
|
|
473
388
|
for (let i = 0; i < metaEntries.length; i++) {
|
|
474
389
|
const entry = metaEntries[i];
|
|
475
390
|
const sepPos = entry.indexOf('=');
|
|
@@ -482,23 +397,24 @@ module.exports.parseDataURI = uri => {
|
|
|
482
397
|
}
|
|
483
398
|
}
|
|
484
399
|
}
|
|
485
|
-
|
|
486
400
|
// Decode data based on encoding with proper error handling
|
|
487
401
|
let bufferData;
|
|
488
402
|
try {
|
|
489
403
|
if (encoding === 'base64') {
|
|
490
404
|
bufferData = Buffer.from(data, 'base64');
|
|
491
|
-
}
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
492
407
|
try {
|
|
493
408
|
bufferData = Buffer.from(decodeURIComponent(data));
|
|
494
|
-
}
|
|
409
|
+
}
|
|
410
|
+
catch (_decodeError) {
|
|
495
411
|
bufferData = Buffer.from(data);
|
|
496
412
|
}
|
|
497
413
|
}
|
|
498
|
-
}
|
|
414
|
+
}
|
|
415
|
+
catch (_bufferError) {
|
|
499
416
|
bufferData = Buffer.alloc(0);
|
|
500
417
|
}
|
|
501
|
-
|
|
502
418
|
return {
|
|
503
419
|
data: bufferData,
|
|
504
420
|
encoding: encoding || null,
|
|
@@ -506,53 +422,31 @@ module.exports.parseDataURI = uri => {
|
|
|
506
422
|
params
|
|
507
423
|
};
|
|
508
424
|
};
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* Resolves a String or a Buffer value for content value. Useful if the value
|
|
512
|
-
* is a Stream or a file or an URL. If the value is a Stream, overwrites
|
|
513
|
-
* the stream object with the resolved value (you can't stream a value twice).
|
|
514
|
-
*
|
|
515
|
-
* This is useful when you want to create a plugin that needs a content value,
|
|
516
|
-
* for example the `html` or `text` value as a String or a Buffer but not as
|
|
517
|
-
* a file path or an URL.
|
|
518
|
-
*
|
|
519
|
-
* @param {Object} data An object or an Array you want to resolve an element for
|
|
520
|
-
* @param {String|Number} key Property name or an Array index
|
|
521
|
-
* @param {Object} [options] Optional access policy: { disableFileAccess, disableUrlAccess }
|
|
522
|
-
* @param {Function} callback Callback function with (err, value)
|
|
523
|
-
*/
|
|
524
|
-
module.exports.resolveContent = (data, key, options, callback) => {
|
|
425
|
+
export function resolveContent(data, key, options, callback) {
|
|
525
426
|
// options is optional; support the legacy resolveContent(data, key, callback) signature
|
|
526
427
|
if (!callback && typeof options === 'function') {
|
|
527
428
|
callback = options;
|
|
528
429
|
options = false;
|
|
529
430
|
}
|
|
530
431
|
options = options || {};
|
|
531
|
-
|
|
532
432
|
let promise;
|
|
533
|
-
|
|
534
433
|
if (!callback) {
|
|
535
434
|
promise = new Promise((resolve, reject) => {
|
|
536
|
-
callback =
|
|
435
|
+
callback = callbackPromise(resolve, reject);
|
|
537
436
|
});
|
|
538
437
|
}
|
|
539
|
-
|
|
540
438
|
resolveContentValue(data, key, options, callback);
|
|
541
|
-
|
|
542
439
|
return promise;
|
|
543
|
-
}
|
|
544
|
-
|
|
440
|
+
}
|
|
545
441
|
function resolveContentValue(data, key, options, callback) {
|
|
546
442
|
let content = (data && data[key] && data[key].content) || data[key];
|
|
547
443
|
const encoding = ((typeof data[key] === 'object' && data[key].encoding) || 'utf8')
|
|
548
444
|
.toString()
|
|
549
445
|
.toLowerCase()
|
|
550
446
|
.replace(/[-_\s]/g, '');
|
|
551
|
-
|
|
552
447
|
if (!content) {
|
|
553
448
|
return callback(null, content);
|
|
554
449
|
}
|
|
555
|
-
|
|
556
450
|
if (typeof content === 'object') {
|
|
557
451
|
if (typeof content.pipe === 'function') {
|
|
558
452
|
return resolveStream(content, (err, value) => {
|
|
@@ -563,75 +457,77 @@ function resolveContentValue(data, key, options, callback) {
|
|
|
563
457
|
// to replace the stream object with the streaming result
|
|
564
458
|
if (data[key].content) {
|
|
565
459
|
data[key].content = value;
|
|
566
|
-
}
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
567
462
|
data[key] = value;
|
|
568
463
|
}
|
|
569
464
|
callback(null, value);
|
|
570
465
|
});
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
|
|
466
|
+
}
|
|
467
|
+
else if (/^data:/i.test(content.path || content.href)) {
|
|
468
|
+
const parsedDataUri = parseDataURI(content.path || content.href);
|
|
574
469
|
return callback(null, parsedDataUri && parsedDataUri.data ? parsedDataUri.data : Buffer.alloc(0));
|
|
575
|
-
}
|
|
470
|
+
}
|
|
471
|
+
else if (content.href || /^https?:\/\//i.test(content.path)) {
|
|
576
472
|
// An href is always a URL, and so is a path that looks like one. Let nmfetch
|
|
577
473
|
// decide whether it is fetchable, it validates the parsed URL. Testing the raw
|
|
578
474
|
// string here instead would let a file: href fall through to the "return as is"
|
|
579
475
|
// default below and travel on inside the resolved message.
|
|
580
476
|
const url = content.href || content.path;
|
|
581
477
|
if (options.disableUrlAccess) {
|
|
582
|
-
|
|
478
|
+
setImmediate(() => {
|
|
583
479
|
const err = new Error('Url access rejected for ' + url);
|
|
584
480
|
err.code = errors.EURLACCESS;
|
|
585
481
|
callback(err);
|
|
586
482
|
});
|
|
483
|
+
return;
|
|
587
484
|
}
|
|
588
485
|
return resolveStream(nmfetch(url, { headers: content.httpHeaders, tls: content.tls }), callback);
|
|
589
|
-
}
|
|
486
|
+
}
|
|
487
|
+
else if (content.path) {
|
|
590
488
|
if (options.disableFileAccess) {
|
|
591
|
-
|
|
489
|
+
setImmediate(() => {
|
|
592
490
|
const err = new Error('File access rejected for ' + content.path);
|
|
593
491
|
err.code = errors.EFILEACCESS;
|
|
594
492
|
callback(err);
|
|
595
493
|
});
|
|
494
|
+
return;
|
|
596
495
|
}
|
|
597
496
|
return resolveStream(fs.createReadStream(content.path), callback);
|
|
598
497
|
}
|
|
599
498
|
}
|
|
600
|
-
|
|
601
499
|
if (typeof data[key].content === 'string' && !['utf8', 'usascii', 'ascii'].includes(encoding)) {
|
|
602
500
|
content = Buffer.from(data[key].content, encoding);
|
|
603
501
|
}
|
|
604
|
-
|
|
605
502
|
// default action, return as is
|
|
606
503
|
setImmediate(() => callback(null, content));
|
|
607
504
|
}
|
|
608
|
-
|
|
609
505
|
/**
|
|
610
506
|
* Copies properties from source objects to target objects
|
|
611
507
|
*/
|
|
612
|
-
|
|
613
|
-
const args = Array.from(arguments);
|
|
508
|
+
export const assign = function (...args) {
|
|
614
509
|
const target = args.shift() || {};
|
|
615
|
-
|
|
616
510
|
args.forEach(source => {
|
|
617
511
|
Object.keys(source || {}).forEach(key => {
|
|
618
512
|
if (isProtoKey(key)) {
|
|
619
513
|
return;
|
|
620
514
|
}
|
|
621
|
-
if (['tls', 'auth'].includes(key) &&
|
|
515
|
+
if (['tls', 'auth'].includes(key) &&
|
|
516
|
+
source[key] &&
|
|
517
|
+
typeof source[key] === 'object') {
|
|
622
518
|
// tls and auth are special keys that need to be enumerated separately
|
|
623
519
|
// other objects are passed as is. Enumerating is a copy of user supplied
|
|
624
520
|
// keys just like the loop above, so it gets the same treatment
|
|
625
|
-
target[key] =
|
|
626
|
-
}
|
|
521
|
+
target[key] = copyOwnKeys(target[key] || {}, source[key]);
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
627
524
|
target[key] = source[key];
|
|
628
525
|
}
|
|
629
526
|
});
|
|
630
527
|
});
|
|
631
528
|
return target;
|
|
632
529
|
};
|
|
633
|
-
|
|
634
|
-
module.exports.encodeXText = str => {
|
|
530
|
+
export const encodeXText = (str) => {
|
|
635
531
|
// ! 0x21
|
|
636
532
|
// + 0x2B
|
|
637
533
|
// = 0x3D
|
|
@@ -645,33 +541,30 @@ module.exports.encodeXText = str => {
|
|
|
645
541
|
const c = buf[i];
|
|
646
542
|
if (c < 0x21 || c > 0x7e || c === 0x2b || c === 0x3d) {
|
|
647
543
|
result += '+' + (c < 0x10 ? '0' : '') + c.toString(16).toUpperCase();
|
|
648
|
-
}
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
649
546
|
result += String.fromCharCode(c);
|
|
650
547
|
}
|
|
651
548
|
}
|
|
652
549
|
return result;
|
|
653
550
|
};
|
|
654
|
-
|
|
655
551
|
/**
|
|
656
552
|
* Streams a stream value into a Buffer
|
|
657
553
|
*
|
|
658
|
-
* @param
|
|
659
|
-
* @param
|
|
554
|
+
* @param stream Readable stream
|
|
555
|
+
* @param callback Callback function with (err, value)
|
|
660
556
|
*/
|
|
661
557
|
function resolveStream(stream, callback) {
|
|
662
558
|
let responded = false;
|
|
663
559
|
const chunks = [];
|
|
664
560
|
let chunklen = 0;
|
|
665
|
-
|
|
666
561
|
stream.on('error', err => {
|
|
667
562
|
if (responded) {
|
|
668
563
|
return;
|
|
669
564
|
}
|
|
670
|
-
|
|
671
565
|
responded = true;
|
|
672
566
|
callback(err);
|
|
673
567
|
});
|
|
674
|
-
|
|
675
568
|
stream.on('readable', () => {
|
|
676
569
|
let chunk;
|
|
677
570
|
while ((chunk = stream.read()) !== null) {
|
|
@@ -679,33 +572,29 @@ function resolveStream(stream, callback) {
|
|
|
679
572
|
chunklen += chunk.length;
|
|
680
573
|
}
|
|
681
574
|
});
|
|
682
|
-
|
|
683
575
|
stream.on('end', () => {
|
|
684
576
|
if (responded) {
|
|
685
577
|
return;
|
|
686
578
|
}
|
|
687
579
|
responded = true;
|
|
688
|
-
|
|
689
580
|
let value;
|
|
690
|
-
|
|
691
581
|
try {
|
|
692
582
|
value = Buffer.concat(chunks, chunklen);
|
|
693
|
-
}
|
|
583
|
+
}
|
|
584
|
+
catch (E) {
|
|
694
585
|
return callback(E);
|
|
695
586
|
}
|
|
696
587
|
callback(null, value);
|
|
697
588
|
});
|
|
698
589
|
}
|
|
699
|
-
|
|
700
590
|
/**
|
|
701
591
|
* Generates a bunyan-like logger that prints to console
|
|
702
592
|
*
|
|
703
|
-
* @returns
|
|
593
|
+
* @returns Bunyan logger instance
|
|
704
594
|
*/
|
|
705
595
|
function createDefaultLogger(levels) {
|
|
706
596
|
const levelMaxLen = levels.reduce((max, level) => Math.max(max, level.length), 0);
|
|
707
597
|
const levelNames = new Map();
|
|
708
|
-
|
|
709
598
|
levels.forEach(level => {
|
|
710
599
|
let levelName = level.toUpperCase();
|
|
711
600
|
if (levelName.length < levelMaxLen) {
|
|
@@ -713,35 +602,30 @@ function createDefaultLogger(levels) {
|
|
|
713
602
|
}
|
|
714
603
|
levelNames.set(level, levelName);
|
|
715
604
|
});
|
|
716
|
-
|
|
717
605
|
const print = (level, entry, message, ...args) => {
|
|
718
606
|
let prefix = '';
|
|
719
607
|
if (entry) {
|
|
720
608
|
if (entry.tnx === 'server') {
|
|
721
609
|
prefix = 'S: ';
|
|
722
|
-
}
|
|
610
|
+
}
|
|
611
|
+
else if (entry.tnx === 'client') {
|
|
723
612
|
prefix = 'C: ';
|
|
724
613
|
}
|
|
725
|
-
|
|
726
614
|
if (entry.sid) {
|
|
727
615
|
prefix = '[' + entry.sid + '] ' + prefix;
|
|
728
616
|
}
|
|
729
|
-
|
|
730
617
|
if (entry.cid) {
|
|
731
618
|
prefix = '[#' + entry.cid + '] ' + prefix;
|
|
732
619
|
}
|
|
733
620
|
}
|
|
734
|
-
|
|
735
621
|
message = util.format(message, ...args);
|
|
736
|
-
message.split(/\r?\n/).forEach(line => {
|
|
622
|
+
message.split(/\r?\n/).forEach((line) => {
|
|
737
623
|
console.log('[%s] %s %s', new Date().toISOString().substr(0, 19).replace(/T/, ' '), levelNames.get(level), prefix + line);
|
|
738
624
|
});
|
|
739
625
|
};
|
|
740
|
-
|
|
741
626
|
const logger = {};
|
|
742
627
|
levels.forEach(level => {
|
|
743
628
|
logger[level] = print.bind(null, level);
|
|
744
629
|
});
|
|
745
|
-
|
|
746
630
|
return logger;
|
|
747
631
|
}
|