UNPKG

@platformos/pos-cli

Version:
2 lines (1 loc) 977 B
const n={get:async(t={})=>{const o=typeof window<"u"&&window.location.port!=="4173"&&window.location.port!=="5173"?`http://localhost:${parseInt(window.location.port)}/api/logsv2`:"http://localhost:3333/api/logsv2";if(t.page=t.page?parseInt(t.page)-1:0,t.size=t.size??20,t.from=t.page*t.size,t.stream_name=t.stream_name??"logs",t.start_time){let e=new Date(t.start_time);e.setHours(23,59,59),t.end_time=Math.floor(e.getTime()*1e3),t.start_time=Math.floor(e.getTime()-2592e5)}t.message&&(t.sql=`SELECT * FROM logs where message ILIKE '%${t.message}%' OR type ILIKE '%${t.message}%' OR options_data_url ILIKE '%${t.message}%'`);const a={query:{sql:t.sql||`SELECT * FROM ${t.stream_name}`,from:t.from,size:t.size,start_time:t.start_time||0,end_time:t.end_time||0,track_total_hits:!0}};return fetch(`${o}`,{method:"POST",body:JSON.stringify(a),headers:{"Content-Type":"application/json"}}).then(e=>e.ok?e.json():Promise.reject(e)).then(e=>e).catch(e=>({error:e}))}};export{n as l};