From 5058726e2234a2da4edd31f0898465798943ebe6 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Fri, 12 Apr 2024 14:09:21 -0700 Subject: [PATCH] feat: Improve `gaxios` exposure (#1794) * feat: Improve `gaxios` exposure * docs: clarify --- src/auth/authclient.ts | 20 ++++++++++++++++++++ src/index.ts | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/auth/authclient.ts b/src/auth/authclient.ts index 8e004d63..69301db8 100644 --- a/src/auth/authclient.ts +++ b/src/auth/authclient.ts @@ -207,6 +207,26 @@ export abstract class AuthClient this.forceRefreshOnFailure = opts.forceRefreshOnFailure ?? false; } + /** + * Return the {@link Gaxios `Gaxios`} instance from the {@link AuthClient.transporter}. + * + * @expiremental + */ + get gaxios(): Gaxios | null { + if (this.transporter instanceof Gaxios) { + return this.transporter; + } else if (this.transporter instanceof DefaultTransporter) { + return this.transporter.instance; + } else if ( + 'instance' in this.transporter && + this.transporter.instance instanceof Gaxios + ) { + return this.transporter.instance; + } + + return null; + } + /** * Provides an alternative Gaxios request implementation with auth credentials */ diff --git a/src/index.ts b/src/index.ts index 77ad950a..1ab32948 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,10 @@ // limitations under the License. import {GoogleAuth} from './auth/googleauth'; +// Export common deps to ensure types/instances are the exact match. Useful +// for consistently configuring the library across versions. export * as gcpMetadata from 'gcp-metadata'; +export * as gaxios from 'gaxios'; export {AuthClient, DEFAULT_UNIVERSE} from './auth/authclient'; export {Compute, ComputeOptions} from './auth/computeclient';