@ohbug/extension-view 0.0.1 → 0.0.2

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- MIT License
1
+ The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 ohbug-org
3
+ Copyright (c) 2022 chenyueban
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -6,87 +6,25 @@
6
6
  <p>An open source application information monitoring platform.</p>
7
7
  </div>
8
8
 
9
- # OhbugExtension starter
9
+ # `@ohbug/extension-view`
10
10
 
11
- Use this template to create your own Ohbug extension.
11
+ [![npm](https://img.shields.io/npm/v/@ohbug/extension-view.svg?style=flat-square)](https://www.npmjs.com/package/@ohbug/extension-view)
12
+ [![npm bundle size](https://img.shields.io/bundlephobia/min/@ohbug/extension-view?style=flat-square)](https://bundlephobia.com/result?p=@ohbug/extension-view)
12
13
 
13
- English | [简体中文](./README-zh_CN.md)
14
+ Ohbug extension to collect view data
14
15
 
15
- ## Quick start
16
+ ## Installation
16
17
 
17
- 1. **Git clone the repo.**
18
- ```shell
19
- git clone git@github.com:ohbug-org/ohbug-extension-starter.git
20
- ```
21
- 1. **Installation dependencies.**
22
- ```shell
23
- cd ohbug-extension-starter/
24
- yarn
25
- ```
26
- 1. **Start developing.**
27
- ```shell
28
- yarn dev
29
- ```
30
- 1. **Build.**
31
- ```shell
32
- yarn build
33
- ```
34
-
35
- ## What's inside?
36
-
37
- A quick look at the directory structure of **Ohbug Extension** project.
38
-
39
- .
40
- ├── node_modules
41
- ├── src
42
- ├── ui
43
- ├── .editorconfig
44
- ├── .eslintrc.js
45
- ├── .gitignore
46
- ├── .prettierrc
47
- ├── LICENSE
48
- ├── package.json
49
- ├── README.md
50
- ├── rollup.config.js
51
- ├── rollup.config.ui.js
52
- └── tsconfig.json
53
-
54
- 1. **`/node_modules`**: This directory contains all of the modules of code.
55
-
56
- 1. **`/src`**: This directory will contain the code for collecting data by Ohbug Extension. `src` is a convention for “source code”.
57
-
58
- 1. **`/ui`**: This directory will contain a [React](https://reactjs.org/) component, the function of this component is to visualize the data collected in the `src` directory.
59
-
60
- 1. **`.editorconfig`**: This is a file format and collection of text editor plugins for maintaining consistent coding styles between different editors and IDEs.
61
-
62
- 1. **`.eslintrc.js`**: This is a configuration file for [Eslint](https://eslint.org/). Eslint is a tool to find and fix problems in your JavaScript code.
63
-
64
- 1. **`.gitignore`**: This file tells git which files it should not track / not maintain a version history for.
65
-
66
- 1. **`.prettierrc`**: This is a configuration file for [Prettier](https://prettier.io/). Prettier is a tool to help keep the formatting of your code consistent.
67
-
68
- 1. **`LICENSE`**: This **ohbug-extension-starter** is licensed under the MIT license.
69
-
70
- 1. **`package.json`**: This file is how npm knows which packages to install for your project. Ohbug will query the extension's `name`, `key`, ui-extension's `name`, `cdn` and other data from this file.
18
+ ```
19
+ pnpm i view @ohbug/extension-view
20
+ ```
71
21
 
72
- 1. **`README.md`**: A text file containing useful reference information about your project.
22
+ ## Usage
73
23
 
74
- ## `package.json` `ohbug` field explanation
24
+ ```javascript
25
+ import Ohbug from '@ohbug/browser'
26
+ import OhbugExtensionView from '@ohbug/extension-view'
75
27
 
76
- ```json
77
- {
78
- "ohbug": {
79
- // The name of the extension
80
- "name": "OhbugExtensionStarter",
81
- // Unique identifying name of the extension
82
- "key": "starter",
83
- "ui": {
84
- // The name of the UI component corresponding to the extension
85
- "name": "OhbugExtensionUIStarter",
86
- // The cdn link of the corresponding UI component of the extension, the Ohbug online console will obtain the resource file according to the link provided here
87
- // Recommend to use jsdelivr or unpkg
88
- "cdn": "your_cdn"
89
- }
90
- }
91
- }
28
+ const client = Ohbug.setup({ apiKey: 'YOUR_API_KEY' })
29
+ client.use(OhbugExtensionView)
92
30
  ```
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- import extension from './extension';
2
- export default extension;
3
- //# sourceMappingURL=index.d.ts.map
1
+ import { OhbugExtension } from '@ohbug/types';
2
+
3
+ declare const extension: OhbugExtension;
4
+
5
+ export { extension as default };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var P=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?P(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 p=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=p;var f=require("@ohbug/utils");function l(t,e){let{client:i}=(0,f.getOhbugObject)(),n=i.createEvent({category:"view",type:"pageView",detail:{initial:e,path:t}});i.notify(n)}function g(t){let{client:e}=(0,f.getOhbugObject)(),i=e.createEvent({category:"view",type:"userView",detail:{path:t}});e.notify(i)}var r=W(require("dayjs"));var w="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 m={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=m.getItem(w);e?(0,r.default)(e).isBefore((0,r.default)(),"day")&&(m.setItem(w,(0,r.default)().toISOString()),g(t)):(m.setItem(w,(0,r.default)().toISOString()),g(t))}var h=_;var X="hidden",x="visible",u=class{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 u}init(){this.sendPageLoad||(document.visibilityState===x?(this.initialVisible=!0,l(window.location.href,!0),h(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),h(window.location.href),this.initialVisible=null),i===!1&&e===!0&&s.isExpired()&&(l(window.location.href),h(window.location.href)),e===!1&&s.update()}},U=u;var a=require("@ohbug/utils");var S;function v(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 y=t,d=e;i.protocol===s.protocol&&i.host===s.host&&(d=s.relative),i.protocol===n.protocol&&i.host===n.host&&(y=n.relative),y!==d&&l(d)}function T(t){return function(i,n,s){return s&&v(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;v(S,t)})}function q(t){let{oldURL:e,newURL:i}=t;v(e,i)}function z(){var t;k(),(t=window==null?void 0:window.addEventListener)==null||t.call(window,"hashchange",q,!0)}var C=z;var G={name:"OhbugExtensionView",onSetup:()=>{U.capturePageVisibility(),C()}},D=G;var K=D;0&&(module.exports={});
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var D=Object.defineProperty;var P=(t,e,i)=>e in t?D(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var o=(t,e,i)=>(P(t,typeof e!="symbol"?e+"":e,i),i);var h=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=h;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 d(t){let{client:e}=E(),i=e.createEvent({category:"view",type:"userView",detail:{path:t}});e.notify(i)}import r from"dayjs";var p="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 f={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=f.getItem(p);e?r(e).isBefore(r(),"day")&&(f.setItem(p,r().toISOString()),d(t)):(f.setItem(p,r().toISOString()),d(t))}var c=H;var M="hidden",I="visible",l=class{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 l}init(){this.sendPageLoad||(document.visibilityState===I?(this.initialVisible=!0,a(window.location.href,!0),c(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),c(window.location.href),this.initialVisible=null),i===!1&&e===!0&&s.isExpired()&&(a(window.location.href),c(window.location.href)),e===!1&&s.update()}},x=l;import{parseUrl as g,replace as w}from"@ohbug/utils";var b;function S(t,e){var y;let i=g((y=window==null?void 0:window.location)==null?void 0:y.href),n=g(t),s=g(e);n.path||(n=i),b=e;let v=t,u=e;i.protocol===s.protocol&&i.host===s.host&&(u=s.relative),i.protocol===n.protocol&&i.host===n.host&&(v=n.relative),v!==u&&a(u)}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()}},C=j;var oe=C;export{oe as default};
package/package.json CHANGED
@@ -1,65 +1,41 @@
1
1
  {
2
- "ohbug": {
3
- "name": "OhbugExtensionView",
4
- "key": "view"
5
- },
6
2
  "name": "@ohbug/extension-view",
7
- "version": "0.0.1",
3
+ "version": "0.0.2",
8
4
  "description": "Ohbug extension to collect view data",
5
+ "license": "MIT",
9
6
  "author": "chenyueban <jasonchan0527@gmail.com>",
10
- "homepage": "https://github.com/ohbug-org/ohbug-extension-view",
7
+ "homepage": "https://github.com/ohbug-org/extensions",
11
8
  "bugs": {
12
- "url": "https://github.com/ohbug-org/ohbug-extension-view/issues"
9
+ "url": "https://github.com/ohbug-org/extensions/issues"
13
10
  },
14
11
  "repository": {
15
12
  "type": "git",
16
- "url": "https://github.com/ohbug-org/ohbug-extension-view"
13
+ "url": "https://github.com/ohbug-org/extensions"
14
+ },
15
+ "main": "dist/index.js",
16
+ "module": "dist/index.mjs",
17
+ "types": "dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "require": "./dist/index.js",
21
+ "import": "./dist/index.mjs",
22
+ "types": "./dist/index.d.ts"
23
+ }
17
24
  },
18
- "license": "MIT",
19
- "main": "dist/index.cjs.js",
20
- "module": "dist/index.esm.js",
21
- "unpkg": "dist/index.umd.js",
22
- "jsdelivr": "dist/index.umd.js",
23
- "types": "dist/src/index.d.ts",
24
25
  "files": [
25
26
  "dist"
26
27
  ],
27
28
  "dependencies": {
28
- "@ohbug/core": "^1.1.3",
29
- "@ohbug/utils": "^1.0.10",
30
- "dayjs": "^1.10.4",
31
- "js-cookie": "^2.2.1"
32
- },
33
- "devDependencies": {
34
- "@chenyueban/lint": "^0.2.11",
35
- "@chenyueban/tsconfig": "^0.1.8",
36
- "@rollup/plugin-commonjs": "^18.0.0",
37
- "@rollup/plugin-node-resolve": "^11.2.1",
38
- "@rollup/plugin-replace": "^2.3.3",
39
- "@types/js-cookie": "^2.2.6",
40
- "cz-conventional-changelog": "3.3.0",
41
- "postcss": "^8.2.10",
42
- "rimraf": "^3.0.2",
43
- "rollup": "^2.46.0",
44
- "rollup-plugin-postcss": "^4.0.0",
45
- "rollup-plugin-terser": "^7.0.2",
46
- "rollup-plugin-typescript2": "^0.30.0",
47
- "standard-version": "^9.2.0",
48
- "typescript": "^4.2.4"
29
+ "@ohbug/types": "^2.1.0",
30
+ "@ohbug/utils": "^2.0.6",
31
+ "dayjs": "^1.11.4"
49
32
  },
50
33
  "publishConfig": {
51
34
  "access": "public"
52
35
  },
53
36
  "scripts": {
54
37
  "prebuild": "rimraf dist",
55
- "build": "rollup -c --environment NODE_ENV:production",
56
- "dev": "rollup -cw",
57
- "update:deps": "yarn upgrade-interactive --latest",
58
- "release": "standard-version"
59
- },
60
- "config": {
61
- "commitizen": {
62
- "path": "./node_modules/cz-conventional-changelog"
63
- }
38
+ "build": "tsup",
39
+ "dev": "tsup --watch"
64
40
  }
65
- }
41
+ }
package/CHANGELOG.md DELETED
@@ -1,24 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
-
5
- ### 0.0.1 (2021-04-29)
6
-
7
- ### Features
8
-
9
- - 完成 PV/UV 的收集功能 ([df77370](https://github.com/ohbug-org/ohbug-extension-view/commit/df77370644e7025b73c0761620b2639b199706d5))
10
-
11
- ### [1.2.1](https://github.com/ohbug-org/ohbug-extension-starter/compare/v1.2.0...v1.2.1) (2021-04-27)
12
-
13
- ### Features
14
-
15
- - **ui:** 恢复 react 依赖 ([9c294f1](https://github.com/ohbug-org/ohbug-extension-starter/commit/9c294f1645c7aa8dd9c643ce073276e48ef0ca9f))
16
- - **ui:** remove unuseless deps ([7bb5b73](https://github.com/ohbug-org/ohbug-extension-starter/commit/7bb5b732515557e7296db75b4048a70e874bd857))
17
-
18
- ## 1.2.0 (2021-04-20)
19
-
20
- ### Features
21
-
22
- - adapt react17 ([f0cea91](https://github.com/ohbug-org/ohbug-extension-starter/commit/f0cea9128058433426589f3f61810e2289ccc311))
23
- - create ohbug-extension-starter ([a8c6151](https://github.com/ohbug-org/ohbug-extension-starter/commit/a8c6151306717f127e3fd428eaec88a664f0b0bd))
24
- - refactored rollup packaging configuration ([459f499](https://github.com/ohbug-org/ohbug-extension-starter/commit/459f499971e8405927f68be36010f36a7ff77bdb))
@@ -1,3 +0,0 @@
1
- export declare function sendPageView(path: string, initial?: boolean): void;
2
- export declare function sendUserView(path: string): void;
3
- //# sourceMappingURL=createEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createEvent.d.ts","sourceRoot":"","sources":["../src/createEvent.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,QAW3D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,QAUxC"}
@@ -1,3 +0,0 @@
1
- declare const extension: import("@ohbug/types").OhbugExtension<any>;
2
- export default extension;
3
- //# sourceMappingURL=extension.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,SAAS,4CAMb,CAAA;AAEF,eAAe,SAAS,CAAA"}