spy-client 2.1.10 → 2.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/head/base.d.ts +1 -1
- package/dist/lib/interface.d.ts +13 -13
- package/dist/spy-client-basic.esm.js +6 -6
- package/dist/spy-client-basic.iife.js +7 -7
- package/dist/spy-client-basic.iife.min.js +1 -1
- package/dist/spy-client-basic.js +8 -8
- package/dist/spy-client-basic.min.js +1 -1
- package/dist/spy-client-basic.mjs +6 -6
- package/dist/spy-client.esm.js +16 -16
- package/dist/spy-client.iife.js +17 -17
- package/dist/spy-client.iife.min.js +1 -1
- package/dist/spy-client.js +18 -18
- package/dist/spy-client.min.js +1 -1
- package/dist/spy-client.mjs +16 -16
- package/dist/spy-head.js +20 -14
- package/dist/spy-head.min.js +1 -1
- package/dist/spy-local-cache.js +12 -12
- package/dist/spy-local-cache.min.js +1 -1
- package/example/index.html +4 -0
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/head/base.d.ts
CHANGED
|
@@ -20,6 +20,6 @@ declare const _default: {
|
|
|
20
20
|
entryMap: any;
|
|
21
21
|
init(conf: SpyHeadConf): void;
|
|
22
22
|
addError(obj: SendObj): void;
|
|
23
|
-
send(obj: SendObj, isSend?: boolean
|
|
23
|
+
send(obj: SendObj, isSend?: boolean, logServer?: string): void;
|
|
24
24
|
};
|
|
25
25
|
export default _default;
|
package/dist/lib/interface.d.ts
CHANGED
|
@@ -32,11 +32,11 @@ export declare class Module {
|
|
|
32
32
|
export interface FIDMetric {
|
|
33
33
|
fid: number;
|
|
34
34
|
}
|
|
35
|
-
export
|
|
35
|
+
export type FIDCB = (metric: FIDMetric) => void;
|
|
36
36
|
export interface LCPMetric {
|
|
37
37
|
lcp: number;
|
|
38
38
|
}
|
|
39
|
-
export
|
|
39
|
+
export type LCPCB = (metric: LCPMetric) => void;
|
|
40
40
|
export declare enum ResType {
|
|
41
41
|
JS = "js",
|
|
42
42
|
CSS = "css",
|
|
@@ -78,7 +78,7 @@ export interface ResourceHostMetric {
|
|
|
78
78
|
hostCacheRate: number;
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
export
|
|
81
|
+
export type ResourceCB = (metric: ResourceMetric, hostMetric: ResourceHostMetric) => void;
|
|
82
82
|
export interface ResourceErrorInfo {
|
|
83
83
|
msg: string;
|
|
84
84
|
xpath: string;
|
|
@@ -86,7 +86,7 @@ export interface ResourceErrorInfo {
|
|
|
86
86
|
type: string;
|
|
87
87
|
dur?: number;
|
|
88
88
|
}
|
|
89
|
-
export
|
|
89
|
+
export type ResourceErrorCB = (info: ResourceErrorInfo) => void;
|
|
90
90
|
export interface TimingMetric {
|
|
91
91
|
dns: number;
|
|
92
92
|
tcp: number;
|
|
@@ -101,11 +101,11 @@ export interface TimingMetric {
|
|
|
101
101
|
t7FirstPaint?: number;
|
|
102
102
|
t7FirstScreen?: number;
|
|
103
103
|
}
|
|
104
|
-
export
|
|
104
|
+
export type TimingCB = (metric: TimingMetric) => void;
|
|
105
105
|
export interface TTIMetric {
|
|
106
106
|
tti: number;
|
|
107
107
|
}
|
|
108
|
-
export
|
|
108
|
+
export type TTICB = (metric: TTIMetric) => void;
|
|
109
109
|
export interface TTIOption {
|
|
110
110
|
interval?: number;
|
|
111
111
|
filterRequest?: (entry: PerformanceEntry) => boolean;
|
|
@@ -113,14 +113,14 @@ export interface TTIOption {
|
|
|
113
113
|
export interface LayoutShiftMetric {
|
|
114
114
|
layoutShift: number;
|
|
115
115
|
}
|
|
116
|
-
export
|
|
116
|
+
export type LayoutShiftCB = (metric: LayoutShiftMetric) => void;
|
|
117
117
|
export interface MemoryMetric {
|
|
118
118
|
usedJSHeapSize: number;
|
|
119
119
|
totalJSHeapSize: number;
|
|
120
120
|
jsHeapSizeLimit: number;
|
|
121
121
|
usedJSHeapRate: number;
|
|
122
122
|
}
|
|
123
|
-
export
|
|
123
|
+
export type MemoryCB = (metric: MemoryMetric) => void;
|
|
124
124
|
export interface NavigatorInfoMetric {
|
|
125
125
|
downlink?: number;
|
|
126
126
|
effectiveType?: '2g' | '3g' | '4g' | 'slow-2g';
|
|
@@ -129,7 +129,7 @@ export interface NavigatorInfoMetric {
|
|
|
129
129
|
deviceMemory?: number;
|
|
130
130
|
hardwareConcurrency?: number;
|
|
131
131
|
}
|
|
132
|
-
export
|
|
132
|
+
export type NavigatorInfoCB = (metric: NavigatorInfoMetric) => void;
|
|
133
133
|
export interface FSPLongtaskMetric {
|
|
134
134
|
fspLongtaskTime: number;
|
|
135
135
|
fspTBT: number;
|
|
@@ -137,7 +137,7 @@ export interface FSPLongtaskMetric {
|
|
|
137
137
|
fspLongtaskRate: number;
|
|
138
138
|
fspLongtaskNum: number;
|
|
139
139
|
}
|
|
140
|
-
export
|
|
140
|
+
export type FSPLongtaskCB = (metric: FSPLongtaskMetric) => void;
|
|
141
141
|
export interface LCPLongtaskMetric {
|
|
142
142
|
lcpLongtaskTime: number;
|
|
143
143
|
lcpTBT: number;
|
|
@@ -145,7 +145,7 @@ export interface LCPLongtaskMetric {
|
|
|
145
145
|
lcpLongtaskRate: number;
|
|
146
146
|
lcpLongtaskNum: number;
|
|
147
147
|
}
|
|
148
|
-
export
|
|
148
|
+
export type LCPLongtaskCB = (metric: LCPLongtaskMetric) => void;
|
|
149
149
|
export interface LoadLongtaskMetric {
|
|
150
150
|
loadLongtaskTime: number;
|
|
151
151
|
loadTBT: number;
|
|
@@ -153,7 +153,7 @@ export interface LoadLongtaskMetric {
|
|
|
153
153
|
loadLongtaskRate: number;
|
|
154
154
|
loadLongtaskNum: number;
|
|
155
155
|
}
|
|
156
|
-
export
|
|
156
|
+
export type LoadLongtaskCB = (metric: LoadLongtaskMetric) => void;
|
|
157
157
|
export interface PageLongtaskMetric {
|
|
158
158
|
pageLongtaskTime: number;
|
|
159
159
|
pageTBT: number;
|
|
@@ -164,7 +164,7 @@ export interface PageLongtaskMetric {
|
|
|
164
164
|
pageIframeLongtaskRate: number;
|
|
165
165
|
pageIframeLongtaskNum: number;
|
|
166
166
|
}
|
|
167
|
-
export
|
|
167
|
+
export type PageLongtaskCB = (metric: PageLongtaskMetric) => void;
|
|
168
168
|
export interface ResOption {
|
|
169
169
|
ignorePaths?: string[];
|
|
170
170
|
trigger?: 'load' | 'leave';
|
|
@@ -31,7 +31,7 @@ var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
|
|
|
31
31
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
32
32
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
33
33
|
function err(msg) {
|
|
34
|
-
console.error("[SpyClient_log]"
|
|
34
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
35
35
|
// throw new Error(msg);
|
|
36
36
|
}
|
|
37
37
|
function stringify(obj) {
|
|
@@ -136,7 +136,7 @@ var SpyClient = /** @class */ (function () {
|
|
|
136
136
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
137
137
|
var infoKey = _a[_i];
|
|
138
138
|
if (!simpleReg.test(infoKey)) {
|
|
139
|
-
err("info."
|
|
139
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
140
140
|
+ 'Length must be not more than 30. '
|
|
141
141
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
142
142
|
return false;
|
|
@@ -144,12 +144,12 @@ var SpyClient = /** @class */ (function () {
|
|
|
144
144
|
var infoVal = query.info[infoKey];
|
|
145
145
|
if (query.type === 'dist') {
|
|
146
146
|
if (infoVal.length > 30) {
|
|
147
|
-
err("info."
|
|
147
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
148
148
|
return false;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
else if (typeof infoVal !== 'number') {
|
|
152
|
-
err("info."
|
|
152
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
153
153
|
return false;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -158,14 +158,14 @@ var SpyClient = /** @class */ (function () {
|
|
|
158
158
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
159
159
|
var dimKey = _c[_b];
|
|
160
160
|
if (!simpleReg.test(dimKey)) {
|
|
161
|
-
err("dim key ["
|
|
161
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
162
162
|
+ 'Length must be not more than 30. '
|
|
163
163
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
164
164
|
return false;
|
|
165
165
|
}
|
|
166
166
|
var dimVal = query.dim[dimKey];
|
|
167
167
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
168
|
-
err("dim."
|
|
168
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
169
169
|
+ 'Length must be not more than 30. '
|
|
170
170
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
171
171
|
return false;
|
|
@@ -34,7 +34,7 @@ var SpyClient = (function () {
|
|
|
34
34
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
35
35
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
36
36
|
function err(msg) {
|
|
37
|
-
console.error("[SpyClient_log]"
|
|
37
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
38
38
|
// throw new Error(msg);
|
|
39
39
|
}
|
|
40
40
|
function stringify(obj) {
|
|
@@ -139,7 +139,7 @@ var SpyClient = (function () {
|
|
|
139
139
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
140
140
|
var infoKey = _a[_i];
|
|
141
141
|
if (!simpleReg.test(infoKey)) {
|
|
142
|
-
err("info."
|
|
142
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
143
143
|
+ 'Length must be not more than 30. '
|
|
144
144
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
145
145
|
return false;
|
|
@@ -147,12 +147,12 @@ var SpyClient = (function () {
|
|
|
147
147
|
var infoVal = query.info[infoKey];
|
|
148
148
|
if (query.type === 'dist') {
|
|
149
149
|
if (infoVal.length > 30) {
|
|
150
|
-
err("info."
|
|
150
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
151
151
|
return false;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
else if (typeof infoVal !== 'number') {
|
|
155
|
-
err("info."
|
|
155
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
156
156
|
return false;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
@@ -161,14 +161,14 @@ var SpyClient = (function () {
|
|
|
161
161
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
162
162
|
var dimKey = _c[_b];
|
|
163
163
|
if (!simpleReg.test(dimKey)) {
|
|
164
|
-
err("dim key ["
|
|
164
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
165
165
|
+ 'Length must be not more than 30. '
|
|
166
166
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
167
167
|
return false;
|
|
168
168
|
}
|
|
169
169
|
var dimVal = query.dim[dimKey];
|
|
170
170
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
171
|
-
err("dim."
|
|
171
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
172
172
|
+ 'Length must be not more than 30. '
|
|
173
173
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
174
174
|
return false;
|
|
@@ -301,4 +301,4 @@ var SpyClient = (function () {
|
|
|
301
301
|
|
|
302
302
|
return SpyClient;
|
|
303
303
|
|
|
304
|
-
}()
|
|
304
|
+
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var SpyClient=
|
|
1
|
+
var SpyClient=(()=>{function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,t)}var t=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",n=t&&t[2]&&+t[2]<14;function u(t){console.error("[SpyClient_log]".concat(t))}function a(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("&")}function s(t){return"[object Array]"===Object.prototype.toString.call(t)}function e(t){if(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,localCache:t.localCache,logServer:t.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return e.prototype.handle=function(t){if(this.check(t)){if(t=o({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},t),this.option.localCache&&this.option.localCache.addLog(t),"number"==typeof t.sample){if(Math.random()>t.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;return delete t.sample,t}},e.prototype.send=function(t,e){void 0===e&&(e=!1);for(var n=[],o=0,r=s(t)?t:[t];o<r.length;o++){var i=r[o];(i=this.handle(i))&&(n.push(i),e||(i=this.option.logServer+a(i),this.request(i)))}e&&this.sendPost(n)},e.prototype.check=function(t){if(this.option.check){var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return u("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return u("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 u("info.msg field must be not empty and is String"),!1}else for(var o=0,r=Object.keys(t.info);o<r.length;o++){var i=r[o];if(!n.test(i))return u("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 u("info.".concat(i," value length execeeds 30 when type == 'dist'")),!1}else if("number"!=typeof a)return u("info.".concat(i," value must be number")),!1}if(t.dim)for(var s=0,p=Object.keys(t.dim);s<p.length;s++){var c=p[s];if(!n.test(c))return u("dim key [".concat(c,"] is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var h=t.dim[c];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(h))return u("dim.".concat(c," value [").concat(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(t){this.send(o({type:"perf"},t))},e.prototype.sendExcept=function(t){this.send(o({type:"except"},t))},e.prototype.sendDist=function(t){this.send(o({type:"dist"},t))},e.prototype.sendCount=function(t){this.send(o({type:"count"},t))},e.prototype.sendExceptForError=function(t,e){var n=o({},e);n.info=o({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(n)},e.prototype.startMark=function(t){this.markCache[t]={start:Date.now()}},e.prototype.endMark=function(t){return this.markCache[t]?(this.markCache[t].total=Date.now()-this.markCache[t].start,this.markCache[t].total):0},e.prototype.clearMark=function(t){this.markCache[t]&&delete this.markCache[t]},e.prototype.getAllMark=function(){for(var t={},e=0,n=Object.keys(this.markCache);e<n.length;e++){var o=n[e];t[o]=this.markCache[o].total}return t},e.prototype.clearAllMark=function(){this.markCache={}},e.prototype.sendPost=function(t){var e=(s(t)?t:[t])[0],e={pid:e.pid,type:e.type,group:e.group},e=this.option.logServer+a(e);this.request(e,t)},e.prototype.request=function(t,e){!n&&navigator&&navigator.sendBeacon&&navigator.sendBeacon(t,e?JSON.stringify(e):void 0)||(e?this.fetch(t,e):(new Image).src=t)},e.prototype.fetch=function(t,e){fetch?fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}):u("Global fetch method doesn't exist")},e})();
|
package/dist/spy-client-basic.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.SpyClient = factory());
|
|
5
|
-
}(this, (function () { 'use strict';
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @file utils
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
38
38
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
39
39
|
function err(msg) {
|
|
40
|
-
console.error("[SpyClient_log]"
|
|
40
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
41
41
|
// throw new Error(msg);
|
|
42
42
|
}
|
|
43
43
|
function stringify(obj) {
|
|
@@ -142,7 +142,7 @@
|
|
|
142
142
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
143
143
|
var infoKey = _a[_i];
|
|
144
144
|
if (!simpleReg.test(infoKey)) {
|
|
145
|
-
err("info."
|
|
145
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
146
146
|
+ 'Length must be not more than 30. '
|
|
147
147
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
148
148
|
return false;
|
|
@@ -150,12 +150,12 @@
|
|
|
150
150
|
var infoVal = query.info[infoKey];
|
|
151
151
|
if (query.type === 'dist') {
|
|
152
152
|
if (infoVal.length > 30) {
|
|
153
|
-
err("info."
|
|
153
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
154
154
|
return false;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
else if (typeof infoVal !== 'number') {
|
|
158
|
-
err("info."
|
|
158
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
159
159
|
return false;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -164,14 +164,14 @@
|
|
|
164
164
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
165
165
|
var dimKey = _c[_b];
|
|
166
166
|
if (!simpleReg.test(dimKey)) {
|
|
167
|
-
err("dim key ["
|
|
167
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
168
168
|
+ 'Length must be not more than 30. '
|
|
169
169
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
170
170
|
return false;
|
|
171
171
|
}
|
|
172
172
|
var dimVal = query.dim[dimKey];
|
|
173
173
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
174
|
-
err("dim."
|
|
174
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
175
175
|
+ 'Length must be not more than 30. '
|
|
176
176
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
177
177
|
return false;
|
|
@@ -304,4 +304,4 @@
|
|
|
304
304
|
|
|
305
305
|
return SpyClient;
|
|
306
306
|
|
|
307
|
-
}))
|
|
307
|
+
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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).SpyClient=e()})(this,function(){function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,t)}var t=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",n=t&&t[2]&&+t[2]<14;function f(t){console.error("[SpyClient_log]".concat(t))}function a(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("&")}function s(t){return"[object Array]"===Object.prototype.toString.call(t)}function e(t){if(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,localCache:t.localCache,logServer:t.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return e.prototype.handle=function(t){if(this.check(t)){if(t=o({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},t),this.option.localCache&&this.option.localCache.addLog(t),"number"==typeof t.sample){if(Math.random()>t.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;return delete t.sample,t}},e.prototype.send=function(t,e){void 0===e&&(e=!1);for(var n=[],o=0,r=s(t)?t:[t];o<r.length;o++){var i=r[o];(i=this.handle(i))&&(n.push(i),e||(i=this.option.logServer+a(i),this.request(i)))}e&&this.sendPost(n)},e.prototype.check=function(t){if(this.option.check){var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return f("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return f("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 f("info.msg field must be not empty and is String"),!1}else for(var o=0,r=Object.keys(t.info);o<r.length;o++){var i=r[o];if(!n.test(i))return f("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 f("info.".concat(i," value length execeeds 30 when type == 'dist'")),!1}else if("number"!=typeof a)return f("info.".concat(i," value must be number")),!1}if(t.dim)for(var s=0,p=Object.keys(t.dim);s<p.length;s++){var c=p[s];if(!n.test(c))return f("dim key [".concat(c,"] is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var h=t.dim[c];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(h))return f("dim.".concat(c," value [").concat(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(t){this.send(o({type:"perf"},t))},e.prototype.sendExcept=function(t){this.send(o({type:"except"},t))},e.prototype.sendDist=function(t){this.send(o({type:"dist"},t))},e.prototype.sendCount=function(t){this.send(o({type:"count"},t))},e.prototype.sendExceptForError=function(t,e){var n=o({},e);n.info=o({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(n)},e.prototype.startMark=function(t){this.markCache[t]={start:Date.now()}},e.prototype.endMark=function(t){return this.markCache[t]?(this.markCache[t].total=Date.now()-this.markCache[t].start,this.markCache[t].total):0},e.prototype.clearMark=function(t){this.markCache[t]&&delete this.markCache[t]},e.prototype.getAllMark=function(){for(var t={},e=0,n=Object.keys(this.markCache);e<n.length;e++){var o=n[e];t[o]=this.markCache[o].total}return t},e.prototype.clearAllMark=function(){this.markCache={}},e.prototype.sendPost=function(t){var e=(s(t)?t:[t])[0],e={pid:e.pid,type:e.type,group:e.group},e=this.option.logServer+a(e);this.request(e,t)},e.prototype.request=function(t,e){!n&&navigator&&navigator.sendBeacon&&navigator.sendBeacon(t,e?JSON.stringify(e):void 0)||(e?this.fetch(t,e):(new Image).src=t)},e.prototype.fetch=function(t,e){fetch?fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}):f("Global fetch method doesn't exist")},e});
|
|
@@ -31,7 +31,7 @@ var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
|
|
|
31
31
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
32
32
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
33
33
|
function err(msg) {
|
|
34
|
-
console.error("[SpyClient_log]"
|
|
34
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
35
35
|
// throw new Error(msg);
|
|
36
36
|
}
|
|
37
37
|
function stringify(obj) {
|
|
@@ -136,7 +136,7 @@ var SpyClient = /** @class */ (function () {
|
|
|
136
136
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
137
137
|
var infoKey = _a[_i];
|
|
138
138
|
if (!simpleReg.test(infoKey)) {
|
|
139
|
-
err("info."
|
|
139
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
140
140
|
+ 'Length must be not more than 30. '
|
|
141
141
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
142
142
|
return false;
|
|
@@ -144,12 +144,12 @@ var SpyClient = /** @class */ (function () {
|
|
|
144
144
|
var infoVal = query.info[infoKey];
|
|
145
145
|
if (query.type === 'dist') {
|
|
146
146
|
if (infoVal.length > 30) {
|
|
147
|
-
err("info."
|
|
147
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
148
148
|
return false;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
else if (typeof infoVal !== 'number') {
|
|
152
|
-
err("info."
|
|
152
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
153
153
|
return false;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -158,14 +158,14 @@ var SpyClient = /** @class */ (function () {
|
|
|
158
158
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
159
159
|
var dimKey = _c[_b];
|
|
160
160
|
if (!simpleReg.test(dimKey)) {
|
|
161
|
-
err("dim key ["
|
|
161
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
162
162
|
+ 'Length must be not more than 30. '
|
|
163
163
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
164
164
|
return false;
|
|
165
165
|
}
|
|
166
166
|
var dimVal = query.dim[dimKey];
|
|
167
167
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
168
|
-
err("dim."
|
|
168
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
169
169
|
+ 'Length must be not more than 30. '
|
|
170
170
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
171
171
|
return false;
|
package/dist/spy-client.esm.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/*! *****************************************************************************
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
5
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
14
|
***************************************************************************** */
|
|
15
15
|
/* global Reflect, Promise */
|
|
16
16
|
|
|
@@ -141,7 +141,7 @@ var defaultLogServer = 'https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?';
|
|
|
141
141
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
142
142
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
143
143
|
function err(msg) {
|
|
144
|
-
console.error("[SpyClient_log]"
|
|
144
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
145
145
|
// throw new Error(msg);
|
|
146
146
|
}
|
|
147
147
|
function stringify(obj) {
|
|
@@ -246,7 +246,7 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
246
246
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
247
247
|
var infoKey = _a[_i];
|
|
248
248
|
if (!simpleReg.test(infoKey)) {
|
|
249
|
-
err("info."
|
|
249
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
250
250
|
+ 'Length must be not more than 30. '
|
|
251
251
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
252
252
|
return false;
|
|
@@ -254,12 +254,12 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
254
254
|
var infoVal = query.info[infoKey];
|
|
255
255
|
if (query.type === 'dist') {
|
|
256
256
|
if (infoVal.length > 30) {
|
|
257
|
-
err("info."
|
|
257
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
258
258
|
return false;
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
else if (typeof infoVal !== 'number') {
|
|
262
|
-
err("info."
|
|
262
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
263
263
|
return false;
|
|
264
264
|
}
|
|
265
265
|
}
|
|
@@ -268,14 +268,14 @@ var SpyClient$1 = /** @class */ (function () {
|
|
|
268
268
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
269
269
|
var dimKey = _c[_b];
|
|
270
270
|
if (!simpleReg.test(dimKey)) {
|
|
271
|
-
err("dim key ["
|
|
271
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
272
272
|
+ 'Length must be not more than 30. '
|
|
273
273
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
274
274
|
return false;
|
|
275
275
|
}
|
|
276
276
|
var dimVal = query.dim[dimKey];
|
|
277
277
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
278
|
-
err("dim."
|
|
278
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
279
279
|
+ 'Length must be not more than 30. '
|
|
280
280
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
281
281
|
return false;
|
package/dist/spy-client.iife.js
CHANGED
|
@@ -2,18 +2,18 @@ var SpyClient = (function () {
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
/*! *****************************************************************************
|
|
5
|
-
Copyright (c) Microsoft Corporation.
|
|
6
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
7
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
8
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
Copyright (c) Microsoft Corporation.
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
13
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
8
|
+
purpose with or without fee is hereby granted.
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
11
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
12
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
13
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
14
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
17
17
|
***************************************************************************** */
|
|
18
18
|
/* global Reflect, Promise */
|
|
19
19
|
|
|
@@ -144,7 +144,7 @@ var SpyClient = (function () {
|
|
|
144
144
|
var ver = navigator && navigator.userAgent ? navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/) : '';
|
|
145
145
|
var isLtIos14 = ver && ver[2] && (+ver[2] < 14);
|
|
146
146
|
function err(msg) {
|
|
147
|
-
console.error("[SpyClient_log]"
|
|
147
|
+
console.error("[SpyClient_log]".concat(msg));
|
|
148
148
|
// throw new Error(msg);
|
|
149
149
|
}
|
|
150
150
|
function stringify(obj) {
|
|
@@ -249,7 +249,7 @@ var SpyClient = (function () {
|
|
|
249
249
|
for (var _i = 0, _a = Object.keys(query.info); _i < _a.length; _i++) {
|
|
250
250
|
var infoKey = _a[_i];
|
|
251
251
|
if (!simpleReg.test(infoKey)) {
|
|
252
|
-
err("info."
|
|
252
|
+
err("info.".concat(infoKey, " is unexpected. ")
|
|
253
253
|
+ 'Length must be not more than 30. '
|
|
254
254
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
255
255
|
return false;
|
|
@@ -257,12 +257,12 @@ var SpyClient = (function () {
|
|
|
257
257
|
var infoVal = query.info[infoKey];
|
|
258
258
|
if (query.type === 'dist') {
|
|
259
259
|
if (infoVal.length > 30) {
|
|
260
|
-
err("info."
|
|
260
|
+
err("info.".concat(infoKey, " value length execeeds 30 when type == 'dist'"));
|
|
261
261
|
return false;
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
else if (typeof infoVal !== 'number') {
|
|
265
|
-
err("info."
|
|
265
|
+
err("info.".concat(infoKey, " value must be number"));
|
|
266
266
|
return false;
|
|
267
267
|
}
|
|
268
268
|
}
|
|
@@ -271,14 +271,14 @@ var SpyClient = (function () {
|
|
|
271
271
|
for (var _b = 0, _c = Object.keys(query.dim); _b < _c.length; _b++) {
|
|
272
272
|
var dimKey = _c[_b];
|
|
273
273
|
if (!simpleReg.test(dimKey)) {
|
|
274
|
-
err("dim key ["
|
|
274
|
+
err("dim key [".concat(dimKey, "] is unexpected. ")
|
|
275
275
|
+ 'Length must be not more than 30. '
|
|
276
276
|
+ 'Supported chars: a-zA-Z0-9-_');
|
|
277
277
|
return false;
|
|
278
278
|
}
|
|
279
279
|
var dimVal = query.dim[dimKey];
|
|
280
280
|
if (!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(dimVal)) {
|
|
281
|
-
err("dim."
|
|
281
|
+
err("dim.".concat(dimKey, " value [").concat(dimVal, "] is unexpected. ")
|
|
282
282
|
+ 'Length must be not more than 30. '
|
|
283
283
|
+ 'Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese');
|
|
284
284
|
return false;
|
|
@@ -1487,4 +1487,4 @@ var SpyClient = (function () {
|
|
|
1487
1487
|
|
|
1488
1488
|
return SpyClient;
|
|
1489
1489
|
|
|
1490
|
-
}()
|
|
1490
|
+
})();
|