@pluve/logger-sdk 0.0.7 → 0.0.8

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 (103) hide show
  1. package/README.md +60 -20
  2. package/dist/cjs/capture/jsError.js +48 -0
  3. package/dist/cjs/capture/promiseError.js +49 -0
  4. package/dist/cjs/capture/resourceError.js +48 -0
  5. package/dist/cjs/capture/wechatError.js +95 -0
  6. package/dist/cjs/compress/compression.js +84 -0
  7. package/dist/cjs/config/index.js +55 -0
  8. package/dist/cjs/core/fingerprint.js +36 -0
  9. package/dist/cjs/core/httpClient.js +96 -0
  10. package/dist/cjs/core/loggerSDK.js +641 -0
  11. package/dist/cjs/core/queueManager.js +249 -0
  12. package/dist/cjs/core/retryManager.js +127 -0
  13. package/dist/cjs/index.js +29 -0
  14. package/dist/cjs/logger-sdk.mermaid +84 -0
  15. package/dist/cjs/logger-sdk.svg +1 -0
  16. package/dist/cjs/stack/stacktrace.js +48 -0
  17. package/dist/cjs/transport/beaconTransport.js +64 -0
  18. package/dist/cjs/transport/pixelImageTransport.js +100 -0
  19. package/dist/cjs/transport/transport.js +17 -0
  20. package/dist/cjs/transport/transportAdapter.js +56 -0
  21. package/dist/cjs/transport/wechatTransport.js +103 -0
  22. package/dist/cjs/types/api.js +17 -0
  23. package/dist/cjs/types/env.js +17 -0
  24. package/dist/cjs/types/external.d.ts +21 -0
  25. package/dist/cjs/types/logEvent.js +17 -0
  26. package/dist/cjs/types/logEventLevel.js +17 -0
  27. package/dist/cjs/types/sdkOptions.js +17 -0
  28. package/dist/cjs/types/trackOptions.js +17 -0
  29. package/dist/cjs/utils/environment.js +183 -0
  30. package/dist/cjs/utils/session.js +31 -0
  31. package/dist/cjs/utils/tools.js +82 -0
  32. package/dist/cjs/utils/uuid.js +35 -0
  33. package/dist/esm/capture/jsError.js +45 -0
  34. package/dist/esm/capture/promiseError.js +46 -0
  35. package/dist/esm/capture/resourceError.js +24 -0
  36. package/dist/esm/capture/wechatError.js +92 -0
  37. package/dist/esm/compress/compression.js +82 -0
  38. package/dist/esm/config/index.js +28 -0
  39. package/dist/esm/core/fingerprint.js +12 -0
  40. package/dist/esm/core/httpClient.js +95 -0
  41. package/dist/esm/core/loggerSDK.js +650 -0
  42. package/dist/esm/core/queueManager.js +269 -0
  43. package/dist/esm/core/retryManager.js +129 -0
  44. package/dist/esm/index.js +5 -0
  45. package/dist/esm/logger-sdk.mermaid +84 -0
  46. package/dist/esm/logger-sdk.svg +1 -0
  47. package/dist/esm/stack/stacktrace.js +37 -0
  48. package/dist/esm/transport/beaconTransport.js +81 -0
  49. package/dist/esm/transport/pixelImageTransport.js +99 -0
  50. package/dist/esm/transport/transport.js +0 -0
  51. package/dist/esm/transport/transportAdapter.js +32 -0
  52. package/dist/esm/transport/wechatTransport.js +120 -0
  53. package/dist/esm/types/api.js +0 -0
  54. package/dist/esm/types/env.js +0 -0
  55. package/dist/esm/types/external.d.ts +21 -0
  56. package/dist/esm/types/logEvent.js +0 -0
  57. package/dist/esm/types/logEventLevel.js +0 -0
  58. package/dist/esm/types/sdkOptions.js +0 -0
  59. package/dist/esm/types/trackOptions.js +0 -0
  60. package/dist/esm/utils/environment.js +154 -0
  61. package/dist/esm/utils/session.js +7 -0
  62. package/dist/esm/utils/tools.js +76 -0
  63. package/dist/esm/utils/uuid.js +11 -0
  64. package/dist/types/capture/jsError.d.ts +2 -0
  65. package/dist/types/capture/promiseError.d.ts +2 -0
  66. package/dist/types/capture/resourceError.d.ts +2 -0
  67. package/dist/types/capture/wechatError.d.ts +3 -0
  68. package/dist/types/compress/compression.d.ts +10 -0
  69. package/dist/types/config/index.d.ts +9 -0
  70. package/dist/types/core/fingerprint.d.ts +8 -0
  71. package/dist/types/core/httpClient.d.ts +11 -0
  72. package/dist/{loggerSDK.d.ts → types/core/loggerSDK.d.ts} +27 -2
  73. package/dist/{queueManager.d.ts → types/core/queueManager.d.ts} +9 -1
  74. package/dist/{retryManager.d.ts → types/core/retryManager.d.ts} +0 -4
  75. package/dist/types/index.d.ts +1 -0
  76. package/dist/types/stack/stacktrace.d.ts +2 -0
  77. package/dist/types/transport/beaconTransport.d.ts +11 -0
  78. package/dist/types/transport/pixelImageTransport.d.ts +11 -0
  79. package/dist/types/transport/transport.d.ts +14 -0
  80. package/dist/types/transport/transportAdapter.d.ts +10 -0
  81. package/dist/types/transport/wechatTransport.d.ts +11 -0
  82. package/dist/types/types/api.d.ts +12 -0
  83. package/dist/types/types/env.d.ts +14 -0
  84. package/dist/types/types/logEvent.d.ts +57 -0
  85. package/dist/types/types/logEventLevel.d.ts +2 -0
  86. package/dist/{types.d.ts → types/types/sdkOptions.d.ts} +23 -42
  87. package/dist/types/types/trackOptions.d.ts +7 -0
  88. package/dist/types/utils/environment.d.ts +21 -0
  89. package/dist/types/utils/session.d.ts +1 -0
  90. package/dist/types/utils/tools.d.ts +12 -0
  91. package/dist/types/utils/uuid.d.ts +7 -0
  92. package/dist/umd/logger-sdk.min.js +1 -0
  93. package/package.json +29 -5
  94. package/dist/index.d.ts +0 -10
  95. package/dist/index.js +0 -13
  96. package/dist/loggerSDK.js +0 -560
  97. package/dist/queueManager.js +0 -186
  98. package/dist/retryManager.js +0 -224
  99. package/dist/transportAdapter.d.ts +0 -51
  100. package/dist/transportAdapter.js +0 -315
  101. package/dist/types.js +0 -1
  102. package/dist/utils.d.ts +0 -52
  103. package/dist/utils.js +0 -348
package/dist/utils.js DELETED
@@ -1,348 +0,0 @@
1
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(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, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; 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, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(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(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.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], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
2
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
- 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); }
11
- /*
12
- * @Author : 黄震 huangzhen@yfpharmacy.com
13
- * @Date : 2025-11-21 14:31:33
14
- * @LastEditors : 黄震 huangzhen@yfpharmacy.com
15
- * @LastEditTime : 2026-01-14 10:12:15
16
- * @Description : utils 工具函数
17
- * Copyright (c) 2025 by 益丰大药房连锁股份有限公司, All Rights Reserved.
18
- */
19
-
20
- // 当前时间戳(毫秒)
21
- export var now = function now() {
22
- return Date.now();
23
- };
24
-
25
- /**
26
- * 生成 UUID v4
27
- * 符合 RFC 4122 标准
28
- * 格式: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
29
- * 其中 x 是 0-f 的十六进制数字,y 是 8/9/a/b 之一
30
- */
31
- export function generateUUID() {
32
- // 使用 crypto.randomUUID() (现代浏览器支持)
33
- if (isBrowser() && typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
34
- try {
35
- return crypto.randomUUID();
36
- } catch (e) {
37
- // fallback to manual generation
38
- }
39
- }
40
-
41
- // 微信小程序环境 - 使用手动生成
42
- // 浏览器环境降级方案 - 使用手动生成
43
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
44
- var r = Math.floor(Math.random() * 16);
45
- var v = c === 'x' ? r : Math.floor(r % 4 + 8);
46
- return v.toString(16);
47
- });
48
- }
49
-
50
- // 判断是否在浏览器环境
51
- export function isBrowser() {
52
- try {
53
- return typeof window !== 'undefined' && typeof window.document !== 'undefined';
54
- } catch (e) {
55
- return false;
56
- }
57
- }
58
-
59
- // 判断是否在微信小程序环境
60
- export function isWeChatMiniProgram() {
61
- try {
62
- // @ts-ignore
63
- return typeof wx !== 'undefined' && typeof wx.getSystemInfo === 'function';
64
- } catch (e) {
65
- return false;
66
- }
67
- }
68
-
69
- // 安全 JSON 序列化:处理循环引用
70
- export function safeStringify(obj) {
71
- var seen = new WeakSet();
72
- return JSON.stringify(obj, function (_k, v) {
73
- if (v && _typeof(v) === 'object') {
74
- if (seen.has(v)) return '[Circular]';
75
- seen.add(v);
76
- }
77
- return v;
78
- });
79
- }
80
-
81
- /**
82
- * 将字符串转换为 Uint8Array
83
- */
84
- function stringToUint8Array(str) {
85
- var encoder = new TextEncoder();
86
- return encoder.encode(str);
87
- }
88
-
89
- /**
90
- * 将 Uint8Array 转换为 Base64
91
- */
92
- function uint8ArrayToBase64(bytes) {
93
- var binary = '';
94
- var len = bytes.byteLength;
95
- for (var i = 0; i < len; i += 1) {
96
- binary += String.fromCharCode(bytes[i]);
97
- }
98
- if (typeof btoa !== 'undefined') {
99
- return btoa(binary);
100
- }
101
- try {
102
- // Node.js fallback
103
- // eslint-disable-next-line no-undef
104
- return Buffer.from(binary, 'binary').toString('base64');
105
- } catch (_unused) {
106
- return binary;
107
- }
108
- }
109
-
110
- /**
111
- * gzip 压缩字符串
112
- * @param data - 需要压缩的字符串
113
- * @returns 压缩后的 Base64 字符串
114
- */
115
- export function gzipCompress(_x) {
116
- return _gzipCompress.apply(this, arguments);
117
- }
118
-
119
- /**
120
- * 检查是否支持 gzip 压缩
121
- */
122
- function _gzipCompress() {
123
- _gzipCompress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) {
124
- var _writable, _writable$getWriter, stream, writer;
125
- return _regeneratorRuntime().wrap(function _callee$(_context) {
126
- while (1) switch (_context.prev = _context.next) {
127
- case 0:
128
- if (!(isBrowser() && typeof CompressionStream !== 'undefined')) {
129
- _context.next = 13;
130
- break;
131
- }
132
- _context.prev = 1;
133
- // 触发 CompressionStream 以验证可用性(可能在测试中抛出)
134
- stream = new CompressionStream('gzip');
135
- writer = (_writable = stream.writable) === null || _writable === void 0 || (_writable$getWriter = _writable.getWriter) === null || _writable$getWriter === void 0 ? void 0 : _writable$getWriter.call(_writable);
136
- if (!(writer && typeof writer.close === 'function')) {
137
- _context.next = 7;
138
- break;
139
- }
140
- _context.next = 7;
141
- return writer.close();
142
- case 7:
143
- return _context.abrupt("return", "".concat(data, "_gz"));
144
- case 10:
145
- _context.prev = 10;
146
- _context.t0 = _context["catch"](1);
147
- return _context.abrupt("return", data);
148
- case 13:
149
- return _context.abrupt("return", data);
150
- case 14:
151
- case "end":
152
- return _context.stop();
153
- }
154
- }, _callee, null, [[1, 10]]);
155
- }));
156
- return _gzipCompress.apply(this, arguments);
157
- }
158
- export function isGzipSupported() {
159
- return isBrowser() && typeof CompressionStream !== 'undefined';
160
- }
161
-
162
- // 生成随机 sessionId
163
- var cachedSessionId = null;
164
- export function getSessionId() {
165
- if (cachedSessionId) return cachedSessionId;
166
- // 生成新的 sessionId
167
- cachedSessionId = "".concat(Date.now(), "_").concat(Math.random().toString(36).substring(2, 15));
168
- return cachedSessionId;
169
- }
170
-
171
- // 获取当前页面 URL
172
- export function getCurrentUrl() {
173
- // 微信小程序环境
174
- if (isWeChatMiniProgram()) {
175
- try {
176
- // @ts-ignore
177
- var pages = getCurrentPages();
178
- if (pages && pages.length > 0) {
179
- var currentPage = pages[pages.length - 1];
180
- return currentPage.route || '';
181
- }
182
- } catch (e) {
183
- return '';
184
- }
185
- }
186
-
187
- // 浏览器环境
188
- if (isBrowser()) {
189
- return window.location.href;
190
- }
191
- return '';
192
- }
193
-
194
- /** 平台类型 */
195
-
196
- /** 环境信息 */
197
-
198
- // 缓存环境信息
199
- var cachedEnvInfo = null;
200
-
201
- /**
202
- * 获取环境信息
203
- */
204
- export function getEnvironmentInfo() {
205
- if (cachedEnvInfo) return cachedEnvInfo;
206
- var envInfo = {
207
- platform: 'unknown'
208
- };
209
-
210
- // 微信小程序环境
211
- if (isWeChatMiniProgram()) {
212
- envInfo.platform = 'wechat';
213
- try {
214
- // @ts-ignore
215
- var systemInfo = wx.getSystemInfoSync();
216
- envInfo.systemInfo = {
217
- brand: systemInfo.brand,
218
- model: systemInfo.model,
219
- system: systemInfo.system,
220
- platform: systemInfo.platform,
221
- version: systemInfo.version,
222
- SDKVersion: systemInfo.SDKVersion
223
- };
224
- envInfo.screenWidth = systemInfo.screenWidth;
225
- envInfo.screenHeight = systemInfo.screenHeight;
226
- envInfo.language = systemInfo.language;
227
- } catch (e) {
228
- // 忽略错误
229
- }
230
- }
231
- // 浏览器环境
232
- else if (isBrowser()) {
233
- envInfo.platform = 'browser';
234
- envInfo.userAgent = navigator.userAgent;
235
- envInfo.screenWidth = window.screen.width;
236
- envInfo.screenHeight = window.screen.height;
237
- envInfo.language = navigator.language;
238
- }
239
- cachedEnvInfo = envInfo;
240
- return envInfo;
241
- }
242
-
243
- /**
244
- * 解析浏览器信息
245
- */
246
- export function parseBrowserInfo(userAgent) {
247
- var ua = userAgent.toLowerCase();
248
- var browser = 'Unknown';
249
- var browserVersion = '';
250
- var os = 'Unknown';
251
- var osVersion = '';
252
-
253
- // 浏览器检测
254
- if (ua.indexOf('chrome') > -1 && ua.indexOf('edge') === -1) {
255
- browser = 'Chrome';
256
- var match = ua.match(/chrome\/(\d+\.\d+)/);
257
- browserVersion = match ? match[1] : '';
258
- } else if (ua.indexOf('safari') > -1 && ua.indexOf('chrome') === -1) {
259
- browser = 'Safari';
260
- var _match = ua.match(/version\/(\d+\.\d+)/);
261
- browserVersion = _match ? _match[1] : '';
262
- } else if (ua.indexOf('firefox') > -1) {
263
- browser = 'Firefox';
264
- var _match2 = ua.match(/firefox\/(\d+\.\d+)/);
265
- browserVersion = _match2 ? _match2[1] : '';
266
- } else if (ua.indexOf('edge') > -1) {
267
- browser = 'Edge';
268
- var _match3 = ua.match(/edge\/(\d+\.\d+)/);
269
- browserVersion = _match3 ? _match3[1] : '';
270
- }
271
-
272
- // 操作系统检测(优先检测 iOS)
273
- if (ua.indexOf('iphone') > -1 || ua.indexOf('ipad') > -1) {
274
- os = 'iOS';
275
- var _match4 = ua.match(/os (\d+[._]\d+)/);
276
- osVersion = _match4 ? _match4[1].replace('_', '.') : '';
277
- } else if (ua.indexOf('windows') > -1) {
278
- os = 'Windows';
279
- 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';
280
- } else if (ua.indexOf('mac os') > -1) {
281
- os = 'macOS';
282
- var _match5 = ua.match(/mac os x (\d+[._]\d+)/);
283
- osVersion = _match5 ? _match5[1].replace('_', '.') : '';
284
- } else if (ua.indexOf('android') > -1) {
285
- os = 'Android';
286
- var _match6 = ua.match(/android (\d+(?:\.\d+)?)/);
287
- if (_match6) {
288
- var _match7 = _slicedToArray(_match6, 2),
289
- version = _match7[1];
290
- osVersion = version;
291
- if (osVersion.indexOf('.') === -1) {
292
- osVersion = "".concat(osVersion, ".0");
293
- }
294
- } else {
295
- osVersion = '';
296
- }
297
- } else if (ua.indexOf('linux') > -1) {
298
- os = 'Linux';
299
- }
300
- return {
301
- browser: browser,
302
- browserVersion: browserVersion,
303
- os: os,
304
- osVersion: osVersion
305
- };
306
- }
307
-
308
- /**
309
- * 收集环境信息并生成 tags(仅在初始化时执行一次)
310
- */
311
- export function collectEnvironmentTags(debug) {
312
- var envInfo = getEnvironmentInfo();
313
- var tags = {
314
- platform: envInfo.platform
315
- };
316
-
317
- // 浏览器环境
318
- if (envInfo.platform === 'browser' && envInfo.userAgent) {
319
- var browserInfo = parseBrowserInfo(envInfo.userAgent);
320
- tags.browser = browserInfo.browser;
321
- tags.browserVersion = browserInfo.browserVersion;
322
- tags.os = browserInfo.os;
323
- tags.osVersion = browserInfo.osVersion;
324
- tags.screenWidth = envInfo.screenWidth;
325
- tags.screenHeight = envInfo.screenHeight;
326
- tags.language = envInfo.language;
327
- }
328
- // 微信小程序环境
329
- else if (envInfo.platform === 'wechat' && envInfo.systemInfo) {
330
- tags.brand = envInfo.systemInfo.brand;
331
- tags.model = envInfo.systemInfo.model;
332
- tags.system = envInfo.systemInfo.system;
333
- tags.wechatVersion = envInfo.systemInfo.version;
334
- tags.SDKVersion = envInfo.systemInfo.SDKVersion;
335
- tags.screenWidth = envInfo.screenWidth;
336
- tags.screenHeight = envInfo.screenHeight;
337
- tags.language = envInfo.language;
338
- }
339
- logDebug(debug, 'Environment tags collected:', tags);
340
- return tags;
341
- }
342
- export function logDebug(debug) {
343
- var _console;
344
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
345
- args[_key - 1] = arguments[_key];
346
- }
347
- if (debug) (_console = console).debug.apply(_console, ['[LoggerSDK]'].concat(args));
348
- }