@@ -20,15 +20,7 @@ import * as protobuf from 'protobufjs';
2020import * as gax from './gax' ;
2121import * as routingHeader from './routingHeader' ;
2222import { Status } from './status' ;
23- import {
24- GoogleAuth ,
25- OAuth2Client ,
26- Compute ,
27- JWT ,
28- UserRefreshClient ,
29- GoogleAuthOptions ,
30- BaseExternalAccountClient ,
31- } from 'google-auth-library' ;
23+ import { GoogleAuth , AuthClient } from 'google-auth-library' ;
3224import { OperationsClientBuilder } from './operationsClient' ;
3325import type { GrpcClientOptions , ClientStubOptions } from './grpc' ;
3426import { GaxCall , GRPCCall } from './apitypes' ;
@@ -85,15 +77,16 @@ export interface ServiceMethods {
8577 [ name : string ] : protobuf . Method ;
8678}
8779
88- export type AuthClient =
89- | OAuth2Client
90- | Compute
91- | JWT
92- | UserRefreshClient
93- | BaseExternalAccountClient ;
80+ /**
81+ * @deprecated use `GoogleAuth` here instead
82+ */
83+ type deprecatedAuthClientAlias = AuthClient ;
9484
9585export class GrpcClient {
96- auth ?: OAuth2Client | GoogleAuth ;
86+ auth ?: GoogleAuth < AuthClient > | deprecatedAuthClientAlias ;
87+ /**
88+ * @deprecated use {@link GrpcClient.auth} instead
89+ */
9790 authClient ?: AuthClient ;
9891 fallback : boolean ;
9992 grpcVersion : string ;
@@ -114,33 +107,36 @@ export class GrpcClient {
114107 * gRPC-fallback version of GrpcClient
115108 * Implements GrpcClient API for a browser using grpc-fallback protocol (sends serialized protobuf to HTTP/1 $rpc endpoint).
116109 *
117- * @param {Object= } options.auth - An instance of OAuth2Client to use in browser, or an instance of GoogleAuth from google-auth-library
118- * to use in Node.js. Required for browser, optional for Node.js.
119- * @constructor
110+ * @param options {@link GrpcClientOptions }
120111 */
121-
122112 constructor (
123- options : ( GrpcClientOptions | { auth : OAuth2Client } ) & {
113+ options : (
114+ | GrpcClientOptions
115+ | {
116+ /**
117+ * @deprecated - use `authClient` for `AuthClient`s instead
118+ */
119+ auth : AuthClient ;
120+ }
121+ ) & {
124122 /**
125123 * Fallback mode to use instead of gRPC.
126124 * A string is accepted for compatibility, all non-empty string values enable the HTTP REST fallback.
127125 */
128126 fallback ?: boolean | string ;
129127 } = { } ,
130128 ) {
131- if ( ! isNodeJS ( ) ) {
132- if ( ! options . auth ) {
133- throw new Error (
134- JSON . stringify ( options ) +
135- 'You need to pass auth instance to use gRPC-fallback client in browser or other non-Node.js environments. Use OAuth2Client from google-auth-library.' ,
136- ) ;
137- }
138- this . auth = options . auth as OAuth2Client ;
129+ if ( options . auth ) {
130+ this . auth = options . auth ;
131+ } else if ( 'authClient' in options ) {
132+ this . auth = options . authClient ;
139133 } else {
140- this . auth =
141- ( options . auth as GoogleAuth ) ||
142- new GoogleAuth ( options as GoogleAuthOptions ) ;
134+ this . auth = new GoogleAuth ( {
135+ authClient : options . auth ,
136+ ...options ,
137+ } ) ;
143138 }
139+
144140 this . fallback = options . fallback ? true : false ;
145141 this . grpcVersion = require ( '../../package.json' ) . version ;
146142 this . httpRules = ( options as GrpcClientOptions ) . httpRules ;
@@ -266,7 +262,7 @@ export class GrpcClient {
266262
267263 /**
268264 * gRPC-fallback version of createStub
269- * Creates a gRPC-fallback stub with authentication headers built from supplied OAuth2Client instance
265+ * Creates a gRPC-fallback stub with authentication headers built from supplied `AuthClient` instance
270266 *
271267 * @param {function } CreateStub - The constructor function of the stub.
272268 * @param {Object } service - A protobufjs Service object (as returned by lookupService)
@@ -284,7 +280,7 @@ export class GrpcClient {
284280 ) {
285281 if ( ! this . authClient ) {
286282 if ( this . auth && 'getClient' in this . auth ) {
287- this . authClient = ( await this . auth . getClient ( ) ) as AuthClient ;
283+ this . authClient = await this . auth . getClient ( ) ;
288284 } else if ( this . auth && 'getRequestHeaders' in this . auth ) {
289285 this . authClient = this . auth ;
290286 }
@@ -342,7 +338,7 @@ export class GrpcClient {
342338 protocol ,
343339 servicePath ,
344340 servicePort ,
345- this . authClient ,
341+ this . auth || this . authClient ,
346342 encoder ,
347343 decoder ,
348344 this . numericEnums ,
@@ -425,6 +421,7 @@ export function createApiCall(
425421 } ;
426422 }
427423 if ( descriptor && 'streaming' in descriptor && ! isNodeJS ( ) ) {
424+ // TODO: with `fetch` this functionality is available in the browser...
428425 return ( ) => {
429426 throw new Error (
430427 'Server streaming over the REST transport is only supported in Node.js.' ,
0 commit comments