node_modules: update (#332)

Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
Dawid Dziurlaanddawidd6 authored and GitHub committed 2026-10-01 09:48:38 +02:00
1 parent c1dac70e3a
commit 6bf0a2f26a
95 files changed
+1102 -503

No files matched your search

+11 -3
View File
@@ -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
View File
@@ -111,6 +111,8 @@ class XOAuth2 extends node_stream_1.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',
@@ -136,11 +138,11 @@ class XOAuth2 extends node_stream_1.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;
@@ -165,7 +167,7 @@ class XOAuth2 extends node_stream_1.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) => {
@@ -204,6 +206,8 @@ class XOAuth2 extends node_stream_1.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) {
@@ -224,7 +228,7 @@ class XOAuth2 extends node_stream_1.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',
@@ -239,7 +243,7 @@ class XOAuth2 extends node_stream_1.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 = {
@@ -265,13 +269,13 @@ class XOAuth2 extends node_stream_1.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({
@@ -281,7 +285,7 @@ class XOAuth2 extends node_stream_1.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) {
@@ -303,7 +307,7 @@ class XOAuth2 extends node_stream_1.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);
@@ -311,7 +315,7 @@ class XOAuth2 extends node_stream_1.Stream {
}
const err = new Error('No access token');
err.code = errors.EOAUTH2;
return callback(err);
return done(err);
});
}
/**