@pluve/logger-sdk 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +195 -76
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +14 -2
- package/dist/cjs/loggerSDK.d.ts +27 -20
- package/dist/cjs/loggerSDK.js +86 -354
- package/dist/cjs/transportAdapter.d.ts +51 -5
- package/dist/cjs/transportAdapter.js +133 -60
- package/dist/cjs/types.d.ts +37 -26
- package/dist/cjs/utils.d.ts +27 -2
- package/dist/cjs/utils.js +151 -12
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +4 -2
- package/dist/esm/loggerSDK.d.ts +27 -20
- package/dist/esm/loggerSDK.js +141 -674
- package/dist/esm/transportAdapter.d.ts +51 -5
- package/dist/esm/transportAdapter.js +260 -111
- package/dist/esm/types.d.ts +37 -26
- package/dist/esm/utils.d.ts +27 -2
- package/dist/esm/utils.js +190 -14
- package/dist/umd/logger-sdk.min.js +1 -1
- package/lib/dbQueue.js +133 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +9 -0
- package/lib/loggerSDK.d.ts +29 -0
- package/lib/loggerSDK.js +571 -0
- package/lib/storeAdapter.js +99 -0
- package/lib/transportAdapter.d.ts +66 -0
- package/lib/transportAdapter.js +406 -0
- package/lib/types.d.ts +35 -0
- package/lib/types.js +1 -0
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +50 -0
- package/package.json +8 -2
- package/dist/cjs/dbQueue.js +0 -88
- package/dist/cjs/storeAdapter.js +0 -64
- package/dist/esm/dbQueue.d.ts +0 -10
- package/dist/esm/dbQueue.js +0 -194
- package/dist/esm/storeAdapter.d.ts +0 -7
- package/dist/esm/storeAdapter.js +0 -139
- /package/{dist/cjs → lib}/dbQueue.d.ts +0 -0
- /package/{dist/cjs → lib}/storeAdapter.d.ts +0 -0
package/dist/esm/utils.js
CHANGED
|
@@ -3,29 +3,30 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
3
3
|
* @Author : 黄震 huangzhen@yfpharmacy.com
|
|
4
4
|
* @Date : 2025-11-21 14:31:33
|
|
5
5
|
* @LastEditors : 黄震 huangzhen@yfpharmacy.com
|
|
6
|
-
* @LastEditTime : 2025-12-
|
|
6
|
+
* @LastEditTime : 2025-12-04 14:13:48
|
|
7
7
|
* @Description : utils 工具函数
|
|
8
8
|
* Copyright (c) 2025 by 益丰大药房连锁股份有限公司, All Rights Reserved.
|
|
9
9
|
*/
|
|
10
|
+
|
|
10
11
|
// 当前时间戳(毫秒)
|
|
11
12
|
export var now = function now() {
|
|
12
13
|
return Date.now();
|
|
13
14
|
};
|
|
14
15
|
|
|
15
|
-
//
|
|
16
|
-
export function
|
|
16
|
+
// 判断是否在浏览器环境
|
|
17
|
+
export function isBrowser() {
|
|
17
18
|
try {
|
|
18
|
-
|
|
19
|
-
return typeof wx !== 'undefined' && typeof wx.request === 'function';
|
|
19
|
+
return typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
20
20
|
} catch (e) {
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
//
|
|
26
|
-
export function
|
|
25
|
+
// 判断是否在微信小程序环境
|
|
26
|
+
export function isWeChatMiniProgram() {
|
|
27
27
|
try {
|
|
28
|
-
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
return typeof wx !== 'undefined' && typeof wx.getSystemInfo === 'function';
|
|
29
30
|
} catch (e) {
|
|
30
31
|
return false;
|
|
31
32
|
}
|
|
@@ -43,11 +44,186 @@ export function safeStringify(obj) {
|
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
// 生成随机 sessionId
|
|
48
|
+
var cachedSessionId = null;
|
|
49
|
+
export function getSessionId() {
|
|
50
|
+
if (cachedSessionId) return cachedSessionId;
|
|
51
|
+
|
|
52
|
+
// 微信小程序环境
|
|
53
|
+
if (isWeChatMiniProgram()) {
|
|
54
|
+
try {
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
var stored = wx.getStorageSync('logger_session_id');
|
|
57
|
+
if (stored) {
|
|
58
|
+
cachedSessionId = stored;
|
|
59
|
+
return stored;
|
|
60
|
+
}
|
|
61
|
+
} catch (e) {
|
|
62
|
+
// 忽略错误
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 浏览器环境 - 尝试从 sessionStorage 读取
|
|
67
|
+
if (isBrowser() && typeof sessionStorage !== 'undefined') {
|
|
68
|
+
try {
|
|
69
|
+
var _stored = sessionStorage.getItem('logger_session_id');
|
|
70
|
+
if (_stored) {
|
|
71
|
+
cachedSessionId = _stored;
|
|
72
|
+
return _stored;
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
// sessionStorage 不可用,忽略
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 生成新的 sessionId
|
|
80
|
+
cachedSessionId = "".concat(Date.now(), "_").concat(Math.random().toString(36).substring(2, 15));
|
|
81
|
+
|
|
82
|
+
// 微信小程序 - 存储到 Storage
|
|
83
|
+
if (isWeChatMiniProgram()) {
|
|
84
|
+
try {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
wx.setStorageSync('logger_session_id', cachedSessionId);
|
|
87
|
+
} catch (e) {
|
|
88
|
+
// 忽略错误
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 浏览器 - 尝试存储到 sessionStorage
|
|
93
|
+
if (isBrowser() && typeof sessionStorage !== 'undefined') {
|
|
94
|
+
try {
|
|
95
|
+
sessionStorage.setItem('logger_session_id', cachedSessionId);
|
|
96
|
+
} catch (e) {
|
|
97
|
+
// 存储失败,忽略
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return cachedSessionId;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 获取当前页面 URL
|
|
104
|
+
export function getCurrentUrl() {
|
|
105
|
+
// 微信小程序环境
|
|
106
|
+
if (isWeChatMiniProgram()) {
|
|
107
|
+
try {
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
var pages = getCurrentPages();
|
|
110
|
+
if (pages && pages.length > 0) {
|
|
111
|
+
var currentPage = pages[pages.length - 1];
|
|
112
|
+
return currentPage.route || '';
|
|
113
|
+
}
|
|
114
|
+
} catch (e) {
|
|
115
|
+
return '';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 浏览器环境
|
|
120
|
+
if (isBrowser()) {
|
|
121
|
+
return window.location.href;
|
|
122
|
+
}
|
|
123
|
+
return '';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 平台类型 */
|
|
127
|
+
|
|
128
|
+
/** 环境信息 */
|
|
129
|
+
|
|
130
|
+
// 缓存环境信息
|
|
131
|
+
var cachedEnvInfo = null;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 获取环境信息
|
|
135
|
+
*/
|
|
136
|
+
export function getEnvironmentInfo() {
|
|
137
|
+
if (cachedEnvInfo) return cachedEnvInfo;
|
|
138
|
+
var envInfo = {
|
|
139
|
+
platform: 'unknown'
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// 微信小程序环境
|
|
143
|
+
if (isWeChatMiniProgram()) {
|
|
144
|
+
envInfo.platform = 'wechat';
|
|
145
|
+
try {
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
var systemInfo = wx.getSystemInfoSync();
|
|
148
|
+
envInfo.systemInfo = {
|
|
149
|
+
brand: systemInfo.brand,
|
|
150
|
+
model: systemInfo.model,
|
|
151
|
+
system: systemInfo.system,
|
|
152
|
+
platform: systemInfo.platform,
|
|
153
|
+
version: systemInfo.version,
|
|
154
|
+
SDKVersion: systemInfo.SDKVersion
|
|
155
|
+
};
|
|
156
|
+
envInfo.screenWidth = systemInfo.screenWidth;
|
|
157
|
+
envInfo.screenHeight = systemInfo.screenHeight;
|
|
158
|
+
envInfo.language = systemInfo.language;
|
|
159
|
+
} catch (e) {
|
|
160
|
+
// 忽略错误
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// 浏览器环境
|
|
164
|
+
else if (isBrowser()) {
|
|
165
|
+
envInfo.platform = 'browser';
|
|
166
|
+
envInfo.userAgent = navigator.userAgent;
|
|
167
|
+
envInfo.screenWidth = window.screen.width;
|
|
168
|
+
envInfo.screenHeight = window.screen.height;
|
|
169
|
+
envInfo.language = navigator.language;
|
|
170
|
+
}
|
|
171
|
+
cachedEnvInfo = envInfo;
|
|
172
|
+
return envInfo;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 解析浏览器信息
|
|
177
|
+
*/
|
|
178
|
+
export function parseBrowserInfo(userAgent) {
|
|
179
|
+
var ua = userAgent.toLowerCase();
|
|
180
|
+
var browser = 'Unknown';
|
|
181
|
+
var browserVersion = '';
|
|
182
|
+
var os = 'Unknown';
|
|
183
|
+
var osVersion = '';
|
|
184
|
+
|
|
185
|
+
// 浏览器检测
|
|
186
|
+
if (ua.indexOf('chrome') > -1 && ua.indexOf('edge') === -1) {
|
|
187
|
+
browser = 'Chrome';
|
|
188
|
+
var match = ua.match(/chrome\/(\d+\.\d+)/);
|
|
189
|
+
browserVersion = match ? match[1] : '';
|
|
190
|
+
} else if (ua.indexOf('safari') > -1 && ua.indexOf('chrome') === -1) {
|
|
191
|
+
browser = 'Safari';
|
|
192
|
+
var _match = ua.match(/version\/(\d+\.\d+)/);
|
|
193
|
+
browserVersion = _match ? _match[1] : '';
|
|
194
|
+
} else if (ua.indexOf('firefox') > -1) {
|
|
195
|
+
browser = 'Firefox';
|
|
196
|
+
var _match2 = ua.match(/firefox\/(\d+\.\d+)/);
|
|
197
|
+
browserVersion = _match2 ? _match2[1] : '';
|
|
198
|
+
} else if (ua.indexOf('edge') > -1) {
|
|
199
|
+
browser = 'Edge';
|
|
200
|
+
var _match3 = ua.match(/edge\/(\d+\.\d+)/);
|
|
201
|
+
browserVersion = _match3 ? _match3[1] : '';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 操作系统检测
|
|
205
|
+
if (ua.indexOf('windows') > -1) {
|
|
206
|
+
os = 'Windows';
|
|
207
|
+
if (ua.indexOf('windows nt 10') > -1) osVersion = '10';else if (ua.indexOf('windows nt 6.3') > -1) osVersion = '8.1';else if (ua.indexOf('windows nt 6.2') > -1) osVersion = '8';else if (ua.indexOf('windows nt 6.1') > -1) osVersion = '7';
|
|
208
|
+
} else if (ua.indexOf('mac os') > -1) {
|
|
209
|
+
os = 'macOS';
|
|
210
|
+
var _match4 = ua.match(/mac os x (\d+[._]\d+)/);
|
|
211
|
+
osVersion = _match4 ? _match4[1].replace('_', '.') : '';
|
|
212
|
+
} else if (ua.indexOf('android') > -1) {
|
|
213
|
+
os = 'Android';
|
|
214
|
+
var _match5 = ua.match(/android (\d+\.\d+)/);
|
|
215
|
+
osVersion = _match5 ? _match5[1] : '';
|
|
216
|
+
} else if (ua.indexOf('iphone') > -1 || ua.indexOf('ipad') > -1) {
|
|
217
|
+
os = 'iOS';
|
|
218
|
+
var _match6 = ua.match(/os (\d+[._]\d+)/);
|
|
219
|
+
osVersion = _match6 ? _match6[1].replace('_', '.') : '';
|
|
220
|
+
} else if (ua.indexOf('linux') > -1) {
|
|
221
|
+
os = 'Linux';
|
|
52
222
|
}
|
|
223
|
+
return {
|
|
224
|
+
browser: browser,
|
|
225
|
+
browserVersion: browserVersion,
|
|
226
|
+
os: os,
|
|
227
|
+
osVersion: osVersion
|
|
228
|
+
};
|
|
53
229
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LoggerSDK=t():e.LoggerSDK=t()}(self,(function(){return function(){var e={750:function(e){function t(e,t,r,n,o,i,a){try{var u=e[i](a),s=u.value}catch(e){return void r(e)}u.done?t(s):Promise.resolve(s).then(n,o)}e.exports=function(e){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=e.apply(r,n);function u(e){t(a,o,i,u,s,"next",e)}function s(e){t(a,o,i,u,s,"throw",e)}u(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports},811:function(e){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports},997:function(e,t,r){var n=r(969);function o(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,n(o.key),o)}}e.exports=function(e,t,r){return t&&o(e.prototype,t),r&&o(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports},411:function(e,t,r){var n=r(969);e.exports=function(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.__esModule=!0,e.exports.default=e.exports},731:function(e,t,r){var n=r(411);function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}e.exports=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e},e.exports.__esModule=!0,e.exports.default=e.exports},25:function(e,t,r){var n=r(505).default;function o(){"use strict";e.exports=o=function(){return r},e.exports.__esModule=!0,e.exports.default=e.exports;var t,r={},i=Object.prototype,a=i.hasOwnProperty,u=Object.defineProperty||function(e,t,r){e[t]=r.value},s="function"==typeof Symbol?Symbol:{},c=s.iterator||"@@iterator",l=s.asyncIterator||"@@asyncIterator",f=s.toStringTag||"@@toStringTag";function p(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{p({},"")}catch(t){p=function(e,t,r){return e[t]=r}}function h(e,t,r,n){var o=t&&t.prototype instanceof g?t:g,i=Object.create(o.prototype),a=new M(n||[]);return u(i,"_invoke",{value:_(e,r,a)}),i}function d(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}r.wrap=h;var v="suspendedStart",y="executing",m="completed",b={};function g(){}function x(){}function w(){}var k={};p(k,c,(function(){return this}));var P=Object.getPrototypeOf,E=P&&P(P(N([])));E&&E!==i&&a.call(E,c)&&(k=E);var S=w.prototype=g.prototype=Object.create(k);function L(e){["next","throw","return"].forEach((function(t){p(e,t,(function(e){return this._invoke(t,e)}))}))}function j(e,t){function r(o,i,u,s){var c=d(e[o],e,i);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==n(f)&&a.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,u,s)}),(function(e){r("throw",e,u,s)})):t.resolve(f).then((function(e){l.value=e,u(l)}),(function(e){return r("throw",e,u,s)}))}s(c.arg)}var o;u(this,"_invoke",{value:function(e,n){function i(){return new t((function(t,o){r(e,n,t,o)}))}return o=o?o.then(i,i):i()}})}function _(e,r,n){var o=v;return function(i,a){if(o===y)throw new Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var s=O(u,n);if(s){if(s===b)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===v)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var c=d(e,r,n);if("normal"===c.type){if(o=n.done?m:"suspendedYield",c.arg===b)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=m,n.method="throw",n.arg=c.arg)}}}function O(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,O(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),b;var i=d(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,b;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,b):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,b)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function M(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function N(e){if(e||""===e){var r=e[c];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(a.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(n(e)+" is not iterable")}return x.prototype=w,u(S,"constructor",{value:w,configurable:!0}),u(w,"constructor",{value:x,configurable:!0}),x.displayName=p(w,f,"GeneratorFunction"),r.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===x||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,w):(e.__proto__=w,p(e,f,"GeneratorFunction")),e.prototype=Object.create(S),e},r.awrap=function(e){return{__await:e}},L(j.prototype),p(j.prototype,l,(function(){return this})),r.AsyncIterator=j,r.async=function(e,t,n,o,i){void 0===i&&(i=Promise);var a=new j(h(e,t,n,o),i);return r.isGeneratorFunction(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},L(S),p(S,f,"Generator"),p(S,c,(function(){return this})),p(S,"toString",(function(){return"[object Generator]"})),r.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=N,M.prototype={constructor:M,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(I),!e)for(var r in this)"t"===r.charAt(0)&&a.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return u.type="throw",u.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=a.call(i,"catchLoc"),c=a.call(i,"finallyLoc");if(s&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,b):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),b},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),b}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;I(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:N(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),b}},r}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports},159:function(e,t,r){var n=r(505).default;e.exports=function(e,t){if("object"!=n(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports},969:function(e,t,r){var n=r(505).default,o=r(159);e.exports=function(e){var t=o(e,"string");return"symbol"==n(t)?t:String(t)},e.exports.__esModule=!0,e.exports.default=e.exports},505:function(e){function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return function(){"use strict";r.r(n),r.d(n,{LoggerSDK:function(){return E}});var e=r(731),t=r.n(e),o=r(25),i=r.n(o),a=r(750),u=r.n(a),s=r(811),c=r.n(s),l=r(997),f=r.n(l),p=r(411),h=r.n(p),d=r(505),v=r.n(d),y=function(){return Date.now()};function m(){try{return"undefined"!=typeof wx&&"function"==typeof wx.request}catch(e){return!1}}function b(){try{return"undefined"!=typeof window&&void 0!==window.document}catch(e){return!1}}function g(e){var t=new WeakSet;return JSON.stringify(e,(function(e,r){if(r&&"object"===v()(r)){if(t.has(r))return"[Circular]";t.add(r)}return r}))}function x(){try{return"undefined"!=typeof indexedDB}catch(e){return!1}}var w=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"logger_sdk_db",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"queue";c()(this,e),h()(this,"dbName",void 0),h()(this,"storeName",void 0),h()(this,"db",null),this.dbName=t,this.storeName=r}var t,r,n,o;return f()(e,[{key:"open",value:(o=u()(i()().mark((function e(){var t=this;return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(b()&&x()){e.next=2;break}return e.abrupt("return");case 2:if(!this.db){e.next=4;break}return e.abrupt("return");case 4:return e.abrupt("return",new Promise((function(e,r){var n=indexedDB.open(t.dbName,1);n.onupgradeneeded=function(){var e=n.result;e.objectStoreNames.contains(t.storeName)||e.createObjectStore(t.storeName,{autoIncrement:!0})},n.onsuccess=function(){t.db=n.result,e()},n.onerror=function(){return r(n.error)}})));case 5:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"add",value:(n=u()(i()().mark((function e(t){var r=this;return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.db){e.next=2;break}return e.abrupt("return");case 2:return e.abrupt("return",new Promise((function(e,n){var o=r.db.transaction(r.storeName,"readwrite").objectStore(r.storeName).add(t);o.onsuccess=function(){return e()},o.onerror=function(){return n(o.error)}})));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"getAll",value:(r=u()(i()().mark((function e(){var t=this;return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.db){e.next=2;break}return e.abrupt("return",[]);case 2:return e.abrupt("return",new Promise((function(e,r){var n=t.db.transaction(t.storeName,"readonly").objectStore(t.storeName).getAll();n.onsuccess=function(){return e(n.result||[])},n.onerror=function(){return r(n.error)}})));case 3:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"clear",value:(t=u()(i()().mark((function e(){var t=this;return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.db){e.next=2;break}return e.abrupt("return");case 2:return e.abrupt("return",new Promise((function(e,r){var n=t.db.transaction(t.storeName,"readwrite").objectStore(t.storeName).clear();n.onsuccess=function(){return e(void 0)},n.onerror=function(){return r(n.error)}})));case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();function k(e,t){return P.apply(this,arguments)}function P(){return(P=u()(i()().mark((function e(r,n){var o,a,u,s,c,l,f,p,h,d,v,x,w;return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a="string"==typeof r?r:g(r),u=(null==n?void 0:n.timeout)||1e4,s=n&&n.endpoint?n.endpoint:(null===(o=n.endpoints)||void 0===o?void 0:o.default)||"",!b()||"undefined"==typeof navigator||"function"!=typeof navigator.sendBeacon||null==n||!n.useBeacon){e.next=9;break}if(c=new Blob([a],{type:"application/json"}),!navigator.sendBeacon(s||"",c)){e.next=8;break}return e.abrupt("return",Promise.resolve());case 8:return e.abrupt("return",Promise.reject(new Error("sendBeacon failed")));case 9:if(!m()){e.next=11;break}return e.abrupt("return",new Promise((function(e,r){var o=null;wx.request({url:s||"",method:"POST",data:a,header:t()({"Content-Type":"application/json"},n&&n.globalHeaders?n.globalHeaders:{}),success:function(){o&&clearTimeout(o),e()},fail:function(e){o&&clearTimeout(o),r(e)}}),o=setTimeout((function(){return r(new Error("timeout"))}),u)})));case 11:if(!b()||null==n||!n.usePixel){e.next=23;break}if(l=(null==n?void 0:n.pixelParam)||"data",f="_=".concat(y()),p=s||"",h="".concat(l,"=").concat(encodeURIComponent(a),"&").concat(f),d=p.includes("?")?"".concat(p,"&").concat(h):"".concat(p,"?").concat(h),v=(null==n?void 0:n.maxPixelUrlLen)||1900,!(d.length>v)){e.next=21;break}e.next=23;break;case 21:return x=new Image,e.abrupt("return",new Promise((function(e,t){var r=null;x.onload=function(){r&&clearTimeout(r),e()},x.onerror=function(){r&&clearTimeout(r),t(new Error("pixel error"))},r=setTimeout((function(){return t(new Error("timeout"))}),u),x.src=d})));case 23:if("function"!=typeof fetch){e.next=27;break}return(w="undefined"!=typeof AbortController?new AbortController:null)&&setTimeout((function(){return w.abort()}),u),e.abrupt("return",fetch(s||"",{method:"POST",headers:t()(t()({"Content-Type":"application/json"},n&&n.globalHeaders?n.globalHeaders:{}),n&&n.headers?n.headers:{}),body:a,keepalive:!(null==n||!n.useBeacon)||void 0,signal:w?w.signal:void 0}).then((function(e){if(!e.ok)throw new Error("network response not ok")})));case 27:return e.abrupt("return",Promise.reject(new Error("no transport available")));case 28:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var E=function(){function e(t){var r=this;c()(this,e),h()(this,"opts",void 0),h()(this,"env",void 0),h()(this,"inMemoryQueue",[]),h()(this,"seq",0),h()(this,"timerId",null),h()(this,"storage",null),h()(this,"closed",!1),h()(this,"idbQueue",null),h()(this,"flushing",!1);var n,o={endpoints:t.endpoints||{},appId:t.appId||"",env:t.env||(m()?"wechat":b()?"h5":"unknown"),batchSize:t.batchSize||10,flushInterval:t.flushInterval||5e3,retryCount:t.retryCount||3,retryBase:t.retryBase||300,storageKey:t.storageKey||"logger_sdk_cache_v2",maxCacheSize:t.maxCacheSize||2e3,timeout:t.timeout||1e4,debug:!!t.debug,transport:t.transport||k,globalHeaders:t.globalHeaders||{},enableAutoPV:!1!==t.enableAutoPV,enablePerf:!1!==t.enablePerf,usePixel:t.usePixel||!1,pixelParam:t.pixelParam||"data",maxPixelUrlLen:t.maxPixelUrlLen||1900};this.opts=Object.assign(o,t),this.env=this.opts.env,"wechat"===this.env?this.storage=(n=this.opts.storageKey,{get:function(){return u()(i()().mark((function e(){return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){wx.getStorage({key:n,success:function(t){return e(t.data)},fail:function(){return e(null)}})})));case 1:case"end":return e.stop()}}),e)})))()},set:function(e){return u()(i()().mark((function t(){return i()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t){wx.setStorage({key:n,data:e,success:function(){return t(void 0)},fail:function(){return t(void 0)}})})));case 1:case"end":return t.stop()}}),t)})))()},remove:function(){return u()(i()().mark((function e(){return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){wx.removeStorage({key:n,success:function(){return e(void 0)},fail:function(){return e(void 0)}})})));case 1:case"end":return e.stop()}}),e)})))()}}):"h5"===this.env?this.storage=function(e){return{get:function(){return u()(i()().mark((function t(){return i()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Promise.resolve(localStorage.getItem(e)));case 1:case"end":return t.stop()}}),t)})))()},set:function(t){return u()(i()().mark((function r(){return i()().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return localStorage.setItem(e,t),r.abrupt("return",Promise.resolve());case 2:case"end":return r.stop()}}),r)})))()},remove:function(){return u()(i()().mark((function t(){return i()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return localStorage.removeItem(e),t.abrupt("return",Promise.resolve());case 2:case"end":return t.stop()}}),t)})))()}}}(this.opts.storageKey):this.storage=null,b()&&x()&&(this.idbQueue=new w("logger_sdk_db","queue"),this.idbQueue.open().catch((function(){r.idbQueue=null}))),this.loadFromStorage().then((function(){r.opts.flushInterval>0&&r.startTimer()})),this.attachGlobalHandlers(),this.opts.enableAutoPV&&"h5"===this.env&&this.installAutoPV(),this.opts.enablePerf&&"h5"===this.env&&("complete"===document.readyState?this.collectPerf():window.addEventListener("load",(function(){return r.collectPerf()})))}var r,n,o,a,s,l,p;return f()(e,[{key:"logDebug",value:function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];this.opts.debug&&(e=console).debug.apply(e,["[LoggerSDK]"].concat(r))}},{key:"loadFromStorage",value:(p=u()(i()().mark((function e(){var t,r;return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.storage){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,e.next=5,this.storage.get();case 5:(t=e.sent)&&(r=JSON.parse(t),this.inMemoryQueue=r.concat(this.inMemoryQueue).slice(-this.opts.maxCacheSize),this.logDebug("loaded persisted queue",this.inMemoryQueue.length)),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(2),this.logDebug("load persisted fail",e.t0);case 12:case"end":return e.stop()}}),e,this,[[2,9]])}))),function(){return p.apply(this,arguments)})},{key:"persistToStorage",value:(l=u()(i()().mark((function e(){return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.storage){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,e.next=5,this.storage.set(g(this.inMemoryQueue));case 5:this.logDebug("persisted queue",this.inMemoryQueue.length),e.next=11;break;case 8:e.prev=8,e.t0=e.catch(2),this.logDebug("persist fail",e.t0);case 11:case"end":return e.stop()}}),e,this,[[2,8]])}))),function(){return l.apply(this,arguments)})},{key:"startTimer",value:function(){var e=this;this.timerId||(this.timerId=setInterval((function(){return e.flush().catch((function(){}))}),this.opts.flushInterval))}},{key:"stopTimer",value:function(){this.timerId&&(clearInterval(this.timerId),this.timerId=null)}},{key:"track",value:(s=u()(i()().mark((function e(t,r){var n;return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.closed){e.next=2;break}return e.abrupt("return");case 2:return this.seq+=1,n={type:t.type||"custom",time:t.time||y(),user:t.user||void 0,ctx:t.ctx||{},level:t.level||"info",seq:this.seq},this.inMemoryQueue.push(n),this.logDebug("enqueue",n),e.next=8,this.persistToStorage();case 8:if(!this.idbQueue){e.next=17;break}return e.prev=9,e.next=12,this.idbQueue.add(n);case 12:e.next=17;break;case 14:e.prev=14,e.t0=e.catch(9),this.logDebug("idb add fail",e.t0);case 17:if(!(this.inMemoryQueue.length>=this.opts.batchSize)){e.next=20;break}return e.next=20,this.flush(r).catch((function(){}));case 20:case"end":return e.stop()}}),e,this,[[9,14]])}))),function(e,t){return s.apply(this,arguments)})},{key:"flush",value:(a=u()(i()().mark((function e(r){var n,o,a,s,c,l,f,p,h=this;return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.closed){e.next=2;break}return e.abrupt("return");case 2:if(0!==this.inMemoryQueue.length){e.next=4;break}return e.abrupt("return");case 4:if(!this.flushing){e.next=6;break}return e.abrupt("return");case 6:return this.flushing=!0,e.prev=7,n=this.inMemoryQueue.slice(0,this.opts.batchSize),o={},n.forEach((function(e){var t=e.level||"info";(o[t]=o[t]||[]).push(e)})),a=function(e){return new Promise((function(t){return setTimeout(t,e)}))},s=function(e,n){var o=h.opts.endpoints[e]||h.opts.endpoints.default,s={appId:h.opts.appId,env:h.env,ts:y(),level:e,events:n},c=h.opts.retryCount;return function n(l){var f=t()(t()({},h.opts),{},{endpoint:o,headers:t()(t()({},h.opts.globalHeaders||{}),r||{})});return h.opts.transport(s,f).then((function(){return!0})).catch(function(){var t=u()(i()().mark((function t(r){var o,u;return i()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o=l+1,h.logDebug("send fail",e,o,r),!(o>c)){t.next=4;break}return t.abrupt("return",!1);case 4:return u=(h.opts.retryBase||300)*Math.pow(2,o-1),t.next=7,a(u);case 7:return t.abrupt("return",n(o));case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())}(0).then((function(t){return{ok:t,level:e,events:n}}))},e.next=15,Promise.all(Object.keys(o).map((function(e){return s(e,o[e])})));case 15:if(c=e.sent,l=new Set(c.filter((function(e){return e.ok})).map((function(e){return e.level}))),(f=c.length>0&&c.every((function(e){return e.ok})))||0!==l.size){e.next=21;break}return this.logDebug("batch send failed, keep batch in queue"),e.abrupt("return");case 21:return p=new Set(n.filter((function(e){return l.has(e.level||"info")})).map((function(e){return e.seq}))),this.inMemoryQueue=this.inMemoryQueue.filter((function(e){return!p.has(e.seq)})),e.next=25,this.persistToStorage();case 25:if(!f||!this.idbQueue){e.next=34;break}return e.prev=26,e.next=29,this.idbQueue.clear();case 29:e.next=34;break;case 31:e.prev=31,e.t0=e.catch(26),this.logDebug("idb clear fail",e.t0);case 34:return e.prev=34,this.flushing=!1,e.finish(34);case 37:case"end":return e.stop()}}),e,this,[[7,,34,37],[26,31]])}))),function(e){return a.apply(this,arguments)})},{key:"flushAll",value:(o=u()(i()().mark((function e(){var t,r=this;return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=0,e.abrupt("return",new Promise((function(e){var n=function(){var o=u()(i()().mark((function o(){return i()().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(t+=1,!(0===r.inMemoryQueue.length||t>=200)){o.next=3;break}return o.abrupt("return",e());case 3:if(r.flushing){o.next=11;break}return o.prev=4,o.next=7,r.flush();case 7:o.next=11;break;case 9:o.prev=9,o.t0=o.catch(4);case 11:setTimeout(n,50);case 12:case"end":return o.stop()}}),o,null,[[4,9]])})));return function(){return o.apply(this,arguments)}}();n()})));case 2:case"end":return e.stop()}}),e)}))),function(){return o.apply(this,arguments)})},{key:"identify",value:(n=u()(i()().mark((function e(t){return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.opts.appId=t&&t.appId||this.opts.appId,this.logDebug("identify",t);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"setCommon",value:(r=u()(i()().mark((function e(t){return i()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:Object.assign(this.opts,t),this.logDebug("setCommon",t);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"destroy",value:function(){this.stopTimer(),this.closed=!0}},{key:"attachGlobalHandlers",value:function(){var e=this;if("h5"===this.env&&"undefined"!=typeof window){var t=window;t.addEventListener&&t.addEventListener("error",(function(t){try{e.track({type:"error",level:"error",ctx:{message:t.message,filename:t.filename,lineno:t.lineno,colno:t.colno,stack:t.error&&t.error.stack}})}catch(e){}})),t.addEventListener&&t.addEventListener("unhandledrejection",(function(t){try{e.track({type:"error",level:"error",ctx:{reason:t.reason&&(t.reason.stack||t.reason)}})}catch(e){}})),t.addEventListener&&t.addEventListener("error",(function(t){if(t.target&&(t.target.src||t.target.href))try{e.track({type:"error",level:"warn",ctx:{resource:t.target.src||t.target.href,tag:t.target.tagName}})}catch(e){}}),!0),document.addEventListener&&document.addEventListener("visibilitychange",(function(){try{"hidden"===document.visibilityState&&e.flushBeacon()}catch(e){}})),t.addEventListener&&t.addEventListener("pagehide",(function(){try{e.flushBeacon()}catch(e){}})),t.addEventListener&&t.addEventListener("beforeunload",(function(){try{e.flushBeacon()}catch(e){}}))}}},{key:"installAutoPV",value:function(){var e=this;if(b()){var t=window,r=t.history,n=t.location,o=r.pushState,i=r.replaceState,a=function(){try{e.track({type:"pageview",level:"info",ctx:{path:n.pathname+n.search,title:document.title}})}catch(e){}};r.pushState=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];o.apply(this,t),window.dispatchEvent(new Event("locationchange"))},r.replaceState=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];i.apply(this,t),window.dispatchEvent(new Event("locationchange"))},window.addEventListener("popstate",(function(){return window.dispatchEvent(new Event("locationchange"))})),window.addEventListener("locationchange",a),a()}}},{key:"collectPerf",value:function(){if(b()&&"performance"in window)try{var e=window.performance,t=e.getEntriesByType&&e.getEntriesByType("navigation")&&e.getEntriesByType("navigation")[0],r=e.getEntriesByType?e.getEntriesByType("paint"):[],n={};if(t)n.ttfb=t.responseStart-t.requestStart,n.domContentLoaded=t.domContentLoadedEventEnd-t.startTime,n.load=t.loadEventEnd-t.startTime;else if(e.timing){var o=e.timing;n.ttfb=o.responseStart-o.requestStart,n.domContentLoaded=o.domContentLoadedEventEnd-o.navigationStart,n.load=o.loadEventEnd-o.navigationStart}r&&r.length&&r.forEach((function(e){n[e.name]=e.startTime})),this.track({type:"perf",level:"info",ctx:n})}catch(e){this.logDebug("collect perf fail",e)}}},{key:"flushBeacon",value:function(){var e=this;if(b()&&0!==this.inMemoryQueue.length){var r={};this.inMemoryQueue.forEach((function(e){var t=e.level||"info";(r[t]=r[t]||[]).push(e)})),Object.keys(r).forEach((function(n){var o=r[n],i=e.opts.endpoints[n]||e.opts.endpoints.default,a={appId:e.opts.appId,env:e.env,ts:y(),level:n,events:o},u=t()(t()({},e.opts),{},{endpoint:i,headers:t()({},e.opts.globalHeaders||{}),useBeacon:!0,usePixel:e.opts.usePixel,pixelParam:e.opts.pixelParam,maxPixelUrlLen:e.opts.maxPixelUrlLen});try{e.opts.transport(a,u)}catch(e){}}))}}}]),e}()}(),n}()}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LoggerSDK=t():e.LoggerSDK=t()}(self,(function(){return function(){var e={750:function(e){function t(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}e.exports=function(e){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=e.apply(r,n);function s(e){t(a,o,i,s,c,"next",e)}function c(e){t(a,o,i,s,c,"throw",e)}s(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports},811:function(e){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports},997:function(e,t,r){var n=r(969);function o(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,n(o.key),o)}}e.exports=function(e,t,r){return t&&o(e.prototype,t),r&&o(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports},411:function(e,t,r){var n=r(969);e.exports=function(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.__esModule=!0,e.exports.default=e.exports},731:function(e,t,r){var n=r(411);function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}e.exports=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e},e.exports.__esModule=!0,e.exports.default=e.exports},25:function(e,t,r){var n=r(505).default;function o(){"use strict";e.exports=o=function(){return r},e.exports.__esModule=!0,e.exports.default=e.exports;var t,r={},i=Object.prototype,a=i.hasOwnProperty,s=Object.defineProperty||function(e,t,r){e[t]=r.value},c="function"==typeof Symbol?Symbol:{},u=c.iterator||"@@iterator",f=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function d(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{d({},"")}catch(t){d=function(e,t,r){return e[t]=r}}function p(e,t,r,n){var o=t&&t.prototype instanceof w?t:w,i=Object.create(o.prototype),a=new D(n||[]);return s(i,"_invoke",{value:P(e,r,a)}),i}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}r.wrap=p;var v="suspendedStart",g="executing",y="completed",m={};function w(){}function x(){}function b(){}var O={};d(O,u,(function(){return this}));var _=Object.getPrototypeOf,S=_&&_(_(M([])));S&&S!==i&&a.call(S,u)&&(O=S);var E=b.prototype=w.prototype=Object.create(O);function L(e){["next","throw","return"].forEach((function(t){d(e,t,(function(e){return this._invoke(t,e)}))}))}function k(e,t){function r(o,i,s,c){var u=h(e[o],e,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==n(l)&&a.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,s,c)}),(function(e){r("throw",e,s,c)})):t.resolve(l).then((function(e){f.value=e,s(f)}),(function(e){return r("throw",e,s,c)}))}c(u.arg)}var o;s(this,"_invoke",{value:function(e,n){function i(){return new t((function(t,o){r(e,n,t,o)}))}return o=o?o.then(i,i):i()}})}function P(e,r,n){var o=v;return function(i,a){if(o===g)throw new Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var s=n.delegate;if(s){var c=j(s,n);if(c){if(c===m)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===v)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=g;var u=h(e,r,n);if("normal"===u.type){if(o=n.done?y:"suspendedYield",u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(o=y,n.method="throw",n.arg=u.arg)}}}function j(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,j(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=h(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,m;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,m):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function I(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function D(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(I,this),this.reset(!0)}function M(e){if(e||""===e){var r=e[u];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(a.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(n(e)+" is not iterable")}return x.prototype=b,s(E,"constructor",{value:b,configurable:!0}),s(b,"constructor",{value:x,configurable:!0}),x.displayName=d(b,l,"GeneratorFunction"),r.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===x||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,d(e,l,"GeneratorFunction")),e.prototype=Object.create(E),e},r.awrap=function(e){return{__await:e}},L(k.prototype),d(k.prototype,f,(function(){return this})),r.AsyncIterator=k,r.async=function(e,t,n,o,i){void 0===i&&(i=Promise);var a=new k(p(e,t,n,o),i);return r.isGeneratorFunction(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},L(E),d(E,l,"Generator"),d(E,u,(function(){return this})),d(E,"toString",(function(){return"[object Generator]"})),r.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=M,D.prototype={constructor:D,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var r in this)"t"===r.charAt(0)&&a.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return s.type="throw",s.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=a.call(i,"catchLoc"),u=a.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,m):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),m},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),T(r),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:M(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),m}},r}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports},159:function(e,t,r){var n=r(505).default;e.exports=function(e,t){if("object"!=n(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports},969:function(e,t,r){var n=r(505).default,o=r(159);e.exports=function(e){var t=o(e,"string");return"symbol"==n(t)?t:String(t)},e.exports.__esModule=!0,e.exports.default=e.exports},505:function(e){function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return function(){"use strict";r.r(n),r.d(n,{LoggerSDK:function(){return M},TransportAdapters:function(){return D},defaultTransport:function(){return I},getEnvironmentInfo:function(){return S},isWeChatMiniProgram:function(){return m},parseBrowserInfo:function(){return E}});var e=r(25),t=r.n(e),o=r(731),i=r.n(o),a=r(750),s=r.n(a),c=r(811),u=r.n(c),f=r(997),l=r.n(f),d=r(411),p=r.n(d),h=r(505),v=r.n(h),g=function(){return Date.now()};function y(){try{return"undefined"!=typeof window&&void 0!==window.document}catch(e){return!1}}function m(){try{return"undefined"!=typeof wx&&"function"==typeof wx.getSystemInfo}catch(e){return!1}}function w(e){var t=new WeakSet;return JSON.stringify(e,(function(e,r){if(r&&"object"===v()(r)){if(t.has(r))return"[Circular]";t.add(r)}return r}))}var x=null;function b(){if(x)return x;if(m())try{var e=wx.getStorageSync("logger_session_id");if(e)return x=e,e}catch(e){}if(y()&&"undefined"!=typeof sessionStorage)try{var t=sessionStorage.getItem("logger_session_id");if(t)return x=t,t}catch(e){}if(x="".concat(Date.now(),"_").concat(Math.random().toString(36).substring(2,15)),m())try{wx.setStorageSync("logger_session_id",x)}catch(e){}if(y()&&"undefined"!=typeof sessionStorage)try{sessionStorage.setItem("logger_session_id",x)}catch(e){}return x}function O(){if(m())try{var e=getCurrentPages();if(e&&e.length>0)return e[e.length-1].route||""}catch(e){return""}return y()?window.location.href:""}var _=null;function S(){if(_)return _;var e={platform:"unknown"};if(m()){e.platform="wechat";try{var t=wx.getSystemInfoSync();e.systemInfo={brand:t.brand,model:t.model,system:t.system,platform:t.platform,version:t.version,SDKVersion:t.SDKVersion},e.screenWidth=t.screenWidth,e.screenHeight=t.screenHeight,e.language=t.language}catch(e){}}else y()&&(e.platform="browser",e.userAgent=navigator.userAgent,e.screenWidth=window.screen.width,e.screenHeight=window.screen.height,e.language=navigator.language);return _=e,e}function E(e){var t=e.toLowerCase(),r="Unknown",n="",o="Unknown",i="";if(t.indexOf("chrome")>-1&&-1===t.indexOf("edge")){r="Chrome";var a=t.match(/chrome\/(\d+\.\d+)/);n=a?a[1]:""}else if(t.indexOf("safari")>-1&&-1===t.indexOf("chrome")){r="Safari";var s=t.match(/version\/(\d+\.\d+)/);n=s?s[1]:""}else if(t.indexOf("firefox")>-1){r="Firefox";var c=t.match(/firefox\/(\d+\.\d+)/);n=c?c[1]:""}else if(t.indexOf("edge")>-1){r="Edge";var u=t.match(/edge\/(\d+\.\d+)/);n=u?u[1]:""}if(t.indexOf("windows")>-1)o="Windows",t.indexOf("windows nt 10")>-1?i="10":t.indexOf("windows nt 6.3")>-1?i="8.1":t.indexOf("windows nt 6.2")>-1?i="8":t.indexOf("windows nt 6.1")>-1&&(i="7");else if(t.indexOf("mac os")>-1){o="macOS";var f=t.match(/mac os x (\d+[._]\d+)/);i=f?f[1].replace("_","."):""}else if(t.indexOf("android")>-1){o="Android";var l=t.match(/android (\d+\.\d+)/);i=l?l[1]:""}else if(t.indexOf("iphone")>-1||t.indexOf("ipad")>-1){o="iOS";var d=t.match(/os (\d+[._]\d+)/);i=d?d[1].replace("_","."):""}else t.indexOf("linux")>-1&&(o="Linux");return{browser:r,browserVersion:n,os:o,osVersion:i}}function L(e){return(null==e?void 0:e.endpoint)||""}var k={name:"beacon",isSupported:function(){return y()&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon},send:function(e,r){return s()(t()().mark((function n(){var o,i,a;return t()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o="string"==typeof e?e:w(e),i=L(r),a=new Blob([o],{type:"application/json"}),navigator.sendBeacon(i,a)){t.next=6;break}throw new Error("sendBeacon failed (queue full or other error)");case 6:case"end":return t.stop()}}),n)})))()}},P={name:"wechat",isSupported:function(){return m()},send:function(e,r){return s()(t()().mark((function n(){var o,i;return t()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o="string"==typeof e?e:w(e),i=L(r),1e4,t.abrupt("return",new Promise((function(e,t){var r,n=!1;r=setTimeout((function(){n||(n=!0,t(new Error("WeChat request timeout after ".concat(1e4,"ms"))))}),1e4),wx.request({url:i,method:"POST",data:o,header:{"Content-Type":"application/json"},success:function(o){r&&clearTimeout(r),n||(n=!0,o.statusCode>=200&&o.statusCode<300?e():t(new Error("HTTP ".concat(o.statusCode))))},fail:function(e){r&&clearTimeout(r),n||(n=!0,t(new Error("WeChat request failed: ".concat(e.errMsg||"unknown error"))))}})})));case 4:case"end":return t.stop()}}),n)})))()}},j={name:"image",isSupported:function(){return y()&&"undefined"!=typeof Image},send:function(e,r){return s()(t()().mark((function n(){var o,i,a,s,c,u,f;return t()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o="string"==typeof e?e:w(e),i=L(r),a=(null==r?void 0:r.pixelParam)||"data",s=(null==r?void 0:r.maxPixelUrlLen)||1900,c="_=".concat(g()),u="".concat(a,"=").concat(encodeURIComponent(o),"&").concat(c),!((f=i.includes("?")?"".concat(i,"&").concat(u):"".concat(i,"?").concat(u)).length>s)){t.next=9;break}throw new Error("URL too long (".concat(f.length," > ").concat(s,")"));case 9:return t.abrupt("return",new Promise((function(e,t){var r,n=new Image,o=!1;r=setTimeout((function(){o||(o=!0,n.src="",t(new Error("Image request timeout after 5000ms")))}),5e3),n.onload=function(){r&&clearTimeout(r),o||(o=!0,e())},n.onerror=function(){r&&clearTimeout(r),o||(o=!0,t(new Error("Image request failed")))},n.src=f})));case 10:case"end":return t.stop()}}),n)})))()}};function I(e,t){return T.apply(this,arguments)}function T(){return(T=s()(t()().mark((function e(r,n){var o;return t()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!m()){e.next=5;break}if(!P.isSupported(n)){e.next=5;break}return e.next=4,P.send(r,n);case 4:case 20:return e.abrupt("return");case 5:if(o=[k,j].find((function(e){return e.isSupported(n)}))){e.next=9;break}throw new Error("No supported transport adapter available");case 9:return e.prev=9,e.next=12,o.send(r,n);case 12:e.next=27;break;case 14:if(e.prev=14,e.t0=e.catch(9),"beacon"!==o.name||!j.isSupported(n)){e.next=26;break}return e.prev=17,e.next=20,j.send(r,n);case 23:throw e.prev=23,e.t1=e.catch(17),e.t0;case 26:throw e.t0;case 27:case"end":return e.stop()}}),e,null,[[9,14],[17,23]])})))).apply(this,arguments)}var D={beacon:k,wechat:P,image:j},M=function(){function e(t){u()(this,e),p()(this,"opts",void 0),p()(this,"seq",0),p()(this,"closed",!1),p()(this,"envTags",void 0),this.opts={endpoint:t.endpoint,appId:t.appId||"unknown",env:t.env||"dev",debug:!!t.debug,pixelParam:t.pixelParam||"data",maxPixelUrlLen:t.maxPixelUrlLen||1900},this.envTags=this.collectEnvironmentTags(),this.attachUnloadHandlers()}var r;return l()(e,[{key:"logDebug",value:function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];this.opts.debug&&(e=console).debug.apply(e,["[LoggerSDK]"].concat(r))}},{key:"collectEnvironmentTags",value:function(){var e=S(),t={platform:e.platform};if("browser"===e.platform&&e.userAgent){var r=E(e.userAgent);t.browser=r.browser,t.browserVersion=r.browserVersion,t.os=r.os,t.osVersion=r.osVersion,t.screenWidth=e.screenWidth,t.screenHeight=e.screenHeight,t.language=e.language}else"wechat"===e.platform&&e.systemInfo&&(t.brand=e.systemInfo.brand,t.model=e.systemInfo.model,t.system=e.systemInfo.system,t.wechatVersion=e.systemInfo.version,t.SDKVersion=e.systemInfo.SDKVersion,t.screenWidth=e.screenWidth,t.screenHeight=e.screenHeight,t.language=e.language);return this.logDebug("Environment tags collected:",t),t}},{key:"track",value:(r=s()(t()().mark((function e(r,n,o){var a;return t()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.closed){e.next=2;break}return e.abrupt("return");case 2:return this.seq+=1,a={eventType:r,ts:g(),appId:this.opts.appId||"unknown",env:this.opts.env||"dev",level:(null==o?void 0:o.level)||"info",message:n,stack:null==o?void 0:o.stack,url:O(),userId:null==o?void 0:o.userId,sessionId:b(),tags:i()(i()({},this.envTags),(null==o?void 0:o.tags)||{})},this.logDebug("track",a),e.prev=5,e.next=8,I(a,this.opts);case 8:e.next=13;break;case 10:e.prev=10,e.t0=e.catch(5),this.logDebug("track failed",e.t0);case 13:case"end":return e.stop()}}),e,this,[[5,10]])}))),function(e,t,n){return r.apply(this,arguments)})},{key:"identify",value:function(e){this.logDebug("identify",e)}},{key:"destroy",value:function(){this.closed=!0}},{key:"attachUnloadHandlers",value:function(){if(m())this.logDebug("WeChat MiniProgram environment detected");else if(y()){var e=window;document.addEventListener&&document.addEventListener("visibilitychange",(function(){try{"hidden"===document.visibilityState&&console.log("Page hidden")}catch(e){}})),e.addEventListener&&e.addEventListener("pagehide",(function(){try{console.log("Page hide")}catch(e){}})),e.addEventListener&&e.addEventListener("beforeunload",(function(){try{console.log("Page unload")}catch(e){}}))}}}]),e}()}(),n}()}));
|
package/lib/dbQueue.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author : 黄震 huangzhen@yfpharmacy.com
|
|
3
|
+
* @Date : 2025-11-21 14:32:51
|
|
4
|
+
* @LastEditors : 黄震 huangzhen@yfpharmacy.com
|
|
5
|
+
* @LastEditTime : 2025-11-21 14:38:50
|
|
6
|
+
* @Description : 描述
|
|
7
|
+
* Copyright (c) 2025 by 益丰大药房连锁股份有限公司, All Rights Reserved.
|
|
8
|
+
*/
|
|
9
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
10
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
13
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
14
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
15
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
19
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
20
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
21
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
22
|
+
function step(op) {
|
|
23
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
24
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
25
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
26
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
27
|
+
switch (op[0]) {
|
|
28
|
+
case 0: case 1: t = op; break;
|
|
29
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
30
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
31
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
32
|
+
default:
|
|
33
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
34
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
35
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
36
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
37
|
+
if (t[2]) _.ops.pop();
|
|
38
|
+
_.trys.pop(); continue;
|
|
39
|
+
}
|
|
40
|
+
op = body.call(thisArg, _);
|
|
41
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
42
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
import { isBrowser, isIndexedDBAvailable } from "./utils";
|
|
46
|
+
// IndexedDB 轻量队列:作为 localStorage 的冗余通道
|
|
47
|
+
var IDBQueue = /** @class */ (function () {
|
|
48
|
+
function IDBQueue(dbName, storeName) {
|
|
49
|
+
if (dbName === void 0) { dbName = 'logger_sdk_db'; }
|
|
50
|
+
if (storeName === void 0) { storeName = 'queue'; }
|
|
51
|
+
this.db = null;
|
|
52
|
+
this.dbName = dbName;
|
|
53
|
+
this.storeName = storeName;
|
|
54
|
+
}
|
|
55
|
+
// 打开数据库并初始化对象仓库
|
|
56
|
+
IDBQueue.prototype.open = function () {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var _this = this;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
if (!isBrowser() || !isIndexedDBAvailable())
|
|
61
|
+
return [2 /*return*/];
|
|
62
|
+
if (this.db)
|
|
63
|
+
return [2 /*return*/];
|
|
64
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
65
|
+
var req = indexedDB.open(_this.dbName, 1);
|
|
66
|
+
req.onupgradeneeded = function () {
|
|
67
|
+
var db = req.result;
|
|
68
|
+
if (!db.objectStoreNames.contains(_this.storeName))
|
|
69
|
+
db.createObjectStore(_this.storeName, { autoIncrement: true });
|
|
70
|
+
};
|
|
71
|
+
req.onsuccess = function () {
|
|
72
|
+
_this.db = req.result;
|
|
73
|
+
resolve();
|
|
74
|
+
};
|
|
75
|
+
req.onerror = function () { return reject(req.error); };
|
|
76
|
+
})];
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
// 入队:追加一条记录
|
|
81
|
+
IDBQueue.prototype.add = function (item) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
var _this = this;
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
if (!this.db)
|
|
86
|
+
return [2 /*return*/];
|
|
87
|
+
return [2 /*return*/, new Promise(function (res, rej) {
|
|
88
|
+
var tx = _this.db.transaction(_this.storeName, 'readwrite');
|
|
89
|
+
var st = tx.objectStore(_this.storeName);
|
|
90
|
+
var r = st.add(item);
|
|
91
|
+
r.onsuccess = function () { return res(); };
|
|
92
|
+
r.onerror = function () { return rej(r.error); };
|
|
93
|
+
})];
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
// 读取全部记录(调试/回溯用)
|
|
98
|
+
IDBQueue.prototype.getAll = function () {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
var _this = this;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
if (!this.db)
|
|
103
|
+
return [2 /*return*/, []];
|
|
104
|
+
return [2 /*return*/, new Promise(function (res, rej) {
|
|
105
|
+
var tx = _this.db.transaction(_this.storeName, 'readonly');
|
|
106
|
+
var st = tx.objectStore(_this.storeName);
|
|
107
|
+
var req = st.getAll();
|
|
108
|
+
req.onsuccess = function () { return res(req.result || []); };
|
|
109
|
+
req.onerror = function () { return rej(req.error); };
|
|
110
|
+
})];
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
// 清空队列:发送成功后用于兜底清理
|
|
115
|
+
IDBQueue.prototype.clear = function () {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
117
|
+
var _this = this;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
if (!this.db)
|
|
120
|
+
return [2 /*return*/];
|
|
121
|
+
return [2 /*return*/, new Promise(function (res, rej) {
|
|
122
|
+
var tx = _this.db.transaction(_this.storeName, 'readwrite');
|
|
123
|
+
var st = tx.objectStore(_this.storeName);
|
|
124
|
+
var req = st.clear();
|
|
125
|
+
req.onsuccess = function () { return res(undefined); };
|
|
126
|
+
req.onerror = function () { return rej(req.error); };
|
|
127
|
+
})];
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
return IDBQueue;
|
|
132
|
+
}());
|
|
133
|
+
export default IDBQueue;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LoggerSDK } from './loggerSDK';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author : 黄震 huangzhen@yfpharmacy.com
|
|
3
|
+
* @Date : 2025-11-21 14:25:26
|
|
4
|
+
* @LastEditors : 黄震 huangzhen@yfpharmacy.com
|
|
5
|
+
* @LastEditTime : 2025-12-02 15:09:28
|
|
6
|
+
* @Description : 描述
|
|
7
|
+
* Copyright (c) 2025 by 益丰大药房连锁股份有限公司, All Rights Reserved.
|
|
8
|
+
*/
|
|
9
|
+
export { LoggerSDK } from './loggerSDK';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LogEvent, SDKOptions } from './types';
|
|
2
|
+
export declare class LoggerSDK {
|
|
3
|
+
private opts;
|
|
4
|
+
private env;
|
|
5
|
+
private inMemoryQueue;
|
|
6
|
+
private seq;
|
|
7
|
+
private timerId;
|
|
8
|
+
private storage;
|
|
9
|
+
private closed;
|
|
10
|
+
private idbQueue;
|
|
11
|
+
private flushing;
|
|
12
|
+
constructor(options: SDKOptions);
|
|
13
|
+
private logDebug;
|
|
14
|
+
private loadFromStorage;
|
|
15
|
+
private persistToStorage;
|
|
16
|
+
private startTimer;
|
|
17
|
+
private stopTimer;
|
|
18
|
+
track(event: Partial<LogEvent>, headers?: Record<string, string>): Promise<void>;
|
|
19
|
+
flush(extraHeaders?: Record<string, string>): Promise<void>;
|
|
20
|
+
flushAll(): Promise<void>;
|
|
21
|
+
identify(user: Record<string, any>): Promise<void>;
|
|
22
|
+
setCommon(params: Record<string, any>): Promise<void>;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
private attachGlobalHandlers;
|
|
25
|
+
private installAutoPV;
|
|
26
|
+
private collectPerf;
|
|
27
|
+
private flushBeacon;
|
|
28
|
+
}
|
|
29
|
+
export default LoggerSDK;
|