11import { TypedHash } from "../collections/collections" ;
2-
3- declare var global : any ;
4-
5- export interface NodeClientData {
6- clientId : string ;
7- clientSecret : string ;
8- siteUrl : string ;
9- }
2+ import { HttpClientImpl } from "../net/httpclient" ;
3+ import { FetchClient } from "../net/fetchclient" ;
104
115export interface LibraryConfiguration {
126
@@ -31,14 +25,9 @@ export interface LibraryConfiguration {
3125 defaultCachingTimeoutSeconds ?: number ;
3226
3327 /**
34- * If true the SP.RequestExecutor will be used to make the requests, you must include the required external libs
35- */
36- useSPRequestExecutor ?: boolean ;
37-
38- /**
39- * If set the library will use node-fetch, typically for use with testing but works with any valid client id/secret pair
28+ * Defines a factory method used to create fetch clients
4029 */
41- nodeClientOptions ?: NodeClientData ;
30+ fetchClientFactory : ( ) => HttpClientImpl ;
4231}
4332
4433export class RuntimeConfigImpl {
@@ -47,17 +36,15 @@ export class RuntimeConfigImpl {
4736 private _defaultCachingStore : "session" | "local" ;
4837 private _defaultCachingTimeoutSeconds : number ;
4938 private _globalCacheDisable : boolean ;
50- private _useSPRequestExecutor : boolean ;
51- private _useNodeClient : boolean ;
52- private _nodeClientData : NodeClientData ;
39+ private _fetchClientFactory : ( ) => HttpClientImpl ;
5340
5441 constructor ( ) {
5542 // these are our default values for the library
5643 this . _headers = null ;
5744 this . _defaultCachingStore = "session" ;
5845 this . _defaultCachingTimeoutSeconds = 30 ;
5946 this . _globalCacheDisable = false ;
60- this . _useSPRequestExecutor = false ;
47+ this . _fetchClientFactory = ( ) => new FetchClient ( ) ;
6148 }
6249
6350 public set ( config : LibraryConfiguration ) : void {
@@ -78,19 +65,8 @@ export class RuntimeConfigImpl {
7865 this . _defaultCachingTimeoutSeconds = config . defaultCachingTimeoutSeconds ;
7966 }
8067
81- if ( config . hasOwnProperty ( "useSPRequestExecutor" ) ) {
82- this . _useSPRequestExecutor = config . useSPRequestExecutor ;
83- }
84-
85- if ( config . hasOwnProperty ( "nodeClientOptions" ) ) {
86- this . _useNodeClient = true ;
87- this . _useSPRequestExecutor = false ; // just don't allow this conflict
88- this . _nodeClientData = config . nodeClientOptions ;
89- // this is to help things work when running in node.js, specifically batching
90- // we shim the _spPageContextInfo object
91- global . _spPageContextInfo = {
92- webAbsoluteUrl : config . nodeClientOptions . siteUrl ,
93- } ;
68+ if ( config . hasOwnProperty ( "fetchClientFactory" ) ) {
69+ this . _fetchClientFactory = config . fetchClientFactory ;
9470 }
9571 }
9672
@@ -110,16 +86,8 @@ export class RuntimeConfigImpl {
11086 return this . _globalCacheDisable ;
11187 }
11288
113- public get useSPRequestExecutor ( ) : boolean {
114- return this . _useSPRequestExecutor ;
115- }
116-
117- public get useNodeFetchClient ( ) : boolean {
118- return this . _useNodeClient ;
119- }
120-
121- public get nodeRequestOptions ( ) : NodeClientData {
122- return this . _nodeClientData ;
89+ public get fetchClientFactory ( ) : ( ) => HttpClientImpl {
90+ return this . _fetchClientFactory ;
12391 }
12492}
12593
0 commit comments