aiplang 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/bin/aiplang.js +7 -7
  2. package/package.json +7 -5
  3. package/server/node_modules/.package-lock.json +9 -0
  4. package/server/node_modules/nodemailer/.gitattributes +6 -0
  5. package/server/node_modules/nodemailer/.ncurc.js +9 -0
  6. package/server/node_modules/nodemailer/.prettierignore +8 -0
  7. package/server/node_modules/nodemailer/.prettierrc +12 -0
  8. package/server/node_modules/nodemailer/.prettierrc.js +10 -0
  9. package/server/node_modules/nodemailer/.release-please-config.json +9 -0
  10. package/server/node_modules/nodemailer/CHANGELOG.md +976 -0
  11. package/server/node_modules/nodemailer/CODE_OF_CONDUCT.md +76 -0
  12. package/server/node_modules/nodemailer/LICENSE +16 -0
  13. package/server/node_modules/nodemailer/README.md +86 -0
  14. package/server/node_modules/nodemailer/SECURITY.txt +22 -0
  15. package/server/node_modules/nodemailer/eslint.config.js +88 -0
  16. package/server/node_modules/nodemailer/lib/addressparser/index.js +382 -0
  17. package/server/node_modules/nodemailer/lib/base64/index.js +140 -0
  18. package/server/node_modules/nodemailer/lib/dkim/index.js +245 -0
  19. package/server/node_modules/nodemailer/lib/dkim/message-parser.js +154 -0
  20. package/server/node_modules/nodemailer/lib/dkim/relaxed-body.js +154 -0
  21. package/server/node_modules/nodemailer/lib/dkim/sign.js +116 -0
  22. package/server/node_modules/nodemailer/lib/errors.js +58 -0
  23. package/server/node_modules/nodemailer/lib/fetch/cookies.js +276 -0
  24. package/server/node_modules/nodemailer/lib/fetch/index.js +278 -0
  25. package/server/node_modules/nodemailer/lib/json-transport/index.js +82 -0
  26. package/server/node_modules/nodemailer/lib/mail-composer/index.js +599 -0
  27. package/server/node_modules/nodemailer/lib/mailer/index.js +446 -0
  28. package/server/node_modules/nodemailer/lib/mailer/mail-message.js +312 -0
  29. package/server/node_modules/nodemailer/lib/mime-funcs/index.js +610 -0
  30. package/server/node_modules/nodemailer/lib/mime-funcs/mime-types.js +2109 -0
  31. package/server/node_modules/nodemailer/lib/mime-node/index.js +1334 -0
  32. package/server/node_modules/nodemailer/lib/mime-node/last-newline.js +33 -0
  33. package/server/node_modules/nodemailer/lib/mime-node/le-unix.js +40 -0
  34. package/server/node_modules/nodemailer/lib/mime-node/le-windows.js +49 -0
  35. package/server/node_modules/nodemailer/lib/nodemailer.js +151 -0
  36. package/server/node_modules/nodemailer/lib/punycode/index.js +460 -0
  37. package/server/node_modules/nodemailer/lib/qp/index.js +230 -0
  38. package/server/node_modules/nodemailer/lib/sendmail-transport/index.js +205 -0
  39. package/server/node_modules/nodemailer/lib/ses-transport/index.js +223 -0
  40. package/server/node_modules/nodemailer/lib/shared/index.js +698 -0
  41. package/server/node_modules/nodemailer/lib/smtp-connection/data-stream.js +105 -0
  42. package/server/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +144 -0
  43. package/server/node_modules/nodemailer/lib/smtp-connection/index.js +1903 -0
  44. package/server/node_modules/nodemailer/lib/smtp-pool/index.js +641 -0
  45. package/server/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +256 -0
  46. package/server/node_modules/nodemailer/lib/smtp-transport/index.js +402 -0
  47. package/server/node_modules/nodemailer/lib/stream-transport/index.js +135 -0
  48. package/server/node_modules/nodemailer/lib/well-known/index.js +47 -0
  49. package/server/node_modules/nodemailer/lib/well-known/services.json +619 -0
  50. package/server/node_modules/nodemailer/lib/xoauth2/index.js +436 -0
  51. package/server/node_modules/nodemailer/package.json +48 -0
  52. package/server/server.js +686 -865
  53. /package/{FLUX-PROJECT-KNOWLEDGE.md → aiplang-knowledge.md} +0 -0
@@ -0,0 +1,436 @@
1
+ 'use strict';
2
+
3
+ const { Stream } = require('stream');
4
+ const nmfetch = require('../fetch');
5
+ const crypto = require('crypto');
6
+ const shared = require('../shared');
7
+ const errors = require('../errors');
8
+
9
+ /**
10
+ * XOAUTH2 access_token generator for Gmail.
11
+ * Create client ID for web applications in Google API console to use it.
12
+ * See Offline Access for receiving the needed refreshToken for an user
13
+ * https://developers.google.com/accounts/docs/OAuth2WebServer#offline
14
+ *
15
+ * Usage for generating access tokens with a custom method using provisionCallback:
16
+ * provisionCallback(user, renew, callback)
17
+ * * user is the username to get the token for
18
+ * * renew is a boolean that if true indicates that existing token failed and needs to be renewed
19
+ * * callback is the callback to run with (error, accessToken [, expires])
20
+ * * accessToken is a string
21
+ * * expires is an optional expire time in milliseconds
22
+ * If provisionCallback is used, then Nodemailer does not try to attempt generating the token by itself
23
+ *
24
+ * @constructor
25
+ * @param {Object} options Client information for token generation
26
+ * @param {String} options.user User e-mail address
27
+ * @param {String} options.clientId Client ID value
28
+ * @param {String} options.clientSecret Client secret value
29
+ * @param {String} options.refreshToken Refresh token for an user
30
+ * @param {String} options.accessUrl Endpoint for token generation, defaults to 'https://accounts.google.com/o/oauth2/token'
31
+ * @param {String} options.accessToken An existing valid accessToken
32
+ * @param {String} options.privateKey Private key for JSW
33
+ * @param {Number} options.expires Optional Access Token expire time in ms
34
+ * @param {Number} options.timeout Optional TTL for Access Token in seconds
35
+ * @param {Function} options.provisionCallback Function to run when a new access token is required
36
+ */
37
+ class XOAuth2 extends Stream {
38
+ constructor(options, logger) {
39
+ super();
40
+
41
+ this.options = options || {};
42
+
43
+ if (options && options.serviceClient) {
44
+ if (!options.privateKey || !options.user) {
45
+ const err = new Error('Options "privateKey" and "user" are required for service account!');
46
+ err.code = errors.EOAUTH2;
47
+ setImmediate(() => this.emit('error', err));
48
+ return;
49
+ }
50
+
51
+ const serviceRequestTimeout = Math.min(Math.max(Number(this.options.serviceRequestTimeout) || 0, 0), 3600);
52
+ this.options.serviceRequestTimeout = serviceRequestTimeout || 5 * 60;
53
+ }
54
+
55
+ this.logger = shared.getLogger(
56
+ {
57
+ logger
58
+ },
59
+ {
60
+ component: this.options.component || 'OAuth2'
61
+ }
62
+ );
63
+
64
+ this.provisionCallback = typeof this.options.provisionCallback === 'function' ? this.options.provisionCallback : false;
65
+
66
+ this.options.accessUrl = this.options.accessUrl || 'https://accounts.google.com/o/oauth2/token';
67
+ this.options.customHeaders = this.options.customHeaders || {};
68
+ this.options.customParams = this.options.customParams || {};
69
+
70
+ this.accessToken = this.options.accessToken || false;
71
+
72
+ if (this.options.expires && Number(this.options.expires)) {
73
+ this.expires = this.options.expires;
74
+ } else {
75
+ const timeout = Math.max(Number(this.options.timeout) || 0, 0);
76
+ this.expires = (timeout && Date.now() + timeout * 1000) || 0;
77
+ }
78
+
79
+ this.renewing = false; // Track if renewal is in progress
80
+ this.renewalQueue = []; // Queue for pending requests during renewal
81
+ }
82
+
83
+ /**
84
+ * Returns or generates (if previous has expired) a XOAuth2 token
85
+ *
86
+ * @param {Boolean} renew If false then use cached access token (if available)
87
+ * @param {Function} callback Callback function with error object and token string
88
+ */
89
+ getToken(renew, callback) {
90
+ if (!renew && this.accessToken && (!this.expires || this.expires > Date.now())) {
91
+ this.logger.debug(
92
+ {
93
+ tnx: 'OAUTH2',
94
+ user: this.options.user,
95
+ action: 'reuse'
96
+ },
97
+ 'Reusing existing access token for %s',
98
+ this.options.user
99
+ );
100
+ return callback(null, this.accessToken);
101
+ }
102
+
103
+ // check if it is possible to renew, if not, return the current token or error
104
+ if (!this.provisionCallback && !this.options.refreshToken && !this.options.serviceClient) {
105
+ if (this.accessToken) {
106
+ this.logger.debug(
107
+ {
108
+ tnx: 'OAUTH2',
109
+ user: this.options.user,
110
+ action: 'reuse'
111
+ },
112
+ 'Reusing existing access token (no refresh capability) for %s',
113
+ this.options.user
114
+ );
115
+ return callback(null, this.accessToken);
116
+ }
117
+ this.logger.error(
118
+ {
119
+ tnx: 'OAUTH2',
120
+ user: this.options.user,
121
+ action: 'renew'
122
+ },
123
+ 'Cannot renew access token for %s: No refresh mechanism available',
124
+ this.options.user
125
+ );
126
+ const err = new Error("Can't create new access token for user");
127
+ err.code = errors.EOAUTH2;
128
+ return callback(err);
129
+ }
130
+
131
+ // If renewal already in progress, queue this request instead of starting another
132
+ if (this.renewing) {
133
+ return this.renewalQueue.push({ renew, callback });
134
+ }
135
+
136
+ this.renewing = true;
137
+
138
+ // Handles token renewal completion - processes queued requests and cleans up
139
+ const generateCallback = (err, accessToken) => {
140
+ this.renewalQueue.forEach(item => item.callback(err, accessToken));
141
+ this.renewalQueue = [];
142
+ this.renewing = false;
143
+
144
+ if (err) {
145
+ this.logger.error(
146
+ {
147
+ err,
148
+ tnx: 'OAUTH2',
149
+ user: this.options.user,
150
+ action: 'renew'
151
+ },
152
+ 'Failed generating new Access Token for %s',
153
+ this.options.user
154
+ );
155
+ } else {
156
+ this.logger.info(
157
+ {
158
+ tnx: 'OAUTH2',
159
+ user: this.options.user,
160
+ action: 'renew'
161
+ },
162
+ 'Generated new Access Token for %s',
163
+ this.options.user
164
+ );
165
+ }
166
+ // Complete original request
167
+ callback(err, accessToken);
168
+ };
169
+
170
+ if (this.provisionCallback) {
171
+ this.provisionCallback(this.options.user, !!renew, (err, accessToken, expires) => {
172
+ if (!err && accessToken) {
173
+ this.accessToken = accessToken;
174
+ this.expires = expires || 0;
175
+ }
176
+ generateCallback(err, accessToken);
177
+ });
178
+ } else {
179
+ this.generateToken(generateCallback);
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Updates token values
185
+ *
186
+ * @param {String} accessToken New access token
187
+ * @param {Number} timeout Access token lifetime in seconds
188
+ *
189
+ * Emits 'token': { user: User email-address, accessToken: the new accessToken, timeout: TTL in seconds}
190
+ */
191
+ updateToken(accessToken, timeout) {
192
+ this.accessToken = accessToken;
193
+ timeout = Math.max(Number(timeout) || 0, 0);
194
+ this.expires = (timeout && Date.now() + timeout * 1000) || 0;
195
+
196
+ this.emit('token', {
197
+ user: this.options.user,
198
+ accessToken: accessToken || '',
199
+ expires: this.expires
200
+ });
201
+ }
202
+
203
+ /**
204
+ * Generates a new XOAuth2 token with the credentials provided at initialization
205
+ *
206
+ * @param {Function} callback Callback function with error object and token string
207
+ */
208
+ generateToken(callback) {
209
+ let urlOptions;
210
+ let loggedUrlOptions;
211
+ if (this.options.serviceClient) {
212
+ // service account - https://developers.google.com/identity/protocols/OAuth2ServiceAccount
213
+ const iat = Math.floor(Date.now() / 1000); // unix time
214
+ const tokenData = {
215
+ iss: this.options.serviceClient,
216
+ scope: this.options.scope || 'https://mail.google.com/',
217
+ sub: this.options.user,
218
+ aud: this.options.accessUrl,
219
+ iat,
220
+ exp: iat + this.options.serviceRequestTimeout
221
+ };
222
+ let token;
223
+ try {
224
+ token = this.jwtSignRS256(tokenData);
225
+ } catch (_err) {
226
+ const err = new Error("Can't generate token. Check your auth options");
227
+ err.code = errors.EOAUTH2;
228
+ return callback(err);
229
+ }
230
+
231
+ urlOptions = {
232
+ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
233
+ assertion: token
234
+ };
235
+
236
+ loggedUrlOptions = {
237
+ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
238
+ assertion: tokenData
239
+ };
240
+ } else {
241
+ if (!this.options.refreshToken) {
242
+ const err = new Error("Can't create new access token for user");
243
+ err.code = errors.EOAUTH2;
244
+ return callback(err);
245
+ }
246
+
247
+ // web app - https://developers.google.com/identity/protocols/OAuth2WebServer
248
+ urlOptions = {
249
+ client_id: this.options.clientId || '',
250
+ client_secret: this.options.clientSecret || '',
251
+ refresh_token: this.options.refreshToken,
252
+ grant_type: 'refresh_token'
253
+ };
254
+
255
+ loggedUrlOptions = {
256
+ client_id: this.options.clientId || '',
257
+ client_secret: (this.options.clientSecret || '').substr(0, 6) + '...',
258
+ refresh_token: (this.options.refreshToken || '').substr(0, 6) + '...',
259
+ grant_type: 'refresh_token'
260
+ };
261
+ }
262
+
263
+ Object.assign(urlOptions, this.options.customParams);
264
+ Object.assign(loggedUrlOptions, this.options.customParams);
265
+
266
+ this.logger.debug(
267
+ {
268
+ tnx: 'OAUTH2',
269
+ user: this.options.user,
270
+ action: 'generate'
271
+ },
272
+ 'Requesting token using: %s',
273
+ JSON.stringify(loggedUrlOptions)
274
+ );
275
+
276
+ this.postRequest(this.options.accessUrl, urlOptions, this.options, (error, body) => {
277
+ let data;
278
+
279
+ if (error) {
280
+ return callback(error);
281
+ }
282
+
283
+ try {
284
+ data = JSON.parse(body.toString());
285
+ } catch (E) {
286
+ return callback(E);
287
+ }
288
+
289
+ if (!data || typeof data !== 'object') {
290
+ this.logger.debug(
291
+ {
292
+ tnx: 'OAUTH2',
293
+ user: this.options.user,
294
+ action: 'post'
295
+ },
296
+ 'Response: %s',
297
+ (body || '').toString()
298
+ );
299
+ const err = new Error('Invalid authentication response');
300
+ err.code = errors.EOAUTH2;
301
+ return callback(err);
302
+ }
303
+
304
+ const logData = Object.assign({}, data);
305
+ if (logData.access_token) {
306
+ logData.access_token = (logData.access_token || '').toString().substr(0, 6) + '...';
307
+ }
308
+
309
+ this.logger.debug(
310
+ {
311
+ tnx: 'OAUTH2',
312
+ user: this.options.user,
313
+ action: 'post'
314
+ },
315
+ 'Response: %s',
316
+ JSON.stringify(logData)
317
+ );
318
+
319
+ if (data.error) {
320
+ // Error Response : https://tools.ietf.org/html/rfc6749#section-5.2
321
+ let errorMessage = data.error;
322
+ if (data.error_description) {
323
+ errorMessage += ': ' + data.error_description;
324
+ }
325
+ if (data.error_uri) {
326
+ errorMessage += ' (' + data.error_uri + ')';
327
+ }
328
+ const err = new Error(errorMessage);
329
+ err.code = errors.EOAUTH2;
330
+ return callback(err);
331
+ }
332
+
333
+ if (data.access_token) {
334
+ this.updateToken(data.access_token, data.expires_in);
335
+ return callback(null, this.accessToken);
336
+ }
337
+
338
+ const err = new Error('No access token');
339
+ err.code = errors.EOAUTH2;
340
+ return callback(err);
341
+ });
342
+ }
343
+
344
+ /**
345
+ * Converts an access_token and user id into a base64 encoded XOAuth2 token
346
+ *
347
+ * @param {String} [accessToken] Access token string
348
+ * @return {String} Base64 encoded token for IMAP or SMTP login
349
+ */
350
+ buildXOAuth2Token(accessToken) {
351
+ const authData = ['user=' + (this.options.user || ''), 'auth=Bearer ' + (accessToken || this.accessToken), '', ''];
352
+ return Buffer.from(authData.join('\x01'), 'utf-8').toString('base64');
353
+ }
354
+
355
+ /**
356
+ * Custom POST request handler.
357
+ * This is only needed to keep paths short in Windows – usually this module
358
+ * is a dependency of a dependency and if it tries to require something
359
+ * like the request module the paths get way too long to handle for Windows.
360
+ * As we do only a simple POST request we do not actually require complicated
361
+ * logic support (no redirects, no nothing) anyway.
362
+ *
363
+ * @param {String} url Url to POST to
364
+ * @param {String|Buffer} payload Payload to POST
365
+ * @param {Function} callback Callback function with (err, buff)
366
+ */
367
+ postRequest(url, payload, params, callback) {
368
+ let returned = false;
369
+
370
+ const chunks = [];
371
+ let chunklen = 0;
372
+
373
+ const req = nmfetch(url, {
374
+ method: 'post',
375
+ headers: params.customHeaders,
376
+ body: payload,
377
+ allowErrorResponse: true
378
+ });
379
+
380
+ req.on('readable', () => {
381
+ let chunk;
382
+ while ((chunk = req.read()) !== null) {
383
+ chunks.push(chunk);
384
+ chunklen += chunk.length;
385
+ }
386
+ });
387
+
388
+ req.once('error', err => {
389
+ if (returned) {
390
+ return;
391
+ }
392
+ returned = true;
393
+ return callback(err);
394
+ });
395
+
396
+ req.once('end', () => {
397
+ if (returned) {
398
+ return;
399
+ }
400
+ returned = true;
401
+ return callback(null, Buffer.concat(chunks, chunklen));
402
+ });
403
+ }
404
+
405
+ /**
406
+ * Encodes a buffer or a string into Base64url format
407
+ *
408
+ * @param {Buffer|String} data The data to convert
409
+ * @return {String} The encoded string
410
+ */
411
+ toBase64URL(data) {
412
+ if (typeof data === 'string') {
413
+ data = Buffer.from(data);
414
+ }
415
+
416
+ return data
417
+ .toString('base64')
418
+ .replace(/[=]+/g, '') // remove '='s
419
+ .replace(/\+/g, '-') // '+' → '-'
420
+ .replace(/\//g, '_'); // '/' → '_'
421
+ }
422
+
423
+ /**
424
+ * Creates a JSON Web Token signed with RS256 (SHA256 + RSA)
425
+ *
426
+ * @param {Object} payload The payload to include in the generated token
427
+ * @return {String} The generated and signed token
428
+ */
429
+ jwtSignRS256(payload) {
430
+ payload = ['{"alg":"RS256","typ":"JWT"}', JSON.stringify(payload)].map(val => this.toBase64URL(val)).join('.');
431
+ const signature = crypto.createSign('RSA-SHA256').update(payload).sign(this.options.privateKey);
432
+ return payload + '.' + this.toBase64URL(signature);
433
+ }
434
+ }
435
+
436
+ module.exports = XOAuth2;
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "nodemailer",
3
+ "version": "8.0.3",
4
+ "description": "Easy as cake e-mail sending from your Node.js applications",
5
+ "main": "lib/nodemailer.js",
6
+ "scripts": {
7
+ "test": "node --test --test-concurrency=1 test/**/*.test.js test/**/*-test.js",
8
+ "test:coverage": "c8 node --test --test-concurrency=1 test/**/*.test.js test/**/*-test.js",
9
+ "format": "prettier --write \"**/*.{js,json,md}\"",
10
+ "format:check": "prettier --check \"**/*.{js,json,md}\"",
11
+ "lint": "eslint .",
12
+ "lint:fix": "eslint . --fix",
13
+ "update": "rm -rf node_modules/ package-lock.json && ncu -u && npm install",
14
+ "test:syntax": "docker run --rm -v \"$PWD:/app:ro\" -w /app node:6-alpine node test/syntax-compat.js"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/nodemailer/nodemailer.git"
19
+ },
20
+ "keywords": [
21
+ "Nodemailer"
22
+ ],
23
+ "author": "Andris Reinman",
24
+ "license": "MIT-0",
25
+ "bugs": {
26
+ "url": "https://github.com/nodemailer/nodemailer/issues"
27
+ },
28
+ "homepage": "https://nodemailer.com/",
29
+ "devDependencies": {
30
+ "@aws-sdk/client-sesv2": "3.1011.0",
31
+ "bunyan": "1.8.15",
32
+ "c8": "11.0.0",
33
+ "eslint": "10.0.3",
34
+ "eslint-config-prettier": "10.1.8",
35
+ "globals": "17.4.0",
36
+ "libbase64": "1.3.0",
37
+ "libmime": "5.3.7",
38
+ "libqp": "2.1.1",
39
+ "nodemailer-ntlm-auth": "1.0.4",
40
+ "prettier": "3.8.1",
41
+ "proxy": "1.0.2",
42
+ "proxy-test-server": "1.0.0",
43
+ "smtp-server": "3.18.1"
44
+ },
45
+ "engines": {
46
+ "node": ">=6.0.0"
47
+ }
48
+ }