@byhealth/data-reporter
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.0-beta.2
@@ -12,5 +12,5 @@ 'use strict'; | ||
const config = { | ||
SDK_VERSION: "1.0.0-beta.1", | ||
SDK_VERSION: "1.0.0-beta.2", | ||
DEBUG: false, | ||
API_URL: '', | ||
API_URL: 'https://trk.by-health.com/trk-api/trk/data', | ||
}; | ||
@@ -251,3 +251,3 @@ | ||
'content-type': 'application/json', | ||
token, | ||
'trk-project': token, | ||
}, | ||
@@ -297,3 +297,10 @@ body: JSON.stringify(data), | ||
if (typeof window === 'object') { | ||
data.metadata.url = window.location.href; | ||
const sensitiveParams = ['token', 'jwt', 'jwtToken', 'openid', 'unionid', 'code', 'state', 'phone', 'mobile']; | ||
const url = new URL(window.location.href); | ||
sensitiveParams.forEach((param) => { | ||
if (url.searchParams.has(param)) { | ||
url.searchParams.set(param, '!hidden!'); | ||
} | ||
}); | ||
data.metadata.url = url.toString(); | ||
data.metadata.title = window.document.title; | ||
@@ -359,3 +366,3 @@ } | ||
'content-type': 'application/json', | ||
token, | ||
'trk-project': token, | ||
}, | ||
@@ -362,0 +369,0 @@ data, |
@@ -10,5 +10,5 @@ import { nanoid } from 'nanoid'; | ||
const config = { | ||
SDK_VERSION: "1.0.0-beta.1", | ||
SDK_VERSION: "1.0.0-beta.2", | ||
DEBUG: false, | ||
API_URL: '', | ||
API_URL: 'https://trk.by-health.com/trk-api/trk/data', | ||
}; | ||
@@ -249,3 +249,3 @@ | ||
'content-type': 'application/json', | ||
token, | ||
'trk-project': token, | ||
}, | ||
@@ -295,3 +295,10 @@ body: JSON.stringify(data), | ||
if (typeof window === 'object') { | ||
data.metadata.url = window.location.href; | ||
const sensitiveParams = ['token', 'jwt', 'jwtToken', 'openid', 'unionid', 'code', 'state', 'phone', 'mobile']; | ||
const url = new URL(window.location.href); | ||
sensitiveParams.forEach((param) => { | ||
if (url.searchParams.has(param)) { | ||
url.searchParams.set(param, '!hidden!'); | ||
} | ||
}); | ||
data.metadata.url = url.toString(); | ||
data.metadata.title = window.document.title; | ||
@@ -357,3 +364,3 @@ } | ||
'content-type': 'application/json', | ||
token, | ||
'trk-project': token, | ||
}, | ||
@@ -360,0 +367,0 @@ data, |
@@ -1,2 +0,2 @@ | ||
!function(){"use strict";let t=(t=21)=>{let e="",s=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[63&s[t]];return e};const e={SDK_VERSION:"1.0.0-beta.1",DEBUG:!1,API_URL:""};function s(t,s,...n){e.DEBUG&&console[t]?.(s,...n)}const n=(t,...e)=>s("warn",t,...e),i=(t,...e)=>s("error",t,...e),{parse:a,stringify:o}=JSON,{keys:r}=Object,h=String,c="string",u={},d="object",l=(t,e)=>e,m=t=>t instanceof h?h(t):t,p=(t,e)=>typeof e===c?new h(e):e,f=(t,e,s,n)=>{const i=[];for(let a=r(s),{length:o}=a,c=0;c<o;c++){const o=a[c],r=s[o];if(r instanceof h){const a=t[r];typeof a!==d||e.has(a)?s[o]=n.call(s,o,a):(e.add(a),s[o]=u,i.push({k:o,a:[t,e,a,n]}))}else s[o]!==u&&(s[o]=n.call(s,o,r))}for(let{length:t}=i,e=0;e<t;e++){const{k:t,a:a}=i[e];s[t]=n.call(s,t,f.apply(null,a))}return s},_=(t,e,s)=>{const n=h(e.push(s)-1);return t.set(s,n),n},g=(t,e,s)=>{const n=e&&typeof e===d?(t,s)=>""===t||-1<e.indexOf(t)?s:void 0:e||l,i=new Map,a=[],r=[];let h=+_(i,a,n.call({"":t},"",t)),u=!h;for(;h<a.length;)u=!0,r[h]=o(a[h++],m,s);return"["+r.join(",")+"]";function m(t,e){if(u)return u=!u,e;const s=n.call(this,t,e);switch(typeof s){case d:if(null===s)return s;case c:return i.get(s)||_(i,a,s)}return s}},w=t=>((t,e)=>{const s=a(t,p).map(m),n=s[0],i=e||l,o=typeof n===d&&n?f(s,new Set,n,i):n;return i.call({"":o},"",o)})(o(t)),y="$uid",k="$cap_queue";class O{_hooks={};_metadata={};_captureQueue=[];_token="";_sending=!1;_storage;_transport;constructor(t){this._storage=t.storage,this._transport=t.transport,!0===t.debug&&(e.DEBUG=!0),t.apiUrl&&(e.API_URL=t.apiUrl),t.token||n("The token is empty, the data will not be transmitted."),this._token=t.token,this._metadata.uid=this.getUid(),this._metadata.sid=this.getSid(),this._metadata.sdk_ver=e.SDK_VERSION,this.emit("ready",this)}on(t,e){return t?"function"!=typeof e?(console.warn("The listener is not a function."),this):(this._hooks[t]||(this._hooks[t]=[]),void(this._hooks[t]=[...this._hooks[t],e])):(console.warn("The hook is empty."),this)}off(t,e){return t?"function"!=typeof e?(console.warn("The listener is not a function."),this):void(this._hooks[t]&&(this._hooks[t]=this._hooks[t].filter((t=>t!==e)))):(console.warn("The hook is empty."),this)}emit(t,...e){const s=this._hooks[t];s&&s.forEach((t=>t(...e)))}meta(t,e){return t?(null===e?delete this._metadata[t]:this._metadata[t]=e,this):(i("The metadata name cannot be empty."),this)}capture(t,e,s){if(!t)return void n("The event name is empty.");const i={id:this.getCid(),event:t,metadata:this.clone({...this._metadata,...s?.metadata}),properties:this.clone(e||{}),timestamp:this.getTime()};s?.timestamp&&(i.metadata.ctime=i.timestamp,i.timestamp=s.timestamp),this.emit("capture",i),this.send(i,{instant:!!s?.instant})}send(t,e){this.emit("send",t,e),e.instant?this._transport.send({token:this._token,data:[t]}):(this._captureQueue.push(t),this.persist(),this._captureQueue.length>=5&&this.nextTick((()=>this.flush()),0)),this.nextTick((()=>this.flush()),5e3)}flush(){if(console.log("flush",this._captureQueue.length,this._sending),0===this._captureQueue.length)return;if(this._sending)return;this._sending=!0;const t=this._captureQueue.splice(0,5);return this.persist(),this._transport.send({token:this._token,data:t}).finally((()=>{this._sending=!1,this._captureQueue.length>0&&this.nextTick((()=>this.flush()))}))}nextTick(t,e=0){setTimeout(t,e)}persist(){this._storage.set(k,this._captureQueue)}rehydrate(){this._captureQueue=this._storage.get(k)||[]}clone(t){return w(a(g(t)))}getTime(){return Date.now()}getCid(){return t(21)}getUid(){let e=this._storage.get(y);return e||(e=t(15),this._storage.set(y,e)),e}getSid(){return t(11)}}class U{_storage;constructor(){this._storage=window.localStorage}get(t){if(!t)return null;try{const e=this._storage.getItem(t);if(null!==e)return JSON.parse(e)}catch(t){}return null}set(t,e){if(t)try{const s=JSON.stringify(e);this._storage.setItem(t,s)}catch(t){}}remove(t){if(t)try{this._storage.removeItem(t)}catch(t){}}}class S{send({token:t,data:s}){return fetch(e.API_URL,{method:"POST",headers:{"content-type":"application/json",token:t},body:JSON.stringify(s),mode:"cors"}).then((t=>t.ok))}}class T extends O{constructor(t){super({...t,storage:new U,transport:new S}),this._metadata.os=this.getOS(),this._metadata.platform=this.getPlatform(),this.on("capture",this.addUrlMeta),this.on("capture",this.addUTMParameter)}getOS(){const t=window?.navigator?.userAgent||"";let e="";return-1!=t.indexOf("Win")&&(e="Windows"),-1!=t.indexOf("Mac")&&(e="MacOS"),-1!=t.indexOf("X11")&&(e="UNIX"),-1!=t.indexOf("Linux")&&(e="Linux"),e}getPlatform(){const t=window?.navigator?.userAgent||"";let e="";return t&&(e="browser"),-1!==t.indexOf("MicroMessenger")&&(e="WeChat"),-1!==t.indexOf("miniProgram")&&(e="MiniProgram"),e}addUrlMeta(t){"object"==typeof window&&(t.metadata.url=window.location.href,t.metadata.title=window.document.title)}addUTMParameter(t){if("object"==typeof window&&"function"==typeof URL){const e=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],s=new URL(window.location.href||"");e.forEach((e=>{const n=s.searchParams.get(e);n&&(t.properties[e]=n)}))}}}let b;function x(t){if(Array.isArray(t)&&"string"==typeof t[0]){const[e,...s]=t;switch(e){case"init":b||(b=new T(s[0]));break;case"on":case"off":case"meta":case"capture":case"flush":b&&b[e]?.apply(b,s)}}}if(!window._bdr?.__integrated){const t=window._bdr;window._bdr={__integrated:!0,push(t){x(t)}},t.forEach((t=>{x(t)}))}}(); | ||
!function(){"use strict";let t=(t=21)=>{let e="",s=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[63&s[t]];return e};const e={SDK_VERSION:"1.0.0-beta.2",DEBUG:!1,API_URL:"https://trk.by-health.com/trk-api/trk/data"};function s(t,s,...n){e.DEBUG&&console[t]?.(s,...n)}const n=(t,...e)=>s("warn",t,...e),i=(t,...e)=>s("error",t,...e),{parse:a,stringify:o}=JSON,{keys:r}=Object,h=String,c="string",u={},d="object",l=(t,e)=>e,p=t=>t instanceof h?h(t):t,m=(t,e)=>typeof e===c?new h(e):e,f=(t,e,s,n)=>{const i=[];for(let a=r(s),{length:o}=a,c=0;c<o;c++){const o=a[c],r=s[o];if(r instanceof h){const a=t[r];typeof a!==d||e.has(a)?s[o]=n.call(s,o,a):(e.add(a),s[o]=u,i.push({k:o,a:[t,e,a,n]}))}else s[o]!==u&&(s[o]=n.call(s,o,r))}for(let{length:t}=i,e=0;e<t;e++){const{k:t,a:a}=i[e];s[t]=n.call(s,t,f.apply(null,a))}return s},_=(t,e,s)=>{const n=h(e.push(s)-1);return t.set(s,n),n},g=(t,e,s)=>{const n=e&&typeof e===d?(t,s)=>""===t||-1<e.indexOf(t)?s:void 0:e||l,i=new Map,a=[],r=[];let h=+_(i,a,n.call({"":t},"",t)),u=!h;for(;h<a.length;)u=!0,r[h]=o(a[h++],p,s);return"["+r.join(",")+"]";function p(t,e){if(u)return u=!u,e;const s=n.call(this,t,e);switch(typeof s){case d:if(null===s)return s;case c:return i.get(s)||_(i,a,s)}return s}},w=t=>((t,e)=>{const s=a(t,m).map(p),n=s[0],i=e||l,o=typeof n===d&&n?f(s,new Set,n,i):n;return i.call({"":o},"",o)})(o(t)),k="$uid",y="$cap_queue";class U{_hooks={};_metadata={};_captureQueue=[];_token="";_sending=!1;_storage;_transport;constructor(t){this._storage=t.storage,this._transport=t.transport,!0===t.debug&&(e.DEBUG=!0),t.apiUrl&&(e.API_URL=t.apiUrl),t.token||n("The token is empty, the data will not be transmitted."),this._token=t.token,this._metadata.uid=this.getUid(),this._metadata.sid=this.getSid(),this._metadata.sdk_ver=e.SDK_VERSION,this.emit("ready",this)}on(t,e){return t?"function"!=typeof e?(console.warn("The listener is not a function."),this):(this._hooks[t]||(this._hooks[t]=[]),void(this._hooks[t]=[...this._hooks[t],e])):(console.warn("The hook is empty."),this)}off(t,e){return t?"function"!=typeof e?(console.warn("The listener is not a function."),this):void(this._hooks[t]&&(this._hooks[t]=this._hooks[t].filter((t=>t!==e)))):(console.warn("The hook is empty."),this)}emit(t,...e){const s=this._hooks[t];s&&s.forEach((t=>t(...e)))}meta(t,e){return t?(null===e?delete this._metadata[t]:this._metadata[t]=e,this):(i("The metadata name cannot be empty."),this)}capture(t,e,s){if(!t)return void n("The event name is empty.");const i={id:this.getCid(),event:t,metadata:this.clone({...this._metadata,...s?.metadata}),properties:this.clone(e||{}),timestamp:this.getTime()};s?.timestamp&&(i.metadata.ctime=i.timestamp,i.timestamp=s.timestamp),this.emit("capture",i),this.send(i,{instant:!!s?.instant})}send(t,e){this.emit("send",t,e),e.instant?this._transport.send({token:this._token,data:[t]}):(this._captureQueue.push(t),this.persist(),this._captureQueue.length>=5&&this.nextTick((()=>this.flush()),0)),this.nextTick((()=>this.flush()),5e3)}flush(){if(console.log("flush",this._captureQueue.length,this._sending),0===this._captureQueue.length)return;if(this._sending)return;this._sending=!0;const t=this._captureQueue.splice(0,5);return this.persist(),this._transport.send({token:this._token,data:t}).finally((()=>{this._sending=!1,this._captureQueue.length>0&&this.nextTick((()=>this.flush()))}))}nextTick(t,e=0){setTimeout(t,e)}persist(){this._storage.set(y,this._captureQueue)}rehydrate(){this._captureQueue=this._storage.get(y)||[]}clone(t){return w(a(g(t)))}getTime(){return Date.now()}getCid(){return t(21)}getUid(){let e=this._storage.get(k);return e||(e=t(15),this._storage.set(k,e)),e}getSid(){return t(11)}}class O{_storage;constructor(){this._storage=window.localStorage}get(t){if(!t)return null;try{const e=this._storage.getItem(t);if(null!==e)return JSON.parse(e)}catch(t){}return null}set(t,e){if(t)try{const s=JSON.stringify(e);this._storage.setItem(t,s)}catch(t){}}remove(t){if(t)try{this._storage.removeItem(t)}catch(t){}}}class S{send({token:t,data:s}){return fetch(e.API_URL,{method:"POST",headers:{"content-type":"application/json","trk-project":t},body:JSON.stringify(s),mode:"cors"}).then((t=>t.ok))}}class T extends U{constructor(t){super({...t,storage:new O,transport:new S}),this._metadata.os=this.getOS(),this._metadata.platform=this.getPlatform(),this.on("capture",this.addUrlMeta),this.on("capture",this.addUTMParameter)}getOS(){const t=window?.navigator?.userAgent||"";let e="";return-1!=t.indexOf("Win")&&(e="Windows"),-1!=t.indexOf("Mac")&&(e="MacOS"),-1!=t.indexOf("X11")&&(e="UNIX"),-1!=t.indexOf("Linux")&&(e="Linux"),e}getPlatform(){const t=window?.navigator?.userAgent||"";let e="";return t&&(e="browser"),-1!==t.indexOf("MicroMessenger")&&(e="WeChat"),-1!==t.indexOf("miniProgram")&&(e="MiniProgram"),e}addUrlMeta(t){if("object"==typeof window){const e=["token","jwt","jwtToken","openid","unionid","code","state","phone","mobile"],s=new URL(window.location.href);e.forEach((t=>{s.searchParams.has(t)&&s.searchParams.set(t,"!hidden!")})),t.metadata.url=s.toString(),t.metadata.title=window.document.title}}addUTMParameter(t){if("object"==typeof window&&"function"==typeof URL){const e=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],s=new URL(window.location.href||"");e.forEach((e=>{const n=s.searchParams.get(e);n&&(t.properties[e]=n)}))}}}let b;function x(t){if(Array.isArray(t)&&"string"==typeof t[0]){const[e,...s]=t;switch(e){case"init":b||(b=new T(s[0]));break;case"on":case"off":case"meta":case"capture":case"flush":b&&b[e]?.apply(b,s)}}}if(!window._bdr?.__integrated){const t=window._bdr;window._bdr={__integrated:!0,push(t){x(t)}},t.forEach((t=>{x(t)}))}}(); | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@byhealth/data-reporter", | ||
"version": "1.0.0-beta.1", | ||
"version": "1.0.0-beta.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69833
966