@pluve/logger-sdk 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +40 -2
  2. package/dist/{cjs/index.d.ts → index.d.ts} +1 -1
  3. package/dist/{esm/index.js → index.js} +2 -2
  4. package/dist/{cjs/loggerSDK.d.ts → loggerSDK.d.ts} +1 -1
  5. package/dist/{esm/loggerSDK.js → loggerSDK.js} +8 -4
  6. package/dist/{esm/transportAdapter.js → transportAdapter.js} +34 -10
  7. package/dist/{esm/types.d.ts → types.d.ts} +5 -1
  8. package/dist/{esm/utils.d.ts → utils.d.ts} +17 -0
  9. package/dist/utils.js +361 -0
  10. package/package.json +3 -5
  11. package/dist/cjs/index.js +0 -41
  12. package/dist/cjs/loggerSDK.js +0 -158
  13. package/dist/cjs/transportAdapter.js +0 -182
  14. package/dist/cjs/types.d.ts +0 -46
  15. package/dist/cjs/types.js +0 -17
  16. package/dist/cjs/utils.d.ts +0 -30
  17. package/dist/cjs/utils.js +0 -208
  18. package/dist/esm/index.d.ts +0 -6
  19. package/dist/esm/loggerSDK.d.ts +0 -36
  20. package/dist/esm/transportAdapter.d.ts +0 -51
  21. package/dist/esm/utils.js +0 -229
  22. package/dist/umd/logger-sdk.min.js +0 -1
  23. package/lib/dbQueue.d.ts +0 -10
  24. package/lib/dbQueue.js +0 -133
  25. package/lib/index.d.ts +0 -1
  26. package/lib/index.js +0 -9
  27. package/lib/loggerSDK.d.ts +0 -29
  28. package/lib/loggerSDK.js +0 -571
  29. package/lib/storeAdapter.d.ts +0 -7
  30. package/lib/storeAdapter.js +0 -99
  31. package/lib/transportAdapter.d.ts +0 -66
  32. package/lib/transportAdapter.js +0 -406
  33. package/lib/types.d.ts +0 -35
  34. package/lib/types.js +0 -1
  35. package/lib/utils.d.ts +0 -5
  36. package/lib/utils.js +0 -50
  37. /package/dist/{cjs/transportAdapter.d.ts → transportAdapter.d.ts} +0 -0
  38. /package/dist/{esm/types.js → types.js} +0 -0
package/dist/esm/utils.js DELETED
@@ -1,229 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- /*
3
- * @Author : 黄震 huangzhen@yfpharmacy.com
4
- * @Date : 2025-11-21 14:31:33
5
- * @LastEditors : 黄震 huangzhen@yfpharmacy.com
6
- * @LastEditTime : 2025-12-04 14:13:48
7
- * @Description : utils 工具函数
8
- * Copyright (c) 2025 by 益丰大药房连锁股份有限公司, All Rights Reserved.
9
- */
10
-
11
- // 当前时间戳(毫秒)
12
- export var now = function now() {
13
- return Date.now();
14
- };
15
-
16
- // 判断是否在浏览器环境
17
- export function isBrowser() {
18
- try {
19
- return typeof window !== 'undefined' && typeof window.document !== 'undefined';
20
- } catch (e) {
21
- return false;
22
- }
23
- }
24
-
25
- // 判断是否在微信小程序环境
26
- export function isWeChatMiniProgram() {
27
- try {
28
- // @ts-ignore
29
- return typeof wx !== 'undefined' && typeof wx.getSystemInfo === 'function';
30
- } catch (e) {
31
- return false;
32
- }
33
- }
34
-
35
- // 安全 JSON 序列化:处理循环引用
36
- export function safeStringify(obj) {
37
- var seen = new WeakSet();
38
- return JSON.stringify(obj, function (_k, v) {
39
- if (v && _typeof(v) === 'object') {
40
- if (seen.has(v)) return '[Circular]';
41
- seen.add(v);
42
- }
43
- return v;
44
- });
45
- }
46
-
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';
222
- }
223
- return {
224
- browser: browser,
225
- browserVersion: browserVersion,
226
- os: os,
227
- osVersion: osVersion
228
- };
229
- }
@@ -1 +0,0 @@
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.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export default class IDBQueue {
2
- private dbName;
3
- private storeName;
4
- private db;
5
- constructor(dbName?: string, storeName?: string);
6
- open(): Promise<void>;
7
- add(item: any): Promise<void>;
8
- getAll(): Promise<any[]>;
9
- clear(): Promise<unknown>;
10
- }
package/lib/dbQueue.js DELETED
@@ -1,133 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
1
- export { LoggerSDK } from './loggerSDK';
package/lib/index.js DELETED
@@ -1,9 +0,0 @@
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';
@@ -1,29 +0,0 @@
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;