@ohbug/extension-view 0.0.4 → 0.1.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.
package/README.md CHANGED
@@ -26,5 +26,5 @@ import Ohbug from '@ohbug/browser'
26
26
  import OhbugExtensionView from '@ohbug/extension-view'
27
27
 
28
28
  const client = Ohbug.setup({ apiKey: 'YOUR_API_KEY' })
29
- client.use(OhbugExtensionView)
29
+ client.use(OhbugExtensionView())
30
30
  ```
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { OhbugExtension } from '@ohbug/types';
2
2
 
3
- declare const extension: OhbugExtension;
3
+ declare const extension: () => OhbugExtension;
4
4
 
5
5
  export { extension as default };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { OhbugExtension } from '@ohbug/types';
2
2
 
3
- declare const extension: OhbugExtension;
3
+ declare const extension: () => OhbugExtension;
4
4
 
5
5
  export { extension as default };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var D=Object.create;var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var N=(t,e,i)=>e in t?c(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var R=(t,e)=>{for(var i in e)c(t,i,{get:e[i],enumerable:!0})},E=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of F(e))!M.call(t,s)&&s!==i&&c(t,s,{get:()=>e[s],enumerable:!(n=A(e,s))||n.enumerable});return t};var W=(t,e,i)=>(i=t!=null?D(H(t)):{},E(e||!t||!t.__esModule?c(i,"default",{value:t,enumerable:!0}):i,t)),j=t=>E(c({},"__esModule",{value:!0}),t);var o=(t,e,i)=>(N(t,typeof e!="symbol"?e+"":e,i),i);var Q={};R(Q,{default:()=>K});module.exports=j(Q);var d=class{constructor(e=18e5){o(this,"session",null);o(this,"timeout",18e5);this.session=new Date().getTime(),this.timeout=e}isExpired(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=new Date().getTime();return this.session+this.timeout<e}update(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=new Date().getTime();return this.session=e,this.session}},I=d;var p=require("@ohbug/utils");function l(t,e){let{client:i}=(0,p.getOhbugObject)(),n=i.createEvent({category:"view",type:"pageView",detail:{initial:e,path:t}});i.notify(n)}function f(t){let{client:e}=(0,p.getOhbugObject)(),i=e.createEvent({category:"view",type:"userView",detail:{path:t}});e.notify(i)}var r=W(require("dayjs"));var g="OhbugExtensionViewUV",B=30;function J(t,e,i=null){let n=JSON.parse(e);return n?(0,r.default)().isAfter((0,r.default)(n.expiry))?(localStorage.removeItem(t),i):n.value:i}var w={getItem(t){let e=localStorage.getItem(t);return e?J(t,e):null},setItem(t,e){let i=(0,r.default)(),n={value:e,expiry:i.add(B,"day").toISOString()};return localStorage.setItem(t,JSON.stringify(n))},removeItem(t){return localStorage.removeItem(t)}};function _(t){let e=w.getItem(g);e?(0,r.default)(e).isBefore((0,r.default)(),"day")&&(w.setItem(g,(0,r.default)().toISOString()),f(t)):(w.setItem(g,(0,r.default)().toISOString()),f(t))}var u=_;var X="hidden",x="visible",m=class t{constructor(){o(this,"visible",null);o(this,"lastVisible",null);o(this,"initialVisible",null);o(this,"sendPageLoad",!1);o(this,"visibleThresholdTimeout",null);o(this,"session");this.handleVisibleChange=this.handleVisibleChange.bind(this),window.addEventListener("visibilitychange",this.handleVisibleChange,!0),this.init(),this.session=new I}static capturePageVisibility(){return new t}init(){this.sendPageLoad||(document.visibilityState===x?(this.initialVisible=!0,l(window.location.href,!0),u(window.location.href),this.sendPageLoad=!0):this.initialVisible=!1)}handleVisibleChange(){this.lastVisible=this.visible,document.visibilityState===x?this.visible=!0:document.visibilityState===X?this.visible=!1:this.visible=null;let{visible:e,lastVisible:i,initialVisible:n,session:s}=this;n===!1&&e===!0&&(l(window.location.href,!0),u(window.location.href),this.initialVisible=null),i===!1&&e===!0&&s.isExpired()&&(l(window.location.href),u(window.location.href)),e===!1&&s.update()}},U=m;var a=require("@ohbug/utils");var S;function y(t,e){var V;let i=(0,a.parseUrl)((V=window==null?void 0:window.location)==null?void 0:V.href),n=(0,a.parseUrl)(t),s=(0,a.parseUrl)(e);n.path||(n=i),S=e;let v=t,h=e;i.protocol===s.protocol&&i.host===s.host&&(h=s.relative),i.protocol===n.protocol&&i.host===n.host&&(v=n.relative),v!==h&&l(h)}function T(t){return function(i,n,s){return s&&y(S,String(s)),t.apply(this,[i,n,s])}}var O,L,b={pushState:(O=window==null?void 0:window.history)==null?void 0:O.pushState,replaceState:(L=window==null?void 0:window.history)==null?void 0:L.replaceState,onpopstate:window==null?void 0:window.onpopstate};function k(){b.pushState=(0,a.replace)(window==null?void 0:window.history,"pushState",T),b.replaceState=(0,a.replace)(window==null?void 0:window.history,"replaceState",T),b.onpopstate=(0,a.replace)(window,"onpopstate",()=>{var e;let t=(e=window==null?void 0:window.location)==null?void 0:e.href;y(S,t)})}function q(t){let{oldURL:e,newURL:i}=t;y(e,i)}function z(){var t;k(),(t=window==null?void 0:window.addEventListener)==null||t.call(window,"hashchange",q,!0)}var P=z;var G={name:"OhbugExtensionView",onSetup:()=>{U.capturePageVisibility(),P()}},C=G;var K=C;
1
+ "use strict";var D=Object.create;var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var N=(t,e,i)=>e in t?c(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var R=(t,e)=>{for(var i in e)c(t,i,{get:e[i],enumerable:!0})},E=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of F(e))!M.call(t,s)&&s!==i&&c(t,s,{get:()=>e[s],enumerable:!(n=A(e,s))||n.enumerable});return t};var W=(t,e,i)=>(i=t!=null?D(H(t)):{},E(e||!t||!t.__esModule?c(i,"default",{value:t,enumerable:!0}):i,t)),j=t=>E(c({},"__esModule",{value:!0}),t);var o=(t,e,i)=>(N(t,typeof e!="symbol"?e+"":e,i),i);var Q={};R(Q,{default:()=>K});module.exports=j(Q);var d=class{constructor(e=18e5){o(this,"session",null);o(this,"timeout",18e5);this.session=new Date().getTime(),this.timeout=e}isExpired(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=new Date().getTime();return this.session+this.timeout<e}update(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=new Date().getTime();return this.session=e,this.session}},I=d;var p=require("@ohbug/utils");function l(t,e){let{client:i}=(0,p.getOhbugObject)(),n=i.createEvent({category:"view",type:"pageView",detail:{initial:e,path:t}});i.notify(n)}function f(t){let{client:e}=(0,p.getOhbugObject)(),i=e.createEvent({category:"view",type:"userView",detail:{path:t}});e.notify(i)}var r=W(require("dayjs"));var g="OhbugExtensionViewUV",B=30;function J(t,e,i=null){let n=JSON.parse(e);return n?(0,r.default)().isAfter((0,r.default)(n.expiry))?(localStorage.removeItem(t),i):n.value:i}var w={getItem(t){let e=localStorage.getItem(t);return e?J(t,e):null},setItem(t,e){let i=(0,r.default)(),n={value:e,expiry:i.add(B,"day").toISOString()};return localStorage.setItem(t,JSON.stringify(n))},removeItem(t){return localStorage.removeItem(t)}};function _(t){let e=w.getItem(g);e?(0,r.default)(e).isBefore((0,r.default)(),"day")&&(w.setItem(g,(0,r.default)().toISOString()),f(t)):(w.setItem(g,(0,r.default)().toISOString()),f(t))}var u=_;var X="hidden",x="visible",m=class t{constructor(){o(this,"visible",null);o(this,"lastVisible",null);o(this,"initialVisible",null);o(this,"sendPageLoad",!1);o(this,"visibleThresholdTimeout",null);o(this,"session");this.handleVisibleChange=this.handleVisibleChange.bind(this),window.addEventListener("visibilitychange",this.handleVisibleChange,!0),this.init(),this.session=new I}static capturePageVisibility(){return new t}init(){this.sendPageLoad||(document.visibilityState===x?(this.initialVisible=!0,l(window.location.href,!0),u(window.location.href),this.sendPageLoad=!0):this.initialVisible=!1)}handleVisibleChange(){this.lastVisible=this.visible,document.visibilityState===x?this.visible=!0:document.visibilityState===X?this.visible=!1:this.visible=null;let{visible:e,lastVisible:i,initialVisible:n,session:s}=this;n===!1&&e===!0&&(l(window.location.href,!0),u(window.location.href),this.initialVisible=null),i===!1&&e===!0&&s.isExpired()&&(l(window.location.href),u(window.location.href)),e===!1&&s.update()}},U=m;var a=require("@ohbug/utils");var S;function y(t,e){var V;let i=(0,a.parseUrl)((V=window==null?void 0:window.location)==null?void 0:V.href),n=(0,a.parseUrl)(t),s=(0,a.parseUrl)(e);n.path||(n=i),S=e;let v=t,h=e;i.protocol===s.protocol&&i.host===s.host&&(h=s.relative),i.protocol===n.protocol&&i.host===n.host&&(v=n.relative),v!==h&&l(h)}function T(t){return function(i,n,s){return s&&y(S,String(s)),t.apply(this,[i,n,s])}}var O,L,b={pushState:(O=window==null?void 0:window.history)==null?void 0:O.pushState,replaceState:(L=window==null?void 0:window.history)==null?void 0:L.replaceState,onpopstate:window==null?void 0:window.onpopstate};function k(){b.pushState=(0,a.replace)(window==null?void 0:window.history,"pushState",T),b.replaceState=(0,a.replace)(window==null?void 0:window.history,"replaceState",T),b.onpopstate=(0,a.replace)(window,"onpopstate",()=>{var e;let t=(e=window==null?void 0:window.location)==null?void 0:e.href;y(S,t)})}function q(t){let{oldURL:e,newURL:i}=t;y(e,i)}function z(){var t;k(),(t=window==null?void 0:window.addEventListener)==null||t.call(window,"hashchange",q,!0)}var P=z;var G=()=>({name:"OhbugExtensionView",onSetup:()=>{U.capturePageVisibility(),P()}}),C=G;var K=C;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var C=Object.defineProperty;var D=(t,e,i)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var o=(t,e,i)=>(D(t,typeof e!="symbol"?e+"":e,i),i);var u=class{constructor(e=18e5){o(this,"session",null);o(this,"timeout",18e5);this.session=new Date().getTime(),this.timeout=e}isExpired(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=new Date().getTime();return this.session+this.timeout<e}update(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=new Date().getTime();return this.session=e,this.session}},V=u;import{getOhbugObject as E}from"@ohbug/utils";function a(t,e){let{client:i}=E(),n=i.createEvent({category:"view",type:"pageView",detail:{initial:e,path:t}});i.notify(n)}function h(t){let{client:e}=E(),i=e.createEvent({category:"view",type:"userView",detail:{path:t}});e.notify(i)}import r from"dayjs";var d="OhbugExtensionViewUV",A=30;function F(t,e,i=null){let n=JSON.parse(e);return n?r().isAfter(r(n.expiry))?(localStorage.removeItem(t),i):n.value:i}var p={getItem(t){let e=localStorage.getItem(t);return e?F(t,e):null},setItem(t,e){let i=r(),n={value:e,expiry:i.add(A,"day").toISOString()};return localStorage.setItem(t,JSON.stringify(n))},removeItem(t){return localStorage.removeItem(t)}};function H(t){let e=p.getItem(d);e?r(e).isBefore(r(),"day")&&(p.setItem(d,r().toISOString()),h(t)):(p.setItem(d,r().toISOString()),h(t))}var l=H;var M="hidden",I="visible",f=class t{constructor(){o(this,"visible",null);o(this,"lastVisible",null);o(this,"initialVisible",null);o(this,"sendPageLoad",!1);o(this,"visibleThresholdTimeout",null);o(this,"session");this.handleVisibleChange=this.handleVisibleChange.bind(this),window.addEventListener("visibilitychange",this.handleVisibleChange,!0),this.init(),this.session=new V}static capturePageVisibility(){return new t}init(){this.sendPageLoad||(document.visibilityState===I?(this.initialVisible=!0,a(window.location.href,!0),l(window.location.href),this.sendPageLoad=!0):this.initialVisible=!1)}handleVisibleChange(){this.lastVisible=this.visible,document.visibilityState===I?this.visible=!0:document.visibilityState===M?this.visible=!1:this.visible=null;let{visible:e,lastVisible:i,initialVisible:n,session:s}=this;n===!1&&e===!0&&(a(window.location.href,!0),l(window.location.href),this.initialVisible=null),i===!1&&e===!0&&s.isExpired()&&(a(window.location.href),l(window.location.href)),e===!1&&s.update()}},x=f;import{parseUrl as g,replace as w}from"@ohbug/utils";var b;function S(t,e){var v;let i=g((v=window==null?void 0:window.location)==null?void 0:v.href),n=g(t),s=g(e);n.path||(n=i),b=e;let y=t,c=e;i.protocol===s.protocol&&i.host===s.host&&(c=s.relative),i.protocol===n.protocol&&i.host===n.host&&(y=n.relative),y!==c&&a(c)}function U(t){return function(i,n,s){return s&&S(b,String(s)),t.apply(this,[i,n,s])}}var T,O,m={pushState:(T=window==null?void 0:window.history)==null?void 0:T.pushState,replaceState:(O=window==null?void 0:window.history)==null?void 0:O.replaceState,onpopstate:window==null?void 0:window.onpopstate};function N(){m.pushState=w(window==null?void 0:window.history,"pushState",U),m.replaceState=w(window==null?void 0:window.history,"replaceState",U),m.onpopstate=w(window,"onpopstate",()=>{var e;let t=(e=window==null?void 0:window.location)==null?void 0:e.href;S(b,t)})}function R(t){let{oldURL:e,newURL:i}=t;S(e,i)}function W(){var t;N(),(t=window==null?void 0:window.addEventListener)==null||t.call(window,"hashchange",R,!0)}var L=W;var j={name:"OhbugExtensionView",onSetup:()=>{x.capturePageVisibility(),L()}},P=j;var ae=P;export{ae as default};
1
+ var C=Object.defineProperty;var D=(t,e,i)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var o=(t,e,i)=>(D(t,typeof e!="symbol"?e+"":e,i),i);var u=class{constructor(e=18e5){o(this,"session",null);o(this,"timeout",18e5);this.session=new Date().getTime(),this.timeout=e}isExpired(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=new Date().getTime();return this.session+this.timeout<e}update(){if(!this.session)throw new Error("Session \u6CA1\u6709\u521D\u59CB\u5316");let e=new Date().getTime();return this.session=e,this.session}},V=u;import{getOhbugObject as E}from"@ohbug/utils";function a(t,e){let{client:i}=E(),n=i.createEvent({category:"view",type:"pageView",detail:{initial:e,path:t}});i.notify(n)}function h(t){let{client:e}=E(),i=e.createEvent({category:"view",type:"userView",detail:{path:t}});e.notify(i)}import r from"dayjs";var d="OhbugExtensionViewUV",A=30;function F(t,e,i=null){let n=JSON.parse(e);return n?r().isAfter(r(n.expiry))?(localStorage.removeItem(t),i):n.value:i}var p={getItem(t){let e=localStorage.getItem(t);return e?F(t,e):null},setItem(t,e){let i=r(),n={value:e,expiry:i.add(A,"day").toISOString()};return localStorage.setItem(t,JSON.stringify(n))},removeItem(t){return localStorage.removeItem(t)}};function H(t){let e=p.getItem(d);e?r(e).isBefore(r(),"day")&&(p.setItem(d,r().toISOString()),h(t)):(p.setItem(d,r().toISOString()),h(t))}var l=H;var M="hidden",I="visible",f=class t{constructor(){o(this,"visible",null);o(this,"lastVisible",null);o(this,"initialVisible",null);o(this,"sendPageLoad",!1);o(this,"visibleThresholdTimeout",null);o(this,"session");this.handleVisibleChange=this.handleVisibleChange.bind(this),window.addEventListener("visibilitychange",this.handleVisibleChange,!0),this.init(),this.session=new V}static capturePageVisibility(){return new t}init(){this.sendPageLoad||(document.visibilityState===I?(this.initialVisible=!0,a(window.location.href,!0),l(window.location.href),this.sendPageLoad=!0):this.initialVisible=!1)}handleVisibleChange(){this.lastVisible=this.visible,document.visibilityState===I?this.visible=!0:document.visibilityState===M?this.visible=!1:this.visible=null;let{visible:e,lastVisible:i,initialVisible:n,session:s}=this;n===!1&&e===!0&&(a(window.location.href,!0),l(window.location.href),this.initialVisible=null),i===!1&&e===!0&&s.isExpired()&&(a(window.location.href),l(window.location.href)),e===!1&&s.update()}},x=f;import{parseUrl as g,replace as w}from"@ohbug/utils";var b;function S(t,e){var v;let i=g((v=window==null?void 0:window.location)==null?void 0:v.href),n=g(t),s=g(e);n.path||(n=i),b=e;let y=t,c=e;i.protocol===s.protocol&&i.host===s.host&&(c=s.relative),i.protocol===n.protocol&&i.host===n.host&&(y=n.relative),y!==c&&a(c)}function U(t){return function(i,n,s){return s&&S(b,String(s)),t.apply(this,[i,n,s])}}var T,O,m={pushState:(T=window==null?void 0:window.history)==null?void 0:T.pushState,replaceState:(O=window==null?void 0:window.history)==null?void 0:O.replaceState,onpopstate:window==null?void 0:window.onpopstate};function N(){m.pushState=w(window==null?void 0:window.history,"pushState",U),m.replaceState=w(window==null?void 0:window.history,"replaceState",U),m.onpopstate=w(window,"onpopstate",()=>{var e;let t=(e=window==null?void 0:window.location)==null?void 0:e.href;S(b,t)})}function R(t){let{oldURL:e,newURL:i}=t;S(e,i)}function W(){var t;N(),(t=window==null?void 0:window.addEventListener)==null||t.call(window,"hashchange",R,!0)}var L=W;var j=()=>({name:"OhbugExtensionView",onSetup:()=>{x.capturePageVisibility(),L()}}),P=j;var ae=P;export{ae as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohbug/extension-view",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "Ohbug extension to collect view data",
5
5
  "license": "MIT",
6
6
  "author": "chenyueban <jasonchan0527@gmail.com>",