spy-client 2.1.12 → 2.1.15

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/spy-head.js CHANGED
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
3
  typeof define === 'function' && define.amd ? define(factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.__spyHead = factory());
5
- }(this, (function () { 'use strict';
5
+ })(this, (function () { 'use strict';
6
6
 
7
7
  /**
8
8
  * @file utils
@@ -92,6 +92,9 @@
92
92
  init: function (conf) {
93
93
  this.conf = conf;
94
94
  },
95
+ update: function (conf) {
96
+ this.conf = Object.assign(this.conf, conf || {});
97
+ },
95
98
  addError: function (obj) {
96
99
  // 有些错误一下出现很多次,都聚合都一个错误,加上次数
97
100
  if (this.winerrors.length > 0) {
@@ -117,8 +120,8 @@
117
120
  return;
118
121
  }
119
122
  logServer = logServer || conf.logServer;
120
- var logUrl = logServer + "?pid=" + obj.pid + "&lid=" + obj.lid + "&ts=" + obj.ts
121
- + ("&type=" + obj.type + "&group=" + obj.group + "&info=" + encodeURIComponent(JSON.stringify(obj.info)));
123
+ var logUrl = "".concat(logServer, "?pid=").concat(obj.pid, "&lid=").concat(obj.lid, "&ts=").concat(obj.ts)
124
+ + "&type=".concat(obj.type, "&group=").concat(obj.group, "&info=").concat(encodeURIComponent(JSON.stringify(obj.info)));
122
125
  if (obj.dim) {
123
126
  logUrl += '&dim=' + encodeURIComponent(JSON.stringify(obj.dim));
124
127
  }
@@ -148,12 +151,12 @@
148
151
  var info = obj.info;
149
152
  var srcElement = event.srcElement;
150
153
  // 设备信息
151
- var dataConnection = navigator.connection || {};
152
- info.downlink = dataConnection.downlink; // 网站下载速度 M/s
153
- info.effectiveType = dataConnection.effectiveType; // 网络类型
154
- info.rtt = dataConnection.rtt; // 网络往返时间 ms
155
- info.deviceMemory = navigator.deviceMemory || 0;
156
- info.hardwareConcurrency = navigator.hardwareConcurrency || 0;
154
+ // const dataConnection = navigator.connection || {};
155
+ // info.downlink = dataConnection.downlink; // 网站下载速度 M/s
156
+ // info.effectiveType = dataConnection.effectiveType; // 网络类型
157
+ // info.rtt = dataConnection.rtt; // 网络往返时间 ms
158
+ // info.deviceMemory = navigator.deviceMemory || 0;
159
+ // info.hardwareConcurrency = navigator.hardwareConcurrency || 0;
157
160
  // JS错误
158
161
  if (srcElement === window) {
159
162
  obj.group = jsError.group;
@@ -177,7 +180,7 @@
177
180
  var historys = [];
178
181
  for (var index = 0; index < winerrors.length; index++) {
179
182
  var item = winerrors[index];
180
- var prefix = item.info.count > 1 ? "(" + item.info.count + ")" : '';
183
+ var prefix = item.info.count > 1 ? "(".concat(item.info.count, ")") : '';
181
184
  historys.push(prefix + item.info.msg);
182
185
  }
183
186
  info.hisErrors = historys.join('----');
@@ -281,11 +284,11 @@
281
284
  return false;
282
285
  }
283
286
  var pf = getResTiming(window.performance.timing);
284
- var netStr = "&wait=" + pf.wait
285
- + ("&dns=" + pf.dns)
286
- + ("&connect=" + pf.connect)
287
- + ("&requestTime=" + pf.req)
288
- + ("&resoneTime=" + pf.res);
287
+ var netStr = "&wait=".concat(pf.wait)
288
+ + "&dns=".concat(pf.dns)
289
+ + "&connect=".concat(pf.connect)
290
+ + "&requestTime=".concat(pf.req)
291
+ + "&resoneTime=".concat(pf.res);
289
292
  return netStr;
290
293
  }
291
294
  // 补充白屏信息:期间发生的JS Error 和 资源 Error
@@ -297,7 +300,7 @@
297
300
  var historys = [];
298
301
  for (var i = 0; i < errors.length; i++) {
299
302
  var stack = (errors[i].info.stack || '').split('\n')[0];
300
- historys.push("(" + i + ")" + (stack || errors[i].info.msg));
303
+ historys.push("(".concat(i, ")").concat(stack || errors[i].info.msg));
301
304
  }
302
305
  return historys.join(';;');
303
306
  }
@@ -368,8 +371,9 @@
368
371
  // 兼容全局变量定义的初始化方式
369
372
  if (window.__spyclientConf) {
370
373
  spyHead.init(window.__spyclientConf);
371
- }
374
+ }
375
+ window.__spyHead = window.__spyHead || spyHead;
372
376
 
373
377
  return spyHead;
374
378
 
375
- })));
379
+ }));
@@ -1 +1 @@
1
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).__spyHead=r()}(this,function(){"use strict";function E(e){var r=function(e){if(URL&&e)try{var r=new URL(e);if(void 0!==r.host)return{protocol:r.protocol,host:r.host,pathname:r.pathname,ext:""}}catch(e){console.error(e)}}(e);if(!r){var n=document.createElement("a");n.href=e,r={protocol:n.protocol,host:n.host||location.host,pathname:n.pathname,ext:""}}var t=r.pathname.split(".");return r.ext=t[t.length-1],r}function c(e){return+e.toFixed(1)}var T={conf:{},winerrors:[],errorDestroy:function(){},observerDestroy:function(){},entryMap:{},init:function(e){this.conf=e},addError:function(e){if(0<this.winerrors.length){var r=this.winerrors[this.winerrors.length-1];if(e.info.msg===r.info.msg)return void(r.info.count+=r.info.count||0)}this.winerrors.length<1e3&&this.winerrors.push(e)},send:function(e,r,n){var t=this.conf;if(e.type=e.type||"except",e.pid=t.pid,e.lid=t.lid,e.ts=Date.now(),this.addError(e),this.interceptor&&this.interceptor(e),!1!==r){var o=(n=n||t.logServer)+"?pid="+e.pid+"&lid="+e.lid+"&ts="+e.ts+"&type="+e.type+"&group="+e.group+"&info="+encodeURIComponent(JSON.stringify(e.info));e.dim&&(o+="&dim="+encodeURIComponent(JSON.stringify(e.dim)));var i=new Image;i.src=o,i.onload=i.onerror=function(){i=null}}}};function r(e){var h=e.resourceError||{},m=e.jsError||{},g=Math.random()<(m.sample?m.sample:0),v=Math.random()<(h.sample?h.sample:0),w=T.winerrors,y=0;function r(e){try{var r=e.target,n={info:{},dim:{},group:""},t=n.info,o=e.srcElement,i=navigator.connection||{};if(t.downlink=i.downlink,t.effectiveType=i.effectiveType,t.rtt=i.rtt,t.deviceMemory=navigator.deviceMemory||0,t.hardwareConcurrency=navigator.hardwareConcurrency||0,o===window){n.group=m.group;var a=e.error||e.reason||{};if(t.msg=e.message||a.message||"",t.file=e.filename,t.ln=e.lineno,t.col=e.colno,t.stack=(a.stack||"").split("\n").slice(0,3).join("\n"),-1!==t.msg.indexOf("MODULE_TIMEOUT")){var s=t.msg.match(/^.*Hang:(.*); Miss:(.*)/);s&&s[2]&&(t.msg="MODULE_TIMEOUT for miss:"+s[2])}for(var c=[],f=0;f<w.length;f++){var d=w[f],u=1<d.info.count?"("+d.info.count+")":"";c.push(u+d.info.msg)}t.hisErrors=c.join("----");var p=!0;m.handler&&(p=m.handler(n)),!1!==p&&T.send(n,g)}else{n.group=h.group,n.dim.type=o.tagName.toLowerCase();var l=o.src||o.href||"";if(-1<l.indexOf("/mwb2.gif?"))return;t.msg=l||"unknown load eror",n.dim.host=E(l).host,r&&"IMG"===r.tagName&&(t.xpath=function(e){if(!e)return{xpath:""};for(var r=[];e&&1===e.nodeType&&e!==e.parentNode;){var n=e.tagName.toLowerCase();if(e.getAttribute("id")?n+="[#"+e.getAttribute("id")+"]":e.classList&&e.classList.length&&(n+="[."+e.classList[e.classList.length-1]+"]"),r.push(n),e===document.body)break;e=e.parentNode}return{xpath:r.join("<")}}(r).xpath),y&&(t.hisErrCount=y);p=!0;h.handler&&(p=h.handler(n)),!1!==p&&T.send(n,v),y++}}catch(e){console.error(e)}}window.addEventListener("error",r,!0),window.addEventListener("unhandledrejection",r,!0),T.errorDestroy=function(){window.removeEventListener("error",r,!0),window.removeEventListener("unhandledrejection",r,!0),T.winerrors=[]}}function n(e){var n=e.whiteScreenError||{},t=n.handler,o=n.selector,i=n.subSelector,r=n.timeout||6e3,a=Math.random()<(n.sample?n.sample:0);function s(){if(!window.performance)return!1;var e=function(e){return{wait:c(e.domainLookupStart-(e.navigationStart||e.fetchStart||e.startTime)),dns:c(e.domainLookupEnd-e.domainLookupStart),connect:c(e.connectEnd-e.connectStart),req:c(e.responseStart-e.requestStart),res:c(e.responseEnd-e.responseStart)}}(window.performance.timing);return"&wait="+e.wait+"&dns="+e.dns+"&connect="+e.connect+"&requestTime="+e.req+"&resoneTime="+e.res}o&&setTimeout(function(){if(function(){var e=document.querySelector(o);return!e||(!e.querySelector(i)||e.clientHeight<2*window.innerHeight/3)}()){var e={group:n.group,info:{msg:"",netTime:s(),hisErrors:function(){if(!T.winerrors)return!1;for(var e=T.winerrors,r=[],n=0;n<e.length;n++){var t=(e[n].info.stack||"").split("\n")[0];r.push("("+n+")"+(t||e[n].info.msg))}return r.join(";;")}(),deviceInfo:function(){var e={},r=navigator.connection||{};return e.downlink=r.downlink,e.effectiveType=r.effectiveType,e.rtt=r.rtt,e.deviceMemory=navigator.deviceMemory||0,e.hardwareConcurrency=navigator.hardwareConcurrency||0,e}()}};e.info.msg="WhiteScren Error";var r=!0;t&&(r=t(e)),!1!==r&&e.info.msg&&T&&T.send(e,a)}},r)}return T.init=function(e){e.logServer||(e.logServer="https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif"),r(this.conf=e),function(){if(window.PerformanceObserver){var e=new window.PerformanceObserver(function(e){for(var r=T.entryMap,n=e.getEntries(),t=0;t<n.length;t++){var o=n[t];r[o.entryType]||(r[o.entryType]=[]),r[o.entryType].push(o)}});T.observerDestroy=function(){e.disconnect()};try{e.observe({entryTypes:["longtask","layout-shift","first-input","largest-contentful-paint"]})}catch(e){}}}(),n(e)},window.__spyclientConf&&T.init(window.__spyclientConf),T});
1
+ ((e,n)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).__spyHead=n()})(this,function(){function y(e){var n,r=(e=>{if(URL&&e)try{var n=new URL(e);if(void 0!==n.host)return{protocol:n.protocol,host:n.host,pathname:n.pathname,ext:""}}catch(e){console.error(e)}})(e),e=(r||((n=document.createElement("a")).href=e,r={protocol:n.protocol,host:n.host||location.host,pathname:n.pathname,ext:""}),r.pathname.split("."));return r.ext=e[e.length-1],r}function n(e){return+e.toFixed(1)}var E={conf:{},winerrors:[],errorDestroy:function(){},observerDestroy:function(){},entryMap:{},init:function(e){this.conf=e},update:function(e){this.conf=Object.assign(this.conf,e||{})},addError:function(e){if(0<this.winerrors.length){var n=this.winerrors[this.winerrors.length-1];if(e.info.msg===n.info.msg)return void(n.info.count+=n.info.count||0)}this.winerrors.length<1e3&&this.winerrors.push(e)},send:function(e,n,r){var t,o=this.conf;e.type=e.type||"except",e.pid=o.pid,e.lid=o.lid,e.ts=Date.now(),this.addError(e),this.interceptor&&this.interceptor(e),!1!==n&&(r=r||o.logServer,n="".concat(r,"?pid=").concat(e.pid,"&lid=").concat(e.lid,"&ts=").concat(e.ts)+"&type=".concat(e.type,"&group=").concat(e.group,"&info=").concat(encodeURIComponent(JSON.stringify(e.info))),e.dim&&(n+="&dim="+encodeURIComponent(JSON.stringify(e.dim))),(t=new Image).src=n,t.onload=t.onerror=function(){t=null})}};function r(e){var h=e.resourceError||{},l=e.jsError||{},m=Math.random()<(l.sample||0),g=Math.random()<(h.sample||0),w=E.winerrors,v=0;function n(e){try{var n=e.target,r={info:{},dim:{},group:""},t=r.info,o=e.srcElement;if(o===window){r.group=l.group;for(var i,s=e.error||e.reason||{},a=(t.msg=e.message||s.message||"",t.file=e.filename,t.ln=e.lineno,t.col=e.colno,t.stack=(s.stack||"").split("\n").slice(0,3).join("\n"),-1!==t.msg.indexOf("MODULE_TIMEOUT")&&(i=t.msg.match(/^.*Hang:(.*); Miss:(.*)/))&&i[2]&&(t.msg="MODULE_TIMEOUT for miss:"+i[2]),[]),c=0;c<w.length;c++){var d=w[c],f=1<d.info.count?"(".concat(d.info.count,")"):"";a.push(f+d.info.msg)}t.hisErrors=a.join("----");var p=!0;!1!==(p=l.handler?l.handler(r):p)&&E.send(r,m)}else{r.group=h.group,r.dim.type=o.tagName.toLowerCase();var u=o.src||o.href||"";-1<u.indexOf("/mwb2.gif?")||(t.msg=u||"unknown load eror",r.dim.host=y(u).host,n&&"IMG"===n.tagName&&(t.xpath=(e=>{if(!e)return{xpath:""};for(var n=[];e&&1===e.nodeType&&e!==e.parentNode;){var r=e.tagName.toLowerCase();if(e.getAttribute("id")?r+="[#"+e.getAttribute("id")+"]":e.classList&&e.classList.length&&(r+="[."+e.classList[e.classList.length-1]+"]"),n.push(r),e===document.body)break;e=e.parentNode}return{xpath:n.join("<")}})(n).xpath),v&&(t.hisErrCount=v),!(p=!0)!==(p=h.handler?h.handler(r):p)&&E.send(r,g),v++)}}catch(e){console.error(e)}}window.addEventListener("error",n,!0),window.addEventListener("unhandledrejection",n,!0),E.errorDestroy=function(){window.removeEventListener("error",n,!0),window.removeEventListener("unhandledrejection",n,!0),E.winerrors=[]}}function t(e){var t=e.whiteScreenError||{},o=t.handler,i=t.selector,s=t.subSelector,e=t.timeout||6e3,a=Math.random()<(t.sample||0);function c(){var e;return!!window.performance&&(e={wait:n((e=window.performance.timing).domainLookupStart-(e.navigationStart||e.fetchStart||e.startTime)),dns:n(e.domainLookupEnd-e.domainLookupStart),connect:n(e.connectEnd-e.connectStart),req:n(e.responseStart-e.requestStart),res:n(e.responseEnd-e.responseStart)},"&wait=".concat(e.wait)+"&dns=".concat(e.dns)+"&connect=".concat(e.connect)+"&requestTime=".concat(e.req)+"&resoneTime=".concat(e.res))}i&&setTimeout(function(){var e,n,r;(r=document.querySelector(i))&&r.querySelector(s)&&!(r.clientHeight<2*window.innerHeight/3)||(r=!0,!((n={group:t.group,info:{msg:"",netTime:c(),hisErrors:(()=>{if(!E.winerrors)return!1;for(var e=E.winerrors,n=[],r=0;r<e.length;r++){var t=(e[r].info.stack||"").split("\n")[0];n.push("(".concat(r,")").concat(t||e[r].info.msg))}return n.join(";;")})(),deviceInfo:(e={},n=navigator.connection||{},e.downlink=n.downlink,e.effectiveType=n.effectiveType,e.rtt=n.rtt,e.deviceMemory=navigator.deviceMemory||0,e.hardwareConcurrency=navigator.hardwareConcurrency||0,e)}}).info.msg="WhiteScren Error")!==(r=o?o(n):r)&&n.info.msg&&E&&E.send(n,a))},e)}return E.init=function(e){if(e.logServer||(e.logServer="https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif"),r(this.conf=e),window.PerformanceObserver){var n=new window.PerformanceObserver(function(e){for(var n=E.entryMap,r=e.getEntries(),t=0;t<r.length;t++){var o=r[t];n[o.entryType]||(n[o.entryType]=[]),n[o.entryType].push(o)}});E.observerDestroy=function(){n.disconnect()};try{n.observe({entryTypes:["longtask","layout-shift","first-input","largest-contentful-paint"]})}catch(e){}}t(e)},window.__spyclientConf&&E.init(window.__spyclientConf),window.__spyHead=window.__spyHead||E,E});
@@ -2,21 +2,21 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
3
  typeof define === 'function' && define.amd ? define(factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SpyLocalCache = factory());
5
- }(this, (function () { 'use strict';
5
+ })(this, (function () { 'use strict';
6
6
 
7
7
  /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation. All rights reserved.
9
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
10
- this file except in compliance with the License. You may obtain a copy of the
11
- License at http://www.apache.org/licenses/LICENSE-2.0
8
+ Copyright (c) Microsoft Corporation.
12
9
 
13
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16
- MERCHANTABLITY OR NON-INFRINGEMENT.
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
17
12
 
18
- See the Apache Version 2.0 License for specific language governing permissions
19
- and limitations under the License.
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
20
  ***************************************************************************** */
21
21
  /* global Reflect, Promise */
22
22
 
@@ -749,4 +749,4 @@
749
749
 
750
750
  return SpyLocalCache;
751
751
 
752
- })));
752
+ }));
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SpyLocalCache=e()}(this,function(){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};function t(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var l=(e.prototype.preOrder=function(t){t.push(this),this.left&&this.left.preOrder(t),this.right&&this.right.preOrder(t)},e);function e(t,e){this.data=t,this.weight=e}function n(t){var e=function(t){if(null==t)return null;var i={};return function t(e,o,r){var n=[].concat(r);n.push(o),null!=e&&(null==e.data?(t(e.left,"0",n),t(e.right,"1",n)):i[e.data]=n.join(""))}(t,"",[]),i}(function(t){for(var e=function(t,e){return t.weight-e.weight};1<t.length;){t.sort(e);var o=t.shift(),r=t.shift();if(o&&r){var n=new l(null,o.weight+r.weight);n.left=o,n.right=r,t.unshift(n)}}return t.shift()}(function(t){for(var e=[],o={},r=0,n=t;r<n.length;r++){var i=n[r];null==o[i]?o[i]=1:o[i]++}for(var a=0,s=Object.entries(o);a<s.length;a++){var u=s[a],h=u[0],c=u[1];e.push(new l(h,c))}return e}(t)));return{result:function(t){for(var e=t.join(""),o=Math.ceil(e.length/8),r=new Array(o+1),n=0,i="",a=0;a<e.length;a+=8)i=e.substring(a,a+8),r[n]=parseInt(i,2),n++;return r[n]=i.length,r}(function(t,e){for(var o=[],r=0,n=t;r<n.length;r++){var i=n[r];o.push(e[i])}return o}(t,e)),codes:e}}function y(t,e){t&&(e|=256);var o=Number(e).toString(2);return t?o.substring(o.length-8):o}function i(t){for(var e=[],o=0;o<t.length;o++)e.push(t.charCodeAt(o));return e}function a(t){for(var e="",o=0,r=t;o<r.length;o++){var n=r[o];e+=String.fromCharCode(n)}return e}function o(t,e){return a(function(t,e){for(var o=[],r=0;r<e.length-1;r++){var n=r!==e.length-2;o.push(y(n,e[r]))}var i=o[o.length-1],a=e[e.length-1];i="00000000".substring(8-(a-i.length))+i,o[o.length-1]=i;for(var s={},u=0,h=Object.entries(t);u<h.length;u++){var c=h[u],l=c[0];s[c[1]]=l}var p=o.join(""),f=[],d=p.length;for(r=0;r<d;){for(var g=1,v=(n=!0,null);n&&r+g<=d;){if(""===(l=p.substring(r,r+g)))break;(v=s[l])?n=!1:g++}f.push(parseInt(v,10)),r+=g}return f}(t,i(e)))}var s=(u.prototype.set=function(t,e){},u.prototype.get=function(t,e){},u.prototype.rm=function(t){},u);function u(){}var h,c=(t(p,h=s),p.isSupport=function(){return!!window.localStorage},p.prototype.set=function(t,e){try{localStorage.setItem(t,e)}catch(t){console.error(t)}},p.prototype.get=function(t,e){var o=null;try{o=localStorage.getItem(t)}catch(t){console.error(t)}e&&e(o)},p.prototype.rm=function(t){try{localStorage.removeItem(t)}catch(t){console.error(t)}},p);function p(){return null!==h&&h.apply(this,arguments)||this}var f,d=(t(g,f=s),g.isSupport=function(){return!!window.indexedDB},g.prototype.set=function(t,e){this.db?this.db.transaction([this.databaseName],"readwrite").objectStore(this.databaseName).add({key:t,value:e}):this.setQueue.push({key:t,value:e})},g.prototype.get=function(t,e){if(this.db){var o=this.db.transaction([this.databaseName]).objectStore(this.databaseName).get(t);o.onsuccess=function(){var t=o.result?o.result:{value:""};e(t.value)}}else this.getQueue.push({key:t,cb:e})},g.prototype.runQueueTask=function(){var e=this;this.setQueue.forEach(function(t){e.set(t.key,t.value)}),this.getQueue.forEach(function(t){e.get(t.key,t.cb)})},g);function g(){var e=f.call(this)||this;e.databaseName="spyLC",e.db=null,e.setQueue=[],e.getQueue=[];var t=window.indexedDB.open(e.databaseName);return t.onupgradeneeded=function(t){e.db=t.target&&t.target.result,e.db&&!e.db.objectStoreNames.contains(e.databaseName)&&e.db.createObjectStore(e.databaseName,{keyPath:"key"}),e.runQueueTask()},t.onsuccess=function(){e.db=t.result,e.runQueueTask()},e}function v(t,e){if(void 0===e&&(e=!1),!t)return"";e||(t=function(t){for(var e="",o=0;o<t.length;o++){var r=t.charCodeAt(o);r<128?e+=String.fromCharCode(r):(127<r&&r<2048?e+=String.fromCharCode(r>>6|192):(e+=String.fromCharCode(r>>12|224),e+=String.fromCharCode(r>>6&63|128)),e+=String.fromCharCode(63&r|128))}return e}(t));function o(){s.push(1<u.length?String.fromCharCode(a[u]):u)}var r,n,i,a={},s=[],u=t.charAt(0),h=u,c=h,l=256;for(e&&s.push(u),r=1;r<t.length;r++)n=t.charAt(r),e?(i=t.charCodeAt(r),u=i<256?n:a[i]||u+h,s.push(u),h=u.charAt(0),a[l++]=c+h,c=u):a.hasOwnProperty(u+n)?u+=n:(o(),a[u+n]=l++,u=n);e||o();var p=s.join("");return e&&(p=function(t){for(var e="",o=0,r=0,n=0,i=0;o<t.length;)(r=t.charCodeAt(o))<128?(e+=String.fromCharCode(r),o++):191<r&&r<224?(n=t.charCodeAt(o+1),e+=String.fromCharCode((31&r)<<6|63&n),o+=2):(n=t.charCodeAt(o+1),i=t.charCodeAt(o+2),e+=String.fromCharCode((15&r)<<12|(63&n)<<6|63&i),o+=3);return e}(p)),p}function m(t){void 0===t&&(t={}),this.tmpList=[],this.option=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e=void 0,o=1,r=arguments.length;o<r;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,t)}({defaultTrigger:!0,compress:"lzw",key:"SpyLocalCache",interval:500,maxRecordLen:30,onFlush:function(){},onSave:function(){},onAdd:function(){return!0},storage:d.isSupport()?"indexedDB":c.isSupport()?"localstorage":"empty"},t),this.load=this.load.bind(this),this.init()}return m.prototype.init=function(){"indexedDB"===this.option.storage?this.storage=new d:"localstorage"===this.option.storage?this.storage=new c:this.storage=new s,"complete"===document.readyState?this.load():window.addEventListener("load",this.load)},m.prototype.load=function(){-1<location.search.indexOf("_FlushLogLocalCache=1")&&this.option.defaultTrigger&&this.flushLog()},m.prototype.addLog=function(t){var e=this;this.option.onAdd&&!this.option.onAdd(t)||(t=JSON.stringify(t),this.tmpList.push(t),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(function(){e.save()},this.option.interval))},m.prototype.getData=function(r){var n=this;try{this.storage.get(this.option.key,function(o){o?n.storage.get(n.option.key+"Codes",function(t){var e=[];try{t=t&&JSON.parse(t),e=n.unzip(o,t).split("\n")}catch(t){console.error(t)}r(e)}):r([])})}catch(t){console.error(t),r([])}},m.prototype.save=function(){var u=this,h=Date.now();this.getData(function(t){var e=u.option.maxRecordLen-1,o=(t.length>e?t.slice(t.length-e,t.length):t).concat(u.tmpList),r=o.join("\n"),n=null,i=0;try{var a=u.zip(r),s="";a.codes?(s=JSON.stringify(a.codes),u.storage.set(u.option.key+"Codes",s)):u.storage.rm(u.option.key+"Codes"),u.storage.set(u.option.key,a.result),i=a.result.length}catch(t){n=t,console.error(t)}u.tmpList=[],u.option.onSave&&u.option.onSave({cost:Date.now()-h,length:i/1024,list:o,error:n})})},m.prototype.flushLog=function(){var o=this;this.getData(function(e){try{for(var t=0;t<e.length;t++)e[t]=JSON.parse(e[t])}catch(t){e=[],o.storage.rm(o.option.key),console.error(t)}for(t=0;t<o.tmpList.length;t++)e.push(JSON.parse(o.tmpList[t]));o.option.onFlush&&o.option.onFlush(e)})},m.prototype.zip=function(t){return"lzw"===this.option.compress?{codes:null,result:v(t)}:"huffman"===this.option.compress?function(t){var e=n(i(t)),o=e.result;return{codes:e.codes,result:a(o)}}(t):{codes:null,result:t}},m.prototype.unzip=function(t,e){return"lzw"===this.option.compress?v(t,!0):"huffman"===this.option.compress?o(e,t):t},m});
1
+ ((t,e)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SpyLocalCache=e()})(this,function(){var r=function(t,e){return(r=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])}))(t,e)};function t(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}e.prototype.preOrder=function(t){t.push(this),this.left&&this.left.preOrder(t),this.right&&this.right.preOrder(t)};var c=e;function e(t,e){this.data=t,this.weight=e}function o(t){var n;return null==t?null:(n={},function t(e,o,r){r=[].concat(r);r.push(o),null!=e&&(null==e.data?(t(e.left,"0",r),t(e.right,"1",r)):n[e.data]=r.join(""))}(t,"",[]),n)}function n(t){var e=o((t=>{for(var e=function(t,e){return t.weight-e.weight};1<t.length;){t.sort(e);var o,r=t.shift(),n=t.shift();r&&n&&((o=new c(null,r.weight+n.weight)).left=r,o.right=n,t.unshift(o))}return t.shift()})((t=>{for(var e=[],o={},r=0,n=t;r<n.length;r++){var i=n[r];null==o[i]?o[i]=1:o[i]++}for(var a=0,s=Object.entries(o);a<s.length;a++){var u=s[a],h=u[0];e.push(new c(h,u[1]))}return e})(t)));return{result:(t=>{for(var e=t.join(""),t=Math.ceil(e.length/8),o=new Array(t+1),r=0,n="",i=0;i<e.length;i+=8)n=e.substring(i,i+8),o[r]=parseInt(n,2),r++;return o[r]=n.length,o})(((t,e)=>{for(var o=[],r=0,n=t;r<n.length;r++){var i=n[r];o.push(e[i])}return o})(t,e)),codes:e}}function i(t,e){for(var o,r,n=[],i=0;i<e.length-1;i++){var a=i!==e.length-2;n.push((o=a,r=e[i],o&&(r|=256),r=Number(r).toString(2),o?r.substring(r.length-8):r))}var s=e[e.length-1],s="00000000".substring(8-(s-(s=n[n.length-1]).length))+s;n[n.length-1]=s;for(var u={},h=0,c=Object.entries(t);h<c.length;h++){var l=c[h],p=l[0];u[l[1]]=p}for(var f=n.join(""),d=[],g=f.length,i=0;i<g;){for(var v=1,a=!0,y=null;a&&i+v<=g;){if(""===(p=f.substring(i,i+v)))break;(y=u[p])?a=!1:v++}d.push(parseInt(y,10)),i+=v}return d}function a(t){for(var e=[],o=0;o<t.length;o++)e.push(t.charCodeAt(o));return e}function s(t){for(var e="",o=0,r=t;o<r.length;o++){var n=r[o];e+=String.fromCharCode(n)}return e}h.prototype.set=function(t,e){},h.prototype.get=function(t,e){},h.prototype.rm=function(t){};var u=h;function h(){}t(f,l=u),f.isSupport=function(){return!!window.localStorage},f.prototype.set=function(t,e){try{localStorage.setItem(t,e)}catch(t){console.error(t)}},f.prototype.get=function(t,e){var o=null;try{o=localStorage.getItem(t)}catch(t){console.error(t)}e&&e(o)},f.prototype.rm=function(t){try{localStorage.removeItem(t)}catch(t){console.error(t)}};var l,p=f;function f(){return null!==l&&l.apply(this,arguments)||this}t(v,d=u),v.isSupport=function(){return!!window.indexedDB},v.prototype.set=function(t,e){this.db?this.db.transaction([this.databaseName],"readwrite").objectStore(this.databaseName).add({key:t,value:e}):this.setQueue.push({key:t,value:e})},v.prototype.get=function(t,e){var o;this.db?(o=this.db.transaction([this.databaseName]).objectStore(this.databaseName).get(t)).onsuccess=function(){var t=o.result||{value:""};e(t.value)}:this.getQueue.push({key:t,cb:e})},v.prototype.runQueueTask=function(){var e=this;this.setQueue.forEach(function(t){e.set(t.key,t.value)}),this.getQueue.forEach(function(t){e.get(t.key,t.cb)})};var d,g=v;function v(){var e=d.call(this)||this,t=(e.databaseName="spyLC",e.db=null,e.setQueue=[],e.getQueue=[],window.indexedDB.open(e.databaseName));return t.onupgradeneeded=function(t){e.db=t.target&&t.target.result,e.db&&!e.db.objectStoreNames.contains(e.databaseName)&&e.db.createObjectStore(e.databaseName,{keyPath:"key"}),e.runQueueTask()},t.onsuccess=function(){e.db=t.result,e.runQueueTask()},e}function y(t,e){if(!t)return"";(e=void 0===e?!1:e)||(t=(t=>{for(var e="",o=0;o<t.length;o++){var r=t.charCodeAt(o);r<128?e+=String.fromCharCode(r):e=127<r&&r<2048?(e+=String.fromCharCode(r>>6|192))+String.fromCharCode(63&r|128):(e=(e+=String.fromCharCode(r>>12|224))+String.fromCharCode(r>>6&63|128))+String.fromCharCode(63&r|128)}return e})(t));function o(){s.push(1<u.length?String.fromCharCode(a[u]):u)}var r,n,i,a={},s=[],u=t.charAt(0),h=u,c=h,l=256;for(e&&s.push(u),r=1;r<t.length;r++)n=t.charAt(r),e?(i=t.charCodeAt(r),u=i<256?n:a[i]||u+h,s.push(u),h=u.charAt(0),a[l++]=c+h,c=u):a.hasOwnProperty(u+n)?u+=n:(o(),a[u+n]=l++,u=n);e||o();var p=s.join("");return p=e?(t=>{for(var e,o,r="",n=0,i=0;n<t.length;)(e=t.charCodeAt(n))<128?(r+=String.fromCharCode(e),n++):191<e&&e<224?(i=t.charCodeAt(n+1),r+=String.fromCharCode((31&e)<<6|63&i),n+=2):(i=t.charCodeAt(n+1),o=t.charCodeAt(n+2),r+=String.fromCharCode((15&e)<<12|(63&i)<<6|63&o),n+=3);return r})(p):p}function m(t){void 0===t&&(t={}),this.tmpList=[],this.option=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e,o=1,r=arguments.length;o<r;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,t)}({defaultTrigger:!0,compress:"lzw",key:"SpyLocalCache",interval:500,maxRecordLen:30,onFlush:function(){},onSave:function(){},onAdd:function(){return!0},storage:g.isSupport()?"indexedDB":p.isSupport()?"localstorage":"empty"},t),this.load=this.load.bind(this),this.init()}return m.prototype.init=function(){"indexedDB"===this.option.storage?this.storage=new g:"localstorage"===this.option.storage?this.storage=new p:this.storage=new u,"complete"===document.readyState?this.load():window.addEventListener("load",this.load)},m.prototype.load=function(){-1<location.search.indexOf("_FlushLogLocalCache=1")&&this.option.defaultTrigger&&this.flushLog()},m.prototype.addLog=function(t){var e=this;this.option.onAdd&&!this.option.onAdd(t)||(t=JSON.stringify(t),this.tmpList.push(t),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(function(){e.save()},this.option.interval))},m.prototype.getData=function(r){var n=this;try{this.storage.get(this.option.key,function(o){o?n.storage.get(n.option.key+"Codes",function(t){var e=[];try{t=t&&JSON.parse(t);e=n.unzip(o,t).split("\n")}catch(t){console.error(t)}r(e)}):r([])})}catch(t){console.error(t),r([])}},m.prototype.save=function(){var a=this,s=Date.now();this.getData(function(t){var e=a.option.maxRecordLen-1,e=(t.length>e?t.slice(t.length-e,t.length):t).concat(a.tmpList),t=e.join("\n"),o=null,r=0;try{var n,i=a.zip(t);i.codes?(n=JSON.stringify(i.codes),a.storage.set(a.option.key+"Codes",n)):a.storage.rm(a.option.key+"Codes"),a.storage.set(a.option.key,i.result),r=i.result.length}catch(t){o=t,console.error(t)}a.tmpList=[],a.option.onSave&&a.option.onSave({cost:Date.now()-s,length:r/1024,list:e,error:o})})},m.prototype.flushLog=function(){var o=this;this.getData(function(e){try{for(var t=0;t<e.length;t++)e[t]=JSON.parse(e[t])}catch(t){e=[],o.storage.rm(o.option.key),console.error(t)}for(t=0;t<o.tmpList.length;t++)e.push(JSON.parse(o.tmpList[t]));o.option.onFlush&&o.option.onFlush(e)})},m.prototype.zip=function(t){var e,o;return"lzw"===this.option.compress?{codes:null,result:y(t)}:"huffman"===this.option.compress?(o=(e=n(a(e=t))).result,{codes:e.codes,result:s(o)}):{codes:null,result:t}},m.prototype.unzip=function(t,e){return"lzw"===this.option.compress?y(t,!0):"huffman"===this.option.compress?s(i(e,a(t))):t},m});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spy-client",
3
- "version": "2.1.12",
3
+ "version": "2.1.15",
4
4
  "description": "spy client",
5
5
  "main": "dist/spy-client.js",
6
6
  "module": "dist/spy-client.esm.js",