import c from 'centra' ; export type UserLogger = { info : ( msg : string ) => void ; warn : ( msg : string ) => void ; error : ( msg : string ) => void ; } ; /** Custom post function based on centra */ export async function post ( apiPath , apiKey , sendObj , logStuff , logger ) { const postData = JSON . stringify ( sendObj ) ; try { const request = c ( apiPath , 'POST' ) ; request . reqHeaders = { 'Content-Type' : 'application/json' , 'Content-Length' : String ( postData . length ) , Authorization : apiKey , } ; const response = await request . body ( postData ) . send ( ) ; if ( logStuff ) { logger . info ( ` posted to ${ apiPath }` ) ; logger . info ( ` statusCode: ${ response . statusCode }` ) ; logger . info ( ` headers: ${ response . headers }` ) ; logger . info ( ` data: ${ await response . text ( ) }` ) ; } return response ; } catch ( e ) { logger . error ( e ) ; return { error : e } ; } } /** Custom get function based on centra */ export async function get < T > ( url , logger ) { try { const response = await c ( url , 'GET' ) . send ( ) ; return response . json ( ) ; } catch ( e ) { logger . error ( e ) ; throw new Error ( `Request to ${ url } failed with Errorcode ${ e }` ) ; } }