@@ -26,7 +26,7 @@ export function _removeTrailingSlash(s: string): string {
2626/**
2727 * @internal
2828 */
29- export abstract class _BaseAPIClient {
29+ export class _BaseAPIClient {
3030 private dpopProvider : DPoPProvider | null ;
3131 userAgent ?: string ;
3232
@@ -47,15 +47,21 @@ export abstract class _BaseAPIClient {
4747 }
4848
4949 // eslint-disable-next-line no-undef
50- abstract _fetchFunction ?: typeof fetch ;
51-
50+ _fetch : typeof fetch ;
5251 // eslint-disable-next-line no-undef
53- abstract _requestClass ? : typeof Request ;
52+ _Request : typeof Request ;
5453
5554 _config ?: _OIDCConfiguration ;
5655
57- constructor ( dpopProvider : DPoPProvider | null ) {
58- this . dpopProvider = dpopProvider ;
56+ constructor ( options : {
57+ // eslint-disable-next-line no-undef
58+ fetch : typeof fetch ;
59+ Request : typeof Request ;
60+ dpopProvider : DPoPProvider | null ;
61+ } ) {
62+ this . _fetch = options . fetch ;
63+ this . _Request = options . Request ;
64+ this . dpopProvider = options . dpopProvider ;
5965 }
6066
6167 protected async _prepareHeaders ( ) : Promise < Record < string , string > > {
@@ -71,10 +77,6 @@ export abstract class _BaseAPIClient {
7177 }
7278
7379 async _doFetch ( request : Request ) : Promise < Response > {
74- if ( ! this . _fetchFunction ) {
75- throw new AuthgearError ( "missing fetchFunction in api client" ) ;
76- }
77-
7880 if ( this . dpopProvider != null ) {
7981 const dpopJWT = await this . dpopProvider . generateDPoPProof ( {
8082 htm : request . method ,
@@ -85,25 +87,18 @@ export abstract class _BaseAPIClient {
8587 }
8688 }
8789
88- return this . _fetchFunction ( request ) ;
90+ return this . _fetch ( request ) ;
8991 }
9092
9193 async _fetchWithoutRefresh (
9294 url : string ,
9395 init ?: RequestInit
9496 ) : Promise < Response > {
95- if ( ! this . _requestClass ) {
96- throw new AuthgearError ( "missing requestClass in api client" ) ;
97- }
98- const request = new this . _requestClass ( url , init ) ;
97+ const request = new this . _Request ( url , init ) ;
9998 return this . _doFetch ( request ) ;
10099 }
101100
102101 async fetch ( input : RequestInfo | URL , init ?: RequestInit ) : Promise < Response > {
103- if ( this . _requestClass == null ) {
104- throw new AuthgearError ( "missing requestClass in api client" ) ;
105- }
106-
107102 if ( this . _delegate == null ) {
108103 throw new AuthgearError ( "missing delegate in api client" ) ;
109104 }
@@ -113,7 +108,7 @@ export abstract class _BaseAPIClient {
113108 await this . _delegate . refreshAccessToken ( ) ;
114109 }
115110
116- const request = new this . _requestClass ( input , init ) ;
111+ const request = new this . _Request ( input , init ) ;
117112
118113 const headers = await this . _prepareHeaders ( ) ;
119114 for ( const key of Object . keys ( headers ) ) {
0 commit comments