import { createLogger , mergeIgnoreCase , VALUE_IS_UNDEFINED } from '@sap-cloud-sdk/util' ; internal export type RequestMethodType = 'get' | 'post' | 'patch' | 'delete' | 'put' ; const logger = createLogger ( { package : 'odata-common' , messageContext : 'odata-request-config' } ) ; internal export abstract class ODataRequestConfig { payload : Record < string , any > | string ; customServicePath : string ; readonly defaultHeaders : Record < string , any > = { 'content-type' : 'application/json' , accept : 'application/json' } ; private _customHeaders : Record < string , string > = { } ; private _customQueryParameters : Record < string , string > = { } ; private _customRequestConfiguration : Record < string , string > = { } ; private _appendedPaths : string [ ] = [ ] ; private _fetchCsrfToken = true ; constructor ( method , defaultServicePath , defaultHeaders ? ) ; param method param defaultServicePath param defaultHeadersOrContentType constructor ( public method , readonly defaultServicePath , defaultHeadersOrContentType ? ) { if ( defaultServicePath === VALUE_IS_UNDEFINED ) { logger . warn ( 'The service path is undefined in "_defaultServicePath".' ) ; } if ( typeof defaultHeadersOrContentType === 'string' ) { this . defaultHeaders [ 'content-type' ] = defaultHeadersOrContentType ; } else { this . defaultHeaders = mergeIgnoreCase ( this . defaultHeaders , defaultHeadersOrContentType ) ; } } set customHeaders ( headers ) { this . _customHeaders = { } ; this . addCustomHeaders ( headers ) ; } get customHeaders ( ) : Record < string , string > { return this . _customHeaders ; } set customQueryParameters ( queryParameters ) { this . _customQueryParameters = { } ; this . addCustomQueryParameters ( queryParameters ) ; } get customQueryParameters ( ) : Record < string , string > { return this . _customQueryParameters ; } set customRequestConfiguration ( requestConfiguration ) { this . _customRequestConfiguration = { } ; this . addCustomRequestConfiguration ( requestConfiguration ) ; } get customRequestConfiguration ( ) : Record < string , string > { return this . _customRequestConfiguration ; } get appendedPaths ( ) : string [ ] { return this . _appendedPaths ; } set fetchCsrfToken ( fetchCsrfToken ) { this . _fetchCsrfToken = fetchCsrfToken ; } get fetchCsrfToken ( ) : boolean { return this . _fetchCsrfToken ; } param headers addCustomHeaders ( headers ) { Object . entries ( headers ) . forEach ( ( [ key , value ] ) => { this . customHeaders [ key . toLowerCase ( ) ] = value ; } ) ; } param queryParameters addCustomQueryParameters ( queryParameters ) { Object . entries ( queryParameters ) . forEach ( ( [ key , value ] ) => { this . customQueryParameters [ key ] = value ; } ) ; } param requestConfiguration addCustomRequestConfiguration ( requestConfiguration ) { Object . entries ( requestConfiguration ) . forEach ( ( [ key , value ] ) => { this . customRequestConfiguration [ key ] = value ; } ) ; } appendPath ( ... path ) { this . appendedPaths . push ( ... path ) ; } protected prependDollarToQueryParameters ( params ) { return Object . entries ( params ) . reduce ( ( newParams , [ key , value ] ) => { newParams [ `$${ key }` ] = value ; return newParams ; } , { } ) ; } internal abstract resourcePath ( ) ; internal abstract queryParameters ( ) ; }