@zenflux/core
Advanced tools
Comparing version 0.0.1-dev.1 to 0.0.1-dev.2
@@ -10,3 +10,3 @@ /** | ||
private readonly apiBaseUrl; | ||
private requestInit; | ||
private readonly requestInit; | ||
private errorHandler?; | ||
@@ -19,3 +19,3 @@ private responseFilter?; | ||
*/ | ||
constructor(apiBaseUrl?: string); | ||
constructor(apiBaseUrl?: string, requestInit?: RequestInit); | ||
/** | ||
@@ -25,3 +25,2 @@ * Function fetch() : Fetch api. | ||
fetch(path: string, method: E_HTTP_METHOD_TYPE, body?: any): Promise<any>; | ||
setRequestInit(requestInit: RequestInit): void; | ||
setErrorHandler(callback: TErrorHandlerCallbackType): void; | ||
@@ -28,0 +27,0 @@ setResponseFilter(callback: TResponseFilterCallbackType): void; |
@@ -10,3 +10,7 @@ export interface IAPIConfig { | ||
baseURL?: string; | ||
/** | ||
* @description: Request Init for fetch API. | ||
*/ | ||
requestInit?: RequestInit; | ||
} | ||
//# sourceMappingURL=config.d.ts.map |
{ | ||
"name": "@zenflux/core", | ||
"version": "0.0.1-dev.1", | ||
"version": "0.0.1-dev.2", | ||
"description": "ZenFlux core", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -23,3 +23,3 @@ /** | ||
private requestInit: RequestInit = { 'credentials': 'include' }; | ||
private readonly requestInit: RequestInit; | ||
@@ -37,3 +37,3 @@ private errorHandler?: TErrorHandlerCallbackType = undefined; | ||
*/ | ||
constructor( apiBaseUrl = 'http://localhost' ) { | ||
constructor( apiBaseUrl = 'http://localhost', requestInit: RequestInit = { 'credentials': 'include' } ) { | ||
super(); | ||
@@ -46,2 +46,4 @@ | ||
this.apiBaseUrl = apiBaseUrl + '/'; | ||
this.requestInit = requestInit; | ||
} | ||
@@ -55,9 +57,10 @@ | ||
const headers = {}; | ||
const params = Object.assign( {}, this.requestInit ), | ||
headers = {}; | ||
if ( method === E_HTTP_METHOD_TYPE.GET ) { | ||
Object.assign( this.requestInit, { headers } ); | ||
Object.assign( params, { headers } ); | ||
} else { | ||
Object.assign( headers, { 'Content-Type': 'application/json' } ); | ||
Object.assign( this.requestInit, { | ||
Object.assign( params, { | ||
method, | ||
@@ -105,6 +108,2 @@ headers: headers, | ||
public setRequestInit( requestInit: RequestInit ) { | ||
this.requestInit = requestInit; | ||
} | ||
public setErrorHandler( callback: TErrorHandlerCallbackType ) { | ||
@@ -111,0 +110,0 @@ if ( this.errorHandler ) { |
@@ -11,2 +11,7 @@ export interface IAPIConfig { | ||
baseURL?: string; | ||
/** | ||
* @description: Request Init for fetch API. | ||
*/ | ||
requestInit?: RequestInit; | ||
} |
@@ -33,6 +33,6 @@ /** | ||
constructor( Config: IAPIConfig) { | ||
constructor( Config: IAPIConfig ) { | ||
super(); | ||
Data.client = new Http( Config.baseURL ); | ||
Data.client = new Http( Config.baseURL, Config.requestInit ); | ||
} | ||
@@ -39,0 +39,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164120
4066