analytica.click 0.0.518 → 0.0.520

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,5 +1,5 @@
1
1
  import 'cross-fetch/polyfill';
2
- import type { PostError } from 'analytica.click';
2
+ import type { PostError, PostErrorData } from '@ui/src/server/schema';
3
3
  export declare const errorTrack: ({ data, overrideBaseUrl, ignoreBrowserErrors, devMode, }: {
4
4
  data: PostError;
5
5
  overrideBaseUrl?: string;
@@ -7,3 +7,4 @@ export declare const errorTrack: ({ data, overrideBaseUrl, ignoreBrowserErrors,
7
7
  ignoreBrowserErrors?: string[];
8
8
  devMode?: boolean;
9
9
  }) => Promise<{} | undefined>;
10
+ export declare const getErrorKey: (p: PostErrorData) => string;
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var J=(e,r)=>{for(var o in r)d(e,o,{get:r[o],enumerable:!0})},N=(e,r,o,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of j(r))!x.call(e,s)&&s!==o&&d(e,s,{get:()=>r[s],enumerable:!(n=P(r,s))||n.enumerable});return e};var R=e=>N(d({},"__esModule",{value:!0}),e);var C={};J(C,{errorTrack:()=>H});module.exports=R(C);var I=require("cross-fetch/polyfill"),f=require("ag-common/dist/common/helpers/log"),S=require("ag-common/dist/common/helpers/string/contains");var p=require("ag-common/dist/common/helpers/hashCode"),g=require("ag-common/dist/common/helpers/log"),k=require("ag-common/dist/common/helpers/object");function T(e){return e?e.match(/^"?[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}"?$/)?((0,g.info)("ignoring react devtools message"),!1):e===JSON.stringify([{}])?((0,g.info)("empty message payload?"),!1):!0:((0,g.info)("no message?"),!1)}var b=e=>{try{let r=/^\[?[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}\]?$/gim,o=/(at \S+?) \(\S+\)\s/gim,n=/^((%[cs])+\s*)+$/gim,s=/^color:/gim,t=[],a=e.message;(0,k.isJson)(a)?t=JSON.parse(a):t=[a];let l=t.findIndex(i=>i.match(n)),m=t.findIndex(i=>i.match(s));l>=0&&m>=0&&m===l+1&&(t=t.filter((i,$)=>![l,m].includes($))),t=t.map(i=>i.includes(".js:")||i.includes("node_modules")?i.replace(o,"$1 (stacktrace)"):i.replace(r,"[date]")),a=JSON.stringify(t);let h=(0,p.hashCode)(a).toString();return(0,g.debug)("got errorKey=",a,h),h}catch{return(0,p.hashCode)(e.message).toString()}};var w=(e,r)=>{let o=[],n={},s=0;return Object.entries(e).forEach(([t,a])=>{s<r?o.push(a):n[t]=a,s+=1}),{part:o,rest:n}};var O=typeof window<"u"&&window.location.hostname==="localhost",c={},u,y,E=async()=>{try{if(Object.keys(c).length>100){let n=Object.keys(c)[0],s=c[n],t=await fetch(`${y}/errors`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify([{key:s.key,data:{...s.data,message:`error overload!: ${s.data.message||"?"}`}}])});if(c={},!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return{}}let{part:e,rest:r}=w(c,10);c=r;let o=await fetch(`${y}/errors`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify(e)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`)}catch(e){let r=e;return{error:r?.message??r.message}}finally{Object.keys(c).length>0?u=setTimeout(E,1e3):u=void 0}},H=async({data:e,overrideBaseUrl:r="https://analytica.click/api",ignoreBrowserErrors:o=["will be removed","performing full reload","tracking error","fetch RSC payload","perform a full reload","warnings#debug_enabled"],devMode:n})=>{if(r||(r="https://analytica.click/api"),r.startsWith("/")&&typeof window>"u"&&(r="https://analytica.click/api"),o.length>0){let t=(0,S.containsInsensitive)(e.data.message,...o);if(t){(0,f.debug)("ignoring error, contains=",t);return}}if(O&&n)(0,f.debug)("allowing local error tracking due to devmode=true");else if(O)return(0,f.debug)(`local error tracking ignored:${e.data.message} ${JSON.stringify(e)}, to ${r}`),{};if(!T(e.data.message))return{};(0,f.debug)("error track",e.data.message,JSON.stringify(e));let s=b(e.data);return c[s]=e,y=r,u??=setTimeout(E,500),{}};0&&(module.exports={errorTrack});
1
+ "use strict";var m=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var j=(e,r)=>{for(var s in r)m(e,s,{get:r[s],enumerable:!0})},J=(e,r,s,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of E(r))!P.call(e,o)&&o!==s&&m(e,o,{get:()=>r[o],enumerable:!(n=$(r,o))||n.enumerable});return e};var x=e=>J(m({},"__esModule",{value:!0}),e);var H={};j(H,{errorTrack:()=>N,getErrorKey:()=>S});module.exports=x(H);var I=require("cross-fetch/polyfill"),d=require("ag-common/dist/common/helpers/hashCode"),a=require("ag-common/dist/common/helpers/log"),T=require("ag-common/dist/common/helpers/object"),w=require("ag-common/dist/common/helpers/string/contains");var h=(e,r)=>{let s=[],n={},o=0;return Object.entries(e).forEach(([t,i])=>{o<r?s.push(i):n[t]=i,o+=1}),{part:s,rest:n}};var k=typeof window<"u"&&window.location.hostname==="localhost",g={},u,p,O=async()=>{try{if(Object.keys(g).length>100){let n=Object.keys(g)[0],o=g[n],t=await fetch(`${p}/errors`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify([{key:o.key,data:{...o.data,message:`error overload!: ${o.data.message||"?"}`}}])});if(g={},!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return{}}let{part:e,rest:r}=h(g,10);g=r;let s=await fetch(`${p}/errors`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify(e)});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`)}catch(e){let r=e;return{error:r?.message??r.message}}finally{Object.keys(g).length>0?u=setTimeout(O,1e3):u=void 0}},N=async({data:e,overrideBaseUrl:r="https://analytica.click/api",ignoreBrowserErrors:s=["will be removed","performing full reload","tracking error","fetch RSC payload","perform a full reload","warnings#debug_enabled"],devMode:n})=>{if(r||(r="https://analytica.click/api"),r.startsWith("/")&&typeof window>"u"&&(r="https://analytica.click/api"),s.length>0){let t=(0,w.containsInsensitive)(e.data.message,...s);if(t){(0,a.debug)("ignoring error, contains=",t);return}}if(k&&n)(0,a.debug)("allowing local error tracking due to devmode=true");else if(k)return(0,a.debug)(`local error tracking ignored:${e.data.message} ${JSON.stringify(e)}, to ${r}`),{};if(!R(e.data.message))return{};(0,a.debug)("error track",e.data.message,JSON.stringify(e));let o=S({...e.data,name:e.data.name??"unknown"});return g[o]=e,p=r,u??=setTimeout(O,500),{}};function R(e){return e?e.match(/^"?[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}"?$/)?((0,a.info)("ignoring react devtools message"),!1):e===JSON.stringify([{}])?((0,a.info)("empty message payload?"),!1):!0:((0,a.info)("no message?"),!1)}var S=e=>{try{let r=/^\[?[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}\]?$/gim,s=/(at \S+?) \(\S+\)\s/gim,n=/^((%[cs])+\s*)+$/gim,o=/^color:/gim,t=[],i=e.message;(0,T.isJson)(i)?t=JSON.parse(i):t=[i];let f=t.findIndex(c=>c.match(n)),l=t.findIndex(c=>c.match(o));f>=0&&l>=0&&l===f+1&&(t=t.filter((c,b)=>![f,l].includes(b))),t=t.map(c=>c.includes(".js:")||c.includes("node_modules")?c.replace(s,"$1 (stacktrace)"):c.replace(r,"[date]")),i=JSON.stringify(t);let y=(0,d.hashCode)(i).toString();return(0,a.debug)("got errorKey=",i,y),y}catch{return(0,d.hashCode)(e.message).toString()}};0&&(module.exports={errorTrack,getErrorKey});
@@ -1,5 +1,5 @@
1
1
  import 'cross-fetch/polyfill';
2
- import type { TEvent, TPage } from 'analytica.click';
2
+ import type { TEvent, TPage } from '../types';
3
3
  /** used for tracking arbitrary events */
4
4
  export declare const event: TEvent;
5
5
  /** used for tracking visits to a page */
@@ -1 +1 @@
1
- "use strict";var g=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var w=(t,r)=>{for(var a in r)g(t,a,{get:r[a],enumerable:!0})},u=(t,r,a,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of f(r))!d.call(t,e)&&e!==a&&g(t,e,{get:()=>r[e],enumerable:!(s=p(r,e))||s.enumerable});return t};var y=t=>u(g({},"__esModule",{value:!0}),t);var m={};w(m,{event:()=>h,page:()=>l});module.exports=y(m);var T=require("cross-fetch/polyfill"),n=require("ag-common/dist/common/helpers/log"),h=async({analyticaToken:t,overrideBaseUrl:r="https://analytica.click/api",eventName:a,devMode:s,valueOverrides:e})=>{let i={eventName:a,browserFingerprint:e?.browserFingerprint};if(!s&&typeof window<"u"&&window.location.hostname==="localhost")return(0,n.debug)(`local page ignored: ${JSON.stringify(i)}, to ${r}`),{};try{let o=await fetch(`${r}/site/event`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:t,data:i})});if(!o.ok){let c=await o.text();return(0,n.warn)("tracking error:"+c),{error:c}}}catch(o){let c=o instanceof Error?o.message:"Unknown error";return(0,n.warn)("tracking error:"+c),{error:c}}return{}},l=async({analyticaToken:t,overrideBaseUrl:r="https://analytica.click/api",devMode:a,valueOverrides:s})=>{let e={pageLocation:"",browserFingerprint:s?.browserFingerprint};if(typeof window<"u"&&(e={...e,pageLocation:window.location.href,browserResolution:`${window.screen.width}:${window.screen.height}`}),typeof document<"u"&&(e={...e,pageReferrer:document.referrer,pageTitle:document.title}),typeof navigator<"u"&&(e={...e,browserLanguage:navigator.language}),!a&&typeof window<"u"&&window.location.hostname==="localhost")return(0,n.debug)(`local page ignored: ${JSON.stringify(e)}, to ${r}`),{};if(!e.pageLocation)return(0,n.warn)("no pageLocation"),{};try{let i=await fetch(`${r}/site/tracking`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:t,data:e})});if(!i.ok){let o=await i.text();return(0,n.warn)("tracking error:"+o),{error:o}}}catch(i){let o=i instanceof Error?i.message:"Unknown error";return(0,n.warn)("tracking error:"+o),{error:o}}return{}};0&&(module.exports={event,page});
1
+ "use strict";var g=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var f=(t,r)=>{for(var a in r)g(t,a,{get:r[a],enumerable:!0})},u=(t,r,a,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of w(r))!d.call(t,e)&&e!==a&&g(t,e,{get:()=>r[e],enumerable:!(s=p(r,e))||s.enumerable});return t};var h=t=>u(g({},"__esModule",{value:!0}),t);var m={};f(m,{event:()=>y,page:()=>l});module.exports=h(m);var T=require("cross-fetch/polyfill"),i=require("ag-common/dist/common/helpers/log"),y=async({analyticaToken:t,overrideBaseUrl:r="https://analytica.click/api",eventName:a,devMode:s,valueOverrides:e})=>{let n={eventName:a,browserFingerprint:e?.browserFingerprint,pageLocation:""};if(typeof window<"u"&&(n={...n,pageLocation:window.location.href,browserResolution:`${window.screen.width}:${window.screen.height}`}),!s&&typeof window<"u"&&window.location.hostname==="localhost")return(0,i.debug)(`local page ignored: ${JSON.stringify(n)}, to ${r}`),{};try{let o=await fetch(`${r}/site/event`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:t,data:n})});if(!o.ok){let c=await o.text();return(0,i.warn)("tracking error:"+c),{error:c}}}catch(o){let c=o instanceof Error?o.message:"Unknown error";return(0,i.warn)("tracking error:"+c),{error:c}}return{}},l=async({analyticaToken:t,overrideBaseUrl:r="https://analytica.click/api",devMode:a,valueOverrides:s})=>{let e={pageLocation:"",browserFingerprint:s?.browserFingerprint};if(typeof window<"u"&&(e={...e,pageLocation:window.location.href,browserResolution:`${window.screen.width}:${window.screen.height}`}),typeof document<"u"&&(e={...e,pageReferrer:document.referrer,pageTitle:document.title}),typeof navigator<"u"&&(e={...e,browserLanguage:navigator.language}),!a&&typeof window<"u"&&window.location.hostname==="localhost")return(0,i.debug)(`local page ignored: ${JSON.stringify(e)}, to ${r}`),{};if(!e.pageLocation)return(0,i.warn)("no pageLocation"),{};try{let n=await fetch(`${r}/site/tracking`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:t,data:e})});if(!n.ok){let o=await n.text();return(0,i.warn)("tracking error:"+o),{error:o}}}catch(n){let o=n instanceof Error?n.message:"Unknown error";return(0,i.warn)("tracking error:"+o),{error:o}}return{}};0&&(module.exports={event,page});