@nocobase/plugin-workflow-mailer 2.4.0-alpha.1 → 2.4.0-alpha.11
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/dist/joi-browser.min.js +1 -1
- package/dist/node_modules/joi/lib/index.js +1 -1
- package/dist/node_modules/joi/lib/messages.js +35 -6
- package/dist/node_modules/joi/lib/types/keys.js +18 -1
- package/dist/node_modules/joi/lib/types/link.js +18 -2
- package/dist/node_modules/joi/lib/types/string.js +2 -2
- 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 +63 -112
- 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/dist/esm/addressparser/index.js +786 -0
- package/dist/node_modules/nodemailer/dist/esm/base64/index.d.ts +36 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/base64/index.js +39 -68
- package/dist/node_modules/nodemailer/dist/esm/dkim/index.d.ts +52 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/dkim/index.js +62 -92
- package/dist/node_modules/nodemailer/dist/esm/dkim/message-parser.d.ts +48 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/message-parser.js +176 -0
- 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/dist/esm/dkim/sign.js +125 -0
- package/dist/node_modules/nodemailer/dist/esm/errors.d.ts +96 -0
- package/dist/node_modules/nodemailer/dist/esm/errors.js +67 -0
- 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/dist/esm/fetch/index.js +344 -0
- package/dist/node_modules/nodemailer/dist/esm/json-transport/index.d.ts +64 -0
- package/dist/node_modules/nodemailer/dist/esm/json-transport/index.js +62 -0
- 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 +283 -275
- package/dist/node_modules/nodemailer/dist/esm/mailer/index.d.ts +237 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/index.js +151 -205
- 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 +111 -125
- 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 +43 -49
- 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 +576 -437
- 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 +7 -15
- 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 -16
- 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 +59 -77
- package/dist/node_modules/nodemailer/dist/esm/sendmail-transport/index.d.ts +69 -0
- package/dist/node_modules/nodemailer/dist/esm/sendmail-transport/index.js +170 -0
- 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/dist/esm/shared/index.js +631 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/objects.d.ts +23 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/objects.js +38 -0
- 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/dist/esm/smtp-connection/http-proxy-client.js +149 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/index.d.ts +416 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/index.js +1797 -0
- 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 +195 -314
- 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 +70 -107
- package/dist/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +156 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-transport/index.js +331 -0
- package/dist/node_modules/nodemailer/dist/esm/stream-transport/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/esm/stream-transport/index.js +106 -0
- 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 +12 -23
- 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/dist/esm/xoauth2/index.js +386 -0
- package/dist/node_modules/nodemailer/dist/well-known/services.json +640 -0
- package/dist/node_modules/nodemailer/package.json +1 -1
- package/package.json +4 -4
- package/dist/node_modules/nodemailer/.gitattributes +0 -6
- package/dist/node_modules/nodemailer/.ncurc.js +0 -7
- package/dist/node_modules/nodemailer/.prettierrc.js +0 -8
- package/dist/node_modules/nodemailer/lib/addressparser/index.js +0 -313
- package/dist/node_modules/nodemailer/lib/dkim/message-parser.js +0 -155
- package/dist/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
- package/dist/node_modules/nodemailer/lib/dkim/sign.js +0 -117
- package/dist/node_modules/nodemailer/lib/fetch/cookies.js +0 -281
- package/dist/node_modules/nodemailer/lib/fetch/index.js +0 -274
- package/dist/node_modules/nodemailer/lib/json-transport/index.js +0 -82
- package/dist/node_modules/nodemailer/lib/mime-funcs/index.js +0 -625
- package/dist/node_modules/nodemailer/lib/nodemailer.js +0 -1
- package/dist/node_modules/nodemailer/lib/sendmail-transport/index.js +0 -210
- package/dist/node_modules/nodemailer/lib/ses-transport/index.js +0 -349
- package/dist/node_modules/nodemailer/lib/shared/index.js +0 -688
- package/dist/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -108
- package/dist/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +0 -143
- package/dist/node_modules/nodemailer/lib/smtp-connection/index.js +0 -1825
- package/dist/node_modules/nodemailer/lib/smtp-transport/index.js +0 -416
- package/dist/node_modules/nodemailer/lib/stream-transport/index.js +0 -135
- package/dist/node_modules/nodemailer/lib/well-known/services.json +0 -343
- package/dist/node_modules/nodemailer/lib/xoauth2/index.js +0 -376
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Stream } from 'node:stream';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import * as shared from '../shared/index.js';
|
|
4
|
+
import type { ResultCallback } from '../errors.js';
|
|
5
|
+
import type { OutgoingHttpHeaders } from 'node:http';
|
|
6
|
+
/**
|
|
7
|
+
* Receives the result of a provisionCallback run: an error, or the new access token and
|
|
8
|
+
* an optional expire time in milliseconds
|
|
9
|
+
*/
|
|
10
|
+
export type XOAuth2ProvisionResultCallback = (err: Error | null, accessToken?: string, expires?: number) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Custom access token provider. `renew` is true when the existing token failed and a new
|
|
13
|
+
* one is needed
|
|
14
|
+
*/
|
|
15
|
+
export type XOAuth2ProvisionCallback = (user: string, renew: boolean, callback: XOAuth2ProvisionResultCallback) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Receives an access token, or the error that prevented generating one. Declared with a
|
|
18
|
+
* required token, the way @types/nodemailer declared it, the error path hands over the
|
|
19
|
+
* error alone
|
|
20
|
+
*/
|
|
21
|
+
export type XOAuth2TokenCallback = (err: Error | null, accessToken: string) => void;
|
|
22
|
+
/**
|
|
23
|
+
* A private key accepted by crypto.createSign().sign()
|
|
24
|
+
*/
|
|
25
|
+
export type XOAuth2PrivateKey = crypto.KeyLike | crypto.SignKeyObjectInput | crypto.SignPrivateKeyInput;
|
|
26
|
+
/**
|
|
27
|
+
* Client information for token generation
|
|
28
|
+
*/
|
|
29
|
+
export interface XOAuth2Options {
|
|
30
|
+
/** User e-mail address */
|
|
31
|
+
user?: string | undefined;
|
|
32
|
+
/** Client ID value */
|
|
33
|
+
clientId?: string | undefined;
|
|
34
|
+
/** Client secret value */
|
|
35
|
+
clientSecret?: string | undefined;
|
|
36
|
+
/** Refresh token for an user */
|
|
37
|
+
refreshToken?: string | undefined;
|
|
38
|
+
/** Endpoint for token generation, defaults to 'https://accounts.google.com/o/oauth2/token' */
|
|
39
|
+
accessUrl?: string | undefined;
|
|
40
|
+
/** An existing valid accessToken */
|
|
41
|
+
accessToken?: string | undefined;
|
|
42
|
+
/** Private key for JSW */
|
|
43
|
+
privateKey?: XOAuth2PrivateKey | undefined;
|
|
44
|
+
/** Optional Access Token expire time in ms */
|
|
45
|
+
expires?: number | undefined;
|
|
46
|
+
/** Optional TTL for Access Token in seconds */
|
|
47
|
+
timeout?: number | undefined;
|
|
48
|
+
/** Function to run when a new access token is required */
|
|
49
|
+
provisionCallback?: XOAuth2ProvisionCallback | undefined;
|
|
50
|
+
/** Optional TLS options forwarded to the HTTPS token request. Defaults to strict cert validation; supply { rejectUnauthorized: false } only for self-hosted OAuth providers on private CAs. */
|
|
51
|
+
tls?: {
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
} | undefined;
|
|
54
|
+
/** Service account client id (the JWT issuer), switches to the JWT bearer flow */
|
|
55
|
+
serviceClient?: string | undefined;
|
|
56
|
+
/** Lifetime of the service account JWT in seconds, defaults to 5 minutes, capped at an hour */
|
|
57
|
+
serviceRequestTimeout?: number | undefined;
|
|
58
|
+
/** OAuth2 scope for the service account flow, defaults to 'https://mail.google.com/' */
|
|
59
|
+
scope?: string | undefined;
|
|
60
|
+
/** Logger component name, defaults to 'OAuth2' */
|
|
61
|
+
component?: string | undefined;
|
|
62
|
+
/** Extra headers for the token request */
|
|
63
|
+
customHeaders?: OutgoingHttpHeaders | undefined;
|
|
64
|
+
/** Timeout for the token request in milliseconds, defaults to 60000, 0 disables it */
|
|
65
|
+
requestTimeout?: number | undefined;
|
|
66
|
+
/** Extra form fields for the token request */
|
|
67
|
+
customParams?: {
|
|
68
|
+
[key: string]: any;
|
|
69
|
+
} | undefined;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The object emitted with the 'token' event once a new access token has been generated
|
|
73
|
+
*/
|
|
74
|
+
export interface XOAuth2Token {
|
|
75
|
+
/** User e-mail address */
|
|
76
|
+
user?: string | undefined;
|
|
77
|
+
/** The new access token */
|
|
78
|
+
accessToken: string;
|
|
79
|
+
/** Expire time as a timestamp in milliseconds, 0 when unknown */
|
|
80
|
+
expires: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A getToken request waiting for an in-flight renewal to complete
|
|
84
|
+
*/
|
|
85
|
+
export interface XOAuth2QueuedRequest {
|
|
86
|
+
renew: boolean;
|
|
87
|
+
callback: ResultCallback<string>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* XOAUTH2 access_token generator for Gmail.
|
|
91
|
+
* Create client ID for web applications in Google API console to use it.
|
|
92
|
+
* See Offline Access for receiving the needed refreshToken for an user
|
|
93
|
+
* https://developers.google.com/accounts/docs/OAuth2WebServer#offline
|
|
94
|
+
*
|
|
95
|
+
* Usage for generating access tokens with a custom method using provisionCallback:
|
|
96
|
+
* provisionCallback(user, renew, callback)
|
|
97
|
+
* * user is the username to get the token for
|
|
98
|
+
* * renew is a boolean that if true indicates that existing token failed and needs to be renewed
|
|
99
|
+
* * callback is the callback to run with (error, accessToken [, expires])
|
|
100
|
+
* * accessToken is a string
|
|
101
|
+
* * expires is an optional expire time in milliseconds
|
|
102
|
+
* If provisionCallback is used, then Nodemailer does not try to attempt generating the token by itself
|
|
103
|
+
*
|
|
104
|
+
* @constructor
|
|
105
|
+
* @param options Client information for token generation
|
|
106
|
+
* @param options.user User e-mail address
|
|
107
|
+
* @param options.clientId Client ID value
|
|
108
|
+
* @param options.clientSecret Client secret value
|
|
109
|
+
* @param options.refreshToken Refresh token for an user
|
|
110
|
+
* @param options.accessUrl Endpoint for token generation, defaults to 'https://accounts.google.com/o/oauth2/token'
|
|
111
|
+
* @param options.accessToken An existing valid accessToken
|
|
112
|
+
* @param options.privateKey Private key for JSW
|
|
113
|
+
* @param options.expires Optional Access Token expire time in ms
|
|
114
|
+
* @param options.timeout Optional TTL for Access Token in seconds
|
|
115
|
+
* @param options.provisionCallback Function to run when a new access token is required
|
|
116
|
+
* @param options.tls Optional TLS options forwarded to the HTTPS token request. Defaults to strict cert validation; supply { rejectUnauthorized: false } only for self-hosted OAuth providers on private CAs.
|
|
117
|
+
*/
|
|
118
|
+
declare class XOAuth2 extends Stream {
|
|
119
|
+
options: XOAuth2Options;
|
|
120
|
+
logger: shared.Logger;
|
|
121
|
+
provisionCallback: XOAuth2ProvisionCallback | false;
|
|
122
|
+
accessToken: string | false;
|
|
123
|
+
expires: number;
|
|
124
|
+
renewing: boolean;
|
|
125
|
+
renewalQueue: XOAuth2QueuedRequest[];
|
|
126
|
+
constructor(options?: XOAuth2Options, logger?: shared.ExternalLogger | boolean);
|
|
127
|
+
/**
|
|
128
|
+
* Returns or generates (if previous has expired) a XOAuth2 token
|
|
129
|
+
*
|
|
130
|
+
* @param renew If false then use cached access token (if available)
|
|
131
|
+
* @param callback Callback function with error object and token string
|
|
132
|
+
*/
|
|
133
|
+
getToken(renew: boolean, callback: XOAuth2TokenCallback): void;
|
|
134
|
+
/**
|
|
135
|
+
* Updates token values
|
|
136
|
+
*
|
|
137
|
+
* @param accessToken New access token
|
|
138
|
+
* @param timeout Access token lifetime in seconds
|
|
139
|
+
*
|
|
140
|
+
* Emits 'token': { user: User email-address, accessToken: the new accessToken, timeout: TTL in seconds}
|
|
141
|
+
*/
|
|
142
|
+
updateToken(accessToken: string, timeout?: number | string): void;
|
|
143
|
+
/**
|
|
144
|
+
* Generates a new XOAuth2 token with the credentials provided at initialization
|
|
145
|
+
*
|
|
146
|
+
* @param callback Callback function with error object and token string
|
|
147
|
+
*/
|
|
148
|
+
generateToken(callback: XOAuth2TokenCallback): void;
|
|
149
|
+
/**
|
|
150
|
+
* Converts an access_token and user id into a base64 encoded XOAuth2 token
|
|
151
|
+
*
|
|
152
|
+
* @param [accessToken] Access token string
|
|
153
|
+
* @return Base64 encoded token for IMAP or SMTP login
|
|
154
|
+
*/
|
|
155
|
+
buildXOAuth2Token(accessToken?: string): string;
|
|
156
|
+
/**
|
|
157
|
+
* Custom POST request handler.
|
|
158
|
+
* This is only needed to keep paths short in Windows, usually this module
|
|
159
|
+
* is a dependency of a dependency and if it tries to require something
|
|
160
|
+
* like the request module the paths get way too long to handle for Windows.
|
|
161
|
+
* As we do only a simple POST request we do not actually require complicated
|
|
162
|
+
* logic support (no redirects, no nothing) anyway.
|
|
163
|
+
*
|
|
164
|
+
* @param url Url to POST to
|
|
165
|
+
* @param payload Payload to POST
|
|
166
|
+
* @param params Client options, the customHeaders and tls values are used for the request
|
|
167
|
+
* @param callback Callback function with (err, buff)
|
|
168
|
+
*/
|
|
169
|
+
postRequest(url: string, payload: {
|
|
170
|
+
[key: string]: any;
|
|
171
|
+
} | string | Buffer, params: XOAuth2Options, callback: (err: Error | null, buff?: Buffer) => void): void;
|
|
172
|
+
/**
|
|
173
|
+
* Encodes a buffer or a string into Base64url format
|
|
174
|
+
*
|
|
175
|
+
* @param data The data to convert
|
|
176
|
+
* @return The encoded string
|
|
177
|
+
*/
|
|
178
|
+
toBase64URL(data: Buffer | string): string;
|
|
179
|
+
/**
|
|
180
|
+
* Creates a JSON Web Token signed with RS256 (SHA256 + RSA)
|
|
181
|
+
*
|
|
182
|
+
* @param payload The payload to include in the generated token
|
|
183
|
+
* @return The generated and signed token
|
|
184
|
+
*/
|
|
185
|
+
jwtSignRS256(payload: {
|
|
186
|
+
[key: string]: any;
|
|
187
|
+
}): string;
|
|
188
|
+
}
|
|
189
|
+
/** The extra request settings of the token request, the customHeaders and customParams options */
|
|
190
|
+
export type XOAuth2RequestParams = Pick<XOAuth2Options, 'customHeaders' | 'customParams'>;
|
|
191
|
+
/**
|
|
192
|
+
* Type aliases in the layout of @types/nodemailer, so `XOAuth2.Options` style references keep working
|
|
193
|
+
*/
|
|
194
|
+
declare namespace XOAuth2 {
|
|
195
|
+
type Options = XOAuth2Options;
|
|
196
|
+
type Token = XOAuth2Token;
|
|
197
|
+
type RequestParams = XOAuth2RequestParams;
|
|
198
|
+
}
|
|
199
|
+
/** The same aliases as module level exports, for `import * as XOAuth2` and `import XOAuth2 = require()` */
|
|
200
|
+
export type { XOAuth2Options as Options, XOAuth2Token as Token, XOAuth2RequestParams as RequestParams };
|
|
201
|
+
export default XOAuth2;
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const node_stream_1 = require("node:stream");
|
|
40
|
+
const index_js_1 = __importDefault(require("../fetch/index.js"));
|
|
41
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
42
|
+
const shared = __importStar(require("../shared/index.js"));
|
|
43
|
+
const errors = __importStar(require("../errors.js"));
|
|
44
|
+
/**
|
|
45
|
+
* XOAUTH2 access_token generator for Gmail.
|
|
46
|
+
* Create client ID for web applications in Google API console to use it.
|
|
47
|
+
* See Offline Access for receiving the needed refreshToken for an user
|
|
48
|
+
* https://developers.google.com/accounts/docs/OAuth2WebServer#offline
|
|
49
|
+
*
|
|
50
|
+
* Usage for generating access tokens with a custom method using provisionCallback:
|
|
51
|
+
* provisionCallback(user, renew, callback)
|
|
52
|
+
* * user is the username to get the token for
|
|
53
|
+
* * renew is a boolean that if true indicates that existing token failed and needs to be renewed
|
|
54
|
+
* * callback is the callback to run with (error, accessToken [, expires])
|
|
55
|
+
* * accessToken is a string
|
|
56
|
+
* * expires is an optional expire time in milliseconds
|
|
57
|
+
* If provisionCallback is used, then Nodemailer does not try to attempt generating the token by itself
|
|
58
|
+
*
|
|
59
|
+
* @constructor
|
|
60
|
+
* @param options Client information for token generation
|
|
61
|
+
* @param options.user User e-mail address
|
|
62
|
+
* @param options.clientId Client ID value
|
|
63
|
+
* @param options.clientSecret Client secret value
|
|
64
|
+
* @param options.refreshToken Refresh token for an user
|
|
65
|
+
* @param options.accessUrl Endpoint for token generation, defaults to 'https://accounts.google.com/o/oauth2/token'
|
|
66
|
+
* @param options.accessToken An existing valid accessToken
|
|
67
|
+
* @param options.privateKey Private key for JSW
|
|
68
|
+
* @param options.expires Optional Access Token expire time in ms
|
|
69
|
+
* @param options.timeout Optional TTL for Access Token in seconds
|
|
70
|
+
* @param options.provisionCallback Function to run when a new access token is required
|
|
71
|
+
* @param options.tls Optional TLS options forwarded to the HTTPS token request. Defaults to strict cert validation; supply { rejectUnauthorized: false } only for self-hosted OAuth providers on private CAs.
|
|
72
|
+
*/
|
|
73
|
+
class XOAuth2 extends node_stream_1.Stream {
|
|
74
|
+
constructor(options, logger) {
|
|
75
|
+
super();
|
|
76
|
+
this.options = options || {};
|
|
77
|
+
this.configError = false;
|
|
78
|
+
if (options && options.serviceClient) {
|
|
79
|
+
if (!options.privateKey || !options.user) {
|
|
80
|
+
// reported through getToken() rather than an 'error' event: the transports forward
|
|
81
|
+
// that event up to the Mail object, where nothing may be listening
|
|
82
|
+
const err = new Error('Options "privateKey" and "user" are required for service account!');
|
|
83
|
+
err.code = errors.EOAUTH2;
|
|
84
|
+
this.configError = err;
|
|
85
|
+
}
|
|
86
|
+
const serviceRequestTimeout = Math.min(Math.max(Number(this.options.serviceRequestTimeout) || 0, 0), 3600);
|
|
87
|
+
this.options.serviceRequestTimeout = serviceRequestTimeout || 5 * 60;
|
|
88
|
+
}
|
|
89
|
+
this.logger = shared.getLogger({
|
|
90
|
+
logger
|
|
91
|
+
}, {
|
|
92
|
+
component: this.options.component || 'OAuth2'
|
|
93
|
+
});
|
|
94
|
+
this.provisionCallback = typeof this.options.provisionCallback === 'function' ? this.options.provisionCallback : false;
|
|
95
|
+
this.options.accessUrl = this.options.accessUrl || 'https://accounts.google.com/o/oauth2/token';
|
|
96
|
+
this.options.customHeaders = this.options.customHeaders || {};
|
|
97
|
+
this.options.customParams = this.options.customParams || {};
|
|
98
|
+
this.accessToken = this.options.accessToken || false;
|
|
99
|
+
if (this.options.expires && Number(this.options.expires)) {
|
|
100
|
+
this.expires = this.options.expires;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const timeout = Math.max(Number(this.options.timeout) || 0, 0);
|
|
104
|
+
this.expires = (timeout && Date.now() + timeout * 1000) || 0;
|
|
105
|
+
}
|
|
106
|
+
this.renewing = false; // Track if renewal is in progress
|
|
107
|
+
this.renewalQueue = []; // Queue for pending requests during renewal
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns or generates (if previous has expired) a XOAuth2 token
|
|
111
|
+
*
|
|
112
|
+
* @param renew If false then use cached access token (if available)
|
|
113
|
+
* @param callback Callback function with error object and token string
|
|
114
|
+
*/
|
|
115
|
+
getToken(renew, callback) {
|
|
116
|
+
// the error paths hand over the error alone
|
|
117
|
+
const done = callback;
|
|
118
|
+
if (this.configError) {
|
|
119
|
+
return done(this.configError);
|
|
120
|
+
}
|
|
121
|
+
if (!renew && this.accessToken && (!this.expires || this.expires > Date.now())) {
|
|
122
|
+
this.logger.debug({
|
|
123
|
+
tnx: 'OAUTH2',
|
|
124
|
+
user: this.options.user,
|
|
125
|
+
action: 'reuse'
|
|
126
|
+
}, 'Reusing existing access token for %s', this.options.user);
|
|
127
|
+
return callback(null, this.accessToken);
|
|
128
|
+
}
|
|
129
|
+
// check if it is possible to renew, if not, return the current token or error
|
|
130
|
+
if (!this.provisionCallback && !this.options.refreshToken && !this.options.serviceClient) {
|
|
131
|
+
if (this.accessToken) {
|
|
132
|
+
this.logger.debug({
|
|
133
|
+
tnx: 'OAUTH2',
|
|
134
|
+
user: this.options.user,
|
|
135
|
+
action: 'reuse'
|
|
136
|
+
}, 'Reusing existing access token (no refresh capability) for %s', this.options.user);
|
|
137
|
+
return callback(null, this.accessToken);
|
|
138
|
+
}
|
|
139
|
+
this.logger.error({
|
|
140
|
+
tnx: 'OAUTH2',
|
|
141
|
+
user: this.options.user,
|
|
142
|
+
action: 'renew'
|
|
143
|
+
}, 'Cannot renew access token for %s: No refresh mechanism available', this.options.user);
|
|
144
|
+
const err = new Error("Can't create new access token for user");
|
|
145
|
+
err.code = errors.EOAUTH2;
|
|
146
|
+
return done(err);
|
|
147
|
+
}
|
|
148
|
+
// If renewal already in progress, queue this request instead of starting another
|
|
149
|
+
if (this.renewing) {
|
|
150
|
+
this.renewalQueue.push({ renew, callback: done });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this.renewing = true;
|
|
154
|
+
// Handles token renewal completion - processes queued requests and cleans up
|
|
155
|
+
const generateCallback = (err, accessToken) => {
|
|
156
|
+
this.renewalQueue.forEach(item => item.callback(err, accessToken));
|
|
157
|
+
this.renewalQueue = [];
|
|
158
|
+
this.renewing = false;
|
|
159
|
+
if (err) {
|
|
160
|
+
this.logger.error({
|
|
161
|
+
err,
|
|
162
|
+
tnx: 'OAUTH2',
|
|
163
|
+
user: this.options.user,
|
|
164
|
+
action: 'renew'
|
|
165
|
+
}, 'Failed generating new Access Token for %s', this.options.user);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
this.logger.info({
|
|
169
|
+
tnx: 'OAUTH2',
|
|
170
|
+
user: this.options.user,
|
|
171
|
+
action: 'renew'
|
|
172
|
+
}, 'Generated new Access Token for %s', this.options.user);
|
|
173
|
+
}
|
|
174
|
+
// Complete original request
|
|
175
|
+
done(err, accessToken);
|
|
176
|
+
};
|
|
177
|
+
if (this.provisionCallback) {
|
|
178
|
+
this.provisionCallback(this.options.user, !!renew, (err, accessToken, expires) => {
|
|
179
|
+
if (!err && accessToken) {
|
|
180
|
+
this.accessToken = accessToken;
|
|
181
|
+
this.expires = expires || 0;
|
|
182
|
+
}
|
|
183
|
+
generateCallback(err, accessToken);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
this.generateToken(generateCallback);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Updates token values
|
|
192
|
+
*
|
|
193
|
+
* @param accessToken New access token
|
|
194
|
+
* @param timeout Access token lifetime in seconds
|
|
195
|
+
*
|
|
196
|
+
* Emits 'token': { user: User email-address, accessToken: the new accessToken, timeout: TTL in seconds}
|
|
197
|
+
*/
|
|
198
|
+
updateToken(accessToken, timeout) {
|
|
199
|
+
this.accessToken = accessToken;
|
|
200
|
+
timeout = Math.max(Number(timeout) || 0, 0);
|
|
201
|
+
this.expires = (timeout && Date.now() + timeout * 1000) || 0;
|
|
202
|
+
this.emit('token', {
|
|
203
|
+
user: this.options.user,
|
|
204
|
+
accessToken: accessToken || '',
|
|
205
|
+
expires: this.expires
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Generates a new XOAuth2 token with the credentials provided at initialization
|
|
210
|
+
*
|
|
211
|
+
* @param callback Callback function with error object and token string
|
|
212
|
+
*/
|
|
213
|
+
generateToken(callback) {
|
|
214
|
+
// the error paths hand over the error alone
|
|
215
|
+
const done = callback;
|
|
216
|
+
let urlOptions;
|
|
217
|
+
let loggedUrlOptions;
|
|
218
|
+
if (this.options.serviceClient) {
|
|
219
|
+
// service account - https://developers.google.com/identity/protocols/OAuth2ServiceAccount
|
|
220
|
+
const iat = Math.floor(Date.now() / 1000); // unix time
|
|
221
|
+
const tokenData = {
|
|
222
|
+
iss: this.options.serviceClient,
|
|
223
|
+
scope: this.options.scope || 'https://mail.google.com/',
|
|
224
|
+
sub: this.options.user,
|
|
225
|
+
aud: this.options.accessUrl,
|
|
226
|
+
iat,
|
|
227
|
+
exp: iat + this.options.serviceRequestTimeout
|
|
228
|
+
};
|
|
229
|
+
let token;
|
|
230
|
+
try {
|
|
231
|
+
token = this.jwtSignRS256(tokenData);
|
|
232
|
+
}
|
|
233
|
+
catch (_err) {
|
|
234
|
+
const err = new Error("Can't generate token. Check your auth options");
|
|
235
|
+
err.code = errors.EOAUTH2;
|
|
236
|
+
return done(err);
|
|
237
|
+
}
|
|
238
|
+
urlOptions = {
|
|
239
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
240
|
+
assertion: token
|
|
241
|
+
};
|
|
242
|
+
loggedUrlOptions = {
|
|
243
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
244
|
+
assertion: tokenData
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
if (!this.options.refreshToken) {
|
|
249
|
+
const err = new Error("Can't create new access token for user");
|
|
250
|
+
err.code = errors.EOAUTH2;
|
|
251
|
+
return done(err);
|
|
252
|
+
}
|
|
253
|
+
// web app - https://developers.google.com/identity/protocols/OAuth2WebServer
|
|
254
|
+
urlOptions = {
|
|
255
|
+
client_id: this.options.clientId || '',
|
|
256
|
+
client_secret: this.options.clientSecret || '',
|
|
257
|
+
refresh_token: this.options.refreshToken,
|
|
258
|
+
grant_type: 'refresh_token'
|
|
259
|
+
};
|
|
260
|
+
loggedUrlOptions = {
|
|
261
|
+
client_id: this.options.clientId || '',
|
|
262
|
+
client_secret: (this.options.clientSecret || '').substr(0, 6) + '...',
|
|
263
|
+
refresh_token: (this.options.refreshToken || '').substr(0, 6) + '...',
|
|
264
|
+
grant_type: 'refresh_token'
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
Object.assign(urlOptions, this.options.customParams);
|
|
268
|
+
Object.assign(loggedUrlOptions, this.options.customParams);
|
|
269
|
+
this.logger.debug({
|
|
270
|
+
tnx: 'OAUTH2',
|
|
271
|
+
user: this.options.user,
|
|
272
|
+
action: 'generate'
|
|
273
|
+
}, 'Requesting token using: %s', JSON.stringify(loggedUrlOptions));
|
|
274
|
+
this.postRequest(this.options.accessUrl, urlOptions, this.options, (error, body) => {
|
|
275
|
+
let data;
|
|
276
|
+
if (error) {
|
|
277
|
+
return done(error);
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
data = JSON.parse(body.toString());
|
|
281
|
+
}
|
|
282
|
+
catch (E) {
|
|
283
|
+
return done(E);
|
|
284
|
+
}
|
|
285
|
+
if (!data || typeof data !== 'object') {
|
|
286
|
+
this.logger.debug({
|
|
287
|
+
tnx: 'OAUTH2',
|
|
288
|
+
user: this.options.user,
|
|
289
|
+
action: 'post'
|
|
290
|
+
}, 'Response: %s', (body || '').toString());
|
|
291
|
+
const err = new Error('Invalid authentication response');
|
|
292
|
+
err.code = errors.EOAUTH2;
|
|
293
|
+
return done(err);
|
|
294
|
+
}
|
|
295
|
+
const logData = Object.assign({}, data);
|
|
296
|
+
if (logData.access_token) {
|
|
297
|
+
logData.access_token = (logData.access_token || '').toString().substr(0, 6) + '...';
|
|
298
|
+
}
|
|
299
|
+
this.logger.debug({
|
|
300
|
+
tnx: 'OAUTH2',
|
|
301
|
+
user: this.options.user,
|
|
302
|
+
action: 'post'
|
|
303
|
+
}, 'Response: %s', JSON.stringify(logData));
|
|
304
|
+
if (data.error) {
|
|
305
|
+
// Error Response : https://tools.ietf.org/html/rfc6749#section-5.2
|
|
306
|
+
let errorMessage = data.error;
|
|
307
|
+
if (data.error_description) {
|
|
308
|
+
errorMessage += ': ' + data.error_description;
|
|
309
|
+
}
|
|
310
|
+
if (data.error_uri) {
|
|
311
|
+
errorMessage += ' (' + data.error_uri + ')';
|
|
312
|
+
}
|
|
313
|
+
const err = new Error(errorMessage);
|
|
314
|
+
err.code = errors.EOAUTH2;
|
|
315
|
+
return done(err);
|
|
316
|
+
}
|
|
317
|
+
if (data.access_token) {
|
|
318
|
+
this.updateToken(data.access_token, data.expires_in);
|
|
319
|
+
return callback(null, this.accessToken);
|
|
320
|
+
}
|
|
321
|
+
const err = new Error('No access token');
|
|
322
|
+
err.code = errors.EOAUTH2;
|
|
323
|
+
return done(err);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Converts an access_token and user id into a base64 encoded XOAuth2 token
|
|
328
|
+
*
|
|
329
|
+
* @param [accessToken] Access token string
|
|
330
|
+
* @return Base64 encoded token for IMAP or SMTP login
|
|
331
|
+
*/
|
|
332
|
+
buildXOAuth2Token(accessToken) {
|
|
333
|
+
const authData = ['user=' + (this.options.user || ''), 'auth=Bearer ' + (accessToken || this.accessToken), '', ''];
|
|
334
|
+
return Buffer.from(authData.join('\x01'), 'utf-8').toString('base64');
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Custom POST request handler.
|
|
338
|
+
* This is only needed to keep paths short in Windows, usually this module
|
|
339
|
+
* is a dependency of a dependency and if it tries to require something
|
|
340
|
+
* like the request module the paths get way too long to handle for Windows.
|
|
341
|
+
* As we do only a simple POST request we do not actually require complicated
|
|
342
|
+
* logic support (no redirects, no nothing) anyway.
|
|
343
|
+
*
|
|
344
|
+
* @param url Url to POST to
|
|
345
|
+
* @param payload Payload to POST
|
|
346
|
+
* @param params Client options, the customHeaders and tls values are used for the request
|
|
347
|
+
* @param callback Callback function with (err, buff)
|
|
348
|
+
*/
|
|
349
|
+
postRequest(url, payload, params, callback) {
|
|
350
|
+
let returned = false;
|
|
351
|
+
const chunks = [];
|
|
352
|
+
let chunklen = 0;
|
|
353
|
+
const fetchOptions = {
|
|
354
|
+
method: 'post',
|
|
355
|
+
headers: params.customHeaders,
|
|
356
|
+
body: payload,
|
|
357
|
+
allowErrorResponse: true,
|
|
358
|
+
// unset falls back to the fetch default, a stalled token endpoint would otherwise keep
|
|
359
|
+
// `renewing` set and queue every later request
|
|
360
|
+
timeout: params.requestTimeout
|
|
361
|
+
};
|
|
362
|
+
// OAuth2 token endpoints are credential-bearing. src/fetch already
|
|
363
|
+
// validates certs by default; pin rejectUnauthorized:true here so the
|
|
364
|
+
// token fetch stays strict, while still layering params.tls (the
|
|
365
|
+
// user's options.tls) on top so callers with a self-hosted provider on
|
|
366
|
+
// a private CA can override.
|
|
367
|
+
if (/^https:/i.test(url)) {
|
|
368
|
+
fetchOptions.tls = Object.assign({ rejectUnauthorized: true }, params.tls || {});
|
|
369
|
+
}
|
|
370
|
+
const req = (0, index_js_1.default)(url, fetchOptions);
|
|
371
|
+
req.on('readable', () => {
|
|
372
|
+
let chunk;
|
|
373
|
+
while ((chunk = req.read()) !== null) {
|
|
374
|
+
chunks.push(chunk);
|
|
375
|
+
chunklen += chunk.length;
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
req.once('error', err => {
|
|
379
|
+
if (returned) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
returned = true;
|
|
383
|
+
return callback(err);
|
|
384
|
+
});
|
|
385
|
+
req.once('end', () => {
|
|
386
|
+
if (returned) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
returned = true;
|
|
390
|
+
return callback(null, Buffer.concat(chunks, chunklen));
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Encodes a buffer or a string into Base64url format
|
|
395
|
+
*
|
|
396
|
+
* @param data The data to convert
|
|
397
|
+
* @return The encoded string
|
|
398
|
+
*/
|
|
399
|
+
toBase64URL(data) {
|
|
400
|
+
if (typeof data === 'string') {
|
|
401
|
+
data = Buffer.from(data);
|
|
402
|
+
}
|
|
403
|
+
return data
|
|
404
|
+
.toString('base64')
|
|
405
|
+
.replace(/[=]+/g, '') // remove '='s
|
|
406
|
+
.replace(/\+/g, '-') // '+' → '-'
|
|
407
|
+
.replace(/\//g, '_'); // '/' → '_'
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Creates a JSON Web Token signed with RS256 (SHA256 + RSA)
|
|
411
|
+
*
|
|
412
|
+
* @param payload The payload to include in the generated token
|
|
413
|
+
* @return The generated and signed token
|
|
414
|
+
*/
|
|
415
|
+
jwtSignRS256(payload) {
|
|
416
|
+
const signedPayload = ['{"alg":"RS256","typ":"JWT"}', JSON.stringify(payload)].map(val => this.toBase64URL(val)).join('.');
|
|
417
|
+
const signature = node_crypto_1.default
|
|
418
|
+
.createSign('RSA-SHA256')
|
|
419
|
+
.update(signedPayload)
|
|
420
|
+
.sign(this.options.privateKey);
|
|
421
|
+
return signedPayload + '.' + this.toBase64URL(signature);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
exports.default = XOAuth2;
|
|
425
|
+
module.exports = exports.default;
|
|
426
|
+
Object.defineProperty(module.exports, 'default', { value: exports.default, enumerable: false, writable: true, configurable: true });
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for addressparser
|
|
3
|
+
*/
|
|
4
|
+
export interface AddressParserOptions {
|
|
5
|
+
/** Flatten groups into a single list of mailboxes */
|
|
6
|
+
flatten?: boolean | undefined;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A single mailbox. Either value may be an empty string when the input did not carry it
|
|
10
|
+
*/
|
|
11
|
+
export interface MailboxAddress {
|
|
12
|
+
name: string;
|
|
13
|
+
address: string;
|
|
14
|
+
group?: undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* An address group. RFC 5322 does not allow nested groups, so any nesting is flattened
|
|
18
|
+
* into `group`
|
|
19
|
+
*/
|
|
20
|
+
export interface GroupAddress {
|
|
21
|
+
name: string;
|
|
22
|
+
group: Address[];
|
|
23
|
+
address?: undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A parsed address entry, either a mailbox or a group
|
|
27
|
+
*/
|
|
28
|
+
export type Address = MailboxAddress | GroupAddress;
|
|
29
|
+
/**
|
|
30
|
+
* Parses structured e-mail addresses from an address field
|
|
31
|
+
*
|
|
32
|
+
* Example:
|
|
33
|
+
*
|
|
34
|
+
* 'Name <address@domain>'
|
|
35
|
+
*
|
|
36
|
+
* will be converted to
|
|
37
|
+
*
|
|
38
|
+
* [{name: 'Name', address: 'address@domain'}]
|
|
39
|
+
*
|
|
40
|
+
* @param str Address field
|
|
41
|
+
* @param options Optional options object
|
|
42
|
+
* @return An array of address objects
|
|
43
|
+
*/
|
|
44
|
+
declare function addressparser(str: string | null | undefined, options: AddressParserOptions & {
|
|
45
|
+
flatten: true;
|
|
46
|
+
}): MailboxAddress[];
|
|
47
|
+
declare function addressparser(str?: string | null, options?: AddressParserOptions): Address[];
|
|
48
|
+
/**
|
|
49
|
+
* Type aliases in the layout of @types/nodemailer, so `addressparser.Address` style references keep working
|
|
50
|
+
*/
|
|
51
|
+
type AddressEntry = Address;
|
|
52
|
+
declare namespace addressparser {
|
|
53
|
+
type Address = MailboxAddress;
|
|
54
|
+
type Group = GroupAddress;
|
|
55
|
+
type AddressOrGroup = AddressEntry;
|
|
56
|
+
}
|
|
57
|
+
/** The names @types/nodemailer used for the group entry and for the union of both entry types */
|
|
58
|
+
export type { GroupAddress as Group, Address as AddressOrGroup };
|
|
59
|
+
export default addressparser;
|