google-auth-library-nodejs icon indicating copy to clipboard operation
google-auth-library-nodejs copied to clipboard

feat!: Normalize `GoogleAuth<T>` to `AuthClient`

Open danielbankhead opened this issue 1 year ago • 0 comments

We should normalize GoogleAuth<T extends AuthClient = JSONClient> to GoogleAuth<T extends AuthClient = AuthClient> (and GoogleAuthOptions as well).

Additionally, we should:

  • change clientOptions from: https://github.com/googleapis/google-auth-library-nodejs/blob/4f94ffe474ee41b560813b81e8d621be848d38d0/src/auth/googleauth.ts#L106-L114 to:

    /**
     * Options object passed to the constructor of the client
     */
    clientOptions?: ConstructorParameters<typeof T>[0];
    

    In both GoogleAuth and GoogleAuthOptions to accurately match the expected client options.

  • change cachedCredential from: https://github.com/googleapis/google-auth-library-nodejs/blob/f950465967e6140d061d44ab0d12f08e0117c0ec/src/auth/googleauth.ts#L160-L161 to:

    cachedCredential: T | null = null; 
    

    in order to normalize the expected AuthClient

Dependencies:

  • https://github.com/googleapis/google-auth-library-nodejs/pull/1624
  • https://github.com/googleapis/google-auth-library-nodejs/pull/1663
  • https://github.com/googleapis/google-auth-library-nodejs/issues/1672

Implementation Notes:

  • Look into overload narrowing (which is a pain at the time of writing), which is required for accurate ConstructorParameters results:
    • https://github.com/microsoft/TypeScript/issues/37079
    • https://stackoverflow.com/questions/59745527/is-it-possible-to-narrow-the-types-of-overloaded-parameters-without-exhaustively
    • Note: We may just have to reorganize overloads in each AuthClient to the desired overload signature as the first overload ('desired' = whichever one exposes the extended AuthClientOptions as the first option).

danielbankhead avatar Oct 13 '23 00:10 danielbankhead