@pluve/logger-sdk 0.0.12 → 0.0.13

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 (45) hide show
  1. package/dist/esm/capture/jsError.js +3 -24
  2. package/dist/esm/capture/promiseError.js +3 -24
  3. package/dist/esm/capture/wechatError.js +9 -31
  4. package/dist/esm/compress/compression.js +21 -44
  5. package/dist/esm/core/httpClient.js +53 -76
  6. package/dist/esm/core/loggerSDK.js +201 -234
  7. package/dist/esm/core/queueManager.js +58 -112
  8. package/dist/esm/core/retryManager.js +44 -70
  9. package/dist/esm/stack/stacktrace.js +8 -31
  10. package/dist/esm/transport/beaconTransport.js +20 -61
  11. package/dist/esm/transport/pixelImageTransport.js +54 -77
  12. package/dist/esm/transport/transportAdapter.js +13 -74
  13. package/dist/esm/transport/wechatTransport.js +53 -94
  14. package/dist/esm/utils/tools.js +12 -35
  15. package/package.json +1 -1
  16. package/dist/cjs/capture/jsError.js +0 -48
  17. package/dist/cjs/capture/promiseError.js +0 -49
  18. package/dist/cjs/capture/resourceError.js +0 -48
  19. package/dist/cjs/capture/wechatError.js +0 -95
  20. package/dist/cjs/compress/compression.js +0 -105
  21. package/dist/cjs/config/index.js +0 -55
  22. package/dist/cjs/core/fingerprint.js +0 -36
  23. package/dist/cjs/core/httpClient.js +0 -96
  24. package/dist/cjs/core/loggerSDK.js +0 -643
  25. package/dist/cjs/core/queueManager.js +0 -263
  26. package/dist/cjs/core/retryManager.js +0 -127
  27. package/dist/cjs/index.js +0 -34
  28. package/dist/cjs/stack/stacktrace.js +0 -48
  29. package/dist/cjs/transport/beaconTransport.js +0 -64
  30. package/dist/cjs/transport/pixelImageTransport.js +0 -99
  31. package/dist/cjs/transport/transport.js +0 -17
  32. package/dist/cjs/transport/transportAdapter.js +0 -73
  33. package/dist/cjs/transport/wechatTransport.js +0 -103
  34. package/dist/cjs/types/api.js +0 -17
  35. package/dist/cjs/types/env.js +0 -17
  36. package/dist/cjs/types/external.d.ts +0 -21
  37. package/dist/cjs/types/logEvent.js +0 -17
  38. package/dist/cjs/types/logEventLevel.js +0 -17
  39. package/dist/cjs/types/sdkOptions.js +0 -17
  40. package/dist/cjs/types/trackOptions.js +0 -17
  41. package/dist/cjs/utils/environment.js +0 -183
  42. package/dist/cjs/utils/session.js +0 -31
  43. package/dist/cjs/utils/tools.js +0 -82
  44. package/dist/cjs/utils/uuid.js +0 -35
  45. package/dist/umd/logger-sdk.min.js +0 -1
@@ -1,53 +1,3 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined")
11
- return require.apply(this, arguments);
12
- throw new Error('Dynamic require of "' + x + '" is not supported');
13
- });
14
- var __copyProps = (to, from, except, desc) => {
15
- if (from && typeof from === "object" || typeof from === "function") {
16
- for (let key of __getOwnPropNames(from))
17
- if (!__hasOwnProp.call(to, key) && key !== except)
18
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
- mod
29
- ));
30
- var __async = (__this, __arguments, generator) => {
31
- return new Promise((resolve, reject) => {
32
- var fulfilled = (value) => {
33
- try {
34
- step(generator.next(value));
35
- } catch (e) {
36
- reject(e);
37
- }
38
- };
39
- var rejected = (value) => {
40
- try {
41
- step(generator.throw(value));
42
- } catch (e) {
43
- reject(e);
44
- }
45
- };
46
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
47
- step((generator = generator.apply(__this, __arguments)).next());
48
- });
49
- };
50
-
51
1
  // src/transport/transportAdapter.ts
52
2
  import { isWeChatMiniProgram } from "../utils/environment";
53
3
  var TransportAdapter = class {
@@ -60,30 +10,19 @@ var TransportAdapter = class {
60
10
  }
61
11
  return TransportAdapter.instance;
62
12
  }
63
- getTransporter() {
64
- return __async(this, null, function* () {
65
- if (isWeChatMiniProgram()) {
66
- const mod = yield Promise.resolve().then(() => __toESM(__require(
67
- /* @vite-ignore */
68
- "./wechatTransport"
69
- )));
70
- return new mod.WechatTransport(this.opts);
71
- }
72
- const beaconMod = yield Promise.resolve().then(() => __toESM(__require(
73
- /* @vite-ignore */
74
- "./beaconTransport"
75
- )));
76
- const pixelMod = yield Promise.resolve().then(() => __toESM(__require(
77
- /* @vite-ignore */
78
- "./pixelImageTransport"
79
- )));
80
- const beacon = new beaconMod.BeaconTransport(this.opts);
81
- const pixel = new pixelMod.PixelImageTransport(this.opts);
82
- if (beacon.isSupported()) {
83
- return beacon;
84
- }
85
- return pixel;
86
- });
13
+ async getTransporter() {
14
+ if (isWeChatMiniProgram()) {
15
+ const mod = await import("./wechatTransport");
16
+ return new mod.WechatTransport(this.opts);
17
+ }
18
+ const beaconMod = await import("./beaconTransport");
19
+ const pixelMod = await import("./pixelImageTransport");
20
+ const beacon = new beaconMod.BeaconTransport(this.opts);
21
+ const pixel = new pixelMod.PixelImageTransport(this.opts);
22
+ if (beacon.isSupported()) {
23
+ return beacon;
24
+ }
25
+ return pixel;
87
26
  }
88
27
  };
89
28
  export {
@@ -1,43 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __async = (__this, __arguments, generator) => {
21
- return new Promise((resolve, reject) => {
22
- var fulfilled = (value) => {
23
- try {
24
- step(generator.next(value));
25
- } catch (e) {
26
- reject(e);
27
- }
28
- };
29
- var rejected = (value) => {
30
- try {
31
- step(generator.throw(value));
32
- } catch (e) {
33
- reject(e);
34
- }
35
- };
36
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
- step((generator = generator.apply(__this, __arguments)).next());
38
- });
39
- };
40
-
41
1
  // src/transport/wechatTransport.ts
42
2
  import { gzipCompress } from "../compress/compression";
43
3
  import { getReportApi } from "../config";
@@ -53,64 +13,63 @@ var WechatTransport = class {
53
13
  isSupported() {
54
14
  return isWeChatMiniProgram();
55
15
  }
56
- send(payload) {
57
- return __async(this, null, function* () {
58
- var _a, _b, _c, _d, _e;
59
- let body = typeof payload === "string" ? payload : safeStringify(payload);
60
- const endpoint = getReportApi(((_a = this.opts) == null ? void 0 : _a.env) || "develop");
61
- const timeout = 1e4;
62
- let contentType = "application/json";
63
- if (((_b = this.opts) == null ? void 0 : _b.enableGzip) && (!((_c = this.opts) == null ? void 0 : _c.gzipOnlyInBatchMode) || payload.items.length > 0)) {
64
- const t = now();
65
- logDebug(!!((_d = this.opts) == null ? void 0 : _d.debug), "WeChat request enable gzip compress: ", t);
66
- const compressedItems = yield gzipCompress(safeStringify(payload.items));
67
- body = safeStringify(__spreadProps(__spreadValues({}, payload), {
68
- items: compressedItems
69
- }));
70
- logDebug(!!((_e = this.opts) == null ? void 0 : _e.debug), "WeChat request gzip compress cost: ", now() - t);
71
- contentType = "application/json; charset=utf-8";
72
- }
73
- return new Promise((resolve, reject) => {
74
- var _a2;
75
- let timeoutId = null;
76
- let settled = false;
77
- timeoutId = setTimeout(() => {
16
+ async send(payload) {
17
+ var _a, _b, _c, _d, _e;
18
+ let body = typeof payload === "string" ? payload : safeStringify(payload);
19
+ const endpoint = getReportApi(((_a = this.opts) == null ? void 0 : _a.env) || "develop");
20
+ const timeout = 1e4;
21
+ let contentType = "application/json";
22
+ if (((_b = this.opts) == null ? void 0 : _b.enableGzip) && (!((_c = this.opts) == null ? void 0 : _c.gzipOnlyInBatchMode) || payload.items.length > 0)) {
23
+ const t = now();
24
+ logDebug(!!((_d = this.opts) == null ? void 0 : _d.debug), "WeChat request enable gzip compress: ", t);
25
+ const compressedItems = await gzipCompress(safeStringify(payload.items));
26
+ body = safeStringify({
27
+ ...payload,
28
+ items: compressedItems
29
+ });
30
+ logDebug(!!((_e = this.opts) == null ? void 0 : _e.debug), "WeChat request gzip compress cost: ", now() - t);
31
+ contentType = "application/json; charset=utf-8";
32
+ }
33
+ return new Promise((resolve, reject) => {
34
+ var _a2;
35
+ let timeoutId = null;
36
+ let settled = false;
37
+ timeoutId = setTimeout(() => {
38
+ if (!settled) {
39
+ settled = true;
40
+ reject(new Error(`WeChat request timeout after ${timeout}ms`));
41
+ }
42
+ }, timeout);
43
+ wx.request({
44
+ url: endpoint,
45
+ method: "POST",
46
+ data: body,
47
+ header: {
48
+ "Content-Type": contentType,
49
+ token: ((_a2 = this.opts) == null ? void 0 : _a2.token) || ""
50
+ },
51
+ success(res) {
52
+ if (timeoutId)
53
+ clearTimeout(timeoutId);
78
54
  if (!settled) {
79
55
  settled = true;
80
- reject(new Error(`WeChat request timeout after ${timeout}ms`));
81
- }
82
- }, timeout);
83
- wx.request({
84
- url: endpoint,
85
- method: "POST",
86
- data: body,
87
- header: {
88
- "Content-Type": contentType,
89
- token: ((_a2 = this.opts) == null ? void 0 : _a2.token) || ""
90
- },
91
- success(res) {
92
- if (timeoutId)
93
- clearTimeout(timeoutId);
94
- if (!settled) {
95
- settled = true;
96
- if (res.statusCode >= 200 && res.statusCode < 300) {
97
- resolve();
98
- } else {
99
- reject(new Error(`HTTP ${res.statusCode}`));
100
- }
101
- }
102
- },
103
- fail(err) {
104
- var _a3;
105
- if (timeoutId)
106
- clearTimeout(timeoutId);
107
- if (!settled) {
108
- settled = true;
109
- logDebug(!!((_a3 = this.opts) == null ? void 0 : _a3.debug), "WeChat request failed", err);
110
- reject(new Error(`WeChat request failed: ${err.errMsg || "unknown error"}`));
56
+ if (res.statusCode >= 200 && res.statusCode < 300) {
57
+ resolve();
58
+ } else {
59
+ reject(new Error(`HTTP ${res.statusCode}`));
111
60
  }
112
61
  }
113
- });
62
+ },
63
+ fail(err) {
64
+ var _a3;
65
+ if (timeoutId)
66
+ clearTimeout(timeoutId);
67
+ if (!settled) {
68
+ settled = true;
69
+ logDebug(!!((_a3 = this.opts) == null ? void 0 : _a3.debug), "WeChat request failed", err);
70
+ reject(new Error(`WeChat request failed: ${err.errMsg || "unknown error"}`));
71
+ }
72
+ }
114
73
  });
115
74
  });
116
75
  }
@@ -1,24 +1,3 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
-
22
1
  // src/utils/tools.ts
23
2
  import { parseStack } from "../stack/stacktrace";
24
3
  var now = () => Date.now();
@@ -48,23 +27,21 @@ function hashToProb(s) {
48
27
  }
49
28
  return h % 1e4 / 1e4;
50
29
  }
51
- function flattenStack(error) {
52
- return __async(this, null, function* () {
53
- if (!error) {
54
- return {
55
- location: "",
56
- throwable: ""
57
- };
58
- }
59
- const stackFrames = yield parseStack(error);
60
- return stackFrames && stackFrames.length > 0 ? {
61
- location: [stackFrames[0]].map((frame) => `${frame.file}:${frame.line}:${frame.column}`).join("\n "),
62
- throwable: stackFrames.map((frame) => `${frame.file}:${frame.line}:${frame.column}`).join("\n ")
63
- } : {
30
+ async function flattenStack(error) {
31
+ if (!error) {
32
+ return {
64
33
  location: "",
65
34
  throwable: ""
66
35
  };
67
- });
36
+ }
37
+ const stackFrames = await parseStack(error);
38
+ return stackFrames && stackFrames.length > 0 ? {
39
+ location: [stackFrames[0]].map((frame) => `${frame.file}:${frame.line}:${frame.column}`).join("\n "),
40
+ throwable: stackFrames.map((frame) => `${frame.file}:${frame.line}:${frame.column}`).join("\n ")
41
+ } : {
42
+ location: "",
43
+ throwable: ""
44
+ };
68
45
  }
69
46
  export {
70
47
  flattenStack,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluve/logger-sdk",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "logger sdk",
5
5
  "keywords": [
6
6
  "logger"
@@ -1,48 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/capture/jsError.ts
20
- var jsError_exports = {};
21
- __export(jsError_exports, {
22
- registerJsErrorCapture: () => registerJsErrorCapture
23
- });
24
- module.exports = __toCommonJS(jsError_exports);
25
- var import_stacktrace = require("../stack/stacktrace");
26
- var import_tools = require("../utils/tools");
27
- function registerJsErrorCapture(debug, callback) {
28
- if (typeof window === "undefined")
29
- return void 0;
30
- const handler = async (e) => {
31
- (0, import_tools.logDebug)(debug, "registerJsErrorCapture error", e);
32
- if (!e.error)
33
- return;
34
- const stack = await (0, import_stacktrace.parseStack)(e.error);
35
- callback({
36
- type: "js",
37
- message: e.error.message,
38
- stack,
39
- throwable: e.error.stack || ""
40
- });
41
- };
42
- window.addEventListener("error", handler);
43
- return () => window.removeEventListener("error", handler);
44
- }
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- registerJsErrorCapture
48
- });
@@ -1,49 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/capture/promiseError.ts
20
- var promiseError_exports = {};
21
- __export(promiseError_exports, {
22
- registerPromiseErrorCapture: () => registerPromiseErrorCapture
23
- });
24
- module.exports = __toCommonJS(promiseError_exports);
25
- var import_stacktrace = require("../stack/stacktrace");
26
- var import_tools = require("../utils/tools");
27
- function registerPromiseErrorCapture(debug, callback) {
28
- if (typeof window === "undefined")
29
- return void 0;
30
- const handler = async (e) => {
31
- (0, import_tools.logDebug)(debug, "registerPromiseErrorCapture unhandledrejection", e);
32
- const { reason } = e;
33
- if (reason instanceof Error) {
34
- const stack = await (0, import_stacktrace.parseStack)(reason);
35
- callback({
36
- type: "promise",
37
- message: reason.message,
38
- stack,
39
- throwable: reason.stack || ""
40
- });
41
- }
42
- };
43
- window.addEventListener("unhandledrejection", handler);
44
- return () => window.removeEventListener("unhandledrejection", handler);
45
- }
46
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {
48
- registerPromiseErrorCapture
49
- });
@@ -1,48 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/capture/resourceError.ts
20
- var resourceError_exports = {};
21
- __export(resourceError_exports, {
22
- registerResourceErrorCapture: () => registerResourceErrorCapture
23
- });
24
- module.exports = __toCommonJS(resourceError_exports);
25
- var import_tools = require("../utils/tools");
26
- function registerResourceErrorCapture(debug, callback) {
27
- if (typeof window === "undefined")
28
- return void 0;
29
- const handler = (e) => {
30
- var _a;
31
- (0, import_tools.logDebug)(debug, "registerResourceErrorCapture error", e);
32
- const target = e.target;
33
- if ((target == null ? void 0 : target.src) || (target == null ? void 0 : target.href)) {
34
- callback({
35
- type: "resource",
36
- message: `Resource load failed: ${(target == null ? void 0 : target.src) || (target == null ? void 0 : target.href)}`,
37
- stack: [],
38
- throwable: ((_a = e == null ? void 0 : e.error) == null ? void 0 : _a.stack) || ""
39
- });
40
- }
41
- };
42
- window.addEventListener("error", handler, true);
43
- return () => window.removeEventListener("error", handler, true);
44
- }
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- registerResourceErrorCapture
48
- });
@@ -1,95 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/capture/wechatError.ts
20
- var wechatError_exports = {};
21
- __export(wechatError_exports, {
22
- registerWechatErrorCapture: () => registerWechatErrorCapture,
23
- registerWechatUnhandledCapture: () => registerWechatUnhandledCapture
24
- });
25
- module.exports = __toCommonJS(wechatError_exports);
26
- var import_stacktrace = require("../stack/stacktrace");
27
- var import_environment = require("../utils/environment");
28
- var import_tools = require("../utils/tools");
29
- function registerWechatErrorCapture(debug, callback) {
30
- if (!(0, import_environment.isWeChatMiniProgram)())
31
- return void 0;
32
- try {
33
- const wxAny = globalThis.wx;
34
- if (wxAny && typeof wxAny.onError === "function") {
35
- const handler = async (error) => {
36
- (0, import_tools.logDebug)(debug, "registerWechatErrorCapture onError", error);
37
- const msg = String((error == null ? void 0 : error.message) ?? error);
38
- const err = error instanceof Error ? error : new Error(msg);
39
- const stack = await (0, import_stacktrace.parseStack)(err);
40
- callback({
41
- type: "js",
42
- message: err.message,
43
- stack,
44
- throwable: err.stack || ""
45
- });
46
- };
47
- wxAny.onError(handler);
48
- return () => {
49
- try {
50
- wxAny.offError && wxAny.offError(handler);
51
- } catch {
52
- }
53
- };
54
- }
55
- } catch (e) {
56
- (0, import_tools.logDebug)(debug, "registerWechatErrorCapture attach failed", e);
57
- }
58
- return void 0;
59
- }
60
- function registerWechatUnhandledCapture(debug, callback) {
61
- if (!(0, import_environment.isWeChatMiniProgram)())
62
- return void 0;
63
- try {
64
- const wxAny = globalThis.wx;
65
- if (wxAny && typeof wxAny.onUnhandledRejection === "function") {
66
- const handler = async (res) => {
67
- const reason = res == null ? void 0 : res.reason;
68
- (0, import_tools.logDebug)(debug, "registerWechatUnhandledCapture onUnhandledRejection", reason);
69
- const err = reason instanceof Error ? reason : new Error(String(reason));
70
- const stack = await (0, import_stacktrace.parseStack)(err);
71
- callback({
72
- type: "promise",
73
- message: err.message,
74
- stack,
75
- throwable: err.stack || ""
76
- });
77
- };
78
- wxAny.onUnhandledRejection(handler);
79
- return () => {
80
- try {
81
- wxAny.offUnhandledRejection && wxAny.offUnhandledRejection(handler);
82
- } catch {
83
- }
84
- };
85
- }
86
- } catch (e) {
87
- (0, import_tools.logDebug)(debug, "registerWechatUnhandledCapture attach failed", e);
88
- }
89
- return void 0;
90
- }
91
- // Annotate the CommonJS export names for ESM import in node:
92
- 0 && (module.exports = {
93
- registerWechatErrorCapture,
94
- registerWechatUnhandledCapture
95
- });
@@ -1,105 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/compress/compression.ts
20
- var compression_exports = {};
21
- __export(compression_exports, {
22
- convert2Base64: () => convert2Base64,
23
- convert2Base64FromArray: () => convert2Base64FromArray,
24
- gzipCompress: () => gzipCompress,
25
- isGzipSupported: () => isGzipSupported
26
- });
27
- module.exports = __toCommonJS(compression_exports);
28
- var import_fflate = require("fflate");
29
- var import_environment = require("../utils/environment");
30
- function toUtf8Bytes(s) {
31
- if (typeof TextEncoder !== "undefined") {
32
- return new TextEncoder().encode(s);
33
- }
34
- const enc = encodeURIComponent(s);
35
- const out = [];
36
- for (let i = 0; i < enc.length; i += 1) {
37
- const c = enc[i];
38
- if (c === "%") {
39
- out.push(parseInt(enc.slice(i + 1, i + 3), 16));
40
- i += 2;
41
- } else {
42
- out.push(c.charCodeAt(0));
43
- }
44
- }
45
- return new Uint8Array(out);
46
- }
47
- async function gzipCompress(data) {
48
- if ((0, import_environment.isBrowser)() && typeof CompressionStream !== "undefined") {
49
- try {
50
- const encoder = new TextEncoder();
51
- const input = encoder.encode(data);
52
- const gzip = new CompressionStream("gzip");
53
- const readable = new Blob([input]).stream();
54
- const compressedStream = readable.pipeThrough(gzip);
55
- const compressedBuffer = await new Response(compressedStream).arrayBuffer();
56
- const bytes = new Uint8Array(compressedBuffer);
57
- return convert2Base64FromArray(bytes);
58
- } catch (e) {
59
- console.log("gzipCompress 压缩失败,尝试使用 fflate 库", e);
60
- }
61
- }
62
- try {
63
- const input = toUtf8Bytes(data);
64
- const compressed = (0, import_fflate.gzipSync)(input);
65
- return convert2Base64FromArray(compressed);
66
- } catch (e) {
67
- console.log("gzipCompress 压缩失败", e);
68
- }
69
- return data;
70
- }
71
- function convert2Base64FromArray(data) {
72
- let binary = "";
73
- for (let i = 0; i < data.length; i += 1) {
74
- binary += String.fromCharCode(data[i]);
75
- }
76
- if (typeof btoa !== "undefined") {
77
- return btoa(binary);
78
- }
79
- if (typeof Buffer !== "undefined") {
80
- return Buffer.from(binary, "base64").toString("base64");
81
- }
82
- throw new Error("convert2Base64FromArray 不支持转换");
83
- }
84
- function convert2Base64(data) {
85
- if (typeof btoa !== "undefined") {
86
- try {
87
- return btoa(data);
88
- } catch {
89
- }
90
- }
91
- if (typeof Buffer !== "undefined") {
92
- return Buffer.from(data, "base64").toString("base64");
93
- }
94
- return data;
95
- }
96
- function isGzipSupported() {
97
- return (0, import_environment.isBrowser)() && typeof CompressionStream !== "undefined";
98
- }
99
- // Annotate the CommonJS export names for ESM import in node:
100
- 0 && (module.exports = {
101
- convert2Base64,
102
- convert2Base64FromArray,
103
- gzipCompress,
104
- isGzipSupported
105
- });