Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@clutter/wt

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clutter/wt - npm Package Compare versions

Comparing version 3.1.0-alpha.1 to 3.1.0-alpha.2

1

dist/client.d.ts

@@ -49,2 +49,3 @@ export declare const SEND_STARTED = "send:started";

schema?: string;
visitorToken?: string;
};

@@ -51,0 +52,0 @@ export declare type WTPayload = {

2

dist/wt.min.js

@@ -1,1 +0,1 @@

var H=Object.create;var l=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptor,z=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertyNames,p=Object.getOwnPropertySymbols,J=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var y=(t,e,n)=>e in t?l(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,i=(t,e)=>{for(var n in e||(e={}))f.call(e,n)&&y(t,n,e[n]);if(p)for(var n of p(e))k.call(e,n)&&y(t,n,e[n]);return t},m=(t,e)=>X(t,z(e));var h=(t,e)=>{var n={};for(var r in t)f.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&p)for(var r of p(t))e.indexOf(r)<0&&k.call(t,r)&&(n[r]=t[r]);return n};var Z=(t,e)=>{for(var n in e)l(t,n,{get:e[n],enumerable:!0})},W=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of G(e))!f.call(t,s)&&s!==n&&l(t,s,{get:()=>e[s],enumerable:!(r=Y(e,s))||r.enumerable});return t};var x=(t,e,n)=>(n=t!=null?H(J(t)):{},W(e||!t||!t.__esModule?l(n,"default",{value:t,enumerable:!0}):n,t)),ee=t=>W(l({},"__esModule",{value:!0}),t);var de={};Z(de,{PAGE_UUID_KEY:()=>M,QUEUE_COMPLETED:()=>I,QUEUE_CONTINUED:()=>K,SEND_COMPLETED:()=>F,SEND_STARTED:()=>V,VISITOR_TOKEN_KEY:()=>Q,WT:()=>b,WTProvider:()=>oe,createProvider:()=>v,default:()=>ue,useTrack:()=>ae,useWT:()=>ce,withContext:()=>q});module.exports=ee(de);var a=x(require("react")),v=(t,{validateEvent:e}={})=>{let n=a.default.createContext({params:{current:{}},track:()=>{throw new Error("No WTProvider found")}});return{WTProvider:({params:o={},children:u})=>{let g=(0,a.useRef)(o),{params:d}=(0,a.useContext)(n);g.current=i(i({},d.current),o);let C=(0,a.useCallback)($=>{let P=i(i({},g.current),$);(!e||e(P))&&t(P)},[]),B=(0,a.useMemo)(()=>({track:C,params:g}),[C]);return a.default.createElement(n.Provider,{value:B},u)},useWT:()=>{let{track:o,params:u}=(0,a.useContext)(n);return{track:o,params:u.current}},useTrack:(o={})=>{let{track:u}=(0,a.useContext)(n),g=(0,a.useRef)(o);return(0,a.useEffect)(()=>{g.current=o}),(0,a.useCallback)(d=>u(i(i({},g.current),d)),[u])}}};var T=x(require("js-cookie")),S=x(require("events"));var w=t=>Object.prototype.toString.call(t)==="[object Function]",D=(t,e,{maxWait:n}={})=>{let r,s,c,o=!1,u=()=>{clearTimeout(r),clearTimeout(s),o=!1,c=void 0},g=(...d)=>(u(),t(...d));return Object.assign((...d)=>{clearTimeout(r),r=window.setTimeout(g,e,...d),!o&&n&&(s=window.setTimeout(g,n,...d),o=!0),c=()=>t(...d)},{clear:u,flush(){return c?c():null}})},O=t=>t==null,R=(t,e)=>Object.keys(t).reduce((n,r)=>e(t[r],r,t)?n:m(i({},n),{[r]:t[r]}),{}),_=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)}),U=t=>Object.keys(t).reduce((e,n)=>(e[n.replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase()]=t[n],e),{});var te=500,ne=1500,A=100,re=7300;function N(t,...e){return w(t)?t(...e):t}var V="send:started",F="send:completed",I="queue:completed",K="queue:continued",Q="wt_visitor_token",M="wt_page_uuid";function j(t,e={}){let n=T.default.get(t);return n||(n=_(),T.default.set(t,n,e)),n}var L=t=>{var e;return(e=new URLSearchParams(t).get("wvt"))!=null?e:void 0},ie=(t={},e)=>L(e)||j(Q,t),se=()=>j(M),b=class{constructor(e){this.loading=!1;this.emitter=new S.default;this.wtConfig={cookieOptions:{expires:re}};this.paramDefaults={};this.eventQueue=[];this.pageUuid=null;this.context=e,this.updateProcessEventsDebounced()}initialize(e){this.config(e),this.wtConfig.cookieOptions&&(this.getUUIDToken(),this.getVisitorToken())}getVisitorToken(){return ie(this.wtConfig.cookieOptions,this.context.location&&this.context.location.search)}getUUIDToken(){return this.pageUuid=se(),this.pageUuid}track(e){var r;let n=typeof e=="string"?{kind:e}:e;this.addToQueue(m(i({},n),{kind:(r=n.kind)!=null?r:"event"}))}flush(){this.processEventsDebounced.flush()}clear(){this.paramDefaults={}}set(e){this.paramDefaults=i(i({},this.paramDefaults),N(e,this.paramDefaults,this))}config(e){this.wtConfig=i(i({},this.wtConfig),N(e,this.wtConfig,this)),this.updateProcessEventsDebounced()}subscribe(e,n){return this.emitter.on(e,n),()=>{this.emitter.removeListener(e,n)}}addToQueue(e){let u=e,{metadata:n}=u,r=h(u,["metadata"]),g=this.paramDefaults,{metadata:d={}}=g,s=h(d,[]),c=h(g,["metadata"]),o=i(i({},s),n);this.eventQueue.push(R(U(m(i(m(i(i({},c),r),{metadata:Object.keys(o).length>0?o:void 0}),this.getEventEnvironmentArgs()),{ts:new Date().valueOf()})),O)),this.processEventsDebounced()}getRoot(){return this.wtConfig.trackerDomain?this.wtConfig.trackerDomain:`//${this.context.location.hostname}`}sendToServer(e,n,r){var s;this.context.fetch(`${this.getRoot()}/wt/t`,i({method:"POST",credentials:"include",body:JSON.stringify(e),headers:i({"Content-Type":"text/plain"},(s=this.wtConfig.fetchConfig)==null?void 0:s.headers),keepalive:!0},this.wtConfig.fetchConfig)).then(c=>{if(c.ok)n();else throw new Error}).catch(()=>{var c,o;(o=(c=this.wtConfig).onError)==null||o.call(c,e),r()}),this.emitter.emit(V)}getRequestEnvironmentArgs(){return{dimensions:{width:this.context.innerWidth,height:this.context.innerHeight},agent:this.context.navigator.userAgent,rts:new Date().valueOf(),wvt:L(this.context.location&&this.context.location.search)}}getEventEnvironmentArgs(){return{url:this.context.location.href,referrer:this.context.document.referrer,page_uuid:this.pageUuid}}processEvents(){if(this.loading)return;let e=this.eventQueue.slice(0,A);if(this.eventQueue=this.eventQueue.slice(A),!e.length)return;let n=i({events:e},this.getRequestEnvironmentArgs());this.loading=!0;let r=()=>{this.emitter.emit(F),this.eventQueue.length?(this.processEventsDebounced(),this.emitter.emit(K)):this.emitter.emit(I),this.loading=!1},s=()=>{this.loading=!1};this.sendToServer(n,r,s)}updateProcessEventsDebounced(){var e,n,r,s;this.processEventsDebounced=D(this.processEvents.bind(this),(n=(e=this.wtConfig.debounce)==null?void 0:e.min)!=null?n:te,{maxWait:(s=(r=this.wtConfig.debounce)==null?void 0:r.max)!=null?s:ne})}};function q(t){return new b(t)}var E=q(global);var{WTProvider:oe,useTrack:ae,useWT:ce}=v(t=>E.track(t)),ue=E;
var H=Object.create;var l=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptor,z=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertyNames,p=Object.getOwnPropertySymbols,J=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var k=(t,e,n)=>e in t?l(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,i=(t,e)=>{for(var n in e||(e={}))f.call(e,n)&&k(t,n,e[n]);if(p)for(var n of p(e))y.call(e,n)&&k(t,n,e[n]);return t},m=(t,e)=>X(t,z(e));var h=(t,e)=>{var n={};for(var r in t)f.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&p)for(var r of p(t))e.indexOf(r)<0&&y.call(t,r)&&(n[r]=t[r]);return n};var Z=(t,e)=>{for(var n in e)l(t,n,{get:e[n],enumerable:!0})},W=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of G(e))!f.call(t,s)&&s!==n&&l(t,s,{get:()=>e[s],enumerable:!(r=Y(e,s))||r.enumerable});return t};var x=(t,e,n)=>(n=t!=null?H(J(t)):{},W(e||!t||!t.__esModule?l(n,"default",{value:t,enumerable:!0}):n,t)),ee=t=>W(l({},"__esModule",{value:!0}),t);var de={};Z(de,{PAGE_UUID_KEY:()=>M,QUEUE_COMPLETED:()=>I,QUEUE_CONTINUED:()=>K,SEND_COMPLETED:()=>F,SEND_STARTED:()=>V,VISITOR_TOKEN_KEY:()=>Q,WT:()=>b,WTProvider:()=>oe,createProvider:()=>v,default:()=>ue,useTrack:()=>ae,useWT:()=>ce,withContext:()=>q});module.exports=ee(de);var a=x(require("react")),v=(t,{validateEvent:e}={})=>{let n=a.default.createContext({params:{current:{}},track:()=>{throw new Error("No WTProvider found")}});return{WTProvider:({params:o={},children:u})=>{let g=(0,a.useRef)(o),{params:d}=(0,a.useContext)(n);g.current=i(i({},d.current),o);let C=(0,a.useCallback)($=>{let P=i(i({},g.current),$);(!e||e(P))&&t(P)},[]),B=(0,a.useMemo)(()=>({track:C,params:g}),[C]);return a.default.createElement(n.Provider,{value:B},u)},useWT:()=>{let{track:o,params:u}=(0,a.useContext)(n);return{track:o,params:u.current}},useTrack:(o={})=>{let{track:u}=(0,a.useContext)(n),g=(0,a.useRef)(o);return(0,a.useEffect)(()=>{g.current=o}),(0,a.useCallback)(d=>u(i(i({},g.current),d)),[u])}}};var T=x(require("js-cookie")),S=x(require("events"));var w=t=>Object.prototype.toString.call(t)==="[object Function]",D=(t,e,{maxWait:n}={})=>{let r,s,c,o=!1,u=()=>{clearTimeout(r),clearTimeout(s),o=!1,c=void 0},g=(...d)=>(u(),t(...d));return Object.assign((...d)=>{clearTimeout(r),r=window.setTimeout(g,e,...d),!o&&n&&(s=window.setTimeout(g,n,...d),o=!0),c=()=>t(...d)},{clear:u,flush(){return c?c():null}})},O=t=>t==null,R=(t,e)=>Object.keys(t).reduce((n,r)=>e(t[r],r,t)?n:m(i({},n),{[r]:t[r]}),{}),_=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)}),U=t=>Object.keys(t).reduce((e,n)=>(e[n.replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase()]=t[n],e),{});var te=500,ne=1500,A=100,re=7300;function N(t,...e){return w(t)?t(...e):t}var V="send:started",F="send:completed",I="queue:completed",K="queue:continued",Q="wt_visitor_token",M="wt_page_uuid";function j(t,e={}){let n=T.default.get(t);return n||(n=_(),T.default.set(t,n,e)),n}var L=t=>{var e;return(e=new URLSearchParams(t).get("wvt"))!=null?e:void 0},ie=(t={},e)=>L(e)||j(Q,t),se=()=>j(M),b=class{constructor(e){this.loading=!1;this.emitter=new S.default;this.wtConfig={cookieOptions:{expires:re}};this.paramDefaults={};this.eventQueue=[];this.pageUuid=null;this.context=e,this.updateProcessEventsDebounced()}initialize(e){this.config(e),this.wtConfig.cookieOptions&&(this.getUUIDToken(),this.getVisitorToken())}getVisitorToken(){return ie(this.wtConfig.cookieOptions,this.context.location&&this.context.location.search)}getUUIDToken(){return this.pageUuid=se(),this.pageUuid}track(e){var r;let n=typeof e=="string"?{kind:e}:e;this.addToQueue(m(i({},n),{kind:(r=n.kind)!=null?r:"event"}))}flush(){this.processEventsDebounced.flush()}clear(){this.paramDefaults={}}set(e){this.paramDefaults=i(i({},this.paramDefaults),N(e,this.paramDefaults,this))}config(e){this.wtConfig=i(i({},this.wtConfig),N(e,this.wtConfig,this)),this.updateProcessEventsDebounced()}subscribe(e,n){return this.emitter.on(e,n),()=>{this.emitter.removeListener(e,n)}}addToQueue(e){let u=e,{metadata:n}=u,r=h(u,["metadata"]),g=this.paramDefaults,{metadata:d={}}=g,s=h(d,[]),c=h(g,["metadata"]),o=i(i({},s),n);this.eventQueue.push(R(U(m(i(m(i(i({},c),r),{metadata:Object.keys(o).length>0?o:void 0}),this.getEventEnvironmentArgs()),{ts:new Date().valueOf()})),O)),this.processEventsDebounced()}getRoot(){return this.wtConfig.trackerDomain?this.wtConfig.trackerDomain:`//${this.context.location.hostname}`}sendToServer(e,n,r){var s;this.context.fetch(`${this.getRoot()}/wt/t`,i({method:"POST",credentials:"include",body:JSON.stringify(e),headers:i({"Content-Type":"text/plain"},(s=this.wtConfig.fetchConfig)==null?void 0:s.headers),keepalive:!0},this.wtConfig.fetchConfig)).then(c=>{if(c.ok)n();else throw new Error}).catch(()=>{var c,o;(o=(c=this.wtConfig).onError)==null||o.call(c,e),r()}),this.emitter.emit(V)}getRequestEnvironmentArgs(){return{dimensions:{width:this.context.innerWidth,height:this.context.innerHeight},agent:this.context.navigator.userAgent,rts:new Date().valueOf(),wvt:L(this.context.location&&this.context.location.search)}}getEventEnvironmentArgs(){return{url:this.context.location.href,referrer:this.context.document.referrer,page_uuid:this.pageUuid}}processEvents(){if(this.loading)return;let e=this.eventQueue.slice(0,A);if(this.eventQueue=this.eventQueue.slice(A),!e.length)return;let n=i({events:e},this.getRequestEnvironmentArgs());this.loading=!0;let r=()=>{this.emitter.emit(F),this.eventQueue.length?(this.processEventsDebounced(),this.emitter.emit(K)):this.emitter.emit(I),this.loading=!1},s=()=>{this.loading=!1};this.sendToServer(n,r,s)}updateProcessEventsDebounced(){var e,n,r,s;this.processEventsDebounced=D(this.processEvents.bind(this),(n=(e=this.wtConfig.debounce)==null?void 0:e.min)!=null?n:te,{maxWait:(s=(r=this.wtConfig.debounce)==null?void 0:r.max)!=null?s:ne})}};function q(t){return new b(t)}var E=q(global);var{WTProvider:oe,useTrack:ae,useWT:ce}=v(t=>E.track(t)),ue=E;
{
"name": "@clutter/wt",
"version": "3.1.0-alpha.1",
"version": "3.1.0-alpha.2",
"scripts": {

@@ -5,0 +5,0 @@ "test": "jest",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc