import destr from 'destr' ; export function getEnv ( name , defaultValue ) { return destr ( process . env [ name ] ) ?? defaultValue ; } export function cachedPromise < T extends ( ... args : any [ ] ) => any > ( fn ) { let p ; return ( ... args ) => { if ( p ) { return p ; } p = Promise . resolve ( fn ( ... args ) ) as ReturnType < T > ; return p ; } ; } export class IPXError extends Error { statusCode ? : number ; statusMessage ? : string ; } export function createError ( message , statusCode ) { const err = new IPXError ( message ) ; err . statusMessage = 'IPX: ' + message ; err . statusCode = statusCode ; return err ; }