UNPKG

@logsnag/remix

Version:

LogSnag client for Remix applications

3 lines 3.4 kB
"use client"; var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var b=(r,t,e)=>t in r?u(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var T=(r,t)=>{for(var e in t)u(r,e,{get:t[e],enumerable:!0})},O=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of l(t))!m.call(r,o)&&o!==e&&u(r,o,{get:()=>t[o],enumerable:!(i=f(t,o))||i.enumerable});return r};var k=r=>O(u({},"__esModule",{value:!0}),r);var a=(r,t,e)=>(b(r,typeof t!="symbol"?t+"":t,e),e);var I={};T(I,{LogSnag:()=>h});module.exports=k(I);var d="https://api.logsnag.com",g="/v1",c={LOG:d+g+"/log",IDENTIFY:d+g+"/identify",INSIGHT:d+g+"/insight",GROUP:d+"/v1/group",PAGE:d+g+"/page"};var n=class extends Error{constructor(e,i,o){super(`HTTP Error Response: ${e} ${i}`);a(this,"message");this.message=this.createReadableString(o)}createReadableString(e){let i="[LogSnag] Failed to publish: ";return e&&e.validation&&Array.isArray(e.validation.body)?i+=e.validation.body.map(o=>o.message).join(", "):i+=": Please check our docs at https://docs.logsnag.com",i}toString(){return this.message}toJSON(){return{message:this.message}}};function y(r){return Math.abs(Date.now()-r)<Math.abs(Date.now()-r*1e3)}function p(r){if(r)return r instanceof Date&&(r=r.getTime()),y(r)&&(r=Math.floor(r/1e3)),r}var h=class{constructor({token:t,project:e,disableTracking:i=!1}){a(this,"token");a(this,"project");a(this,"disabled",!1);this.token=t,this.project=e,this.disabled=i||!1}disableTracking(){this.disabled=!0}enableTracking(){this.disabled=!1}isTrackingDisabled(){return this.disabled}getProject(){return this.project}createAuthorizationHeader(){return`Bearer ${this.token}`}createHeaders(){return{"Content-Type":"application/json",Authorization:this.createAuthorizationHeader()}}get insight(){return{track:this.insightTrack.bind(this),increment:this.insightIncrement.bind(this)}}async track(t){if(this.isTrackingDisabled())return!0;let e=this.createHeaders(),i="POST";t.timestamp=p(t.timestamp);let o=JSON.stringify({...t,project:this.getProject()}),s=await fetch(c.LOG,{method:i,body:o,headers:e});if(!s.ok)throw new n(s.status,s.statusText,await s.json());return!0}async identify(t){if(this.isTrackingDisabled())return!0;let e=this.createHeaders(),i="POST",o=JSON.stringify({...t,project:this.getProject()}),s=await fetch(c.IDENTIFY,{method:i,body:o,headers:e});if(!s.ok)throw new n(s.status,s.statusText,await s.json());return!0}async group(t){if(this.isTrackingDisabled())return!0;let e=this.createHeaders(),i="POST",o=JSON.stringify({...t,project:this.getProject()}),s=await fetch(c.GROUP,{method:i,body:o,headers:e});if(!s.ok)throw new n(s.status,s.statusText,await s.json());return!0}async insightTrack(t){if(this.isTrackingDisabled())return!0;let e=this.createHeaders(),i="POST",o=JSON.stringify({...t,project:this.getProject()}),s=await fetch(c.INSIGHT,{method:i,body:o,headers:e});if(!s.ok)throw new n(s.status,s.statusText,await s.json());return!0}async insightIncrement(t){if(this.isTrackingDisabled())return!0;let e=this.createHeaders(),i="PATCH",o=JSON.stringify({project:this.getProject(),icon:t.icon,title:t.title,value:{$inc:t.value}}),s=await fetch(c.INSIGHT,{method:i,body:o,headers:e});if(!s.ok)throw new n(s.status,s.statusText,await s.json());return!0}};0&&(module.exports={LogSnag}); //# sourceMappingURL=index.js.map