writetrack 0.10.3 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- function p(n){let{url:o,headers:i={},retries:t=0,backoffMs:e=100,maxBackoffMs:a=3e4,keepalive:c=!1}=n;return{async send(f){let u=null;for(let s=0;s<=t;s++){if(s>0){let r=Math.min(e*Math.pow(2,s-1),a);await new Promise(l=>setTimeout(l,r))}try{let r=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",...i},body:JSON.stringify(f),keepalive:c});if(r.ok)return;u=new Error(`Webhook failed: ${r.status} ${r.statusText}`)}catch(r){u=r instanceof Error?r:new Error(String(r))}}throw u}}}function m(n){return n instanceof Error?n.message:String(n)}function d(n){let{client:o,actionName:i="writetrack_session",tags:t={}}=n;return{async send(e){let a={...t,duration:e.metadata.duration,keystrokeCount:e.session.events.length,qualityLevel:e.quality.qualityLevel,targetElement:e.metadata.targetElement,schemaVersion:e.version};e.metadata.userId&&(a.userId=e.metadata.userId),e.metadata.contentId&&(a.contentId=e.metadata.contentId),e.metadata.custom&&(a.custom=e.metadata.custom);try{o.addAction(i,a)}catch(c){throw new Error(`Datadog addAction failed: ${m(c)}`)}}}}function g(n){let{client:o,eventName:i="WriteTrack Session"}=n;return{async send(t){let e={duration:t.metadata.duration,keystrokeCount:t.session.events.length,qualityLevel:t.quality.qualityLevel,targetElement:t.metadata.targetElement,schemaVersion:t.version};t.metadata.userId&&(e.userId=t.metadata.userId),t.metadata.contentId&&(e.contentId=t.metadata.contentId),t.metadata.custom&&(e.custom=t.metadata.custom),o.track(i,e)}}}function v(n){let{tracer:o,spanName:i="writetrack.session"}=n;return{async send(t){let e=o.startSpan(i);try{e.setAttribute("writetrack.duration",t.metadata.duration),e.setAttribute("writetrack.keystroke_count",t.session.events.length),e.setAttribute("writetrack.quality_level",t.quality.qualityLevel),e.setAttribute("writetrack.target_element",t.metadata.targetElement),e.setAttribute("writetrack.schema_version",t.version),t.metadata.userId&&e.setAttribute("writetrack.user_id",t.metadata.userId),t.metadata.contentId&&e.setAttribute("writetrack.content_id",t.metadata.contentId),e.setStatus({code:1})}finally{e.end()}}}}export{d as datadog,v as opentelemetry,g as segment,p as webhook};
1
+ function p(r){let{url:i,headers:a={},retries:t=0,backoffMs:e=100,maxBackoffMs:o=3e4,keepalive:u=!1}=r;return{async send(f){let m=null;for(let s=0;s<=t;s++){if(s>0){let n=Math.min(e*Math.pow(2,s-1),o);await new Promise(l=>setTimeout(l,n))}try{let n=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",...a},body:JSON.stringify(f),keepalive:u});if(n.ok)return;m=new Error(`Webhook failed: ${n.status} ${n.statusText}`)}catch(n){m=n instanceof Error?n:new Error(String(n))}}throw m}}}function c(r){return r instanceof Error?r.message:String(r)}function d(r){let{client:i,actionName:a="writetrack_session",tags:t={}}=r;return{async send(e){let o={...t,duration:e.metadata.duration,keystrokeCount:e.session.events.length,qualityLevel:e.quality.qualityLevel,targetElement:e.metadata.targetElement,schemaVersion:e.version};e.metadata.userId&&(o.userId=e.metadata.userId),e.metadata.contentId&&(o.contentId=e.metadata.contentId),e.metadata.custom&&(o.custom=e.metadata.custom);try{i.addAction(a,o)}catch(u){throw new Error(`Datadog addAction failed: ${c(u)}`)}}}}function g(r){let{client:i,eventName:a="WriteTrack Session"}=r;return{async send(t){let e={duration:t.metadata.duration,keystrokeCount:t.session.events.length,qualityLevel:t.quality.qualityLevel,targetElement:t.metadata.targetElement,schemaVersion:t.version};t.metadata.userId&&(e.userId=t.metadata.userId),t.metadata.contentId&&(e.contentId=t.metadata.contentId),t.metadata.custom&&(e.custom=t.metadata.custom);try{i.track(a,e)}catch(o){throw new Error(`Segment track failed: ${c(o)}`)}}}}function v(r){let{tracer:i,spanName:a="writetrack.session"}=r;return{async send(t){let e=i.startSpan(a);try{e.setAttribute("writetrack.duration",t.metadata.duration),e.setAttribute("writetrack.keystroke_count",t.session.events.length),e.setAttribute("writetrack.quality_level",t.quality.qualityLevel),e.setAttribute("writetrack.target_element",t.metadata.targetElement),e.setAttribute("writetrack.schema_version",t.version),t.metadata.userId&&e.setAttribute("writetrack.user_id",t.metadata.userId),t.metadata.contentId&&e.setAttribute("writetrack.content_id",t.metadata.contentId),t.metadata.custom&&e.setAttribute("writetrack.custom",JSON.stringify(t.metadata.custom)),e.setStatus({code:1})}finally{e.end()}}}}export{d as datadog,v as opentelemetry,g as segment,p as webhook};