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.
Files changed (48) hide show
  1. package/CHANGELOG.md +123 -0
  2. package/README.md +113 -0
  3. package/dist/sentry-miniapp.cjs.js +187 -39
  4. package/dist/sentry-miniapp.cjs.js.map +1 -1
  5. package/dist/sentry-miniapp.esm.js +187 -39
  6. package/dist/sentry-miniapp.esm.js.map +1 -1
  7. package/dist/sentry-miniapp.umd.js +187 -39
  8. package/dist/sentry-miniapp.umd.js.map +1 -1
  9. package/dist/types/client.d.ts +4 -6
  10. package/dist/types/client.d.ts.map +1 -1
  11. package/dist/types/integrations/index.d.ts +2 -0
  12. package/dist/types/integrations/index.d.ts.map +1 -1
  13. package/dist/types/integrations/networkbreadcrumbs.d.ts +29 -0
  14. package/dist/types/integrations/networkbreadcrumbs.d.ts.map +1 -0
  15. package/dist/types/integrations/rewriteframes.d.ts +35 -0
  16. package/dist/types/integrations/rewriteframes.d.ts.map +1 -0
  17. package/dist/types/sdk.d.ts +6 -4
  18. package/dist/types/sdk.d.ts.map +1 -1
  19. package/dist/types/transports/offlineStore.d.ts +4 -1
  20. package/dist/types/transports/offlineStore.d.ts.map +1 -1
  21. package/dist/types/types.d.ts +6 -0
  22. package/dist/types/types.d.ts.map +1 -1
  23. package/dist/types/version.d.ts +1 -1
  24. package/package.json +94 -16
  25. package/src/.keep +0 -0
  26. package/src/client.ts +203 -0
  27. package/src/crossPlatform.ts +407 -0
  28. package/src/eventbuilder.ts +291 -0
  29. package/src/helpers.ts +214 -0
  30. package/src/index.ts +86 -0
  31. package/src/integrations/dedupe.ts +215 -0
  32. package/src/integrations/globalhandlers.ts +209 -0
  33. package/src/integrations/httpcontext.ts +140 -0
  34. package/src/integrations/index.ts +10 -0
  35. package/src/integrations/linkederrors.ts +107 -0
  36. package/src/integrations/networkbreadcrumbs.ts +155 -0
  37. package/src/integrations/performance.ts +622 -0
  38. package/src/integrations/rewriteframes.ts +77 -0
  39. package/src/integrations/router.ts +180 -0
  40. package/src/integrations/system.ts +135 -0
  41. package/src/integrations/trycatch.ts +233 -0
  42. package/src/polyfills.ts +242 -0
  43. package/src/sdk.ts +182 -0
  44. package/src/transports/index.ts +3 -0
  45. package/src/transports/offlineStore.ts +85 -0
  46. package/src/transports/xhr.ts +68 -0
  47. package/src/types.ts +129 -0
  48. package/src/version.ts +3 -0
@@ -4940,7 +4940,7 @@ Reason: ${reason}`
4940
4940
  }
4941
4941
  isolationScope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs);
4942
4942
  }
4943
- const SDK_VERSION = "1.2.0";
4943
+ const SDK_VERSION = "1.3.1";
4944
4944
  const SDK_NAME = "sentry.javascript.miniapp";
4945
4945
  const getSDK = () => {
4946
4946
  let currentSdk = {
@@ -5142,15 +5142,16 @@ Reason: ${reason}`
5142
5142
  }
5143
5143
  return createTransport(options, makeRequest);
5144
5144
  }
5145
- const MAX_OFFLINE_CACHE_SIZE = 30;
5145
+ const DEFAULT_OFFLINE_CACHE_SIZE = 30;
5146
5146
  const OFFLINE_STORE_KEY = "sentry_offline_store";
5147
- function createMiniappOfflineStore(_options) {
5147
+ function createMiniappOfflineStore(options) {
5148
+ const maxCacheSize = options.offlineCacheLimit || DEFAULT_OFFLINE_CACHE_SIZE;
5148
5149
  return {
5149
5150
  push: (env) => __async(null, null, function* () {
5150
5151
  try {
5151
5152
  const store = getStore();
5152
5153
  store.push(env);
5153
- if (store.length > MAX_OFFLINE_CACHE_SIZE) {
5154
+ if (store.length > maxCacheSize) {
5154
5155
  store.shift();
5155
5156
  }
5156
5157
  setStore(store);
@@ -5162,7 +5163,7 @@ Reason: ${reason}`
5162
5163
  try {
5163
5164
  const store = getStore();
5164
5165
  store.unshift(env);
5165
- if (store.length > MAX_OFFLINE_CACHE_SIZE) {
5166
+ if (store.length > maxCacheSize) {
5166
5167
  store.pop();
5167
5168
  }
5168
5169
  setStore(store);
@@ -5227,6 +5228,7 @@ Reason: ${reason}`
5227
5228
  }));
5228
5229
  if (options.enableOfflineCache !== false) {
5229
5230
  return makeOfflineTransport(() => baseTransport)(__spreadProps(__spreadValues({}, transportOptions), {
5231
+ offlineCacheLimit: options.offlineCacheLimit,
5230
5232
  createStore: createMiniappOfflineStore,
5231
5233
  flushAtStartup: true
5232
5234
  // 启动时自动重试发送
@@ -5321,29 +5323,14 @@ Reason: ${reason}`
5321
5323
  }
5322
5324
  }
5323
5325
  /**
5324
- * Show a report dialog to the user to send feedback to a specific event.
5325
- * 向用户显示报告对话框以将反馈发送到特定事件。
5326
- * 注意:小程序环境使用模态对话框模拟此功能
5327
- *
5328
- * @param options Set individual options for the dialog
5329
- */
5330
- showReportDialog(options = {}) {
5331
- const showModal = sdk().showModal;
5332
- if (showModal) {
5333
- showModal({
5334
- title: options.title || "错误反馈",
5335
- content: options.subtitle || "应用遇到了一个错误,是否要发送错误报告?",
5336
- confirmText: "发送",
5337
- cancelText: "取消",
5338
- success: (res) => {
5339
- if (res.confirm && options.onLoad) {
5340
- options.onLoad();
5341
- }
5342
- }
5343
- });
5344
- } else {
5345
- console.warn("sentry-miniapp: showModal is not available in current miniapp platform", options);
5346
- }
5326
+ * @deprecated Miniapp environment does not support Sentry's default HTML report dialog.
5327
+ * Please implement your own UI form to collect user feedback (name, email, comments)
5328
+ * and use `Sentry.captureFeedback()` to submit it to Sentry.
5329
+ */
5330
+ showReportDialog(_options = {}) {
5331
+ console.warn(
5332
+ "[sentry-miniapp] showReportDialog is deprecated and does nothing. Please build your own UI and use `Sentry.captureFeedback()` instead."
5333
+ );
5347
5334
  }
5348
5335
  /**
5349
5336
  * Capture feedback using the new feedback API.
@@ -5557,13 +5544,13 @@ Reason: ${reason}`
5557
5544
  setupOnce() {
5558
5545
  const global2 = globalThis;
5559
5546
  if (global2.setTimeout) {
5560
- fill(global2, "setTimeout", this._wrapTimeFunction.bind(this));
5547
+ fill$1(global2, "setTimeout", this._wrapTimeFunction.bind(this));
5561
5548
  }
5562
5549
  if (global2.setInterval) {
5563
- fill(global2, "setInterval", this._wrapTimeFunction.bind(this));
5550
+ fill$1(global2, "setInterval", this._wrapTimeFunction.bind(this));
5564
5551
  }
5565
5552
  if (global2.requestAnimationFrame) {
5566
- fill(global2, "requestAnimationFrame", this._wrapRAF.bind(this));
5553
+ fill$1(global2, "requestAnimationFrame", this._wrapRAF.bind(this));
5567
5554
  }
5568
5555
  }
5569
5556
  };
@@ -5644,7 +5631,7 @@ Reason: ${reason}`
5644
5631
  }
5645
5632
  return sentryWrapped;
5646
5633
  }
5647
- function fill(source, name, replacementFactory) {
5634
+ function fill$1(source, name, replacementFactory) {
5648
5635
  if (!(name in source)) {
5649
5636
  return;
5650
5637
  }
@@ -6667,13 +6654,173 @@ Reason: ${reason}`
6667
6654
  const performanceIntegration = (options) => {
6668
6655
  return () => new PerformanceIntegration(options);
6669
6656
  };
6657
+ const _RewriteFrames = class _RewriteFrames {
6658
+ constructor(options = {}) {
6659
+ this.name = _RewriteFrames.id;
6660
+ this._prefix = options.prefix || "app:///";
6661
+ }
6662
+ /**
6663
+ * @inheritDoc
6664
+ */
6665
+ setupOnce() {
6666
+ }
6667
+ /**
6668
+ * @inheritDoc
6669
+ */
6670
+ processEvent(event) {
6671
+ if (event.exception && event.exception.values) {
6672
+ event.exception.values.forEach((exception) => {
6673
+ if (exception.stacktrace && exception.stacktrace.frames) {
6674
+ exception.stacktrace.frames.forEach((frame) => {
6675
+ if (frame.filename) {
6676
+ frame.filename = this._normalizeFilename(frame.filename);
6677
+ }
6678
+ });
6679
+ }
6680
+ });
6681
+ }
6682
+ return event;
6683
+ }
6684
+ /**
6685
+ * Normalizes a filename from various miniapp platforms
6686
+ */
6687
+ _normalizeFilename(filename) {
6688
+ let normalized = filename;
6689
+ normalized = normalized.replace(/^(appservice|app-service|WAService)\//i, "").replace(/^https?:\/\/[^/]+\//i, "").replace(/^[a-z]+:\/\//i, "").replace(/^\//, "");
6690
+ if (normalized.startsWith(this._prefix)) {
6691
+ return normalized;
6692
+ }
6693
+ return `${this._prefix}${normalized}`;
6694
+ }
6695
+ };
6696
+ _RewriteFrames.id = "RewriteFrames";
6697
+ let RewriteFrames = _RewriteFrames;
6698
+ function fill(source, name, replacementFactory) {
6699
+ if (!(name in source)) {
6700
+ return;
6701
+ }
6702
+ const original = source[name];
6703
+ const wrapped = replacementFactory(original);
6704
+ if (typeof wrapped === "function") {
6705
+ try {
6706
+ wrapped.prototype = wrapped.prototype || {};
6707
+ wrapped.prototype.constructor = wrapped;
6708
+ } catch (_Oo) {
6709
+ }
6710
+ }
6711
+ source[name] = wrapped;
6712
+ }
6713
+ const _NetworkBreadcrumbs = class _NetworkBreadcrumbs {
6714
+ constructor(options = {}) {
6715
+ this.name = _NetworkBreadcrumbs.id;
6716
+ this._traceNetworkBody = !!options.traceNetworkBody;
6717
+ }
6718
+ /**
6719
+ * @inheritDoc
6720
+ */
6721
+ setupOnce() {
6722
+ const miniappSdk = sdk();
6723
+ if (miniappSdk && typeof miniappSdk.request === "function") {
6724
+ fill(miniappSdk, "request", this._createRequestWrapper.bind(this));
6725
+ }
6726
+ if (miniappSdk && typeof miniappSdk.httpRequest === "function") {
6727
+ fill(miniappSdk, "httpRequest", this._createRequestWrapper.bind(this));
6728
+ }
6729
+ }
6730
+ /**
6731
+ * Wraps the miniapp request API to capture breadcrumbs
6732
+ */
6733
+ _createRequestWrapper(originalRequest) {
6734
+ const traceNetworkBody = this._traceNetworkBody;
6735
+ return function(options) {
6736
+ if (!options || typeof options !== "object") {
6737
+ return originalRequest.call(this, options);
6738
+ }
6739
+ const url = options.url || "";
6740
+ const client = getClient();
6741
+ let dsnUrl = "";
6742
+ if (client) {
6743
+ const dsn = client.getOptions().dsn;
6744
+ if (dsn) {
6745
+ try {
6746
+ const dsnMatch = dsn.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?([^:/\n]+)/i);
6747
+ if (dsnMatch && dsnMatch[1]) {
6748
+ dsnUrl = dsnMatch[1];
6749
+ }
6750
+ } catch (e) {
6751
+ }
6752
+ }
6753
+ }
6754
+ if (typeof url === "string") {
6755
+ const isSentryRequest = dsnUrl && url.indexOf(dsnUrl) !== -1 || url.indexOf("sentry.io") !== -1;
6756
+ if (isSentryRequest) {
6757
+ return originalRequest.call(this, options);
6758
+ }
6759
+ }
6760
+ const method = (options.method || "GET").toUpperCase();
6761
+ const requestData = options.data;
6762
+ const breadcrumbData = {
6763
+ url,
6764
+ method
6765
+ };
6766
+ if (traceNetworkBody && requestData) {
6767
+ try {
6768
+ breadcrumbData["request_body"] = typeof requestData === "string" ? requestData : JSON.stringify(requestData);
6769
+ } catch (e) {
6770
+ breadcrumbData["request_body"] = "[Cannot serialize request body]";
6771
+ }
6772
+ }
6773
+ const originalSuccess = options.success;
6774
+ const originalFail = options.fail;
6775
+ options.success = function(...args) {
6776
+ const res = args[0] || {};
6777
+ const statusCode = res.statusCode || res.status;
6778
+ breadcrumbData["status_code"] = statusCode;
6779
+ if (traceNetworkBody && res.data) {
6780
+ try {
6781
+ breadcrumbData["response_body"] = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
6782
+ } catch (e) {
6783
+ breadcrumbData["response_body"] = "[Cannot serialize response body]";
6784
+ }
6785
+ }
6786
+ addBreadcrumb({
6787
+ type: "http",
6788
+ category: "xhr",
6789
+ data: breadcrumbData,
6790
+ level: statusCode >= 400 ? "warning" : "info"
6791
+ });
6792
+ if (typeof originalSuccess === "function") {
6793
+ return originalSuccess.apply(this, args);
6794
+ }
6795
+ };
6796
+ options.fail = function(...args) {
6797
+ const err = args[0] || {};
6798
+ breadcrumbData["error"] = err.errMsg || err.errorMessage || "Network request failed";
6799
+ addBreadcrumb({
6800
+ type: "http",
6801
+ category: "xhr",
6802
+ data: breadcrumbData,
6803
+ level: "error"
6804
+ });
6805
+ if (typeof originalFail === "function") {
6806
+ return originalFail.apply(this, args);
6807
+ }
6808
+ };
6809
+ return originalRequest.call(this, options);
6810
+ };
6811
+ }
6812
+ };
6813
+ _NetworkBreadcrumbs.id = "NetworkBreadcrumbs";
6814
+ let NetworkBreadcrumbs = _NetworkBreadcrumbs;
6670
6815
  const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
6671
6816
  __proto__: null,
6672
6817
  Dedupe,
6673
6818
  GlobalHandlers,
6674
6819
  HttpContext,
6675
6820
  LinkedErrors,
6821
+ NetworkBreadcrumbs,
6676
6822
  PerformanceIntegration,
6823
+ RewriteFrames,
6677
6824
  Router,
6678
6825
  System,
6679
6826
  TryCatch,
@@ -6709,6 +6856,10 @@ Reason: ${reason}`
6709
6856
  stackParser: () => [],
6710
6857
  transport: options.transport
6711
6858
  });
6859
+ if (opts.enableSourceMap !== false) {
6860
+ opts.integrations.push(new RewriteFrames());
6861
+ }
6862
+ opts.integrations.push(new NetworkBreadcrumbs({ traceNetworkBody: opts.traceNetworkBody }));
6712
6863
  setContext("miniapp", {
6713
6864
  platform: appName,
6714
6865
  environment: "miniapp"
@@ -6731,13 +6882,10 @@ Reason: ${reason}`
6731
6882
  initAndBind(MiniappClient, opts);
6732
6883
  return getCurrentScope().getClient();
6733
6884
  }
6734
- function showReportDialog(options = {}) {
6735
- const client = getCurrentScope().getClient();
6736
- if (client) {
6737
- client.showReportDialog(options);
6738
- } else {
6739
- console.warn("sentry-miniapp: No client available for showReportDialog");
6740
- }
6885
+ function showReportDialog(_options = {}) {
6886
+ console.warn(
6887
+ "[sentry-miniapp] showReportDialog is deprecated and does nothing. Please build your own UI and use `Sentry.captureFeedback()` instead."
6888
+ );
6741
6889
  }
6742
6890
  function wrap(fn) {
6743
6891
  return (function(...args) {