spy-client 2.0.7 → 2.1.1

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.
Files changed (41) hide show
  1. package/README.md +119 -10
  2. package/dist/head/base.d.ts +1 -1
  3. package/dist/lib/huffman.d.ts +9 -0
  4. package/dist/lib/interface.d.ts +59 -1
  5. package/dist/lib/util.d.ts +22 -0
  6. package/dist/module/longtask.d.ts +1 -1
  7. package/dist/module/resource.d.ts +19 -9
  8. package/dist/module/tti.d.ts +1 -1
  9. package/dist/spy-client-basic.esm.js +233 -1167
  10. package/dist/spy-client-basic.iife.js +237 -1171
  11. package/dist/spy-client-basic.iife.min.js +1 -1
  12. package/dist/spy-client-basic.js +238 -1172
  13. package/dist/spy-client-basic.min.js +1 -1
  14. package/dist/spy-client-basic.mjs +82 -54
  15. package/dist/spy-client.d.ts +5 -4
  16. package/dist/spy-client.esm.js +1393 -5662
  17. package/dist/spy-client.iife.js +1401 -5670
  18. package/dist/spy-client.iife.min.js +1 -1
  19. package/dist/spy-client.js +1402 -5671
  20. package/dist/spy-client.min.js +1 -1
  21. package/dist/spy-client.mjs +704 -455
  22. package/dist/spy-head.js +330 -276
  23. package/dist/spy-head.min.js +1 -1
  24. package/dist/spy-local-cache.d.ts +18 -0
  25. package/dist/spy-local-cache.js +690 -0
  26. package/dist/spy-local-cache.min.js +1 -0
  27. package/example/index.html +8 -2
  28. package/example/local-cache.html +97 -0
  29. package/example/saveCache.js +41 -0
  30. package/karma.conf.js +111 -0
  31. package/package.json +21 -20
  32. package/src/head/error.ts +14 -15
  33. package/src/head/whitescreen.ts +8 -5
  34. package/src/lib/huffman.ts +326 -0
  35. package/src/lib/interface.ts +70 -1
  36. package/src/lib/util.ts +101 -0
  37. package/src/module/resource.ts +226 -129
  38. package/src/spy-client-basic.ts +8 -7
  39. package/src/spy-client.ts +15 -6
  40. package/src/spy-local-cache.ts +385 -0
  41. package/src/types/globals.d.ts +1 -1
@@ -1 +1 @@
1
- var SpyClient=function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t,e){return t(e={exports:{}},e.exports),e.exports}function n(t){return t&&t.Math==Math&&t}function a(t){try{return!!t()}catch(t){return!0}}function o(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}function r(t){return m.call(t).slice(8,-1)}function i(t){if(null==t)throw TypeError("Can't call method on "+t);return t}function u(t){return O(i(t))}function c(t){return"object"==typeof t?null!==t:"function"==typeof t}function f(t,e){if(!c(t))return t;var n,r;if(e&&"function"==typeof(n=t.toString)&&!c(r=n.call(t)))return r;if("function"==typeof(n=t.valueOf)&&!c(r=n.call(t)))return r;if(!e&&"function"==typeof(n=t.toString)&&!c(r=n.call(t)))return r;throw TypeError("Can't convert object to primitive value")}function s(t,e){return S.call(t,e)}function l(t){if(!c(t))throw TypeError(String(t)+" is not an object");return t}function p(e,n){try{P(h,e,n)}catch(t){h[e]=n}return n}var h=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof t&&t)||Function("return this")(),d=!a(function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]}),y={}.propertyIsEnumerable,g=Object.getOwnPropertyDescriptor,v={f:g&&!y.call({1:2},1)?function(t){var e=g(this,t);return!!e&&e.enumerable}:y},m={}.toString,b="".split,O=a(function(){return!Object("z").propertyIsEnumerable(0)})?function(t){return"String"==r(t)?b.call(t,""):Object(t)}:Object,S={}.hasOwnProperty,k=h.document,w=c(k)&&c(k.createElement),j=!d&&!a(function(){return 7!=Object.defineProperty(function(t){return w?k.createElement(t):{}}("div"),"a",{get:function(){return 7}}).a}),x=Object.getOwnPropertyDescriptor,C={f:d?x:function(t,e){if(t=u(t),e=f(e,!0),j)try{return x(t,e)}catch(t){}if(s(t,e))return o(!v.f.call(t,e),t[e])}},E=Object.defineProperty,A={f:d?E:function(t,e,n){if(l(t),e=f(e,!0),l(n),j)try{return E(t,e,n)}catch(t){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(t[e]=n.value),t}},P=d?function(t,e,n){return A.f(t,e,o(1,n))}:function(t,e,n){return t[e]=n,t},M="__core-js_shared__",T=h[M]||p(M,{}),D=Function.toString;"function"!=typeof T.inspectSource&&(T.inspectSource=function(t){return D.call(t)});function _(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++B+G).toString(36)}var I,z,L,N,F=T.inspectSource,R=h.WeakMap,Z="function"==typeof R&&/native code/.test(F(R)),q=e(function(t){(t.exports=function(t,e){return T[t]||(T[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.6.4",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})}),B=0,G=Math.random(),K=q("keys"),U={},W=h.WeakMap;if(Z){var $=new W,J=$.get,Q=$.has,V=$.set;I=function(t,e){return V.call($,t,e),e},z=function(t){return J.call($,t)||{}},L=function(t){return Q.call($,t)}}else{var Y=K[N="state"]||(K[N]=_(N));U[Y]=!0,I=function(t,e){return P(t,Y,e),e},z=function(t){return s(t,Y)?t[Y]:{}},L=function(t){return s(t,Y)}}function H(t){return"function"==typeof t?t:void 0}function X(t,e){return arguments.length<2?H(yt[t])||H(h[t]):yt[t]&&yt[t][e]||h[t]&&h[t][e]}function tt(t){return isNaN(t=+t)?0:(0<t?vt:gt)(t)}function et(t){return 0<t?mt(tt(t),9007199254740991):0}function nt(c){return function(t,e,n){var r,o=u(t),i=et(o.length),a=function(t,e){var n=tt(t);return n<0?bt(n+e,0):Ot(n,e)}(n,i);if(c&&e!=e){for(;a<i;)if((r=o[a++])!=r)return!0}else for(;a<i;a++)if((c||a in o)&&o[a]===e)return c||a||0;return!c&&-1}}function rt(t,e){var n,r=u(t),o=0,i=[];for(n in r)!s(U,n)&&s(r,n)&&i.push(n);for(;e.length>o;)s(r,n=e[o++])&&(~kt(i,n)||i.push(n));return i}function ot(t,e){for(var n=Et(e),r=A.f,o=C.f,i=0;i<n.length;i++){var a=n[i];s(t,a)||r(t,a,o(e,a))}}function it(t,e){var n=Mt[Pt(t)];return n==Dt||n!=Tt&&("function"==typeof e?a(e):!!e)}function at(t,e){var n,r,o,i,a,c=t.target,u=t.global,f=t.stat;if(n=u?h:f?h[c]||p(c,{}):(h[c]||{}).prototype)for(r in e){if(i=e[r],o=t.noTargetGet?(a=It(n,r))&&a.value:n[r],!_t(u?r:c+(f?".":"#")+r,t.forced)&&void 0!==o){if(typeof i==typeof o)continue;ot(i,o)}(t.sham||o&&o.sham)&&P(i,"sham",!0),dt(n,r,i,t)}}function ct(t){return Object(i(t))}function ut(t,e,n){var r=f(e);r in t?A.f(t,r,o(0,n)):t[r]=n}function ft(t){return s(Ft,t)||(Lt&&s(Rt,t)?Ft[t]=Rt[t]:Ft[t]=Zt("Symbol."+t)),Ft[t]}function st(t,e){var n;return zt(t)&&("function"!=typeof(n=t.constructor)||n!==Array&&!zt(n.prototype)?c(n)&&null===(n=n[qt])&&(n=void 0):n=void 0),new(void 0===n?Array:n)(0===e?0:e)}var lt,pt,ht={set:I,get:z,has:L,enforce:function(t){return L(t)?z(t):I(t,{})},getterFor:function(n){return function(t){var e;if(!c(t)||(e=z(t)).type!==n)throw TypeError("Incompatible receiver, "+n+" required");return e}}},dt=e(function(t){var e=ht.get,c=ht.enforce,u=String(String).split("String");(t.exports=function(t,e,n,r){var o=!!r&&!!r.unsafe,i=!!r&&!!r.enumerable,a=!!r&&!!r.noTargetGet;"function"==typeof n&&("string"!=typeof e||s(n,"name")||P(n,"name",e),c(n).source=u.join("string"==typeof e?e:"")),t!==h?(o?!a&&t[e]&&(i=!0):delete t[e],i?t[e]=n:P(t,e,n)):i?t[e]=n:p(e,n)})(Function.prototype,"toString",function(){return"function"==typeof this&&e(this).source||F(this)})}),yt=h,gt=Math.ceil,vt=Math.floor,mt=Math.min,bt=Math.max,Ot=Math.min,St={includes:nt(!0),indexOf:nt(!1)},kt=St.indexOf,wt=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],jt=wt.concat("length","prototype"),xt={f:Object.getOwnPropertyNames||function(t){return rt(t,jt)}},Ct={f:Object.getOwnPropertySymbols},Et=X("Reflect","ownKeys")||function(t){var e=xt.f(l(t)),n=Ct.f;return n?e.concat(n(t)):e},At=/#|\.prototype\./,Pt=it.normalize=function(t){return String(t).replace(At,".").toLowerCase()},Mt=it.data={},Tt=it.NATIVE="N",Dt=it.POLYFILL="P",_t=it,It=C.f,zt=Array.isArray||function(t){return"Array"==r(t)},Lt=!!Object.getOwnPropertySymbols&&!a(function(){return!String(Symbol())}),Nt=Lt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Ft=q("wks"),Rt=h.Symbol,Zt=Nt?Rt:Rt&&Rt.withoutSetter||_,qt=ft("species"),Bt=X("navigator","userAgent")||"",Gt=h.process,Kt=Gt&&Gt.versions,Ut=Kt&&Kt.v8;Ut?pt=(lt=Ut.split("."))[0]+lt[1]:Bt&&(!(lt=Bt.match(/Edge\/(\d+)/))||74<=lt[1])&&(lt=Bt.match(/Chrome\/(\d+)/))&&(pt=lt[1]);function Wt(e){return 51<=Jt||!a(function(){var t=[];return(t.constructor={})[Qt]=function(){return{foo:1}},1!==t[e](Boolean).foo})}function $t(t){if(!c(t))return!1;var e=t[Vt];return void 0!==e?!!e:zt(t)}var Jt=pt&&+pt,Qt=ft("species"),Vt=ft("isConcatSpreadable"),Yt=9007199254740991,Ht="Maximum allowed index exceeded",Xt=51<=Jt||!a(function(){var t=[];return t[Vt]=!1,t.concat()[0]!==t}),te=Wt("concat");at({target:"Array",proto:!0,forced:!Xt||!te},{concat:function(t){var e,n,r,o,i,a=ct(this),c=st(a,0),u=0;for(e=-1,r=arguments.length;e<r;e++)if($t(i=-1===e?a:arguments[e])){if(o=et(i.length),Yt<u+o)throw TypeError(Ht);for(n=0;n<o;n++,u++)n in i&&ut(c,u,i[n])}else{if(Yt<=u)throw TypeError(Ht);ut(c,u++,i)}return c.length=u,c}});function ee(t,e){var n=[][t];return!!n&&a(function(){n.call(null,e||function(){throw 1},1)})}function ne(t){throw t}function re(t,e){if(s(ie,t))return ie[t];var n=[][t],r=!!s(e=e||{},"ACCESSORS")&&e.ACCESSORS,o=s(e,0)?e[0]:ne,i=s(e,1)?e[1]:void 0;return ie[t]=!!n&&!a(function(){if(r&&!d)return!0;var t={length:-1};r?oe(t,1,{enumerable:!0,get:ne}):t[1]=1,n.call(t,o,i)})}var oe=Object.defineProperty,ie={},ae=St.indexOf,ce=[].indexOf,ue=!!ce&&1/[1].indexOf(1,-0)<0,fe=ee("indexOf"),se=re("indexOf",{ACCESSORS:!0,1:0});at({target:"Array",proto:!0,forced:ue||!fe||!se},{indexOf:function(t,e){return ue?ce.apply(this,arguments)||0:ae(this,t,1<arguments.length?e:void 0)}});var le=[].join,pe=O!=Object,he=ee("join",",");at({target:"Array",proto:!0,forced:pe||!he},{join:function(t){return le.call(u(this),void 0===t?",":t)}});function de(r,o,t){if(function(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function")}(r),void 0===o)return r;switch(t){case 0:return function(){return r.call(o)};case 1:return function(t){return r.call(o,t)};case 2:return function(t,e){return r.call(o,t,e)};case 3:return function(t,e,n){return r.call(o,t,e,n)}}return function(){return r.apply(o,arguments)}}function ye(h){var d=1==h,y=2==h,g=3==h,v=4==h,m=6==h,b=5==h||m;return function(t,e,n,r){for(var o,i,a=ct(t),c=O(a),u=de(e,n,3),f=et(c.length),s=0,l=r||st,p=d?l(t,f):y?l(t,0):void 0;s<f;s++)if((b||s in c)&&(i=u(o=c[s],s,a),h))if(d)p[s]=i;else if(i)switch(h){case 3:return!0;case 5:return o;case 6:return s;case 2:ge.call(p,o)}else if(v)return!1;return m?-1:g||v?v:p}}var ge=[].push,ve={forEach:ye(0),map:ye(1),filter:ye(2),some:ye(3),every:ye(4),find:ye(5),findIndex:ye(6)}.map,me=Wt("map"),be=re("map");at({target:"Array",proto:!0,forced:!me||!be},{map:function(t,e){return ve(this,t,1<arguments.length?e:void 0)}}),at({target:"Date",stat:!0},{now:function(){return(new Date).getTime()}});var Oe=Date.prototype,Se="Invalid Date",ke="toString",we=Oe[ke],je=Oe.getTime;new Date(NaN)+""!=Se&&dt(Oe,ke,function(){var t=je.call(this);return t==t?we.call(this):Se});var xe=Object.keys||function(t){return rt(t,wt)},Ce=Object.assign,Ee=Object.defineProperty,Ae=!Ce||a(function(){if(d&&1!==Ce({b:1},Ce(Ee({},"a",{enumerable:!0,get:function(){Ee(this,"b",{value:3,enumerable:!1})}}),{b:2})).b)return!0;var t={},e={},n=Symbol(),r="abcdefghijklmnopqrst";return t[n]=7,r.split("").forEach(function(t){e[t]=t}),7!=Ce({},t)[n]||xe(Ce({},e)).join("")!=r})?function(t,e){for(var n=ct(t),r=arguments.length,o=1,i=Ct.f,a=v.f;o<r;)for(var c,u=O(arguments[o++]),f=i?xe(u).concat(i(u)):xe(u),s=f.length,l=0;l<s;)c=f[l++],d&&!a.call(u,c)||(n[c]=u[c]);return n}:Ce;function Pe(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}at({target:"Object",stat:!0,forced:Object.assign!==Ae},{assign:Ae}),at({target:"Object",stat:!0,forced:a(function(){xe(1)})},{keys:function(t){return xe(ct(t))}});var Me,Te,De,_e=/(iPhone|iPod|iPad)/.test(navigator.userAgent);function Ie(t){console.error("[SpyClient_log]".concat(t))}function ze(t){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,ze),this.sample={},this.markCache={},!t.pid)throw new Error("pid is required");this.option={pid:t.pid,lid:t.lid,check:!1!==t.check,sample:t.sample,logServer:t.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return Me=ze,(Te=[{key:"send",value:function(t){if(this.check(t)){if("number"==typeof t.sample){if(Math.random()>t.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;delete(t=Object.assign({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},t)).sample;var e=this.option.logServer+function(n){return Object.keys(n).map(function(t){var e=n[t];return void 0===e?e="":"string"!=typeof e&&(e=JSON.stringify(e)),encodeURIComponent(t)+"="+encodeURIComponent(e)}).join("&")}(t);!_e&&navigator.sendBeacon&&navigator.sendBeacon(e)||((new Image).src=e)}}},{key:"check",value:function(t){if(!this.option.check)return!0;var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return Ie("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return Ie("group length execeeds 30"),!1;var n=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===t.type){if("string"!=typeof t.info.msg||!t.info.msg.length)return Ie("info.msg field must be not empty and is String"),!1}else for(var r=0,o=Object.keys(t.info);r<o.length;r++){var i=o[r];if(!n.test(i))return Ie("info.".concat(i," is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var a=t.info[i];if("dist"===t.type){if(30<a.length)return Ie("info.".concat(i," value length execeeds 30 when type == 'dist'")),!1}else if("number"!=typeof a)return Ie("info.".concat(i," value must be number")),!1}if(t.dim)for(var c=0,u=Object.keys(t.dim);c<u.length;c++){var f=u[c];if(!n.test(f))return Ie("dim key [".concat(f,"] is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=t.dim[f];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(s))return Ie("dim.".concat(f," value [").concat(s,"] is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0}},{key:"sendPerf",value:function(t){this.send(Object.assign({type:"perf"},t))}},{key:"sendExcept",value:function(t){this.send(Object.assign({type:"except"},t))}},{key:"sendDist",value:function(t){this.send(Object.assign({type:"dist"},t))}},{key:"sendCount",value:function(t){this.send(Object.assign({type:"count"},t))}},{key:"sendExceptForError",value:function(t,e){var n=Object.assign({},e);n.info=Object.assign({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(n)}},{key:"startMark",value:function(t){this.markCache[t]={start:Date.now()}}},{key:"endMark",value:function(t){return this.markCache[t]?(this.markCache[t].total=Date.now()-this.markCache[t].start,this.markCache[t].total):0}},{key:"clearMark",value:function(t){this.markCache[t]&&delete this.markCache[t]}},{key:"getAllMark",value:function(){for(var t={},e=0,n=Object.keys(this.markCache);e<n.length;e++){var r=n[e];t[r]=this.markCache[r].total}return t}},{key:"clearAllMark",value:function(){this.markCache={}}}])&&Pe(Me.prototype,Te),void(De&&Pe(Me,De)),ze}();
1
+ var SpyClient=function(){"use strict";function r(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return(Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,e)}var t=/(iPhone|iPod|iPad)/.test(navigator.userAgent);function u(e){console.error("[SpyClient_log]"+e)}function e(e){if(this.sample={},this.markCache={},!e.pid)throw new Error("pid is required");this.option={pid:e.pid,lid:e.lid,check:!1!==e.check,sample:e.sample,logServer:e.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return e.prototype.send=function(e){if(this.check(e)){if("number"==typeof e.sample){if(Math.random()>e.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;delete(e=r({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},e)).sample;var n,e=this.option.logServer+(n=e,Object.keys(n).map(function(e){var t=n[e];return void 0===t?t="":"string"!=typeof t&&(t=JSON.stringify(t)),encodeURIComponent(e)+"="+encodeURIComponent(t)}).join("&"));!t&&navigator.sendBeacon&&navigator.sendBeacon(e)||((new Image).src=e)}},e.prototype.check=function(e){if(!this.option.check)return!0;var t=["perf","except","dist","count"];if(-1===t.indexOf(e.type))return u("type only is one of "+t.join(", ")),!1;if(e.group&&30<e.group.length)return u("group length execeeds 30"),!1;var n=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===e.type){if("string"!=typeof e.info.msg||!e.info.msg.length)return u("info.msg field must be not empty and is String"),!1}else for(var r=0,o=Object.keys(e.info);r<o.length;r++){var i=o[r];if(!n.test(i))return u("info."+i+" is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=e.info[i];if("dist"===e.type){if(30<s.length)return u("info."+i+" value length execeeds 30 when type == 'dist'"),!1}else if("number"!=typeof s)return u("info."+i+" value must be number"),!1}if(e.dim)for(var a=0,p=Object.keys(e.dim);a<p.length;a++){var c=p[a];if(!n.test(c))return u("dim key ["+c+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var h=e.dim[c];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(h))return u("dim."+c+" value ["+h+"] is unexpected. Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0},e.prototype.sendPerf=function(e){this.send(r({type:"perf"},e))},e.prototype.sendExcept=function(e){this.send(r({type:"except"},e))},e.prototype.sendDist=function(e){this.send(r({type:"dist"},e))},e.prototype.sendCount=function(e){this.send(r({type:"count"},e))},e.prototype.sendExceptForError=function(e,t){var n=r({},t);n.info=r({},t.info||{},{msg:e.message,stack:e.stack}),this.sendExcept(n)},e.prototype.startMark=function(e){this.markCache[e]={start:Date.now()}},e.prototype.endMark=function(e){return this.markCache[e]?(this.markCache[e].total=Date.now()-this.markCache[e].start,this.markCache[e].total):0},e.prototype.clearMark=function(e){this.markCache[e]&&delete this.markCache[e]},e.prototype.getAllMark=function(){for(var e={},t=0,n=Object.keys(this.markCache);t<n.length;t++){var r=n[t];e[r]=this.markCache[r].total}return e},e.prototype.clearAllMark=function(){this.markCache={}},e}();
@@ -1,1177 +1,243 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define(factory) :
4
- (global = global || self, global.SpyClient = factory());
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define(factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SpyClient = factory());
5
5
  }(this, (function () { 'use strict';
6
6
 
7
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
-
9
- function createCommonjsModule(fn, module) {
10
- return module = { exports: {} }, fn(module, module.exports), module.exports;
11
- }
12
-
13
- var check = function (it) {
14
- return it && it.Math == Math && it;
15
- };
16
-
17
- // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
18
- var global_1 =
19
- // eslint-disable-next-line no-undef
20
- check(typeof globalThis == 'object' && globalThis) ||
21
- check(typeof window == 'object' && window) ||
22
- check(typeof self == 'object' && self) ||
23
- check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
24
- // eslint-disable-next-line no-new-func
25
- Function('return this')();
26
-
27
- var fails = function (exec) {
28
- try {
29
- return !!exec();
30
- } catch (error) {
31
- return true;
32
- }
33
- };
34
-
35
- // Thank's IE8 for his funny defineProperty
36
- var descriptors = !fails(function () {
37
- return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
38
- });
39
-
40
- var nativePropertyIsEnumerable = {}.propertyIsEnumerable;
41
- var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
42
-
43
- // Nashorn ~ JDK8 bug
44
- var NASHORN_BUG = getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1);
45
-
46
- // `Object.prototype.propertyIsEnumerable` method implementation
47
- // https://tc39.github.io/ecma262/#sec-object.prototype.propertyisenumerable
48
- var f = NASHORN_BUG ? function propertyIsEnumerable(V) {
49
- var descriptor = getOwnPropertyDescriptor(this, V);
50
- return !!descriptor && descriptor.enumerable;
51
- } : nativePropertyIsEnumerable;
52
-
53
- var objectPropertyIsEnumerable = {
54
- f: f
55
- };
56
-
57
- var createPropertyDescriptor = function (bitmap, value) {
58
- return {
59
- enumerable: !(bitmap & 1),
60
- configurable: !(bitmap & 2),
61
- writable: !(bitmap & 4),
62
- value: value
63
- };
64
- };
65
-
66
- var toString = {}.toString;
67
-
68
- var classofRaw = function (it) {
69
- return toString.call(it).slice(8, -1);
70
- };
71
-
72
- var split = ''.split;
73
-
74
- // fallback for non-array-like ES3 and non-enumerable old V8 strings
75
- var indexedObject = fails(function () {
76
- // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
77
- // eslint-disable-next-line no-prototype-builtins
78
- return !Object('z').propertyIsEnumerable(0);
79
- }) ? function (it) {
80
- return classofRaw(it) == 'String' ? split.call(it, '') : Object(it);
81
- } : Object;
82
-
83
- // `RequireObjectCoercible` abstract operation
84
- // https://tc39.github.io/ecma262/#sec-requireobjectcoercible
85
- var requireObjectCoercible = function (it) {
86
- if (it == undefined) throw TypeError("Can't call method on " + it);
87
- return it;
88
- };
89
-
90
- // toObject with fallback for non-array-like ES3 strings
91
-
92
-
93
-
94
- var toIndexedObject = function (it) {
95
- return indexedObject(requireObjectCoercible(it));
96
- };
97
-
98
- var isObject = function (it) {
99
- return typeof it === 'object' ? it !== null : typeof it === 'function';
100
- };
101
-
102
- // `ToPrimitive` abstract operation
103
- // https://tc39.github.io/ecma262/#sec-toprimitive
104
- // instead of the ES6 spec version, we didn't implement @@toPrimitive case
105
- // and the second argument - flag - preferred type is a string
106
- var toPrimitive = function (input, PREFERRED_STRING) {
107
- if (!isObject(input)) return input;
108
- var fn, val;
109
- if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
110
- if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
111
- if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
112
- throw TypeError("Can't convert object to primitive value");
113
- };
114
-
115
- var hasOwnProperty = {}.hasOwnProperty;
116
-
117
- var has = function (it, key) {
118
- return hasOwnProperty.call(it, key);
119
- };
120
-
121
- var document = global_1.document;
122
- // typeof document.createElement is 'object' in old IE
123
- var EXISTS = isObject(document) && isObject(document.createElement);
124
-
125
- var documentCreateElement = function (it) {
126
- return EXISTS ? document.createElement(it) : {};
127
- };
128
-
129
- // Thank's IE8 for his funny defineProperty
130
- var ie8DomDefine = !descriptors && !fails(function () {
131
- return Object.defineProperty(documentCreateElement('div'), 'a', {
132
- get: function () { return 7; }
133
- }).a != 7;
134
- });
135
-
136
- var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
137
-
138
- // `Object.getOwnPropertyDescriptor` method
139
- // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
140
- var f$1 = descriptors ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
141
- O = toIndexedObject(O);
142
- P = toPrimitive(P, true);
143
- if (ie8DomDefine) try {
144
- return nativeGetOwnPropertyDescriptor(O, P);
145
- } catch (error) { /* empty */ }
146
- if (has(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]);
147
- };
148
-
149
- var objectGetOwnPropertyDescriptor = {
150
- f: f$1
151
- };
152
-
153
- var anObject = function (it) {
154
- if (!isObject(it)) {
155
- throw TypeError(String(it) + ' is not an object');
156
- } return it;
157
- };
158
-
159
- var nativeDefineProperty = Object.defineProperty;
160
-
161
- // `Object.defineProperty` method
162
- // https://tc39.github.io/ecma262/#sec-object.defineproperty
163
- var f$2 = descriptors ? nativeDefineProperty : function defineProperty(O, P, Attributes) {
164
- anObject(O);
165
- P = toPrimitive(P, true);
166
- anObject(Attributes);
167
- if (ie8DomDefine) try {
168
- return nativeDefineProperty(O, P, Attributes);
169
- } catch (error) { /* empty */ }
170
- if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
171
- if ('value' in Attributes) O[P] = Attributes.value;
172
- return O;
173
- };
174
-
175
- var objectDefineProperty = {
176
- f: f$2
177
- };
178
-
179
- var createNonEnumerableProperty = descriptors ? function (object, key, value) {
180
- return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value));
181
- } : function (object, key, value) {
182
- object[key] = value;
183
- return object;
184
- };
185
-
186
- var setGlobal = function (key, value) {
187
- try {
188
- createNonEnumerableProperty(global_1, key, value);
189
- } catch (error) {
190
- global_1[key] = value;
191
- } return value;
192
- };
193
-
194
- var SHARED = '__core-js_shared__';
195
- var store = global_1[SHARED] || setGlobal(SHARED, {});
196
-
197
- var sharedStore = store;
198
-
199
- var functionToString = Function.toString;
200
-
201
- // this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper
202
- if (typeof sharedStore.inspectSource != 'function') {
203
- sharedStore.inspectSource = function (it) {
204
- return functionToString.call(it);
205
- };
206
- }
207
-
208
- var inspectSource = sharedStore.inspectSource;
209
-
210
- var WeakMap = global_1.WeakMap;
211
-
212
- var nativeWeakMap = typeof WeakMap === 'function' && /native code/.test(inspectSource(WeakMap));
213
-
214
- var shared = createCommonjsModule(function (module) {
215
- (module.exports = function (key, value) {
216
- return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
217
- })('versions', []).push({
218
- version: '3.6.4',
219
- mode: 'global',
220
- copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
221
- });
222
- });
223
-
224
- var id = 0;
225
- var postfix = Math.random();
226
-
227
- var uid = function (key) {
228
- return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
229
- };
230
-
231
- var keys = shared('keys');
232
-
233
- var sharedKey = function (key) {
234
- return keys[key] || (keys[key] = uid(key));
235
- };
236
-
237
- var hiddenKeys = {};
238
-
239
- var WeakMap$1 = global_1.WeakMap;
240
- var set, get, has$1;
241
-
242
- var enforce = function (it) {
243
- return has$1(it) ? get(it) : set(it, {});
244
- };
245
-
246
- var getterFor = function (TYPE) {
247
- return function (it) {
248
- var state;
249
- if (!isObject(it) || (state = get(it)).type !== TYPE) {
250
- throw TypeError('Incompatible receiver, ' + TYPE + ' required');
251
- } return state;
252
- };
253
- };
254
-
255
- if (nativeWeakMap) {
256
- var store$1 = new WeakMap$1();
257
- var wmget = store$1.get;
258
- var wmhas = store$1.has;
259
- var wmset = store$1.set;
260
- set = function (it, metadata) {
261
- wmset.call(store$1, it, metadata);
262
- return metadata;
263
- };
264
- get = function (it) {
265
- return wmget.call(store$1, it) || {};
266
- };
267
- has$1 = function (it) {
268
- return wmhas.call(store$1, it);
269
- };
270
- } else {
271
- var STATE = sharedKey('state');
272
- hiddenKeys[STATE] = true;
273
- set = function (it, metadata) {
274
- createNonEnumerableProperty(it, STATE, metadata);
275
- return metadata;
276
- };
277
- get = function (it) {
278
- return has(it, STATE) ? it[STATE] : {};
279
- };
280
- has$1 = function (it) {
281
- return has(it, STATE);
282
- };
283
- }
284
-
285
- var internalState = {
286
- set: set,
287
- get: get,
288
- has: has$1,
289
- enforce: enforce,
290
- getterFor: getterFor
291
- };
292
-
293
- var redefine = createCommonjsModule(function (module) {
294
- var getInternalState = internalState.get;
295
- var enforceInternalState = internalState.enforce;
296
- var TEMPLATE = String(String).split('String');
297
-
298
- (module.exports = function (O, key, value, options) {
299
- var unsafe = options ? !!options.unsafe : false;
300
- var simple = options ? !!options.enumerable : false;
301
- var noTargetGet = options ? !!options.noTargetGet : false;
302
- if (typeof value == 'function') {
303
- if (typeof key == 'string' && !has(value, 'name')) createNonEnumerableProperty(value, 'name', key);
304
- enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : '');
305
- }
306
- if (O === global_1) {
307
- if (simple) O[key] = value;
308
- else setGlobal(key, value);
309
- return;
310
- } else if (!unsafe) {
311
- delete O[key];
312
- } else if (!noTargetGet && O[key]) {
313
- simple = true;
314
- }
315
- if (simple) O[key] = value;
316
- else createNonEnumerableProperty(O, key, value);
317
- // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
318
- })(Function.prototype, 'toString', function toString() {
319
- return typeof this == 'function' && getInternalState(this).source || inspectSource(this);
320
- });
321
- });
322
-
323
- var path = global_1;
324
-
325
- var aFunction = function (variable) {
326
- return typeof variable == 'function' ? variable : undefined;
327
- };
328
-
329
- var getBuiltIn = function (namespace, method) {
330
- return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global_1[namespace])
331
- : path[namespace] && path[namespace][method] || global_1[namespace] && global_1[namespace][method];
332
- };
333
-
334
- var ceil = Math.ceil;
335
- var floor = Math.floor;
336
-
337
- // `ToInteger` abstract operation
338
- // https://tc39.github.io/ecma262/#sec-tointeger
339
- var toInteger = function (argument) {
340
- return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor : ceil)(argument);
341
- };
342
-
343
- var min = Math.min;
344
-
345
- // `ToLength` abstract operation
346
- // https://tc39.github.io/ecma262/#sec-tolength
347
- var toLength = function (argument) {
348
- return argument > 0 ? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
349
- };
350
-
351
- var max = Math.max;
352
- var min$1 = Math.min;
353
-
354
- // Helper for a popular repeating case of the spec:
355
- // Let integer be ? ToInteger(index).
356
- // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
357
- var toAbsoluteIndex = function (index, length) {
358
- var integer = toInteger(index);
359
- return integer < 0 ? max(integer + length, 0) : min$1(integer, length);
360
- };
361
-
362
- // `Array.prototype.{ indexOf, includes }` methods implementation
363
- var createMethod = function (IS_INCLUDES) {
364
- return function ($this, el, fromIndex) {
365
- var O = toIndexedObject($this);
366
- var length = toLength(O.length);
367
- var index = toAbsoluteIndex(fromIndex, length);
368
- var value;
369
- // Array#includes uses SameValueZero equality algorithm
370
- // eslint-disable-next-line no-self-compare
371
- if (IS_INCLUDES && el != el) while (length > index) {
372
- value = O[index++];
373
- // eslint-disable-next-line no-self-compare
374
- if (value != value) return true;
375
- // Array#indexOf ignores holes, Array#includes - not
376
- } else for (;length > index; index++) {
377
- if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
378
- } return !IS_INCLUDES && -1;
379
- };
380
- };
381
-
382
- var arrayIncludes = {
383
- // `Array.prototype.includes` method
384
- // https://tc39.github.io/ecma262/#sec-array.prototype.includes
385
- includes: createMethod(true),
386
- // `Array.prototype.indexOf` method
387
- // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
388
- indexOf: createMethod(false)
389
- };
390
-
391
- var indexOf = arrayIncludes.indexOf;
392
-
393
-
394
- var objectKeysInternal = function (object, names) {
395
- var O = toIndexedObject(object);
396
- var i = 0;
397
- var result = [];
398
- var key;
399
- for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key);
400
- // Don't enum bug & hidden keys
401
- while (names.length > i) if (has(O, key = names[i++])) {
402
- ~indexOf(result, key) || result.push(key);
403
- }
404
- return result;
405
- };
406
-
407
- // IE8- don't enum bug keys
408
- var enumBugKeys = [
409
- 'constructor',
410
- 'hasOwnProperty',
411
- 'isPrototypeOf',
412
- 'propertyIsEnumerable',
413
- 'toLocaleString',
414
- 'toString',
415
- 'valueOf'
416
- ];
417
-
418
- var hiddenKeys$1 = enumBugKeys.concat('length', 'prototype');
419
-
420
- // `Object.getOwnPropertyNames` method
421
- // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
422
- var f$3 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
423
- return objectKeysInternal(O, hiddenKeys$1);
424
- };
425
-
426
- var objectGetOwnPropertyNames = {
427
- f: f$3
428
- };
429
-
430
- var f$4 = Object.getOwnPropertySymbols;
431
-
432
- var objectGetOwnPropertySymbols = {
433
- f: f$4
434
- };
435
-
436
- // all object keys, includes non-enumerable and symbols
437
- var ownKeys = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
438
- var keys = objectGetOwnPropertyNames.f(anObject(it));
439
- var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
440
- return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
441
- };
442
-
443
- var copyConstructorProperties = function (target, source) {
444
- var keys = ownKeys(source);
445
- var defineProperty = objectDefineProperty.f;
446
- var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
447
- for (var i = 0; i < keys.length; i++) {
448
- var key = keys[i];
449
- if (!has(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
450
- }
451
- };
452
-
453
- var replacement = /#|\.prototype\./;
454
-
455
- var isForced = function (feature, detection) {
456
- var value = data[normalize(feature)];
457
- return value == POLYFILL ? true
458
- : value == NATIVE ? false
459
- : typeof detection == 'function' ? fails(detection)
460
- : !!detection;
461
- };
462
-
463
- var normalize = isForced.normalize = function (string) {
464
- return String(string).replace(replacement, '.').toLowerCase();
465
- };
466
-
467
- var data = isForced.data = {};
468
- var NATIVE = isForced.NATIVE = 'N';
469
- var POLYFILL = isForced.POLYFILL = 'P';
470
-
471
- var isForced_1 = isForced;
472
-
473
- var getOwnPropertyDescriptor$1 = objectGetOwnPropertyDescriptor.f;
474
-
475
-
476
-
477
-
478
-
479
-
480
- /*
481
- options.target - name of the target object
482
- options.global - target is the global object
483
- options.stat - export as static methods of target
484
- options.proto - export as prototype methods of target
485
- options.real - real prototype method for the `pure` version
486
- options.forced - export even if the native feature is available
487
- options.bind - bind methods to the target, required for the `pure` version
488
- options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
489
- options.unsafe - use the simple assignment of property instead of delete + defineProperty
490
- options.sham - add a flag to not completely full polyfills
491
- options.enumerable - export as enumerable property
492
- options.noTargetGet - prevent calling a getter on target
493
- */
494
- var _export = function (options, source) {
495
- var TARGET = options.target;
496
- var GLOBAL = options.global;
497
- var STATIC = options.stat;
498
- var FORCED, target, key, targetProperty, sourceProperty, descriptor;
499
- if (GLOBAL) {
500
- target = global_1;
501
- } else if (STATIC) {
502
- target = global_1[TARGET] || setGlobal(TARGET, {});
503
- } else {
504
- target = (global_1[TARGET] || {}).prototype;
505
- }
506
- if (target) for (key in source) {
507
- sourceProperty = source[key];
508
- if (options.noTargetGet) {
509
- descriptor = getOwnPropertyDescriptor$1(target, key);
510
- targetProperty = descriptor && descriptor.value;
511
- } else targetProperty = target[key];
512
- FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
513
- // contained in target
514
- if (!FORCED && targetProperty !== undefined) {
515
- if (typeof sourceProperty === typeof targetProperty) continue;
516
- copyConstructorProperties(sourceProperty, targetProperty);
517
- }
518
- // add a flag to not completely full polyfills
519
- if (options.sham || (targetProperty && targetProperty.sham)) {
520
- createNonEnumerableProperty(sourceProperty, 'sham', true);
521
- }
522
- // extend global
523
- redefine(target, key, sourceProperty, options);
524
- }
525
- };
526
-
527
- // `IsArray` abstract operation
528
- // https://tc39.github.io/ecma262/#sec-isarray
529
- var isArray = Array.isArray || function isArray(arg) {
530
- return classofRaw(arg) == 'Array';
531
- };
532
-
533
- // `ToObject` abstract operation
534
- // https://tc39.github.io/ecma262/#sec-toobject
535
- var toObject = function (argument) {
536
- return Object(requireObjectCoercible(argument));
537
- };
538
-
539
- var createProperty = function (object, key, value) {
540
- var propertyKey = toPrimitive(key);
541
- if (propertyKey in object) objectDefineProperty.f(object, propertyKey, createPropertyDescriptor(0, value));
542
- else object[propertyKey] = value;
543
- };
544
-
545
- var nativeSymbol = !!Object.getOwnPropertySymbols && !fails(function () {
546
- // Chrome 38 Symbol has incorrect toString conversion
547
- // eslint-disable-next-line no-undef
548
- return !String(Symbol());
549
- });
550
-
551
- var useSymbolAsUid = nativeSymbol
552
- // eslint-disable-next-line no-undef
553
- && !Symbol.sham
554
- // eslint-disable-next-line no-undef
555
- && typeof Symbol.iterator == 'symbol';
556
-
557
- var WellKnownSymbolsStore = shared('wks');
558
- var Symbol$1 = global_1.Symbol;
559
- var createWellKnownSymbol = useSymbolAsUid ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid;
560
-
561
- var wellKnownSymbol = function (name) {
562
- if (!has(WellKnownSymbolsStore, name)) {
563
- if (nativeSymbol && has(Symbol$1, name)) WellKnownSymbolsStore[name] = Symbol$1[name];
564
- else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
565
- } return WellKnownSymbolsStore[name];
566
- };
567
-
568
- var SPECIES = wellKnownSymbol('species');
569
-
570
- // `ArraySpeciesCreate` abstract operation
571
- // https://tc39.github.io/ecma262/#sec-arrayspeciescreate
572
- var arraySpeciesCreate = function (originalArray, length) {
573
- var C;
574
- if (isArray(originalArray)) {
575
- C = originalArray.constructor;
576
- // cross-realm fallback
577
- if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined;
578
- else if (isObject(C)) {
579
- C = C[SPECIES];
580
- if (C === null) C = undefined;
581
- }
582
- } return new (C === undefined ? Array : C)(length === 0 ? 0 : length);
583
- };
584
-
585
- var engineUserAgent = getBuiltIn('navigator', 'userAgent') || '';
586
-
587
- var process = global_1.process;
588
- var versions = process && process.versions;
589
- var v8 = versions && versions.v8;
590
- var match, version;
591
-
592
- if (v8) {
593
- match = v8.split('.');
594
- version = match[0] + match[1];
595
- } else if (engineUserAgent) {
596
- match = engineUserAgent.match(/Edge\/(\d+)/);
597
- if (!match || match[1] >= 74) {
598
- match = engineUserAgent.match(/Chrome\/(\d+)/);
599
- if (match) version = match[1];
600
- }
601
- }
602
-
603
- var engineV8Version = version && +version;
604
-
605
- var SPECIES$1 = wellKnownSymbol('species');
606
-
607
- var arrayMethodHasSpeciesSupport = function (METHOD_NAME) {
608
- // We can't use this feature detection in V8 since it causes
609
- // deoptimization and serious performance degradation
610
- // https://github.com/zloirock/core-js/issues/677
611
- return engineV8Version >= 51 || !fails(function () {
612
- var array = [];
613
- var constructor = array.constructor = {};
614
- constructor[SPECIES$1] = function () {
615
- return { foo: 1 };
616
- };
617
- return array[METHOD_NAME](Boolean).foo !== 1;
618
- });
619
- };
620
-
621
- var IS_CONCAT_SPREADABLE = wellKnownSymbol('isConcatSpreadable');
622
- var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF;
623
- var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded';
624
-
625
- // We can't use this feature detection in V8 since it causes
626
- // deoptimization and serious performance degradation
627
- // https://github.com/zloirock/core-js/issues/679
628
- var IS_CONCAT_SPREADABLE_SUPPORT = engineV8Version >= 51 || !fails(function () {
629
- var array = [];
630
- array[IS_CONCAT_SPREADABLE] = false;
631
- return array.concat()[0] !== array;
632
- });
633
-
634
- var SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('concat');
635
-
636
- var isConcatSpreadable = function (O) {
637
- if (!isObject(O)) return false;
638
- var spreadable = O[IS_CONCAT_SPREADABLE];
639
- return spreadable !== undefined ? !!spreadable : isArray(O);
640
- };
641
-
642
- var FORCED = !IS_CONCAT_SPREADABLE_SUPPORT || !SPECIES_SUPPORT;
643
-
644
- // `Array.prototype.concat` method
645
- // https://tc39.github.io/ecma262/#sec-array.prototype.concat
646
- // with adding support of @@isConcatSpreadable and @@species
647
- _export({ target: 'Array', proto: true, forced: FORCED }, {
648
- concat: function concat(arg) { // eslint-disable-line no-unused-vars
649
- var O = toObject(this);
650
- var A = arraySpeciesCreate(O, 0);
651
- var n = 0;
652
- var i, k, length, len, E;
653
- for (i = -1, length = arguments.length; i < length; i++) {
654
- E = i === -1 ? O : arguments[i];
655
- if (isConcatSpreadable(E)) {
656
- len = toLength(E.length);
657
- if (n + len > MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED);
658
- for (k = 0; k < len; k++, n++) if (k in E) createProperty(A, n, E[k]);
659
- } else {
660
- if (n >= MAX_SAFE_INTEGER) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED);
661
- createProperty(A, n++, E);
662
- }
663
- }
664
- A.length = n;
665
- return A;
666
- }
667
- });
668
-
669
- var arrayMethodIsStrict = function (METHOD_NAME, argument) {
670
- var method = [][METHOD_NAME];
671
- return !!method && fails(function () {
672
- // eslint-disable-next-line no-useless-call,no-throw-literal
673
- method.call(null, argument || function () { throw 1; }, 1);
674
- });
675
- };
676
-
677
- var defineProperty = Object.defineProperty;
678
- var cache = {};
679
-
680
- var thrower = function (it) { throw it; };
681
-
682
- var arrayMethodUsesToLength = function (METHOD_NAME, options) {
683
- if (has(cache, METHOD_NAME)) return cache[METHOD_NAME];
684
- if (!options) options = {};
685
- var method = [][METHOD_NAME];
686
- var ACCESSORS = has(options, 'ACCESSORS') ? options.ACCESSORS : false;
687
- var argument0 = has(options, 0) ? options[0] : thrower;
688
- var argument1 = has(options, 1) ? options[1] : undefined;
689
-
690
- return cache[METHOD_NAME] = !!method && !fails(function () {
691
- if (ACCESSORS && !descriptors) return true;
692
- var O = { length: -1 };
693
-
694
- if (ACCESSORS) defineProperty(O, 1, { enumerable: true, get: thrower });
695
- else O[1] = 1;
696
-
697
- method.call(O, argument0, argument1);
698
- });
699
- };
700
-
701
- var $indexOf = arrayIncludes.indexOf;
702
-
703
-
704
-
705
- var nativeIndexOf = [].indexOf;
706
-
707
- var NEGATIVE_ZERO = !!nativeIndexOf && 1 / [1].indexOf(1, -0) < 0;
708
- var STRICT_METHOD = arrayMethodIsStrict('indexOf');
709
- var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', { ACCESSORS: true, 1: 0 });
710
-
711
- // `Array.prototype.indexOf` method
712
- // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
713
- _export({ target: 'Array', proto: true, forced: NEGATIVE_ZERO || !STRICT_METHOD || !USES_TO_LENGTH }, {
714
- indexOf: function indexOf(searchElement /* , fromIndex = 0 */) {
715
- return NEGATIVE_ZERO
716
- // convert -0 to +0
717
- ? nativeIndexOf.apply(this, arguments) || 0
718
- : $indexOf(this, searchElement, arguments.length > 1 ? arguments[1] : undefined);
719
- }
720
- });
721
-
722
- var nativeJoin = [].join;
723
-
724
- var ES3_STRINGS = indexedObject != Object;
725
- var STRICT_METHOD$1 = arrayMethodIsStrict('join', ',');
726
-
727
- // `Array.prototype.join` method
728
- // https://tc39.github.io/ecma262/#sec-array.prototype.join
729
- _export({ target: 'Array', proto: true, forced: ES3_STRINGS || !STRICT_METHOD$1 }, {
730
- join: function join(separator) {
731
- return nativeJoin.call(toIndexedObject(this), separator === undefined ? ',' : separator);
732
- }
733
- });
734
-
735
- var aFunction$1 = function (it) {
736
- if (typeof it != 'function') {
737
- throw TypeError(String(it) + ' is not a function');
738
- } return it;
739
- };
740
-
741
- // optional / simple context binding
742
- var functionBindContext = function (fn, that, length) {
743
- aFunction$1(fn);
744
- if (that === undefined) return fn;
745
- switch (length) {
746
- case 0: return function () {
747
- return fn.call(that);
748
- };
749
- case 1: return function (a) {
750
- return fn.call(that, a);
751
- };
752
- case 2: return function (a, b) {
753
- return fn.call(that, a, b);
754
- };
755
- case 3: return function (a, b, c) {
756
- return fn.call(that, a, b, c);
757
- };
758
- }
759
- return function (/* ...args */) {
760
- return fn.apply(that, arguments);
761
- };
762
- };
763
-
764
- var push = [].push;
765
-
766
- // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation
767
- var createMethod$1 = function (TYPE) {
768
- var IS_MAP = TYPE == 1;
769
- var IS_FILTER = TYPE == 2;
770
- var IS_SOME = TYPE == 3;
771
- var IS_EVERY = TYPE == 4;
772
- var IS_FIND_INDEX = TYPE == 6;
773
- var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
774
- return function ($this, callbackfn, that, specificCreate) {
775
- var O = toObject($this);
776
- var self = indexedObject(O);
777
- var boundFunction = functionBindContext(callbackfn, that, 3);
778
- var length = toLength(self.length);
779
- var index = 0;
780
- var create = specificCreate || arraySpeciesCreate;
781
- var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
782
- var value, result;
783
- for (;length > index; index++) if (NO_HOLES || index in self) {
784
- value = self[index];
785
- result = boundFunction(value, index, O);
786
- if (TYPE) {
787
- if (IS_MAP) target[index] = result; // map
788
- else if (result) switch (TYPE) {
789
- case 3: return true; // some
790
- case 5: return value; // find
791
- case 6: return index; // findIndex
792
- case 2: push.call(target, value); // filter
793
- } else if (IS_EVERY) return false; // every
794
- }
795
- }
796
- return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
797
- };
798
- };
799
-
800
- var arrayIteration = {
801
- // `Array.prototype.forEach` method
802
- // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
803
- forEach: createMethod$1(0),
804
- // `Array.prototype.map` method
805
- // https://tc39.github.io/ecma262/#sec-array.prototype.map
806
- map: createMethod$1(1),
807
- // `Array.prototype.filter` method
808
- // https://tc39.github.io/ecma262/#sec-array.prototype.filter
809
- filter: createMethod$1(2),
810
- // `Array.prototype.some` method
811
- // https://tc39.github.io/ecma262/#sec-array.prototype.some
812
- some: createMethod$1(3),
813
- // `Array.prototype.every` method
814
- // https://tc39.github.io/ecma262/#sec-array.prototype.every
815
- every: createMethod$1(4),
816
- // `Array.prototype.find` method
817
- // https://tc39.github.io/ecma262/#sec-array.prototype.find
818
- find: createMethod$1(5),
819
- // `Array.prototype.findIndex` method
820
- // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
821
- findIndex: createMethod$1(6)
822
- };
823
-
824
- var $map = arrayIteration.map;
825
-
826
-
827
-
828
- var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('map');
829
- // FF49- issue
830
- var USES_TO_LENGTH$1 = arrayMethodUsesToLength('map');
831
-
832
- // `Array.prototype.map` method
833
- // https://tc39.github.io/ecma262/#sec-array.prototype.map
834
- // with adding support of @@species
835
- _export({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH$1 }, {
836
- map: function map(callbackfn /* , thisArg */) {
837
- return $map(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
838
- }
839
- });
840
-
841
- // `Date.now` method
842
- // https://tc39.github.io/ecma262/#sec-date.now
843
- _export({ target: 'Date', stat: true }, {
844
- now: function now() {
845
- return new Date().getTime();
846
- }
847
- });
848
-
849
- var DatePrototype = Date.prototype;
850
- var INVALID_DATE = 'Invalid Date';
851
- var TO_STRING = 'toString';
852
- var nativeDateToString = DatePrototype[TO_STRING];
853
- var getTime = DatePrototype.getTime;
854
-
855
- // `Date.prototype.toString` method
856
- // https://tc39.github.io/ecma262/#sec-date.prototype.tostring
857
- if (new Date(NaN) + '' != INVALID_DATE) {
858
- redefine(DatePrototype, TO_STRING, function toString() {
859
- var value = getTime.call(this);
860
- // eslint-disable-next-line no-self-compare
861
- return value === value ? nativeDateToString.call(this) : INVALID_DATE;
862
- });
863
- }
864
-
865
- // `Object.keys` method
866
- // https://tc39.github.io/ecma262/#sec-object.keys
867
- var objectKeys = Object.keys || function keys(O) {
868
- return objectKeysInternal(O, enumBugKeys);
869
- };
870
-
871
- var nativeAssign = Object.assign;
872
- var defineProperty$1 = Object.defineProperty;
873
-
874
- // `Object.assign` method
875
- // https://tc39.github.io/ecma262/#sec-object.assign
876
- var objectAssign = !nativeAssign || fails(function () {
877
- // should have correct order of operations (Edge bug)
878
- if (descriptors && nativeAssign({ b: 1 }, nativeAssign(defineProperty$1({}, 'a', {
879
- enumerable: true,
880
- get: function () {
881
- defineProperty$1(this, 'b', {
882
- value: 3,
883
- enumerable: false
884
- });
885
- }
886
- }), { b: 2 })).b !== 1) return true;
887
- // should work with symbols and should have deterministic property order (V8 bug)
888
- var A = {};
889
- var B = {};
890
- // eslint-disable-next-line no-undef
891
- var symbol = Symbol();
892
- var alphabet = 'abcdefghijklmnopqrst';
893
- A[symbol] = 7;
894
- alphabet.split('').forEach(function (chr) { B[chr] = chr; });
895
- return nativeAssign({}, A)[symbol] != 7 || objectKeys(nativeAssign({}, B)).join('') != alphabet;
896
- }) ? function assign(target, source) { // eslint-disable-line no-unused-vars
897
- var T = toObject(target);
898
- var argumentsLength = arguments.length;
899
- var index = 1;
900
- var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
901
- var propertyIsEnumerable = objectPropertyIsEnumerable.f;
902
- while (argumentsLength > index) {
903
- var S = indexedObject(arguments[index++]);
904
- var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S);
905
- var length = keys.length;
906
- var j = 0;
907
- var key;
908
- while (length > j) {
909
- key = keys[j++];
910
- if (!descriptors || propertyIsEnumerable.call(S, key)) T[key] = S[key];
911
- }
912
- } return T;
913
- } : nativeAssign;
914
-
915
- // `Object.assign` method
916
- // https://tc39.github.io/ecma262/#sec-object.assign
917
- _export({ target: 'Object', stat: true, forced: Object.assign !== objectAssign }, {
918
- assign: objectAssign
919
- });
920
-
921
- var FAILS_ON_PRIMITIVES = fails(function () { objectKeys(1); });
922
-
923
- // `Object.keys` method
924
- // https://tc39.github.io/ecma262/#sec-object.keys
925
- _export({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES }, {
926
- keys: function keys(it) {
927
- return objectKeys(toObject(it));
928
- }
929
- });
930
-
931
- function _classCallCheck(instance, Constructor) {
932
- if (!(instance instanceof Constructor)) {
933
- throw new TypeError("Cannot call a class as a function");
934
- }
935
- }
936
-
937
- function _defineProperties(target, props) {
938
- for (var i = 0; i < props.length; i++) {
939
- var descriptor = props[i];
940
- descriptor.enumerable = descriptor.enumerable || false;
941
- descriptor.configurable = true;
942
- if ("value" in descriptor) descriptor.writable = true;
943
- Object.defineProperty(target, descriptor.key, descriptor);
944
- }
945
- }
946
-
947
- function _createClass(Constructor, protoProps, staticProps) {
948
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
949
- if (staticProps) _defineProperties(Constructor, staticProps);
950
- return Constructor;
951
- }
952
-
953
- var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
954
- var isIos = /(iPhone|iPod|iPad)/.test(navigator.userAgent);
955
-
956
- function err(msg) {
957
- console.error("[SpyClient_log]".concat(msg));
958
- }
959
-
960
- function stringify(obj) {
961
- return Object.keys(obj).map(function (key) {
962
- var value = obj[key];
963
-
964
- if (typeof value === 'undefined') {
965
- value = '';
966
- } else if (typeof value !== 'string') {
967
- value = JSON.stringify(value);
968
- }
969
-
970
- return encodeURIComponent(key) + '=' + encodeURIComponent(value);
971
- }).join('&');
972
- }
973
-
974
- var SpyClient = function () {
975
- function SpyClient(option) {
976
- _classCallCheck(this, SpyClient);
977
-
978
- this.sample = {};
979
- this.markCache = {};
980
-
981
- if (!option.pid) {
982
- throw new Error('pid is required');
983
- }
984
-
985
- this.option = {
986
- pid: option.pid,
987
- lid: option.lid,
988
- check: option.check !== false,
989
- sample: option.sample,
990
- logServer: option.logServer || defaultLogServer
991
- };
992
- }
993
-
994
- _createClass(SpyClient, [{
995
- key: "send",
996
- value: function send(query) {
997
- if (!this.check(query)) {
998
- return;
999
- }
1000
-
1001
- if (typeof query.sample === 'number') {
1002
- if (Math.random() > query.sample) {
1003
- return;
1004
- }
1005
- } else if (typeof this.option.sample === 'number' && Math.random() > this.option.sample) {
1006
- return;
1007
- }
1008
-
1009
- query = Object.assign({
1010
- pid: this.option.pid,
1011
- lid: this.option.lid,
1012
- ts: Date.now(),
1013
- group: 'common'
1014
- }, query);
1015
- delete query.sample;
1016
- var url = this.option.logServer + stringify(query);
1017
-
1018
- if (!(!isIos && navigator.sendBeacon && navigator.sendBeacon(url))) {
1019
- new Image().src = url;
1020
- }
1021
- }
1022
- }, {
1023
- key: "check",
1024
- value: function check(query) {
1025
- if (!this.option.check) {
1026
- return true;
1027
- }
1028
-
1029
- var types = ['perf', 'except', 'dist', 'count'];
1030
-
1031
- if (types.indexOf(query.type) === -1) {
1032
- err('type only is one of ' + types.join(', '));
1033
- return false;
1034
- }
1035
-
1036
- if (query.group && query.group.length > 30) {
1037
- err('group length execeeds 30');
1038
- return false;
1039
- }
1040
-
1041
- var simpleReg = /^[a-zA-Z0-9-_]{0,30}$/;
1042
-
1043
- if (query.type === 'except') {
1044
- if (!(typeof query.info.msg === 'string' && query.info.msg.length)) {
1045
- err('info.msg field must be not empty and is String');
1046
- return false;
1047
- }
1048
- } else {
1049
- for (var _i = 0, _Object$keys = Object.keys(query.info); _i < _Object$keys.length; _i++) {
1050
- var infoKey = _Object$keys[_i];
1051
-
1052
- if (!simpleReg.test(infoKey)) {
1053
- err("info.".concat(infoKey, " is unexpected. ") + 'Length must be not more than 30. ' + 'Supported chars: a-zA-Z0-9-_');
1054
- return false;
1055
- }
1056
-
1057
- var infoVal = query.info[infoKey];
1058
-
1059
- if (query.type === 'dist') {
1060
- if (infoVal.length > 30) {
1061
- err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
1062
- return false;
1063
- }
1064
- } else if (typeof infoVal !== 'number') {
1065
- err("info.".concat(infoKey, " value must be number"));
1066
- return false;
1067
- }
1068
- }
1069
- }
1070
-
1071
- if (query.dim) {
1072
- for (var _i2 = 0, _Object$keys2 = Object.keys(query.dim); _i2 < _Object$keys2.length; _i2++) {
1073
- var dimKey = _Object$keys2[_i2];
1074
-
1075
- if (!simpleReg.test(dimKey)) {
1076
- err("dim key [".concat(dimKey, "] is unexpected. ") + 'Length must be not more than 30. ' + 'Supported chars: a-zA-Z0-9-_');
1077
- return false;
1078
- }
1079
-
1080
- var dimVal = query.dim[dimKey];
1081
-
1082
- if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
1083
- err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ") + 'Length must be not more than 30. ' + 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
1084
- return false;
1085
- }
1086
- }
1087
- }
1088
-
1089
- return true;
1090
- }
1091
- }, {
1092
- key: "sendPerf",
1093
- value: function sendPerf(option) {
1094
- this.send(Object.assign({
1095
- type: 'perf'
1096
- }, option));
1097
- }
1098
- }, {
1099
- key: "sendExcept",
1100
- value: function sendExcept(option) {
1101
- this.send(Object.assign({
1102
- type: 'except'
1103
- }, option));
1104
- }
1105
- }, {
1106
- key: "sendDist",
1107
- value: function sendDist(option) {
1108
- this.send(Object.assign({
1109
- type: 'dist'
1110
- }, option));
1111
- }
1112
- }, {
1113
- key: "sendCount",
1114
- value: function sendCount(option) {
1115
- this.send(Object.assign({
1116
- type: 'count'
1117
- }, option));
1118
- }
1119
- }, {
1120
- key: "sendExceptForError",
1121
- value: function sendExceptForError(e, option) {
1122
- var newOpt = Object.assign({}, option);
1123
- newOpt.info = Object.assign({}, option.info || {}, {
1124
- msg: e.message,
1125
- stack: e.stack
1126
- });
1127
- this.sendExcept(newOpt);
1128
- }
1129
- }, {
1130
- key: "startMark",
1131
- value: function startMark(sign) {
1132
- this.markCache[sign] = {
1133
- start: Date.now()
1134
- };
1135
- }
1136
- }, {
1137
- key: "endMark",
1138
- value: function endMark(sign) {
1139
- if (this.markCache[sign]) {
1140
- this.markCache[sign].total = Date.now() - this.markCache[sign].start;
1141
- return this.markCache[sign].total;
1142
- }
1143
-
1144
- return 0;
1145
- }
1146
- }, {
1147
- key: "clearMark",
1148
- value: function clearMark(sign) {
1149
- if (this.markCache[sign]) {
1150
- delete this.markCache[sign];
1151
- }
1152
- }
1153
- }, {
1154
- key: "getAllMark",
1155
- value: function getAllMark() {
1156
- var ret = {};
1157
-
1158
- for (var _i3 = 0, _Object$keys3 = Object.keys(this.markCache); _i3 < _Object$keys3.length; _i3++) {
1159
- var sign = _Object$keys3[_i3];
1160
- ret[sign] = this.markCache[sign].total;
1161
- }
1162
-
1163
- return ret;
1164
- }
1165
- }, {
1166
- key: "clearAllMark",
1167
- value: function clearAllMark() {
1168
- this.markCache = {};
1169
- }
1170
- }]);
1171
-
1172
- return SpyClient;
1173
- }();
1174
-
1175
- return SpyClient;
7
+ /**
8
+ * @file utils
9
+ * @author kaivean
10
+ */
11
+ function assign() {
12
+ var args = [];
13
+ for (var _i = 0; _i < arguments.length; _i++) {
14
+ args[_i] = arguments[_i];
15
+ }
16
+ var __assign = Object.assign || function __assign(t) {
17
+ for (var s = void 0, i = 1, n = arguments.length; i < n; i++) {
18
+ // eslint-disable-next-line prefer-rest-params
19
+ s = arguments[i];
20
+ for (var p in s) {
21
+ if (Object.prototype.hasOwnProperty.call(s, p)) {
22
+ t[p] = s[p];
23
+ }
24
+ }
25
+ }
26
+ return t;
27
+ };
28
+ return __assign.apply(this, args);
29
+ }
30
+
31
+ /**
32
+ * @file SpyClient
33
+ * @author kaivean
34
+ */
35
+ var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
36
+ var isIos = /(iPhone|iPod|iPad)/.test(navigator.userAgent);
37
+ function err(msg) {
38
+ console.error("[SpyClient_log]" + msg);
39
+ // throw new Error(msg);
40
+ }
41
+ function stringify(obj) {
42
+ return Object.keys(obj).map(function (key) {
43
+ var value = obj[key];
44
+ if (typeof value === 'undefined') {
45
+ value = '';
46
+ }
47
+ else if (typeof value !== 'string') {
48
+ value = JSON.stringify(value);
49
+ }
50
+ return encodeURIComponent(key) + '=' + encodeURIComponent(value);
51
+ }).join('&');
52
+ }
53
+ var SpyClient = /** @class */ (function () {
54
+ function SpyClient(option) {
55
+ this.sample = {};
56
+ this.markCache = {};
57
+ if (!option.pid) {
58
+ throw new Error('pid is required');
59
+ }
60
+ this.option = {
61
+ pid: option.pid,
62
+ lid: option.lid,
63
+ check: option.check !== false,
64
+ sample: option.sample,
65
+ logServer: option.logServer || defaultLogServer,
66
+ };
67
+ }
68
+ SpyClient.prototype.send = function (query) {
69
+ if (!this.check(query)) {
70
+ return;
71
+ }
72
+ // 当前api设置了抽样,
73
+ if (typeof query.sample === 'number') {
74
+ if (Math.random() > query.sample) {
75
+ return;
76
+ }
77
+ }
78
+ else if (typeof this.option.sample === 'number' && Math.random() > this.option.sample) { // 否则,用全局抽样
79
+ return;
80
+ }
81
+ query = assign({
82
+ pid: this.option.pid,
83
+ lid: this.option.lid,
84
+ ts: Date.now(),
85
+ group: 'common',
86
+ }, query);
87
+ delete query.sample;
88
+ var url = this.option.logServer + stringify(query);
89
+ // 目前服务器端支持sendBeacon的post请求,可以优先采用,该api可以降低打点丢失率
90
+ // 但是ios有些问题:在webkit浏览内核环境下,beacon requests的请求方式存在证书验证的bug.
91
+ // 修复说明在如下链接中:https://bugs.webkit.org/show_bug.cgi?id=193508
92
+ // 但是目前为止,在iOS12.2版本中该问题依旧存在
93
+ if (!(!isIos
94
+ && navigator.sendBeacon
95
+ && navigator.sendBeacon(url))) {
96
+ (new Image()).src = url;
97
+ }
98
+ };
99
+ SpyClient.prototype.check = function (query) {
100
+ if (!this.option.check) {
101
+ return true;
102
+ }
103
+ var types = ['perf', 'except', 'dist', 'count'];
104
+ if (types.indexOf(query.type) === -1) {
105
+ err('type only is one of ' + types.join(', '));
106
+ return false;
107
+ }
108
+ if (query.group && query.group.length > 30) {
109
+ err('group length execeeds 30');
110
+ return false;
111
+ }
112
+ var simpleReg = /^[a-zA-Z0-9-_]{0,30}$/;
113
+ if (query.type === 'except') {
114
+ if (!(typeof query.info.msg === 'string' && query.info.msg.length)) {
115
+ err('info.msg field must be not empty and is String');
116
+ return false;
117
+ }
118
+ }
119
+ else {
120
+ for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
121
+ var infoKey = _a[_i];
122
+ if (!simpleReg.test(infoKey)) {
123
+ err("info." + infoKey + " is unexpected. "
124
+ + 'Length must be not more than 30. '
125
+ + 'Supported chars: a-zA-Z0-9-_');
126
+ return false;
127
+ }
128
+ var infoVal = query.info[infoKey];
129
+ if (query.type === 'dist') {
130
+ if (infoVal.length > 30) {
131
+ err("info." + infoKey + " value length execeeds 30 when type == 'dist'");
132
+ return false;
133
+ }
134
+ }
135
+ else if (typeof infoVal !== 'number') {
136
+ err("info." + infoKey + " value must be number");
137
+ return false;
138
+ }
139
+ }
140
+ }
141
+ if (query.dim) {
142
+ for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
143
+ var dimKey = _c[_b];
144
+ if (!simpleReg.test(dimKey)) {
145
+ err("dim key [" + dimKey + "] is unexpected. "
146
+ + 'Length must be not more than 30. '
147
+ + 'Supported chars: a-zA-Z0-9-_');
148
+ return false;
149
+ }
150
+ var dimVal = query.dim[dimKey];
151
+ if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
152
+ err("dim." + dimKey + " value [" + dimVal + "] is unexpected. "
153
+ + 'Length must be not more than 30. '
154
+ + 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
155
+ return false;
156
+ }
157
+ }
158
+ }
159
+ return true;
160
+ };
161
+ /**
162
+ *
163
+ * @param option 配置
164
+ */
165
+ SpyClient.prototype.sendPerf = function (option) {
166
+ this.send(assign({
167
+ type: 'perf',
168
+ }, option));
169
+ };
170
+ /**
171
+ *
172
+ * @param option 错误配置项
173
+ */
174
+ SpyClient.prototype.sendExcept = function (option) {
175
+ this.send(assign({
176
+ type: 'except',
177
+ }, option));
178
+ };
179
+ /**
180
+ *
181
+ * @param option 配置
182
+ */
183
+ SpyClient.prototype.sendDist = function (option) {
184
+ this.send(assign({
185
+ type: 'dist',
186
+ }, option));
187
+ };
188
+ /**
189
+ *
190
+ * @param option 配置
191
+ */
192
+ SpyClient.prototype.sendCount = function (option) {
193
+ this.send(assign({
194
+ type: 'count',
195
+ }, option));
196
+ };
197
+ /**
198
+ *
199
+ * @param e 错误实例
200
+ * @param option 错误配置项
201
+ */
202
+ SpyClient.prototype.sendExceptForError = function (e, option) {
203
+ var newOpt = assign({}, option);
204
+ newOpt.info = assign({}, option.info || {}, {
205
+ msg: e.message,
206
+ stack: e.stack,
207
+ });
208
+ this.sendExcept(newOpt);
209
+ };
210
+ SpyClient.prototype.startMark = function (sign) {
211
+ this.markCache[sign] = {
212
+ start: Date.now(),
213
+ };
214
+ };
215
+ SpyClient.prototype.endMark = function (sign) {
216
+ if (this.markCache[sign]) {
217
+ this.markCache[sign].total = Date.now() - this.markCache[sign].start;
218
+ return this.markCache[sign].total;
219
+ }
220
+ return 0;
221
+ };
222
+ SpyClient.prototype.clearMark = function (sign) {
223
+ if (this.markCache[sign]) {
224
+ delete this.markCache[sign];
225
+ }
226
+ };
227
+ SpyClient.prototype.getAllMark = function () {
228
+ var ret = {};
229
+ for (var _i = 0, _a = Object.keys(this.markCache); _i < _a.length; _i++) {
230
+ var sign = _a[_i];
231
+ ret[sign] = this.markCache[sign].total;
232
+ }
233
+ return ret;
234
+ };
235
+ SpyClient.prototype.clearAllMark = function () {
236
+ this.markCache = {};
237
+ };
238
+ return SpyClient;
239
+ }());
240
+
241
+ return SpyClient;
1176
242
 
1177
243
  })));