sentry-miniapp 1.2.0 → 1.4.0
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/CHANGELOG.md +123 -0
- package/README.md +113 -0
- package/dist/sentry-miniapp.cjs.js +187 -39
- package/dist/sentry-miniapp.cjs.js.map +1 -1
- package/dist/sentry-miniapp.esm.js +187 -39
- package/dist/sentry-miniapp.esm.js.map +1 -1
- package/dist/sentry-miniapp.umd.js +187 -39
- package/dist/sentry-miniapp.umd.js.map +1 -1
- package/dist/types/client.d.ts +4 -6
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/integrations/index.d.ts +2 -0
- package/dist/types/integrations/index.d.ts.map +1 -1
- package/dist/types/integrations/networkbreadcrumbs.d.ts +29 -0
- package/dist/types/integrations/networkbreadcrumbs.d.ts.map +1 -0
- package/dist/types/integrations/rewriteframes.d.ts +35 -0
- package/dist/types/integrations/rewriteframes.d.ts.map +1 -0
- package/dist/types/sdk.d.ts +6 -4
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/transports/offlineStore.d.ts +4 -1
- package/dist/types/transports/offlineStore.d.ts.map +1 -1
- package/dist/types/types.d.ts +6 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +94 -16
- package/src/.keep +0 -0
- package/src/client.ts +203 -0
- package/src/crossPlatform.ts +407 -0
- package/src/eventbuilder.ts +291 -0
- package/src/helpers.ts +214 -0
- package/src/index.ts +86 -0
- package/src/integrations/dedupe.ts +215 -0
- package/src/integrations/globalhandlers.ts +209 -0
- package/src/integrations/httpcontext.ts +140 -0
- package/src/integrations/index.ts +10 -0
- package/src/integrations/linkederrors.ts +107 -0
- package/src/integrations/networkbreadcrumbs.ts +155 -0
- package/src/integrations/performance.ts +622 -0
- package/src/integrations/rewriteframes.ts +77 -0
- package/src/integrations/router.ts +180 -0
- package/src/integrations/system.ts +135 -0
- package/src/integrations/trycatch.ts +233 -0
- package/src/polyfills.ts +242 -0
- package/src/sdk.ts +182 -0
- package/src/transports/index.ts +3 -0
- package/src/transports/offlineStore.ts +85 -0
- package/src/transports/xhr.ts +68 -0
- package/src/types.ts +129 -0
- package/src/version.ts +3 -0
|
@@ -4936,7 +4936,7 @@ function addBreadcrumb(breadcrumb, hint) {
|
|
|
4936
4936
|
}
|
|
4937
4937
|
isolationScope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs);
|
|
4938
4938
|
}
|
|
4939
|
-
const SDK_VERSION = "1.
|
|
4939
|
+
const SDK_VERSION = "1.3.1";
|
|
4940
4940
|
const SDK_NAME = "sentry.javascript.miniapp";
|
|
4941
4941
|
const getSDK = () => {
|
|
4942
4942
|
let currentSdk = {
|
|
@@ -5138,15 +5138,16 @@ function createMiniappTransport(options) {
|
|
|
5138
5138
|
}
|
|
5139
5139
|
return createTransport(options, makeRequest);
|
|
5140
5140
|
}
|
|
5141
|
-
const
|
|
5141
|
+
const DEFAULT_OFFLINE_CACHE_SIZE = 30;
|
|
5142
5142
|
const OFFLINE_STORE_KEY = "sentry_offline_store";
|
|
5143
|
-
function createMiniappOfflineStore(
|
|
5143
|
+
function createMiniappOfflineStore(options) {
|
|
5144
|
+
const maxCacheSize = options.offlineCacheLimit || DEFAULT_OFFLINE_CACHE_SIZE;
|
|
5144
5145
|
return {
|
|
5145
5146
|
push: (env) => __async(null, null, function* () {
|
|
5146
5147
|
try {
|
|
5147
5148
|
const store = getStore();
|
|
5148
5149
|
store.push(env);
|
|
5149
|
-
if (store.length >
|
|
5150
|
+
if (store.length > maxCacheSize) {
|
|
5150
5151
|
store.shift();
|
|
5151
5152
|
}
|
|
5152
5153
|
setStore(store);
|
|
@@ -5158,7 +5159,7 @@ function createMiniappOfflineStore(_options) {
|
|
|
5158
5159
|
try {
|
|
5159
5160
|
const store = getStore();
|
|
5160
5161
|
store.unshift(env);
|
|
5161
|
-
if (store.length >
|
|
5162
|
+
if (store.length > maxCacheSize) {
|
|
5162
5163
|
store.pop();
|
|
5163
5164
|
}
|
|
5164
5165
|
setStore(store);
|
|
@@ -5223,6 +5224,7 @@ class MiniappClient extends Client {
|
|
|
5223
5224
|
}));
|
|
5224
5225
|
if (options.enableOfflineCache !== false) {
|
|
5225
5226
|
return makeOfflineTransport(() => baseTransport)(__spreadProps(__spreadValues({}, transportOptions), {
|
|
5227
|
+
offlineCacheLimit: options.offlineCacheLimit,
|
|
5226
5228
|
createStore: createMiniappOfflineStore,
|
|
5227
5229
|
flushAtStartup: true
|
|
5228
5230
|
// 启动时自动重试发送
|
|
@@ -5317,29 +5319,14 @@ class MiniappClient extends Client {
|
|
|
5317
5319
|
}
|
|
5318
5320
|
}
|
|
5319
5321
|
/**
|
|
5320
|
-
*
|
|
5321
|
-
*
|
|
5322
|
-
*
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
if (showModal) {
|
|
5329
|
-
showModal({
|
|
5330
|
-
title: options.title || "错误反馈",
|
|
5331
|
-
content: options.subtitle || "应用遇到了一个错误,是否要发送错误报告?",
|
|
5332
|
-
confirmText: "发送",
|
|
5333
|
-
cancelText: "取消",
|
|
5334
|
-
success: (res) => {
|
|
5335
|
-
if (res.confirm && options.onLoad) {
|
|
5336
|
-
options.onLoad();
|
|
5337
|
-
}
|
|
5338
|
-
}
|
|
5339
|
-
});
|
|
5340
|
-
} else {
|
|
5341
|
-
console.warn("sentry-miniapp: showModal is not available in current miniapp platform", options);
|
|
5342
|
-
}
|
|
5322
|
+
* @deprecated Miniapp environment does not support Sentry's default HTML report dialog.
|
|
5323
|
+
* Please implement your own UI form to collect user feedback (name, email, comments)
|
|
5324
|
+
* and use `Sentry.captureFeedback()` to submit it to Sentry.
|
|
5325
|
+
*/
|
|
5326
|
+
showReportDialog(_options = {}) {
|
|
5327
|
+
console.warn(
|
|
5328
|
+
"[sentry-miniapp] showReportDialog is deprecated and does nothing. Please build your own UI and use `Sentry.captureFeedback()` instead."
|
|
5329
|
+
);
|
|
5343
5330
|
}
|
|
5344
5331
|
/**
|
|
5345
5332
|
* Capture feedback using the new feedback API.
|
|
@@ -5553,13 +5540,13 @@ const _TryCatch = class _TryCatch {
|
|
|
5553
5540
|
setupOnce() {
|
|
5554
5541
|
const global2 = globalThis;
|
|
5555
5542
|
if (global2.setTimeout) {
|
|
5556
|
-
fill(global2, "setTimeout", this._wrapTimeFunction.bind(this));
|
|
5543
|
+
fill$1(global2, "setTimeout", this._wrapTimeFunction.bind(this));
|
|
5557
5544
|
}
|
|
5558
5545
|
if (global2.setInterval) {
|
|
5559
|
-
fill(global2, "setInterval", this._wrapTimeFunction.bind(this));
|
|
5546
|
+
fill$1(global2, "setInterval", this._wrapTimeFunction.bind(this));
|
|
5560
5547
|
}
|
|
5561
5548
|
if (global2.requestAnimationFrame) {
|
|
5562
|
-
fill(global2, "requestAnimationFrame", this._wrapRAF.bind(this));
|
|
5549
|
+
fill$1(global2, "requestAnimationFrame", this._wrapRAF.bind(this));
|
|
5563
5550
|
}
|
|
5564
5551
|
}
|
|
5565
5552
|
};
|
|
@@ -5640,7 +5627,7 @@ function wrap$1(fn, options = {}, before) {
|
|
|
5640
5627
|
}
|
|
5641
5628
|
return sentryWrapped;
|
|
5642
5629
|
}
|
|
5643
|
-
function fill(source, name, replacementFactory) {
|
|
5630
|
+
function fill$1(source, name, replacementFactory) {
|
|
5644
5631
|
if (!(name in source)) {
|
|
5645
5632
|
return;
|
|
5646
5633
|
}
|
|
@@ -6663,13 +6650,173 @@ let PerformanceIntegration = _PerformanceIntegration;
|
|
|
6663
6650
|
const performanceIntegration = (options) => {
|
|
6664
6651
|
return () => new PerformanceIntegration(options);
|
|
6665
6652
|
};
|
|
6653
|
+
const _RewriteFrames = class _RewriteFrames {
|
|
6654
|
+
constructor(options = {}) {
|
|
6655
|
+
this.name = _RewriteFrames.id;
|
|
6656
|
+
this._prefix = options.prefix || "app:///";
|
|
6657
|
+
}
|
|
6658
|
+
/**
|
|
6659
|
+
* @inheritDoc
|
|
6660
|
+
*/
|
|
6661
|
+
setupOnce() {
|
|
6662
|
+
}
|
|
6663
|
+
/**
|
|
6664
|
+
* @inheritDoc
|
|
6665
|
+
*/
|
|
6666
|
+
processEvent(event) {
|
|
6667
|
+
if (event.exception && event.exception.values) {
|
|
6668
|
+
event.exception.values.forEach((exception) => {
|
|
6669
|
+
if (exception.stacktrace && exception.stacktrace.frames) {
|
|
6670
|
+
exception.stacktrace.frames.forEach((frame) => {
|
|
6671
|
+
if (frame.filename) {
|
|
6672
|
+
frame.filename = this._normalizeFilename(frame.filename);
|
|
6673
|
+
}
|
|
6674
|
+
});
|
|
6675
|
+
}
|
|
6676
|
+
});
|
|
6677
|
+
}
|
|
6678
|
+
return event;
|
|
6679
|
+
}
|
|
6680
|
+
/**
|
|
6681
|
+
* Normalizes a filename from various miniapp platforms
|
|
6682
|
+
*/
|
|
6683
|
+
_normalizeFilename(filename) {
|
|
6684
|
+
let normalized = filename;
|
|
6685
|
+
normalized = normalized.replace(/^(appservice|app-service|WAService)\//i, "").replace(/^https?:\/\/[^/]+\//i, "").replace(/^[a-z]+:\/\//i, "").replace(/^\//, "");
|
|
6686
|
+
if (normalized.startsWith(this._prefix)) {
|
|
6687
|
+
return normalized;
|
|
6688
|
+
}
|
|
6689
|
+
return `${this._prefix}${normalized}`;
|
|
6690
|
+
}
|
|
6691
|
+
};
|
|
6692
|
+
_RewriteFrames.id = "RewriteFrames";
|
|
6693
|
+
let RewriteFrames = _RewriteFrames;
|
|
6694
|
+
function fill(source, name, replacementFactory) {
|
|
6695
|
+
if (!(name in source)) {
|
|
6696
|
+
return;
|
|
6697
|
+
}
|
|
6698
|
+
const original = source[name];
|
|
6699
|
+
const wrapped = replacementFactory(original);
|
|
6700
|
+
if (typeof wrapped === "function") {
|
|
6701
|
+
try {
|
|
6702
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
6703
|
+
wrapped.prototype.constructor = wrapped;
|
|
6704
|
+
} catch (_Oo) {
|
|
6705
|
+
}
|
|
6706
|
+
}
|
|
6707
|
+
source[name] = wrapped;
|
|
6708
|
+
}
|
|
6709
|
+
const _NetworkBreadcrumbs = class _NetworkBreadcrumbs {
|
|
6710
|
+
constructor(options = {}) {
|
|
6711
|
+
this.name = _NetworkBreadcrumbs.id;
|
|
6712
|
+
this._traceNetworkBody = !!options.traceNetworkBody;
|
|
6713
|
+
}
|
|
6714
|
+
/**
|
|
6715
|
+
* @inheritDoc
|
|
6716
|
+
*/
|
|
6717
|
+
setupOnce() {
|
|
6718
|
+
const miniappSdk = sdk();
|
|
6719
|
+
if (miniappSdk && typeof miniappSdk.request === "function") {
|
|
6720
|
+
fill(miniappSdk, "request", this._createRequestWrapper.bind(this));
|
|
6721
|
+
}
|
|
6722
|
+
if (miniappSdk && typeof miniappSdk.httpRequest === "function") {
|
|
6723
|
+
fill(miniappSdk, "httpRequest", this._createRequestWrapper.bind(this));
|
|
6724
|
+
}
|
|
6725
|
+
}
|
|
6726
|
+
/**
|
|
6727
|
+
* Wraps the miniapp request API to capture breadcrumbs
|
|
6728
|
+
*/
|
|
6729
|
+
_createRequestWrapper(originalRequest) {
|
|
6730
|
+
const traceNetworkBody = this._traceNetworkBody;
|
|
6731
|
+
return function(options) {
|
|
6732
|
+
if (!options || typeof options !== "object") {
|
|
6733
|
+
return originalRequest.call(this, options);
|
|
6734
|
+
}
|
|
6735
|
+
const url = options.url || "";
|
|
6736
|
+
const client = getClient();
|
|
6737
|
+
let dsnUrl = "";
|
|
6738
|
+
if (client) {
|
|
6739
|
+
const dsn = client.getOptions().dsn;
|
|
6740
|
+
if (dsn) {
|
|
6741
|
+
try {
|
|
6742
|
+
const dsnMatch = dsn.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?([^:/\n]+)/i);
|
|
6743
|
+
if (dsnMatch && dsnMatch[1]) {
|
|
6744
|
+
dsnUrl = dsnMatch[1];
|
|
6745
|
+
}
|
|
6746
|
+
} catch (e) {
|
|
6747
|
+
}
|
|
6748
|
+
}
|
|
6749
|
+
}
|
|
6750
|
+
if (typeof url === "string") {
|
|
6751
|
+
const isSentryRequest = dsnUrl && url.indexOf(dsnUrl) !== -1 || url.indexOf("sentry.io") !== -1;
|
|
6752
|
+
if (isSentryRequest) {
|
|
6753
|
+
return originalRequest.call(this, options);
|
|
6754
|
+
}
|
|
6755
|
+
}
|
|
6756
|
+
const method = (options.method || "GET").toUpperCase();
|
|
6757
|
+
const requestData = options.data;
|
|
6758
|
+
const breadcrumbData = {
|
|
6759
|
+
url,
|
|
6760
|
+
method
|
|
6761
|
+
};
|
|
6762
|
+
if (traceNetworkBody && requestData) {
|
|
6763
|
+
try {
|
|
6764
|
+
breadcrumbData["request_body"] = typeof requestData === "string" ? requestData : JSON.stringify(requestData);
|
|
6765
|
+
} catch (e) {
|
|
6766
|
+
breadcrumbData["request_body"] = "[Cannot serialize request body]";
|
|
6767
|
+
}
|
|
6768
|
+
}
|
|
6769
|
+
const originalSuccess = options.success;
|
|
6770
|
+
const originalFail = options.fail;
|
|
6771
|
+
options.success = function(...args) {
|
|
6772
|
+
const res = args[0] || {};
|
|
6773
|
+
const statusCode = res.statusCode || res.status;
|
|
6774
|
+
breadcrumbData["status_code"] = statusCode;
|
|
6775
|
+
if (traceNetworkBody && res.data) {
|
|
6776
|
+
try {
|
|
6777
|
+
breadcrumbData["response_body"] = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
6778
|
+
} catch (e) {
|
|
6779
|
+
breadcrumbData["response_body"] = "[Cannot serialize response body]";
|
|
6780
|
+
}
|
|
6781
|
+
}
|
|
6782
|
+
addBreadcrumb({
|
|
6783
|
+
type: "http",
|
|
6784
|
+
category: "xhr",
|
|
6785
|
+
data: breadcrumbData,
|
|
6786
|
+
level: statusCode >= 400 ? "warning" : "info"
|
|
6787
|
+
});
|
|
6788
|
+
if (typeof originalSuccess === "function") {
|
|
6789
|
+
return originalSuccess.apply(this, args);
|
|
6790
|
+
}
|
|
6791
|
+
};
|
|
6792
|
+
options.fail = function(...args) {
|
|
6793
|
+
const err = args[0] || {};
|
|
6794
|
+
breadcrumbData["error"] = err.errMsg || err.errorMessage || "Network request failed";
|
|
6795
|
+
addBreadcrumb({
|
|
6796
|
+
type: "http",
|
|
6797
|
+
category: "xhr",
|
|
6798
|
+
data: breadcrumbData,
|
|
6799
|
+
level: "error"
|
|
6800
|
+
});
|
|
6801
|
+
if (typeof originalFail === "function") {
|
|
6802
|
+
return originalFail.apply(this, args);
|
|
6803
|
+
}
|
|
6804
|
+
};
|
|
6805
|
+
return originalRequest.call(this, options);
|
|
6806
|
+
};
|
|
6807
|
+
}
|
|
6808
|
+
};
|
|
6809
|
+
_NetworkBreadcrumbs.id = "NetworkBreadcrumbs";
|
|
6810
|
+
let NetworkBreadcrumbs = _NetworkBreadcrumbs;
|
|
6666
6811
|
const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
6667
6812
|
__proto__: null,
|
|
6668
6813
|
Dedupe,
|
|
6669
6814
|
GlobalHandlers,
|
|
6670
6815
|
HttpContext,
|
|
6671
6816
|
LinkedErrors,
|
|
6817
|
+
NetworkBreadcrumbs,
|
|
6672
6818
|
PerformanceIntegration,
|
|
6819
|
+
RewriteFrames,
|
|
6673
6820
|
Router,
|
|
6674
6821
|
System,
|
|
6675
6822
|
TryCatch,
|
|
@@ -6705,6 +6852,10 @@ function init(options = {}) {
|
|
|
6705
6852
|
stackParser: () => [],
|
|
6706
6853
|
transport: options.transport
|
|
6707
6854
|
});
|
|
6855
|
+
if (opts.enableSourceMap !== false) {
|
|
6856
|
+
opts.integrations.push(new RewriteFrames());
|
|
6857
|
+
}
|
|
6858
|
+
opts.integrations.push(new NetworkBreadcrumbs({ traceNetworkBody: opts.traceNetworkBody }));
|
|
6708
6859
|
setContext("miniapp", {
|
|
6709
6860
|
platform: appName,
|
|
6710
6861
|
environment: "miniapp"
|
|
@@ -6727,13 +6878,10 @@ function init(options = {}) {
|
|
|
6727
6878
|
initAndBind(MiniappClient, opts);
|
|
6728
6879
|
return getCurrentScope().getClient();
|
|
6729
6880
|
}
|
|
6730
|
-
function showReportDialog(
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
} else {
|
|
6735
|
-
console.warn("sentry-miniapp: No client available for showReportDialog");
|
|
6736
|
-
}
|
|
6881
|
+
function showReportDialog(_options = {}) {
|
|
6882
|
+
console.warn(
|
|
6883
|
+
"[sentry-miniapp] showReportDialog is deprecated and does nothing. Please build your own UI and use `Sentry.captureFeedback()` instead."
|
|
6884
|
+
);
|
|
6737
6885
|
}
|
|
6738
6886
|
function wrap(fn) {
|
|
6739
6887
|
return (function(...args) {
|