mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-10-09 09:59:45 +07:00
node_modules: update (#332)
Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
1 parent
c1dac70e3a
commit
6bf0a2f26a
95 files changed
+1102
-503
No files matched your search
+11
-3
@@ -1,6 +1,7 @@
|
||||
import { Stream } from 'node:stream';
|
||||
import crypto from 'node:crypto';
|
||||
import * as shared from '../shared/index.js';
|
||||
import type { ResultCallback } from '../errors.js';
|
||||
import type { OutgoingHttpHeaders } from 'node:http';
|
||||
/**
|
||||
* Receives the result of a provisionCallback run: an error, or the new access token and
|
||||
@@ -13,9 +14,11 @@ export type XOAuth2ProvisionResultCallback = (err: Error | null, accessToken?: s
|
||||
*/
|
||||
export type XOAuth2ProvisionCallback = (user: string, renew: boolean, callback: XOAuth2ProvisionResultCallback) => void;
|
||||
/**
|
||||
* Receives an access token, or the error that prevented generating one
|
||||
* Receives an access token, or the error that prevented generating one. Declared with a
|
||||
* required token, the way @types/nodemailer declared it, the error path hands over the
|
||||
* error alone
|
||||
*/
|
||||
export type XOAuth2TokenCallback = (err: Error | null, accessToken?: string) => void;
|
||||
export type XOAuth2TokenCallback = (err: Error | null, accessToken: string) => void;
|
||||
/**
|
||||
* A private key accepted by crypto.createSign().sign()
|
||||
*/
|
||||
@@ -79,7 +82,7 @@ export interface XOAuth2Token {
|
||||
*/
|
||||
export interface XOAuth2QueuedRequest {
|
||||
renew: boolean;
|
||||
callback: XOAuth2TokenCallback;
|
||||
callback: ResultCallback<string>;
|
||||
}
|
||||
/**
|
||||
* XOAUTH2 access_token generator for Gmail.
|
||||
@@ -181,11 +184,16 @@ declare class XOAuth2 extends Stream {
|
||||
[key: string]: any;
|
||||
}): string;
|
||||
}
|
||||
/** The extra request settings of the token request, the customHeaders and customParams options */
|
||||
export type XOAuth2RequestParams = Pick<XOAuth2Options, 'customHeaders' | 'customParams'>;
|
||||
/**
|
||||
* Type aliases in the layout of @types/nodemailer, so `XOAuth2.Options` style references keep working
|
||||
*/
|
||||
declare namespace XOAuth2 {
|
||||
type Options = XOAuth2Options;
|
||||
type Token = XOAuth2Token;
|
||||
type RequestParams = XOAuth2RequestParams;
|
||||
}
|
||||
/** The same aliases as module level exports, for `import * as XOAuth2` and `import XOAuth2 = require()` */
|
||||
export type { XOAuth2Options as Options, XOAuth2Token as Token, XOAuth2RequestParams as RequestParams };
|
||||
export default XOAuth2;
|
||||
+14
-10
@@ -73,6 +73,8 @@ class XOAuth2 extends Stream {
|
||||
* @param callback Callback function with error object and token string
|
||||
*/
|
||||
getToken(renew, callback) {
|
||||
// the error paths hand over the error alone
|
||||
const done = callback;
|
||||
if (!renew && this.accessToken && (!this.expires || this.expires > Date.now())) {
|
||||
this.logger.debug({
|
||||
tnx: 'OAUTH2',
|
||||
@@ -98,11 +100,11 @@ class XOAuth2 extends Stream {
|
||||
}, 'Cannot renew access token for %s: No refresh mechanism available', this.options.user);
|
||||
const err = new Error("Can't create new access token for user");
|
||||
err.code = errors.EOAUTH2;
|
||||
return callback(err);
|
||||
return done(err);
|
||||
}
|
||||
// If renewal already in progress, queue this request instead of starting another
|
||||
if (this.renewing) {
|
||||
this.renewalQueue.push({ renew, callback });
|
||||
this.renewalQueue.push({ renew, callback: done });
|
||||
return;
|
||||
}
|
||||
this.renewing = true;
|
||||
@@ -127,7 +129,7 @@ class XOAuth2 extends Stream {
|
||||
}, 'Generated new Access Token for %s', this.options.user);
|
||||
}
|
||||
// Complete original request
|
||||
callback(err, accessToken);
|
||||
done(err, accessToken);
|
||||
};
|
||||
if (this.provisionCallback) {
|
||||
this.provisionCallback(this.options.user, !!renew, (err, accessToken, expires) => {
|
||||
@@ -166,6 +168,8 @@ class XOAuth2 extends Stream {
|
||||
* @param callback Callback function with error object and token string
|
||||
*/
|
||||
generateToken(callback) {
|
||||
// the error paths hand over the error alone
|
||||
const done = callback;
|
||||
let urlOptions;
|
||||
let loggedUrlOptions;
|
||||
if (this.options.serviceClient) {
|
||||
@@ -186,7 +190,7 @@ class XOAuth2 extends Stream {
|
||||
catch (_err) {
|
||||
const err = new Error("Can't generate token. Check your auth options");
|
||||
err.code = errors.EOAUTH2;
|
||||
return callback(err);
|
||||
return done(err);
|
||||
}
|
||||
urlOptions = {
|
||||
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
||||
@@ -201,7 +205,7 @@ class XOAuth2 extends Stream {
|
||||
if (!this.options.refreshToken) {
|
||||
const err = new Error("Can't create new access token for user");
|
||||
err.code = errors.EOAUTH2;
|
||||
return callback(err);
|
||||
return done(err);
|
||||
}
|
||||
// web app - https://developers.google.com/identity/protocols/OAuth2WebServer
|
||||
urlOptions = {
|
||||
@@ -227,13 +231,13 @@ class XOAuth2 extends Stream {
|
||||
this.postRequest(this.options.accessUrl, urlOptions, this.options, (error, body) => {
|
||||
let data;
|
||||
if (error) {
|
||||
return callback(error);
|
||||
return done(error);
|
||||
}
|
||||
try {
|
||||
data = JSON.parse(body.toString());
|
||||
}
|
||||
catch (E) {
|
||||
return callback(E);
|
||||
return done(E);
|
||||
}
|
||||
if (!data || typeof data !== 'object') {
|
||||
this.logger.debug({
|
||||
@@ -243,7 +247,7 @@ class XOAuth2 extends Stream {
|
||||
}, 'Response: %s', (body || '').toString());
|
||||
const err = new Error('Invalid authentication response');
|
||||
err.code = errors.EOAUTH2;
|
||||
return callback(err);
|
||||
return done(err);
|
||||
}
|
||||
const logData = Object.assign({}, data);
|
||||
if (logData.access_token) {
|
||||
@@ -265,7 +269,7 @@ class XOAuth2 extends Stream {
|
||||
}
|
||||
const err = new Error(errorMessage);
|
||||
err.code = errors.EOAUTH2;
|
||||
return callback(err);
|
||||
return done(err);
|
||||
}
|
||||
if (data.access_token) {
|
||||
this.updateToken(data.access_token, data.expires_in);
|
||||
@@ -273,7 +277,7 @@ class XOAuth2 extends Stream {
|
||||
}
|
||||
const err = new Error('No access token');
|
||||
err.code = errors.EOAUTH2;
|
||||
return callback(err);
|
||||
return done(err);
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user