import { AxiosRequestConfig } from 'axios' ; import { ItemMetadata } from './items' ; export type TransportErrorDescription = { message ? : string ; extensions ? : Record < string , any > & { code ? : string ; } ; } ; export type TransportResponse < T , R = any > = { raw : R ; data ? : T ; meta ? : ItemMetadata ; errors ? : TransportErrorDescription [ ] ; status : number ; statusText ? : string ; headers : any ; } ; export type TransportMethods = 'get' | 'delete' | 'head' | 'options' | 'post' | 'put' | 'patch' ; export type TransportRequestOptions = { params ? : any ; headers ? : any ; onUploadProgress ? : ( ( progressEvent : any ) => void ) | undefined ; } ; export type TransportOptions = TransportRequestOptions & { url : string ; beforeRequest ? : ( config : AxiosRequestConfig ) => AxiosRequestConfig ; } ; export abstract class ITransport { abstract get < T = any , R = any > ( path , options ? ) ; abstract head < T = any , R = any > ( path , options ? ) ; abstract options < T = any , R = any > ( path , options ? ) ; abstract delete < T = any , P = any , R = any > ( path , data ? , options ? ) ; abstract post < T = any , P = any , R = any > ( path , data ? , options ? ) ; abstract put < T = any , P = any , R = any > ( path , data ? , options ? ) ; abstract patch < T = any , P = any , R = any > ( path , data ? , options ? ) ; } export class TransportError < T = any , R = any > extends Error { public readonly errors : TransportErrorDescription [ ] ; public readonly response ? : Partial < TransportResponse < T , R > > ; public readonly parent : Error | null ; constructor ( parent , response ? ) { if ( response ?. errors ?. length ) { super ( response ?. errors [ 0 ] ?. message ) ; } else { super ( parent ?. message || 'Unknown transport error' ) ; } this . parent = parent ; this . response = response ; this . errors = response ?. errors || [ ] ; if ( ! Object . values ( response || { } ) . some ( ( value ) => value !== undefined ) ) { this . response = undefined ; } Object . setPrototypeOf ( this , TransportError . prototype ) ; } }