11import 'cross-fetch/polyfill'
22
3- import {
4- Config ,
5- IndexRequest ,
6- EnqueuedUpdate ,
7- IndexResponse ,
8- IndexOptions ,
9- } from '../types'
3+ import { Config , EnqueuedTask } from '../types'
104
115import { httpResponseErrorHandler , httpErrorHandler } from '../errors'
126
@@ -15,7 +9,7 @@ class HttpRequests {
159 url : URL
1610
1711 constructor ( config : Config ) {
18- this . headers = config . headers || { }
12+ this . headers = Object . assign ( { } , config . headers || { } ) // assign to avoid referencing
1913 this . headers [ 'Content-Type' ] = 'application/json'
2014 if ( config . apiKey ) {
2115 this . headers [ 'Authorization' ] = `Bearer ${ config . apiKey } `
@@ -53,7 +47,7 @@ class HttpRequests {
5347 }
5448
5549 try {
56- const response : Response = await fetch ( constructURL . toString ( ) , {
50+ const response : any = await fetch ( constructURL . toString ( ) , {
5751 ...config ,
5852 method,
5953 body : JSON . stringify ( body ) ,
@@ -98,14 +92,7 @@ class HttpRequests {
9892 } )
9993 }
10094
101- async post (
102- url : string ,
103- data : IndexRequest ,
104- params ?: { [ key : string ] : any } ,
105- config ?: Record < string , any >
106- ) : Promise < IndexResponse >
107-
108- async post < T = any , R = EnqueuedUpdate > (
95+ async post < T = any , R = EnqueuedTask > (
10996 url : string ,
11097 data ?: T ,
11198 params ?: { [ key : string ] : any } ,
@@ -127,14 +114,7 @@ class HttpRequests {
127114 } )
128115 }
129116
130- async put (
131- url : string ,
132- data : IndexOptions | IndexRequest ,
133- params ?: { [ key : string ] : any } ,
134- config ?: Record < string , any >
135- ) : Promise < IndexResponse >
136-
137- async put < T = any , R = EnqueuedUpdate > (
117+ async put < T = any , R = EnqueuedTask > (
138118 url : string ,
139119 data ?: T ,
140120 params ?: { [ key : string ] : any } ,
@@ -161,7 +141,7 @@ class HttpRequests {
161141 data ?: any ,
162142 params ?: { [ key : string ] : any } ,
163143 config ?: Record < string , any >
164- ) : Promise < void >
144+ ) : Promise < EnqueuedTask >
165145 async delete < T > (
166146 url : string ,
167147 data ?: any ,
0 commit comments