@@ -2,9 +2,9 @@ import type { Bbox, SearchPayload, DateRange, ApiError, GenericObject } from '..
22
33type RequestPayload = SearchPayload ;
44type FetchOptions = {
5- method : string ,
6- payload : RequestPayload ,
7- headers : GenericObject
5+ method ? : string ,
6+ payload ? : RequestPayload ,
7+ headers ? : GenericObject
88}
99
1010class StacApi {
@@ -67,22 +67,16 @@ class StacApi {
6767 return Promise . reject ( e ) ;
6868 }
6969
70- fetch ( url : string , options : FetchOptions ) : Promise < Response > {
71- const { method, payload, headers } = options ;
72- const { bbox, dateRange, ...restPayload } = payload ;
70+ fetch ( url : string , options : Partial < FetchOptions > = { } ) : Promise < Response > {
71+ const { method = 'GET' , payload = { } , headers = { } } = options ;
7372
7473 return fetch ( url , {
7574 method,
7675 headers : {
7776 'Content-Type' : 'application/json' ,
7877 ...headers
7978 } ,
80- body : JSON . stringify ( {
81- ...restPayload ,
82- bbox : this . fixBboxCoordinateOrder ( bbox ) ,
83- datetime : this . makeDatetimePayload ( dateRange ) ,
84- limit : 25
85- } )
79+ body : JSON . stringify ( payload )
8680 } ) . then ( async ( response ) => {
8781 if ( response . ok ) {
8882 return response ;
@@ -93,7 +87,17 @@ class StacApi {
9387 }
9488
9589 search ( payload : SearchPayload , headers = { } ) : Promise < Response > {
96- return this . fetch ( `${ this . baseUrl } /search` , { method : 'POST' , payload, headers } ) ;
90+ const { bbox, dateRange, ...restPayload } = payload ;
91+ const requestPayload = {
92+ ...restPayload ,
93+ bbox : this . fixBboxCoordinateOrder ( bbox ) ,
94+ datetime : this . makeDatetimePayload ( dateRange ) ,
95+ limit : 25
96+ } ;
97+ return this . fetch (
98+ `${ this . baseUrl } /search` ,
99+ { method : 'POST' , payload : requestPayload , headers }
100+ ) ;
97101 }
98102}
99103
0 commit comments