analytica.click 0.0.538 → 0.0.539
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.
- package/dist/helpers/server.js +1 -1
- package/dist/index.d.ts +6 -13
- package/dist/index.js +1 -1
- package/dist/ui/src/server/schema/index.d.ts +6 -12
- package/package.json +1 -1
package/dist/helpers/server.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var
|
1
|
+
"use strict";var g=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var l=(r,t)=>{for(var o in t)g(r,o,{get:t[o],enumerable:!0})},y=(r,t,o,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of f(t))!w.call(r,s)&&s!==o&&g(r,s,{get:()=>t[s],enumerable:!(d=p(t,s))||d.enumerable});return r};var h=r=>y(g({},"__esModule",{value:!0}),r);var k={};l(k,{event:()=>u,metric:()=>v,page:()=>m});module.exports=h(k);var b=require("cross-fetch/polyfill"),i=require("ag-common/dist/common/helpers/log"),u=async r=>{let{analyticaToken:t,overrideBaseUrl:o="https://analytica.click/api",eventName:d,devMode:s,valueOverrides:a}=r;if(!s&&typeof window<"u"&&window.location.hostname==="localhost")return(0,i.debug)(`local page ignored: ${JSON.stringify(r)}, to ${o}`),{};let n={eventName:d,browserFingerprint:a?.browserFingerprint,pageLocation:""};typeof window<"u"&&(n={...n,pageLocation:window.location.href,browserResolution:`${window.screen.width}:${window.screen.height}`}),typeof navigator<"u"&&(n={...n,browser:navigator.userAgent});try{let e=await fetch(`${o}/site/event`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:t,data:n})});if(!e.ok){let c=await e.text();return(0,i.warn)("tracking error:"+c),{error:c}}}catch(e){let c=e instanceof Error?e.message:"Unknown error";return(0,i.warn)("tracking error:"+c),{error:c}}return{}},m=async r=>{let{analyticaToken:t,overrideBaseUrl:o="https://analytica.click/api",devMode:d,valueOverrides:s}=r;if(!d&&typeof window<"u"&&window.location.hostname==="localhost")return(0,i.debug)(`local page ignored: ${JSON.stringify(r)}, to ${o}`),{};let a={pageLocation:"",browserFingerprint:s?.browserFingerprint};if(typeof window<"u"&&(a={...a,pageLocation:window.location.href,browserResolution:`${window.screen.width}:${window.screen.height}`}),typeof document<"u"&&(a={...a,pageReferrer:document.referrer,pageTitle:document.title}),typeof navigator<"u"&&(a={...a,browserLanguage:navigator.language,browser:navigator.userAgent}),!a.pageLocation)return(0,i.warn)("no pageLocation"),{};try{let n=await fetch(`${o}/site/tracking`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:t,data:a})});if(!n.ok){let e=await n.text();return(0,i.warn)("tracking error:"+e),{error:e}}}catch(n){let e=n instanceof Error?n.message:"Unknown error";return(0,i.warn)("tracking error:"+e),{error:e}}return{}},v=async r=>{let{analyticaToken:t,overrideBaseUrl:o="https://analytica.click/api",type:d,value:s,devMode:a}=r;if(!a&&typeof window<"u"&&window.location.hostname==="localhost")return(0,i.debug)(`local metric ignored: ${JSON.stringify(r)}, to ${o}`),{};if(d==="health")return(0,i.warn)('Type "health" is reserved for system metrics'),{error:'Type "health" is reserved for system metrics'};let n={type:d,value:s};try{let e=await fetch(`${o}/site/metric`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:t,data:n})});if(!e.ok){let c=await e.text();return(0,i.warn)("metric tracking error:"+c),{error:c}}}catch(e){let c=e instanceof Error?e.message:"Unknown error";return(0,i.warn)("metric tracking error:"+c),{error:c}}return{}};0&&(module.exports={event,metric,page});
|
package/dist/index.d.ts
CHANGED
@@ -159,7 +159,6 @@ declare module 'analytica.click/dist/types' {
|
|
159
159
|
analyticaToken: string;
|
160
160
|
overrideBaseUrl?: string;
|
161
161
|
type: string;
|
162
|
-
name: string;
|
163
162
|
value: number;
|
164
163
|
/** internal testing only. also allows local sending of errors */
|
165
164
|
devMode?: boolean;
|
@@ -358,18 +357,16 @@ declare module 'analytica.click/dist/ui/src/server/schema/index' {
|
|
358
357
|
}, z.core.$strip>;
|
359
358
|
export const UserMetricSchema: z.ZodObject<{
|
360
359
|
type: z.ZodString;
|
361
|
-
name: z.ZodString;
|
362
360
|
value: z.ZodNumber;
|
363
361
|
}, z.core.$strip>;
|
364
|
-
export const MetricItemSchema: z.
|
362
|
+
export const MetricItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
365
363
|
type: z.ZodLiteral<"health">;
|
366
364
|
responseTimeMs: z.ZodNumber;
|
367
365
|
success: z.ZodBoolean;
|
368
366
|
}, z.core.$strip>, z.ZodObject<{
|
369
367
|
type: z.ZodString;
|
370
|
-
name: z.ZodString;
|
371
368
|
value: z.ZodNumber;
|
372
|
-
}, z.core.$strip>]>;
|
369
|
+
}, z.core.$strip>], "type">;
|
373
370
|
export const MetricSchema: z.ZodObject<{
|
374
371
|
account: z.ZodOptional<z.ZodString>;
|
375
372
|
site: z.ZodString;
|
@@ -378,15 +375,14 @@ declare module 'analytica.click/dist/ui/src/server/schema/index' {
|
|
378
375
|
SERVER: "SERVER";
|
379
376
|
CLIENT: "CLIENT";
|
380
377
|
}>;
|
381
|
-
metric: z.
|
378
|
+
metric: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
382
379
|
type: z.ZodLiteral<"health">;
|
383
380
|
responseTimeMs: z.ZodNumber;
|
384
381
|
success: z.ZodBoolean;
|
385
382
|
}, z.core.$strip>, z.ZodObject<{
|
386
383
|
type: z.ZodString;
|
387
|
-
name: z.ZodString;
|
388
384
|
value: z.ZodNumber;
|
389
|
-
}, z.core.$strip>]>;
|
385
|
+
}, z.core.$strip>], "type">;
|
390
386
|
}, z.core.$strip>;
|
391
387
|
export interface IMetric extends z.infer<typeof MetricSchema> {
|
392
388
|
}
|
@@ -566,14 +562,12 @@ declare module 'analytica.click/dist/ui/src/server/schema/index' {
|
|
566
562
|
}, z.core.$strip>;
|
567
563
|
export const PostMetricDataSchema: z.ZodObject<{
|
568
564
|
type: z.ZodString;
|
569
|
-
name: z.ZodString;
|
570
565
|
value: z.ZodNumber;
|
571
566
|
}, z.core.$strip>;
|
572
567
|
export const PostMetricSchema: z.ZodObject<{
|
573
568
|
key: z.ZodString;
|
574
569
|
data: z.ZodObject<{
|
575
570
|
type: z.ZodString;
|
576
|
-
name: z.ZodString;
|
577
571
|
value: z.ZodNumber;
|
578
572
|
}, z.core.$strip>;
|
579
573
|
}, z.core.$strip>;
|
@@ -695,15 +689,14 @@ declare module 'analytica.click/dist/ui/src/server/schema/index' {
|
|
695
689
|
SERVER: "SERVER";
|
696
690
|
CLIENT: "CLIENT";
|
697
691
|
}>;
|
698
|
-
metric: z.
|
692
|
+
metric: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
699
693
|
type: z.ZodLiteral<"health">;
|
700
694
|
responseTimeMs: z.ZodNumber;
|
701
695
|
success: z.ZodBoolean;
|
702
696
|
}, z.core.$strip>, z.ZodObject<{
|
703
697
|
type: z.ZodString;
|
704
|
-
name: z.ZodString;
|
705
698
|
value: z.ZodNumber;
|
706
|
-
}, z.core.$strip>]>;
|
699
|
+
}, z.core.$strip>], "type">;
|
707
700
|
}, z.core.$strip>>>;
|
708
701
|
languages: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
709
702
|
account: z.ZodOptional<z.ZodString>;
|
package/dist/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
'use client';"use strict";var Y=Object.create;var h=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var ee=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var te=(e,r)=>{for(var t in r)h(e,t,{get:r[t],enumerable:!0})},N=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of V(r))!re.call(e,i)&&i!==t&&h(e,i,{get:()=>r[i],enumerable:!(o=Z(r,i))||o.enumerable});return e};var oe=(e,r,t)=>(t=e!=null?Y(ee(e)):{},N(r||!e||!e.__esModule?h(t,"default",{value:e,enumerable:!0}):t,e)),ne=e=>N(h({},"__esModule",{value:!0}),e);var de={};te(de,{AnalyticaClickProvider:()=>se,AnalyticaConfigContext:()=>y,Modal:()=>O,errorTrack:()=>p,event:()=>M,getErrorKey:()=>F,metric:()=>R,page:()=>$,tokenMissing:()=>u,useAnalytica:()=>ce});module.exports=ne(de);var X=require("react");var v=require("ag-common/dist/common/helpers/log"),T=oe(require("react"));var z=require("react");var pe=require("cross-fetch/polyfill"),E=require("ag-common/dist/common/helpers/hashCode"),f=require("ag-common/dist/common/helpers/log"),B=require("ag-common/dist/common/helpers/object"),D=require("ag-common/dist/common/helpers/string/contains");var A=(e,r)=>{let t=[],o={},i=0;return Object.entries(e).forEach(([n,a])=>{i<r?t.push(a):o[n]=a,i+=1}),{part:t,rest:o}};var J=typeof window<"u"&&window.location.hostname==="localhost",g={},x,b,L=async()=>{try{if(Object.keys(g).length>100){let o=Object.keys(g)[0],i=g[o],n=await fetch(`${b}/errors`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify([{key:i.key,data:{...i.data,message:`error overload!: ${i.data.message||"?"}`}}])});if(g={},!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return{}}let{part:e,rest:r}=A(g,10);g=r;let t=await fetch(`${b}/errors`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify(e)});if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`)}catch(e){let r=e;return{error:r?.message??r.message}}finally{Object.keys(g).length>0?x=setTimeout(L,1e3):x=void 0}},p=async({data:e,overrideBaseUrl:r="https://analytica.click/api",ignoreBrowserErrors:t=["will be removed","performing full reload","tracking error","fetch RSC payload","perform a full reload","warnings#debug_enabled",'"digest"',"punycode"],devMode:o})=>{if(r||(r="https://analytica.click/api"),r.startsWith("/")&&typeof window>"u"&&(r="https://analytica.click/api"),t.length>0){let n=(0,D.containsInsensitive)(e.data.message,...t);if(n){(0,f.debug)("ignoring error, contains=",n);return}}if(J&&o)(0,f.debug)("allowing local error tracking due to devmode=true");else if(J)return(0,f.debug)(`local error tracking ignored:${e.data.message} ${JSON.stringify(e)}, to ${r}`),{};if(!ae(e.data.message))return{};(0,f.debug)("error track",e.data.message,JSON.stringify(e));let i=F({...e.data,name:e.data.name??"unknown"});return g[i]=e,b=r,x??=setTimeout(L,500),{}};function ae(e){return e?e.match(/^"?[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}"?$/)?((0,f.info)("ignoring react devtools message"),!1):e===JSON.stringify([{}])?((0,f.info)("empty message payload?"),!1):!0:((0,f.info)("no message?"),!1)}var F=e=>{try{let r=/^\[?[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}\]?$/gim,t=/(at \S+?) \(\S+\)\s/gim,o=/^((%[cs])+\s*)+$/gim,i=/^color:/gim,n=[],a=e.message;(0,B.isJson)(a)?n=JSON.parse(a):n=[a];let s=n.findIndex(l=>l.match(o)),c=n.findIndex(l=>l.match(i));s>=0&&c>=0&&c===s+1&&(n=n.filter((l,Q)=>![s,c].includes(Q))),n=n.map(l=>l.includes(".js:")||l.includes("node_modules")?l.replace(t,"$1 (stacktrace)"):l.replace(r,"[date]")),a=JSON.stringify(n);let m=(0,E.hashCode)(a).toString();return(0,f.debug)("got errorKey=",a,m),m}catch{return(0,E.hashCode)(e.message).toString()}};async function C({ev:e,values:r}){if(!r.analyticaToken)return;let t={message:e.message,href:window.location.href,filename:e.filename,name:"",stack:e.error.stack};await p({...r,data:{key:r.analyticaToken,data:t}})}function H(e){(0,z.useEffect)(()=>{let r=t=>C({ev:t,values:e});if(e.analyticaToken)return window.addEventListener("error",r),()=>{try{window.removeEventListener("error",r)}catch{}}},[])}var U=require("react");function j(e){(0,U.useEffect)(()=>{if(window.consoleset||!e.analyticaToken)return;window.consoleset=!0;let r=window.console.error;window.console.error=(...o)=>{p({...e,data:{data:{href:window.location.href,message:JSON.stringify(o)},key:e.analyticaToken}}),r(...o)};let t=window.console.warn;window.console.warn=(...o)=>{p({...e,data:{data:{href:window.location.href,message:JSON.stringify(o)},key:e.analyticaToken}}),t(...o)}},[])}var u=e=>`[Analytica.${e}] Please load analytica token in AnalyticaClickProvider to use this component`;function W(e){if(global.nodeset||typeof window<"u"||!e.analyticaToken)return;global.nodeset=!0;let r=global.console.error;global.console.error=(...o)=>{p({...e,data:{data:{href:"server",message:JSON.stringify(o)},key:e.analyticaToken}}),r(...o)};let t=global.console.warn;global.console.warn=(...o)=>{p({...e,data:{data:{href:"server",message:JSON.stringify(o)},key:e.analyticaToken}}),t(...o)}}var K=require("react");var w=require("react/jsx-runtime"),ie={fontSize:"2rem"},k=class extends K.Component{constructor(r){super(r),this.state={hasError:void 0},this.seenError=!1}static getDerivedStateFromError(r){let t=typeof window<"u"&&window.location.href;return{hasError:{...r,message:r?.message??r,...r?.stack&&{error:{stack:r?.stack}},...t&&{href:t}}}}render(){let{hasError:r}=this.state,{children:t,notify:o}=this.props;return r?(o&&o(r),(0,w.jsx)(O,{open:!0,setOpen:()=>{},children:(0,w.jsxs)("div",{style:ie,children:["A fatal error has occurred - the admin has been notified.",(0,w.jsx)("button",{type:"button",onClick:()=>window.location.reload(),children:"Press here to restart app"})]})})):t}};var P=require("react/jsx-runtime"),_=({children:e})=>{let r=(0,T.useContext)(y);return j(r),H(r),W(r),(0,v.debug)("installed analytica.click error handlers"),r.analyticaToken?(0,P.jsx)(k,{notify:t=>C({ev:t,values:r}),children:e}):((0,v.warn)(u("ErrorBoundary")),(0,P.jsx)(T.default.Fragment,{children:e}))};var S=require("react/jsx-runtime"),y=(0,X.createContext)(void 0),se=({children:e,values:r})=>(0,S.jsx)(y.Provider,{value:r,children:(0,S.jsx)(_,{children:e})});var I=require("react/jsx-runtime"),O=({open:e,setOpen:r,children:t})=>e?(0,I.jsx)("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>r(!1),children:(0,I.jsx)("div",{style:{backgroundColor:"white",padding:"2rem",borderRadius:"8px",maxWidth:"500px",maxHeight:"80vh",overflow:"auto",position:"relative",boxShadow:"0 10px 25px rgba(0, 0, 0, 0.2)"},onClick:o=>o.stopPropagation(),children:t})}):null;var Fe=require("cross-fetch/polyfill"),d=require("ag-common/dist/common/helpers/log"),M=async e=>{let{analyticaToken:r,overrideBaseUrl:t="https://analytica.click/api",eventName:o,devMode:i,valueOverrides:n}=e;if(!i&&typeof window<"u"&&window.location.hostname==="localhost")return(0,d.debug)(`local page ignored: ${JSON.stringify(e)}, to ${t}`),{};let a={eventName:o,browserFingerprint:n?.browserFingerprint,pageLocation:""};typeof window<"u"&&(a={...a,pageLocation:window.location.href,browserResolution:`${window.screen.width}:${window.screen.height}`}),typeof navigator<"u"&&(a={...a,browser:navigator.userAgent});try{let s=await fetch(`${t}/site/event`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:r,data:a})});if(!s.ok){let c=await s.text();return(0,d.warn)("tracking error:"+c),{error:c}}}catch(s){let c=s instanceof Error?s.message:"Unknown error";return(0,d.warn)("tracking error:"+c),{error:c}}return{}},$=async e=>{let{analyticaToken:r,overrideBaseUrl:t="https://analytica.click/api",devMode:o,valueOverrides:i}=e;if(!o&&typeof window<"u"&&window.location.hostname==="localhost")return(0,d.debug)(`local page ignored: ${JSON.stringify(e)}, to ${t}`),{};let n={pageLocation:"",browserFingerprint:i?.browserFingerprint};if(typeof window<"u"&&(n={...n,pageLocation:window.location.href,browserResolution:`${window.screen.width}:${window.screen.height}`}),typeof document<"u"&&(n={...n,pageReferrer:document.referrer,pageTitle:document.title}),typeof navigator<"u"&&(n={...n,browserLanguage:navigator.language,browser:navigator.userAgent}),!n.pageLocation)return(0,d.warn)("no pageLocation"),{};try{let a=await fetch(`${t}/site/tracking`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:r,data:n})});if(!a.ok){let s=await a.text();return(0,d.warn)("tracking error:"+s),{error:s}}}catch(a){let s=a instanceof Error?a.message:"Unknown error";return(0,d.warn)("tracking error:"+s),{error:s}}return{}},R=async e=>{let{analyticaToken:r,overrideBaseUrl:t="https://analytica.click/api",type:o,name:i,value:n,devMode:a}=e;if(!a&&typeof window<"u"&&window.location.hostname==="localhost")return(0,d.debug)(`local metric ignored: ${JSON.stringify(e)}, to ${t}`),{};if(o==="health")return(0,d.warn)('Type "health" is reserved for system metrics'),{error:'Type "health" is reserved for system metrics'};let s={type:o,name:i,value:n};try{let c=await fetch(`${t}/site/metric`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:r,data:s})});if(!c.ok){let m=await c.text();return(0,d.warn)("metric tracking error:"+m),{error:m}}}catch(c){let m=c instanceof Error?c.message:"Unknown error";return(0,d.warn)("metric tracking error:"+m),{error:m}}return{}};var q=require("ag-common/dist/common/helpers/log"),G=require("react");var ce=()=>{let e=(0,G.useContext)(y);if(!e.analyticaToken){(0,q.warn)(u("useAnalytica"));let r=async()=>({error:"no token"});return{event:r,page:r,metric:r}}return{event:r=>M({...r,...e}),page:r=>$({...r,...e}),metric:r=>R({...r,...e})}};0&&(module.exports={AnalyticaClickProvider,AnalyticaConfigContext,Modal,errorTrack,event,getErrorKey,metric,page,tokenMissing,useAnalytica});
|
1
|
+
'use client';"use strict";var Y=Object.create;var w=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var ee=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var te=(e,r)=>{for(var t in r)w(e,t,{get:r[t],enumerable:!0})},N=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of V(r))!re.call(e,i)&&i!==t&&w(e,i,{get:()=>r[i],enumerable:!(o=Z(r,i))||o.enumerable});return e};var oe=(e,r,t)=>(t=e!=null?Y(ee(e)):{},N(r||!e||!e.__esModule?w(t,"default",{value:e,enumerable:!0}):t,e)),ne=e=>N(w({},"__esModule",{value:!0}),e);var de={};te(de,{AnalyticaClickProvider:()=>se,AnalyticaConfigContext:()=>g,Modal:()=>C,errorTrack:()=>p,event:()=>I,getErrorKey:()=>F,metric:()=>$,page:()=>M,tokenMissing:()=>y,useAnalytica:()=>ce});module.exports=ne(de);var X=require("react");var k=require("ag-common/dist/common/helpers/log"),v=oe(require("react"));var z=require("react");var pe=require("cross-fetch/polyfill"),T=require("ag-common/dist/common/helpers/hashCode"),f=require("ag-common/dist/common/helpers/log"),B=require("ag-common/dist/common/helpers/object"),D=require("ag-common/dist/common/helpers/string/contains");var A=(e,r)=>{let t=[],o={},i=0;return Object.entries(e).forEach(([n,a])=>{i<r?t.push(a):o[n]=a,i+=1}),{part:t,rest:o}};var J=typeof window<"u"&&window.location.hostname==="localhost",m={},E,x,L=async()=>{try{if(Object.keys(m).length>100){let o=Object.keys(m)[0],i=m[o],n=await fetch(`${x}/errors`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify([{key:i.key,data:{...i.data,message:`error overload!: ${i.data.message||"?"}`}}])});if(m={},!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return{}}let{part:e,rest:r}=A(m,10);m=r;let t=await fetch(`${x}/errors`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify(e)});if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`)}catch(e){let r=e;return{error:r?.message??r.message}}finally{Object.keys(m).length>0?E=setTimeout(L,1e3):E=void 0}},p=async({data:e,overrideBaseUrl:r="https://analytica.click/api",ignoreBrowserErrors:t=["will be removed","performing full reload","tracking error","fetch RSC payload","perform a full reload","warnings#debug_enabled",'"digest"',"punycode"],devMode:o})=>{if(r||(r="https://analytica.click/api"),r.startsWith("/")&&typeof window>"u"&&(r="https://analytica.click/api"),t.length>0){let n=(0,D.containsInsensitive)(e.data.message,...t);if(n){(0,f.debug)("ignoring error, contains=",n);return}}if(J&&o)(0,f.debug)("allowing local error tracking due to devmode=true");else if(J)return(0,f.debug)(`local error tracking ignored:${e.data.message} ${JSON.stringify(e)}, to ${r}`),{};if(!ae(e.data.message))return{};(0,f.debug)("error track",e.data.message,JSON.stringify(e));let i=F({...e.data,name:e.data.name??"unknown"});return m[i]=e,x=r,E??=setTimeout(L,500),{}};function ae(e){return e?e.match(/^"?[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}"?$/)?((0,f.info)("ignoring react devtools message"),!1):e===JSON.stringify([{}])?((0,f.info)("empty message payload?"),!1):!0:((0,f.info)("no message?"),!1)}var F=e=>{try{let r=/^\[?[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}\]?$/gim,t=/(at \S+?) \(\S+\)\s/gim,o=/^((%[cs])+\s*)+$/gim,i=/^color:/gim,n=[],a=e.message;(0,B.isJson)(a)?n=JSON.parse(a):n=[a];let s=n.findIndex(l=>l.match(o)),c=n.findIndex(l=>l.match(i));s>=0&&c>=0&&c===s+1&&(n=n.filter((l,Q)=>![s,c].includes(Q))),n=n.map(l=>l.includes(".js:")||l.includes("node_modules")?l.replace(t,"$1 (stacktrace)"):l.replace(r,"[date]")),a=JSON.stringify(n);let R=(0,T.hashCode)(a).toString();return(0,f.debug)("got errorKey=",a,R),R}catch{return(0,T.hashCode)(e.message).toString()}};async function b({ev:e,values:r}){if(!r.analyticaToken)return;let t={message:e.message,href:window.location.href,filename:e.filename,name:"",stack:e.error.stack};await p({...r,data:{key:r.analyticaToken,data:t}})}function H(e){(0,z.useEffect)(()=>{let r=t=>b({ev:t,values:e});if(e.analyticaToken)return window.addEventListener("error",r),()=>{try{window.removeEventListener("error",r)}catch{}}},[])}var U=require("react");function j(e){(0,U.useEffect)(()=>{if(window.consoleset||!e.analyticaToken)return;window.consoleset=!0;let r=window.console.error;window.console.error=(...o)=>{p({...e,data:{data:{href:window.location.href,message:JSON.stringify(o)},key:e.analyticaToken}}),r(...o)};let t=window.console.warn;window.console.warn=(...o)=>{p({...e,data:{data:{href:window.location.href,message:JSON.stringify(o)},key:e.analyticaToken}}),t(...o)}},[])}var y=e=>`[Analytica.${e}] Please load analytica token in AnalyticaClickProvider to use this component`;function W(e){if(global.nodeset||typeof window<"u"||!e.analyticaToken)return;global.nodeset=!0;let r=global.console.error;global.console.error=(...o)=>{p({...e,data:{data:{href:"server",message:JSON.stringify(o)},key:e.analyticaToken}}),r(...o)};let t=global.console.warn;global.console.warn=(...o)=>{p({...e,data:{data:{href:"server",message:JSON.stringify(o)},key:e.analyticaToken}}),t(...o)}}var K=require("react");var u=require("react/jsx-runtime"),ie={fontSize:"2rem"},h=class extends K.Component{constructor(r){super(r),this.state={hasError:void 0},this.seenError=!1}static getDerivedStateFromError(r){let t=typeof window<"u"&&window.location.href;return{hasError:{...r,message:r?.message??r,...r?.stack&&{error:{stack:r?.stack}},...t&&{href:t}}}}render(){let{hasError:r}=this.state,{children:t,notify:o}=this.props;return r?(o&&o(r),(0,u.jsx)(C,{open:!0,setOpen:()=>{},children:(0,u.jsxs)("div",{style:ie,children:["A fatal error has occurred - the admin has been notified.",(0,u.jsx)("button",{type:"button",onClick:()=>window.location.reload(),children:"Press here to restart app"})]})})):t}};var O=require("react/jsx-runtime"),_=({children:e})=>{let r=(0,v.useContext)(g);return j(r),H(r),W(r),(0,k.debug)("installed analytica.click error handlers"),r.analyticaToken?(0,O.jsx)(h,{notify:t=>b({ev:t,values:r}),children:e}):((0,k.warn)(y("ErrorBoundary")),(0,O.jsx)(v.default.Fragment,{children:e}))};var P=require("react/jsx-runtime"),g=(0,X.createContext)(void 0),se=({children:e,values:r})=>(0,P.jsx)(g.Provider,{value:r,children:(0,P.jsx)(_,{children:e})});var S=require("react/jsx-runtime"),C=({open:e,setOpen:r,children:t})=>e?(0,S.jsx)("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>r(!1),children:(0,S.jsx)("div",{style:{backgroundColor:"white",padding:"2rem",borderRadius:"8px",maxWidth:"500px",maxHeight:"80vh",overflow:"auto",position:"relative",boxShadow:"0 10px 25px rgba(0, 0, 0, 0.2)"},onClick:o=>o.stopPropagation(),children:t})}):null;var Fe=require("cross-fetch/polyfill"),d=require("ag-common/dist/common/helpers/log"),I=async e=>{let{analyticaToken:r,overrideBaseUrl:t="https://analytica.click/api",eventName:o,devMode:i,valueOverrides:n}=e;if(!i&&typeof window<"u"&&window.location.hostname==="localhost")return(0,d.debug)(`local page ignored: ${JSON.stringify(e)}, to ${t}`),{};let a={eventName:o,browserFingerprint:n?.browserFingerprint,pageLocation:""};typeof window<"u"&&(a={...a,pageLocation:window.location.href,browserResolution:`${window.screen.width}:${window.screen.height}`}),typeof navigator<"u"&&(a={...a,browser:navigator.userAgent});try{let s=await fetch(`${t}/site/event`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:r,data:a})});if(!s.ok){let c=await s.text();return(0,d.warn)("tracking error:"+c),{error:c}}}catch(s){let c=s instanceof Error?s.message:"Unknown error";return(0,d.warn)("tracking error:"+c),{error:c}}return{}},M=async e=>{let{analyticaToken:r,overrideBaseUrl:t="https://analytica.click/api",devMode:o,valueOverrides:i}=e;if(!o&&typeof window<"u"&&window.location.hostname==="localhost")return(0,d.debug)(`local page ignored: ${JSON.stringify(e)}, to ${t}`),{};let n={pageLocation:"",browserFingerprint:i?.browserFingerprint};if(typeof window<"u"&&(n={...n,pageLocation:window.location.href,browserResolution:`${window.screen.width}:${window.screen.height}`}),typeof document<"u"&&(n={...n,pageReferrer:document.referrer,pageTitle:document.title}),typeof navigator<"u"&&(n={...n,browserLanguage:navigator.language,browser:navigator.userAgent}),!n.pageLocation)return(0,d.warn)("no pageLocation"),{};try{let a=await fetch(`${t}/site/tracking`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:r,data:n})});if(!a.ok){let s=await a.text();return(0,d.warn)("tracking error:"+s),{error:s}}}catch(a){let s=a instanceof Error?a.message:"Unknown error";return(0,d.warn)("tracking error:"+s),{error:s}}return{}},$=async e=>{let{analyticaToken:r,overrideBaseUrl:t="https://analytica.click/api",type:o,value:i,devMode:n}=e;if(!n&&typeof window<"u"&&window.location.hostname==="localhost")return(0,d.debug)(`local metric ignored: ${JSON.stringify(e)}, to ${t}`),{};if(o==="health")return(0,d.warn)('Type "health" is reserved for system metrics'),{error:'Type "health" is reserved for system metrics'};let a={type:o,value:i};try{let s=await fetch(`${t}/site/metric`,{method:"POST",headers:{"Content-Type":"application/json",authorization:""},body:JSON.stringify({key:r,data:a})});if(!s.ok){let c=await s.text();return(0,d.warn)("metric tracking error:"+c),{error:c}}}catch(s){let c=s instanceof Error?s.message:"Unknown error";return(0,d.warn)("metric tracking error:"+c),{error:c}}return{}};var q=require("ag-common/dist/common/helpers/log"),G=require("react");var ce=()=>{let e=(0,G.useContext)(g);if(!e.analyticaToken){(0,q.warn)(y("useAnalytica"));let r=async()=>({error:"no token"});return{event:r,page:r,metric:r}}return{event:r=>I({...r,...e}),page:r=>M({...r,...e}),metric:r=>$({...r,...e})}};0&&(module.exports={AnalyticaClickProvider,AnalyticaConfigContext,Modal,errorTrack,event,getErrorKey,metric,page,tokenMissing,useAnalytica});
|
@@ -175,18 +175,16 @@ export declare const HealthMetricSchema: z.ZodObject<{
|
|
175
175
|
}, z.core.$strip>;
|
176
176
|
export declare const UserMetricSchema: z.ZodObject<{
|
177
177
|
type: z.ZodString;
|
178
|
-
name: z.ZodString;
|
179
178
|
value: z.ZodNumber;
|
180
179
|
}, z.core.$strip>;
|
181
|
-
export declare const MetricItemSchema: z.
|
180
|
+
export declare const MetricItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
182
181
|
type: z.ZodLiteral<"health">;
|
183
182
|
responseTimeMs: z.ZodNumber;
|
184
183
|
success: z.ZodBoolean;
|
185
184
|
}, z.core.$strip>, z.ZodObject<{
|
186
185
|
type: z.ZodString;
|
187
|
-
name: z.ZodString;
|
188
186
|
value: z.ZodNumber;
|
189
|
-
}, z.core.$strip>]>;
|
187
|
+
}, z.core.$strip>], "type">;
|
190
188
|
export declare const MetricSchema: z.ZodObject<{
|
191
189
|
account: z.ZodOptional<z.ZodString>;
|
192
190
|
site: z.ZodString;
|
@@ -195,15 +193,14 @@ export declare const MetricSchema: z.ZodObject<{
|
|
195
193
|
SERVER: "SERVER";
|
196
194
|
CLIENT: "CLIENT";
|
197
195
|
}>;
|
198
|
-
metric: z.
|
196
|
+
metric: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
199
197
|
type: z.ZodLiteral<"health">;
|
200
198
|
responseTimeMs: z.ZodNumber;
|
201
199
|
success: z.ZodBoolean;
|
202
200
|
}, z.core.$strip>, z.ZodObject<{
|
203
201
|
type: z.ZodString;
|
204
|
-
name: z.ZodString;
|
205
202
|
value: z.ZodNumber;
|
206
|
-
}, z.core.$strip>]>;
|
203
|
+
}, z.core.$strip>], "type">;
|
207
204
|
}, z.core.$strip>;
|
208
205
|
export interface IMetric extends z.infer<typeof MetricSchema> {
|
209
206
|
}
|
@@ -383,14 +380,12 @@ export declare const PostErrorSchema: z.ZodObject<{
|
|
383
380
|
}, z.core.$strip>;
|
384
381
|
export declare const PostMetricDataSchema: z.ZodObject<{
|
385
382
|
type: z.ZodString;
|
386
|
-
name: z.ZodString;
|
387
383
|
value: z.ZodNumber;
|
388
384
|
}, z.core.$strip>;
|
389
385
|
export declare const PostMetricSchema: z.ZodObject<{
|
390
386
|
key: z.ZodString;
|
391
387
|
data: z.ZodObject<{
|
392
388
|
type: z.ZodString;
|
393
|
-
name: z.ZodString;
|
394
389
|
value: z.ZodNumber;
|
395
390
|
}, z.core.$strip>;
|
396
391
|
}, z.core.$strip>;
|
@@ -512,15 +507,14 @@ export declare const SiteDataSchema: z.ZodObject<{
|
|
512
507
|
SERVER: "SERVER";
|
513
508
|
CLIENT: "CLIENT";
|
514
509
|
}>;
|
515
|
-
metric: z.
|
510
|
+
metric: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
516
511
|
type: z.ZodLiteral<"health">;
|
517
512
|
responseTimeMs: z.ZodNumber;
|
518
513
|
success: z.ZodBoolean;
|
519
514
|
}, z.core.$strip>, z.ZodObject<{
|
520
515
|
type: z.ZodString;
|
521
|
-
name: z.ZodString;
|
522
516
|
value: z.ZodNumber;
|
523
|
-
}, z.core.$strip>]>;
|
517
|
+
}, z.core.$strip>], "type">;
|
524
518
|
}, z.core.$strip>>>;
|
525
519
|
languages: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
526
520
|
account: z.ZodOptional<z.ZodString>;
|