@swifty.js/sentry 0.0.4 → 0.0.6

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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -144
  3. package/dist/constants/index.cjs +1 -1
  4. package/dist/constants/index.js +1 -1
  5. package/dist/core/api.cjs +1 -1
  6. package/dist/core/api.d.ts +28 -9
  7. package/dist/core/api.js +1 -1
  8. package/dist/core/breadcrumb.cjs +1 -1
  9. package/dist/core/breadcrumb.js +1 -1
  10. package/dist/core/decorate-http.cjs +1 -1
  11. package/dist/core/decorate-http.js +1 -1
  12. package/dist/core/decorate-route.cjs +1 -1
  13. package/dist/core/decorate-route.js +1 -1
  14. package/dist/core/decorates.cjs +1 -1
  15. package/dist/core/decorates.js +1 -1
  16. package/dist/core/error-dedup.cjs +1 -0
  17. package/dist/core/error-dedup.js +1 -0
  18. package/dist/core/framework-error.cjs +1 -1
  19. package/dist/core/framework-error.js +1 -1
  20. package/dist/core/handle-code-error.cjs +1 -1
  21. package/dist/core/handle-code-error.js +1 -1
  22. package/dist/core/handle-error.cjs +1 -1
  23. package/dist/core/handle-error.js +1 -1
  24. package/dist/core/handle-events.cjs +1 -1
  25. package/dist/core/handle-events.js +1 -1
  26. package/dist/core/handle-route.cjs +1 -1
  27. package/dist/core/handle-route.js +1 -1
  28. package/dist/core/identity.cjs +1 -1
  29. package/dist/core/identity.js +1 -1
  30. package/dist/core/options-schema.cjs +1 -1
  31. package/dist/core/options-schema.d.ts +42 -45
  32. package/dist/core/options-schema.js +1 -1
  33. package/dist/core/pv-lifecycle.cjs +1 -1
  34. package/dist/core/pv-lifecycle.js +1 -1
  35. package/dist/core/sdk-lifecycle.cjs +1 -1
  36. package/dist/core/sdk-lifecycle.d.ts +1 -1
  37. package/dist/core/sdk-lifecycle.js +1 -1
  38. package/dist/core/setup.cjs +1 -1
  39. package/dist/core/setup.js +1 -1
  40. package/dist/core/white-screen.cjs +1 -1
  41. package/dist/core/white-screen.js +1 -1
  42. package/dist/index.cjs +1 -1
  43. package/dist/index.d.ts +4 -5
  44. package/dist/index.js +1 -1
  45. package/dist/node/dev-endpoint.cjs +1 -0
  46. package/dist/node/dev-endpoint.js +1 -0
  47. package/dist/package.json.cjs +1 -1
  48. package/dist/package.json.js +1 -1
  49. package/dist/plugins/exposure/index.cjs +1 -1
  50. package/dist/plugins/exposure/index.d.ts +0 -1
  51. package/dist/plugins/exposure/index.js +1 -1
  52. package/dist/plugins/performance/first-screen-paint.cjs +1 -1
  53. package/dist/plugins/performance/first-screen-paint.js +1 -1
  54. package/dist/plugins/performance/index.cjs +1 -1
  55. package/dist/plugins/performance/index.d.ts +0 -1
  56. package/dist/plugins/performance/index.js +1 -1
  57. package/dist/plugins/performance/navigation-timing.cjs +1 -1
  58. package/dist/plugins/performance/navigation-timing.js +1 -1
  59. package/dist/plugins/performance/perf.cjs +1 -1
  60. package/dist/plugins/performance/perf.js +1 -1
  61. package/dist/plugins/performance/resource-element-fallback.cjs +1 -1
  62. package/dist/plugins/performance/resource-element-fallback.js +1 -1
  63. package/dist/plugins/performance/resource-timing.cjs +1 -1
  64. package/dist/plugins/performance/resource-timing.js +1 -1
  65. package/dist/plugins/screen-record/index.cjs +1 -1
  66. package/dist/plugins/screen-record/index.js +1 -1
  67. package/dist/plugins/screen-record/recorder.cjs +1 -1
  68. package/dist/plugins/screen-record/recorder.d.ts +1 -1
  69. package/dist/plugins/screen-record/recorder.js +1 -1
  70. package/dist/react.cjs +1 -1
  71. package/dist/react.d.ts +7 -80
  72. package/dist/react.js +1 -1
  73. package/dist/reporter/index.cjs +1 -1
  74. package/dist/reporter/index.js +1 -1
  75. package/dist/reporter/network-listener.cjs +1 -1
  76. package/dist/reporter/network-listener.js +1 -1
  77. package/dist/reporter/offline-cache.cjs +1 -1
  78. package/dist/reporter/offline-cache.js +1 -1
  79. package/dist/reporter/report-data-schema.cjs +1 -1
  80. package/dist/reporter/report-data-schema.js +1 -1
  81. package/dist/reporter/report-data.cjs +1 -1
  82. package/dist/reporter/report-data.js +1 -1
  83. package/dist/reporter/server-recovery.cjs +1 -1
  84. package/dist/reporter/server-recovery.js +1 -1
  85. package/dist/reporter/transports.cjs +1 -1
  86. package/dist/reporter/transports.js +1 -1
  87. package/dist/source-map/source-map.cjs +1 -0
  88. package/dist/source-map/source-map.js +1 -0
  89. package/dist/source-map/vite.cjs +1 -0
  90. package/dist/source-map/vite.js +1 -0
  91. package/dist/source-map/webpack.cjs +1 -0
  92. package/dist/source-map/webpack.js +1 -0
  93. package/dist/types/common.d.ts +10 -11
  94. package/dist/types/enums.cjs +1 -1
  95. package/dist/types/enums.d.ts +1 -45
  96. package/dist/types/enums.js +1 -1
  97. package/dist/types/options.d.ts +9 -13
  98. package/dist/types/plugin.cjs +1 -1
  99. package/dist/types/plugin.d.ts +0 -3
  100. package/dist/types/plugin.js +1 -1
  101. package/dist/utils/click-data.cjs +1 -1
  102. package/dist/utils/click-data.js +1 -1
  103. package/dist/utils/data-structures.cjs +1 -1
  104. package/dist/utils/data-structures.js +1 -1
  105. package/dist/utils/dom2str.cjs +1 -0
  106. package/dist/utils/dom2str.js +1 -0
  107. package/dist/utils/get-base-data.cjs +1 -1
  108. package/dist/utils/get-base-data.js +1 -1
  109. package/dist/utils/logger.cjs +1 -1
  110. package/dist/utils/logger.js +1 -1
  111. package/dist/utils/noop.cjs +1 -0
  112. package/dist/utils/noop.js +1 -0
  113. package/dist/utils/sentry.cjs +1 -1
  114. package/dist/utils/sentry.js +1 -1
  115. package/dist/utils/session.cjs +1 -1
  116. package/dist/utils/session.js +1 -1
  117. package/dist/utils/throttle.cjs +1 -1
  118. package/dist/utils/throttle.js +1 -1
  119. package/dist/utils/transform-http-data.cjs +1 -1
  120. package/dist/utils/transform-http-data.js +1 -1
  121. package/dist/utils/uuid.cjs +1 -0
  122. package/dist/utils/uuid.js +1 -0
  123. package/dist/vite.cjs +1 -1
  124. package/dist/vite.d.ts +2 -2
  125. package/dist/vite.js +1 -1
  126. package/dist/vue.cjs +1 -1
  127. package/dist/vue.js +1 -1
  128. package/dist/webpack.cjs +1 -1
  129. package/dist/webpack.js +1 -1
  130. package/package.json +22 -26
  131. package/dist/core/ip.cjs +0 -1
  132. package/dist/core/ip.d.ts +0 -24
  133. package/dist/core/ip.js +0 -1
  134. package/dist/reporter/batch.cjs +0 -1
  135. package/dist/reporter/batch.js +0 -1
  136. package/dist/sourcemap/sourcemap.cjs +0 -1
  137. package/dist/sourcemap/sourcemap.js +0 -1
  138. package/dist/sourcemap/vite.cjs +0 -1
  139. package/dist/sourcemap/vite.js +0 -1
  140. package/dist/sourcemap/webpack.cjs +0 -1
  141. package/dist/sourcemap/webpack.js +0 -1
  142. package/dist/utils/base64.cjs +0 -1
  143. package/dist/utils/base64.js +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 hangtiancheng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -23,7 +23,7 @@ npm install vue
23
23
  ## Package Exports
24
24
 
25
25
  ```ts
26
- import { init, destroy, isInitialized, pluginEnable } from "@swifty.js/sentry";
26
+ import { init, destroy, isInitialized, enablePlugin } from "@swifty.js/sentry";
27
27
  import { PerformancePlugin, ScreenRecordPlugin, ExposurePlugin } from "@swifty.js/sentry/plugins";
28
28
  import { ReactErrorBoundary } from "@swifty.js/sentry/react";
29
29
  import { vuePlugin } from "@swifty.js/sentry/vue";
@@ -34,7 +34,7 @@ Each public export provides ESM, CJS, and TypeScript declaration files.
34
34
  ## Quick Start
35
35
 
36
36
  ```ts
37
- import { init, pluginEnable } from "@swifty.js/sentry";
37
+ import { init, enablePlugin } from "@swifty.js/sentry";
38
38
  import { PerformancePlugin, ScreenRecordPlugin, ExposurePlugin } from "@swifty.js/sentry/plugins";
39
39
 
40
40
  init({
@@ -43,9 +43,7 @@ init({
43
43
  userId: "anonymous",
44
44
  });
45
45
 
46
- pluginEnable(PerformancePlugin);
47
- pluginEnable(ScreenRecordPlugin);
48
- pluginEnable(ExposurePlugin);
46
+ enablePlugin(new PerformancePlugin(), new ScreenRecordPlugin(), new ExposurePlugin());
49
47
  ```
50
48
 
51
49
  `dsn` must be a non-empty string. If `dsn` is empty, initialization is rejected.
@@ -71,7 +69,7 @@ init({
71
69
 
72
70
  ### destroy
73
71
 
74
- `destroy()` cleans plugin instances, event subscriptions, browser listeners, and decorated global methods.
72
+ `destroy()` cleans plugin instances, event subscriptions, browser listeners, and decorated global methods, and resets per-session state (breadcrumbs, error deduplication, queued reports).
75
73
 
76
74
  ```ts
77
75
  import { destroy } from "@swifty.js/sentry";
@@ -95,48 +93,43 @@ if (!isInitialized()) {
95
93
 
96
94
  `init` accepts partial options. Values not provided by the caller use SDK defaults.
97
95
 
98
- | Option | Type | Default | Description |
99
- | ---------------------------- | ---------------------- | --------------------------------------------------- | ------------------------------------------------------ |
100
- | `dsn` | `string` | `""` | Report endpoint. Required for initialization. |
101
- | `projectId` | `string` | `"unknown"` | Frontend project identifier. |
102
- | `userId` | `string` | `"unknown"` | Current user identifier. |
103
- | `disabled` | `boolean` | `false` | Disable the SDK. |
104
- | `enableXhr` | `boolean` | `true` | Capture XMLHttpRequest requests. |
105
- | `enableFetch` | `boolean` | `true` | Capture fetch requests. |
106
- | `enableClick` | `boolean` | `true` | Capture declarative click events. |
107
- | `enableError` | `boolean` | `true` | Capture runtime and resource errors. |
108
- | `enableUnhandledRejection` | `boolean` | `true` | Capture unhandled promise rejections. |
109
- | `enableHashChange` | `boolean` | `true` | Capture hash navigation. |
110
- | `enableHistory` | `boolean` | `true` | Capture history navigation. |
111
- | `enablePerformance` | `boolean` | `true` | Enable performance-related capture. |
112
- | `enableScreenRecord` | `boolean` | `true` | Enable screen-record-related reporting. |
113
- | `enableWhiteScreen` | `boolean` | `true` | Enable white-screen detection. |
114
- | `enableFingerprint` | `boolean` | `false` | Enable FingerprintJS anonymous visitor identity. |
115
- | `anonymousId` | `string` | `"unknown"` | SDK-generated anonymous visitor id. |
116
- | `visitorId` | `string` | `"unknown"` | Backend-bound visitor id. |
117
- | `useImageReport` | `boolean` | `false` | Allow image transport. |
118
- | `screenRecordDurationMs` | `number` | `3000` | Rolling screen record window length. |
119
- | `screenRecordEventTypes` | `EventType[]` | `[Error, Xhr, Fetch, Resource, UnhandledRejection]` | Event types that trigger screen record reporting. |
120
- | `hasSkeleton` | `boolean` | `false` | Whether the page has a skeleton screen. |
121
- | `rootCssSelectors` | `string[]` | `["html", "body", "#app", "#root"]` | Root selectors used by white-screen detection. |
122
- | `clickThrottleDelay` | `number` | `0` | Click capture throttle delay in milliseconds. |
123
- | `requestTimeoutMilliseconds` | `number` | `3000` | Request timeout in milliseconds. |
124
- | `maxBreadcrumbs` | `number` | `30` | Breadcrumb capacity. |
125
- | `repeatCodeError` | `boolean` | `false` | Report duplicate code errors. |
126
- | `enableHttpPerformance` | `boolean` | `false` | Report successful HTTP requests as performance events. |
127
- | `ignoreErrors` | `(string \| RegExp)[]` | `[]` | Runtime error ignore rules. |
128
- | `excludeApis` | `(string \| RegExp)[]` | `[]` | HTTP request ignore rules. |
129
- | `cacheMaxLength` | `number` | `10` | Maximum batch size. |
130
- | `cacheWaitingTime` | `number` | `2000` | Batch wait time in milliseconds. |
131
- | `maxQueueLength` | `number` | `200` | Maximum queued events while offline or retrying. |
132
- | `retryIntervalMilliseconds` | `number` | `60000` | Server recovery probe interval. |
133
- | `offlineCacheKey` | `string` | `"swifty_sentry_offline_cache"` | localStorage key for offline cache. |
134
- | `tracesSampleRate` | `number` | `1` | Sampling rate from 0 to 1. |
135
- | `onBeforePushBreadcrumb` | `function` | `undefined` | Hook before storing a breadcrumb. |
136
- | `onBeforeReportData` | `function` | `undefined` | Hook before one event enters Reporter queue. |
137
- | `beforePushEventList` | `function` | `undefined` | Hook before a batch enters transport. |
138
- | `afterSendData` | `function` | `undefined` | Hook after a batch enters transport successfully. |
139
- | `handleHttpError` | `function` | `undefined` | Custom HTTP error callback. |
96
+ | Option | Type | Default | Description |
97
+ | --------------------------- | ---------------------- | --------------------------------------------------- | ------------------------------------------------------ |
98
+ | `dsn` | `string` | `""` | Report endpoint. Required for initialization. |
99
+ | `projectId` | `string` | `"unknown"` | Frontend project identifier. |
100
+ | `userId` | `string` | `"unknown"` | Current user identifier. |
101
+ | `disabled` | `boolean` | `false` | Disable the SDK. |
102
+ | `enableXhr` | `boolean` | `true` | Capture XMLHttpRequest requests. |
103
+ | `enableFetch` | `boolean` | `true` | Capture fetch requests. |
104
+ | `enableClick` | `boolean` | `true` | Capture declarative click events. |
105
+ | `enableError` | `boolean` | `true` | Capture runtime and resource errors. |
106
+ | `enableUnhandledRejection` | `boolean` | `true` | Capture unhandled promise rejections. |
107
+ | `enableHashChange` | `boolean` | `true` | Capture hash navigation. |
108
+ | `enableHistory` | `boolean` | `true` | Capture history navigation. |
109
+ | `enableWhiteScreen` | `boolean` | `true` | Enable white-screen detection. |
110
+ | `enableFingerprint` | `boolean` | `false` | Enable FingerprintJS anonymous visitor identity. |
111
+ | `anonymousId` | `string` | `"unknown"` | SDK-generated anonymous visitor id. |
112
+ | `visitorId` | `string` | `"unknown"` | Backend-bound visitor id. |
113
+ | `screenRecordDurationMs` | `number` | `3000` | Rolling screen record window length. |
114
+ | `screenRecordEventTypes` | `EventType[]` | `[Error, Xhr, Fetch, Resource, UnhandledRejection]` | Event types that trigger screen record reporting. |
115
+ | `hasSkeleton` | `boolean` | `false` | Whether the page has a skeleton screen. |
116
+ | `rootCssSelectors` | `string[]` | `["html", "body", "#app", "#root"]` | Root selectors used by white-screen detection. |
117
+ | `clickThrottleDelay` | `number` | `0` | Click capture throttle delay in milliseconds. |
118
+ | `maxBreadcrumbs` | `number` | `30` | Breadcrumb capacity. |
119
+ | `repeatCodeError` | `boolean` | `false` | Report duplicate code errors. |
120
+ | `enableHttpPerformance` | `boolean` | `false` | Report successful HTTP requests as performance events. |
121
+ | `ignoreErrors` | `(string \| RegExp)[]` | `[]` | Runtime error ignore rules. |
122
+ | `excludeApis` | `(string \| RegExp)[]` | `[]` | HTTP request ignore rules. |
123
+ | `cacheMaxLength` | `number` | `10` | Maximum batch size. |
124
+ | `cacheWaitingTime` | `number` | `2000` | Batch wait time in milliseconds. |
125
+ | `maxQueueLength` | `number` | `200` | Maximum queued events while offline or retrying. |
126
+ | `retryIntervalMilliseconds` | `number` | `60000` | Server recovery probe interval. |
127
+ | `offlineCacheKey` | `string` | `"swifty_sentry_offline_cache"` | localStorage key for offline cache. |
128
+ | `tracesSampleRate` | `number` | `1` | Sampling rate from 0 to 1. |
129
+ | `beforeBreadcrumb` | `function` | `undefined` | Hook before storing a breadcrumb. |
130
+ | `beforeSend` | `function` | `undefined` | Hook before one event enters Reporter queue. |
131
+ | `beforeSendBatch` | `function` | `undefined` | Hook before a batch enters transport. |
132
+ | `afterSend` | `function` | `undefined` | Hook after a batch enters transport successfully. |
140
133
 
141
134
  Example production configuration:
142
135
 
@@ -159,21 +152,23 @@ init({
159
152
 
160
153
  Reporter sends `IReportData` objects to the configured `dsn`.
161
154
 
162
- | Field | Description |
163
- | ------------ | ------------------------------------------ |
164
- | `id` | Reporter instance id. |
165
- | `type` | Event type. |
166
- | `name` | Event name. |
167
- | `message` | Event message. |
168
- | `status` | `OK` or `Error`. |
169
- | `time` | Formatted time. |
170
- | `timestamp` | Numeric timestamp. |
171
- | `url` | Current page URL. |
172
- | `userId` | User identifier. |
173
- | `projectId` | Project identifier. |
174
- | `sdkVersion` | SDK version. |
175
- | `deviceInfo` | Device, browser, OS, and fingerprint data. |
176
- | `payload` | Original event payload. |
155
+ | Field | Description |
156
+ | ------------- | ------------------------------------- |
157
+ | `id` | Reporter instance id. |
158
+ | `type` | Event type. |
159
+ | `name` | Event name. |
160
+ | `message` | Event message. |
161
+ | `status` | `OK` or `Error`. |
162
+ | `time` | Formatted time. |
163
+ | `timestamp` | Numeric timestamp. |
164
+ | `url` | Current page URL. |
165
+ | `userId` | User identifier. |
166
+ | `anonymousId` | FingerprintJS anonymous visitor id. |
167
+ | `visitorId` | Backend-bound visitor id. |
168
+ | `projectId` | Project identifier. |
169
+ | `sdkVersion` | SDK version. |
170
+ | `deviceInfo` | Device, browser, OS, and screen data. |
171
+ | `payload` | Original event payload. |
177
172
 
178
173
  ## Event Types
179
174
 
@@ -266,7 +261,7 @@ On hash or history route changes, it:
266
261
  - Deduplicates unchanged URLs.
267
262
  - Reports `PageDwell` for the previous page.
268
263
  - Reports a new PV for the next page.
269
- - Flushes current dwell time on `beforeunload` when possible.
264
+ - Flushes current dwell time on `pagehide` when possible.
270
265
 
271
266
  Dwell time less than or equal to 100 ms is ignored to reduce noise.
272
267
 
@@ -317,20 +312,20 @@ Custom `swifty-sentry-*` attributes become `params`.
317
312
 
318
313
  The reported click payload (`DeclarativeClickData`) includes:
319
314
 
320
- | Field | Type | Description |
321
- | ---------------- | ------------------------------------------ | ------------------------------------------------------------------------------ |
322
- | `ev` | `string` | Event ID (from `swifty-sentry-ev`, `title`, `swifty-sentry-el`, or tag). |
323
- | `msg` | `string` | Human-readable message (from `swifty-sentry-msg`, text, `aria-label`, or tag). |
324
- | `triggerPageUrl` | `string` | Current page URL (`location.href`). |
325
- | `x` | `number` | Click X coordinate (element offset + scroll offset). |
326
- | `y` | `number` | Click Y coordinate (element offset + scroll offset). |
327
- | `params` | `Readonly<Record<string, string \| null>>` | Custom `swifty-sentry-*` attributes (excluding reserved keys). |
328
- | `elementPath` | `string` | XPath-like path from element to body (max 128 characters). |
329
- | `triggerTime` | `number` | `Date.now()` at click time. |
315
+ | Field | Type | Description |
316
+ | ---------------- | ------------------------------------------ | -------------------------------------------------------------------------------- |
317
+ | `ev` | `string` | Event ID (from `swifty-sentry-ev`, `title`, `swifty-sentry-el`, or tag). |
318
+ | `msg` | `string` | Human-readable message (from `swifty-sentry-msg`, text, `aria-label`, or tag). |
319
+ | `triggerPageUrl` | `string` | Current page URL (`location.href`). |
320
+ | `x` | `number` | Click X coordinate (element offset + scroll offset). |
321
+ | `y` | `number` | Click Y coordinate (element offset + scroll offset). |
322
+ | `params` | `Readonly<Record<string, string \| null>>` | Custom `swifty-sentry-*` attributes (excluding reserved keys). |
323
+ | `elementPath` | `string` | CSS-selector-like ancestor path (nearest 5 levels with id/class, max 128 chars). |
324
+ | `triggerTime` | `number` | `Date.now()` at click time. |
330
325
 
331
326
  ## White-Screen Detection
332
327
 
333
- White-screen detection samples viewport points after the page is ready and checks whether those points still resolve to configured root elements.
328
+ White-screen detection samples viewport points every second after the page is ready and checks whether those points still resolve to configured root elements. Sampling stops as soon as real content is observed; a white screen is reported only when the page stays blank for 10 consecutive samples. In skeleton mode the first sample records a baseline of on-screen selectors, and a report is sent only when the skeleton never transitions to different content within the sampling window.
334
329
 
335
330
  Default root selectors:
336
331
 
@@ -410,20 +405,19 @@ Reporter behavior:
410
405
  - Flushes cached events after network recovery.
411
406
  - Probes server recovery with HEAD requests after failed fetch reports.
412
407
  - Avoids concurrent flush races with an `isFlushing` guard.
413
- - Supports `sendBeacon`, image, and fetch transports.
408
+ - Supports `sendBeacon` and fetch transports.
414
409
 
415
410
  Transport priority:
416
411
 
417
412
  1. Use `navigator.sendBeacon` for batches up to 60 KB.
418
- 2. Use image transport when `useImageReport` is true and the batch is up to 2 KB.
419
- 3. Use fetch POST as the fallback.
413
+ 2. Use fetch POST as the fallback, with `keepalive` enabled for bodies up to 60 KB.
420
414
 
421
415
  Flush offline cache manually:
422
416
 
423
417
  ```ts
424
- import { sendLocal } from "@swifty.js/sentry";
418
+ import { flushOfflineCache } from "@swifty.js/sentry";
425
419
 
426
- await sendLocal();
420
+ await flushOfflineCache();
427
421
  ```
428
422
 
429
423
  ## Reporter Hooks
@@ -431,20 +425,20 @@ await sendLocal();
431
425
  Register hooks after initialization or provide equivalent hooks in `init` options.
432
426
 
433
427
  ```ts
434
- import { afterSendData, beforePushEventList, beforeSendData } from "@swifty.js/sentry";
428
+ import { afterSend, beforeSend, beforeSendBatch } from "@swifty.js/sentry";
435
429
 
436
- beforeSendData((data) => {
430
+ beforeSend((data) => {
437
431
  if (data.type === "Click") {
438
432
  return false;
439
433
  }
440
434
  return data;
441
435
  });
442
436
 
443
- beforePushEventList((eventList) => {
437
+ beforeSendBatch((eventList) => {
444
438
  return eventList.filter((item) => item.status !== "OK");
445
439
  });
446
440
 
447
- afterSendData((eventList) => {
441
+ afterSend((eventList) => {
448
442
  console.log("reported", eventList.length);
449
443
  });
450
444
  ```
@@ -454,13 +448,13 @@ Equivalent initialization form:
454
448
  ```ts
455
449
  init({
456
450
  dsn: "/api/log",
457
- onBeforeReportData(data) {
451
+ beforeSend(data) {
458
452
  return data;
459
453
  },
460
- beforePushEventList(eventList) {
454
+ beforeSendBatch(eventList) {
461
455
  return eventList;
462
456
  },
463
- afterSendData(eventList) {
457
+ afterSend(eventList) {
464
458
  console.log(eventList.length);
465
459
  },
466
460
  });
@@ -517,34 +511,15 @@ tracePageView({
517
511
  });
518
512
  ```
519
513
 
520
- ### getBaseInfo and getUserId
521
-
522
- ```ts
523
- import { getBaseInfo, getUserId } from "@swifty.js/sentry";
524
-
525
- const baseInfo = getBaseInfo();
526
- const userId = getUserId();
527
- ```
528
-
529
- ### getIPs
530
-
531
- `getIPs` attempts to collect WebRTC ICE candidate IP values in browsers that support the required APIs. It returns an empty array when unsupported.
532
-
533
- ```ts
534
- import { getIPs } from "@swifty.js/sentry";
535
-
536
- const ips = await getIPs();
537
- ```
538
-
539
514
  ## Plugin System
540
515
 
541
516
  Plugins extend the SDK without coupling optional capabilities to the core entry. A plugin class extends `SentryPlugin`, implements `init`, and can implement `destroy` for cleanup.
542
517
 
543
518
  ```ts
544
- import { pluginEnable } from "@swifty.js/sentry";
519
+ import { enablePlugin } from "@swifty.js/sentry";
545
520
  import { PerformancePlugin } from "@swifty.js/sentry/plugins";
546
521
 
547
- const plugin = pluginEnable(PerformancePlugin);
522
+ enablePlugin(new PerformancePlugin());
548
523
  ```
549
524
 
550
525
  Enabled plugins are stored in the plugin registry. `destroy()` calls each plugin's `destroy()` method when available.
@@ -552,10 +527,10 @@ Enabled plugins are stored in the plugin registry. `destroy()` calls each plugin
552
527
  ## PerformancePlugin
553
528
 
554
529
  ```ts
555
- import { pluginEnable } from "@swifty.js/sentry";
530
+ import { enablePlugin } from "@swifty.js/sentry";
556
531
  import { PerformancePlugin } from "@swifty.js/sentry/plugins";
557
532
 
558
- pluginEnable(PerformancePlugin);
533
+ enablePlugin(new PerformancePlugin());
559
534
  ```
560
535
 
561
536
  The plugin collects:
@@ -572,31 +547,31 @@ Unsupported browser capabilities are skipped safely.
572
547
  ## ScreenRecordPlugin
573
548
 
574
549
  ```ts
575
- import { pluginEnable } from "@swifty.js/sentry";
550
+ import { enablePlugin } from "@swifty.js/sentry";
576
551
  import { ScreenRecordPlugin, unzipScreenRecord } from "@swifty.js/sentry/plugins";
577
552
 
578
- pluginEnable(ScreenRecordPlugin);
553
+ enablePlugin(new ScreenRecordPlugin());
579
554
 
580
- pluginEnable(ScreenRecordPlugin, {
581
- durationMs: 5000,
582
- });
555
+ // With custom options
556
+ enablePlugin(new ScreenRecordPlugin({ durationMs: 5000 }));
583
557
  ```
584
558
 
585
559
  Screen recording is based on rrweb. The plugin keeps a rolling record window. When selected error or network events occur, the recent record window is reported as a `ScreenRecord` event.
586
560
 
587
- Decode a record payload:
561
+ Decode a record payload (async — pako is loaded on demand):
588
562
 
589
563
  ```ts
590
- const events = unzipScreenRecord(recordPayload);
564
+ const events = await unzipScreenRecord(recordPayload);
591
565
  ```
592
566
 
593
567
  ## ExposurePlugin
594
568
 
595
569
  ```ts
596
- import { pluginEnable } from "@swifty.js/sentry";
570
+ import { enablePlugin } from "@swifty.js/sentry";
597
571
  import { ExposurePlugin } from "@swifty.js/sentry/plugins";
598
572
 
599
- const exposure = pluginEnable(ExposurePlugin);
573
+ const exposure = new ExposurePlugin();
574
+ enablePlugin(exposure);
600
575
  ```
601
576
 
602
577
  Observe one element:
@@ -709,8 +684,8 @@ import { defineConfig } from "vite";
709
684
  import { sentryPlugin } from "@swifty.js/sentry/vite";
710
685
 
711
686
  export default defineConfig({
712
- // `url` should equals to @swifty.js/sentry `init({ dsn: "/api/log" })` config `dsn`
713
- plugins: [sentryPlugin({ url: "/api/log" })],
687
+ // `dsn` should match the @swifty.js/sentry `init({ dsn: "/api/log" })` dsn value
688
+ plugins: [sentryPlugin({ dsn: "/api/log" })],
714
689
  });
715
690
  ```
716
691
 
@@ -718,21 +693,44 @@ export default defineConfig({
718
693
 
719
694
  | Export | Vite Version | Description |
720
695
  | --------------- | ------------ | --------------------------------------- |
721
- | `sentryPlugin` | Vite 6/8 | Default export. For current Vite. |
696
+ | `sentryPlugin` | Vite 8 | Default export. For current Vite. |
722
697
  | `sentryPlugin7` | Vite 7 | For projects using Vite 7 specifically. |
723
698
 
699
+ Both factories take an optional options object.
700
+
724
701
  ### Options
725
702
 
726
703
  | Option | Type | Default | Description |
727
704
  | ------ | -------- | ----------- | ---------------------------------------- |
728
- | `url` | `string` | `"/sentry"` | The URL path to intercept POST requests. |
705
+ | `dsn` | `string` | `"/sentry"` | The URL path to intercept POST requests. |
706
+
707
+ The plugin only activates for the dev server (`apply: "serve"`), creates a `logs/` directory in `process.cwd()`, writes a timestamped JSONL log file (`sentry_YYYYMMDDHHMMSS.jsonl`), enriches error records with original source positions resolved from the dev server's module graph source maps, and returns `{ code: 0, message: "success" }`.
708
+
709
+ ## Webpack Dev-Server Plugin
710
+
711
+ The `@swifty.js/sentry/webpack` subpath provides the same mock report endpoint for webpack-dev-server, plus source map resolution based on emitted `.map` assets.
729
712
 
730
- The plugin creates a `logs/` directory in `process.cwd()`, writes a timestamped JSONL log file (`sentry_YYYYMMDDHHMMSS.jsonl`), parses each request body as JSON, and returns `{ code: 0, message: "success" }`.
713
+ ```ts
714
+ // webpack.config.mjs
715
+ import { sentryPlugin } from "@swifty.js/sentry/webpack";
716
+
717
+ export default {
718
+ plugins: [sentryPlugin({ dsn: "/api/log" })],
719
+ devServer: {
720
+ // ...
721
+ },
722
+ };
723
+ ```
724
+
725
+ | Export | Description |
726
+ | --------------------- | ----------------------------------------------------------------------------- |
727
+ | `sentryPlugin` | Factory returning a `SentryWebpackPlugin` instance. Default export. |
728
+ | `SentryWebpackPlugin` | Webpack plugin class. No-op unless `compiler.options.devServer` exists. |
729
+ | `sentryMiddleware` | Connect/express-style middleware for manual mounting (no source map support). |
731
730
 
732
731
  ## Browser Compatibility
733
732
 
734
- - `sendBeacon` is preferred for small batches.
735
- - Image and fetch transports are used as fallbacks.
733
+ - `sendBeacon` is preferred for batches up to 60 KB; `fetch` POST is the fallback, using `keepalive` only for bodies up to 60 KB.
736
734
  - `PerformanceObserver` powers Web Vitals, long task, and resource timing when available.
737
735
  - `MutationObserver` is used as a fallback for dynamically inserted resources.
738
736
  - `IntersectionObserver` is required by `ExposurePlugin`.
@@ -750,21 +748,3 @@ pnpm build
750
748
  ```
751
749
 
752
750
  Coverage thresholds are 70 for lines, functions, branches, and statements.
753
-
754
- ## Build and Publish
755
-
756
- ```bash
757
- pnpm build
758
- pnpm build:tsup
759
- python3 publish.py --dry-run
760
- ```
761
-
762
- Publish after npm login:
763
-
764
- ```bash
765
- python3 publish.py --publish --registry https://registry.npmjs.org/
766
- ```
767
-
768
- The publish script validates lint, typecheck, tests, coverage, build output, ESM imports, CJS requires, package exports, absence of sourcemaps, absence of `dist/node_modules`, and absence of package tarball residue.
769
-
770
- Published npm files are limited to `dist` and package metadata. Source files, tests, sourcemaps, and temporary tarballs are not published.
@@ -1 +1 @@
1
- "use strict";var e=require("../types/enums.cjs"),r=require("../package.json.cjs");const{version:n}=r.default,t="unknown",o={dsn:"",projectId:t,userId:t,disabled:!1,enableXhr:!0,enableFetch:!0,enableClick:!0,enableError:!0,enableUnhandledRejection:!0,enableHashChange:!0,enableHistory:!0,enablePerformance:!0,enableScreenRecord:!0,enableWhiteScreen:!0,enableFingerprint:!1,anonymousId:t,visitorId:t,maxBreadcrumbs:30,useImageReport:!1,screenRecordEventTypes:[e.EventType.Error,e.EventType.Xhr,e.EventType.Fetch,e.EventType.Resource,e.EventType.UnhandledRejection],hasSkeleton:!1,rootCssSelectors:["html","body","#app","#root"],clickThrottleDelay:0,requestTimeoutMilliseconds:3e3,screenRecordDurationMs:3e3,repeatCodeError:!1,enableHttpPerformance:!1,ignoreErrors:[],excludeApis:[],cacheMaxLength:10,cacheWaitingTime:2e3,maxQueueLength:200,retryIntervalMilliseconds:6e4,offlineCacheKey:"swifty_sentry_offline_cache",tracesSampleRate:1,debug:!1};exports.DEFAULT_OPTIONS=o,exports.MAX_BREADCRUMBS=30,exports.MAX_WHITE_SCREEN_SAMPLE_COUNT=10,exports.SDK_VERSION=n,exports.UNKNOWN=t,exports.WHITE_SCREEN_SAMPLE_INTERVAL=1e3;
1
+ "use strict";var e=require("../types/enums.cjs"),r=require("../package.json.cjs");const{version:n}=r.default,t="unknown",a={dsn:"",projectId:t,userId:t,disabled:!1,enableXhr:!0,enableFetch:!0,enableClick:!0,enableError:!0,enableUnhandledRejection:!0,enableHashChange:!0,enableHistory:!0,enableWhiteScreen:!0,enableFingerprint:!1,anonymousId:t,visitorId:t,maxBreadcrumbs:30,screenRecordEventTypes:[e.EventType.Error,e.EventType.Xhr,e.EventType.Fetch,e.EventType.Resource,e.EventType.UnhandledRejection],hasSkeleton:!1,rootCssSelectors:["html","body","#app","#root"],clickThrottleDelay:0,screenRecordDurationMs:3e3,repeatCodeError:!1,enableHttpPerformance:!1,ignoreErrors:[],excludeApis:[],cacheMaxLength:10,cacheWaitingTime:2e3,maxQueueLength:200,retryIntervalMilliseconds:6e4,offlineCacheKey:"swifty_sentry_offline_cache",tracesSampleRate:1,debug:!1};exports.DEFAULT_OPTIONS=a,exports.MAX_BREADCRUMBS=30,exports.MAX_WHITE_SCREEN_SAMPLE_COUNT=10,exports.SDK_VERSION=n,exports.UNKNOWN=t,exports.WHITE_SCREEN_SAMPLE_INTERVAL=1e3;
@@ -1 +1 @@
1
- import{EventType as e}from"../types/enums.js";import r from"../package.json.js";const{version:n}=r,o=30,a=10,t=1e3,s="unknown",c={dsn:"",projectId:s,userId:s,disabled:!1,enableXhr:!0,enableFetch:!0,enableClick:!0,enableError:!0,enableUnhandledRejection:!0,enableHashChange:!0,enableHistory:!0,enablePerformance:!0,enableScreenRecord:!0,enableWhiteScreen:!0,enableFingerprint:!1,anonymousId:s,visitorId:s,maxBreadcrumbs:30,useImageReport:!1,screenRecordEventTypes:[e.Error,e.Xhr,e.Fetch,e.Resource,e.UnhandledRejection],hasSkeleton:!1,rootCssSelectors:["html","body","#app","#root"],clickThrottleDelay:0,requestTimeoutMilliseconds:3e3,screenRecordDurationMs:3e3,repeatCodeError:!1,enableHttpPerformance:!1,ignoreErrors:[],excludeApis:[],cacheMaxLength:10,cacheWaitingTime:2e3,maxQueueLength:200,retryIntervalMilliseconds:6e4,offlineCacheKey:"swifty_sentry_offline_cache",tracesSampleRate:1,debug:!1};export{c as DEFAULT_OPTIONS,o as MAX_BREADCRUMBS,a as MAX_WHITE_SCREEN_SAMPLE_COUNT,n as SDK_VERSION,s as UNKNOWN,t as WHITE_SCREEN_SAMPLE_INTERVAL};
1
+ import{EventType as e}from"../types/enums.js";import r from"../package.json.js";const{version:n}=r,o=30,a=10,t=1e3,s="unknown",c={dsn:"",projectId:s,userId:s,disabled:!1,enableXhr:!0,enableFetch:!0,enableClick:!0,enableError:!0,enableUnhandledRejection:!0,enableHashChange:!0,enableHistory:!0,enableWhiteScreen:!0,enableFingerprint:!1,anonymousId:s,visitorId:s,maxBreadcrumbs:30,screenRecordEventTypes:[e.Error,e.Xhr,e.Fetch,e.Resource,e.UnhandledRejection],hasSkeleton:!1,rootCssSelectors:["html","body","#app","#root"],clickThrottleDelay:0,screenRecordDurationMs:3e3,repeatCodeError:!1,enableHttpPerformance:!1,ignoreErrors:[],excludeApis:[],cacheMaxLength:10,cacheWaitingTime:2e3,maxQueueLength:200,retryIntervalMilliseconds:6e4,offlineCacheKey:"swifty_sentry_offline_cache",tracesSampleRate:1,debug:!1};export{c as DEFAULT_OPTIONS,o as MAX_BREADCRUMBS,a as MAX_WHITE_SCREEN_SAMPLE_COUNT,n as SDK_VERSION,s as UNKNOWN,t as WHITE_SCREEN_SAMPLE_INTERVAL};
package/dist/core/api.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("../types/enums.cjs");require("../constants/index.cjs");var t=require("../utils/get-base-data.cjs"),r=require("../utils/sentry.cjs");require("../utils/is-type.cjs");var a=require("./handle-error.cjs");require("./breadcrumb.cjs");var s=require("../reporter/index.cjs");exports.afterSendData=function(e){r.default.setOptions({afterSendData:e})},exports.beforePushEventList=function(e){r.default.setOptions({beforePushEventList:e})},exports.beforeSendData=function(e){r.default.setOptions({onBeforeReportData:e})},exports.getBaseInfo=function(){return t.default()},exports.getUserId=function(){return r.default.options.userId},exports.sendLocal=async function(){await s.default.flushOfflineCache()},exports.traceCustomEvent=function(r){s.default.send({...t.default(),type:e.EventType.Custom,status:e.Status.OK,name:r.name,message:r.message,extra:r.extra})},exports.traceError=function(r){a.handleError({...t.default(),type:e.EventType.Error,status:e.Status.Error,extra:r})},exports.tracePageView=function(r={}){s.default.send({...t.default(),type:e.EventType.PV,name:r.name??"ManualPageView",message:r.message??location.href,status:e.Status.OK,extra:r.extra??{url:location.href,referrer:document.referrer}})},exports.tracePerformance=function(r){s.default.send({...t.default(),type:e.EventType.Performance,status:e.Status.OK,...r})};
1
+ "use strict";var e=require("../types/enums.cjs");require("../constants/index.cjs");var t=require("../utils/get-base-data.cjs"),r=require("../utils/sentry.cjs");require("../utils/is-type.cjs"),require("../utils/logger.cjs");var s=require("./handle-error.cjs"),a=require("../reporter/index.cjs");exports.afterSend=function(e){r.default.setOptions({afterSend:e})},exports.beforeSend=function(e){r.default.setOptions({beforeSend:e})},exports.beforeSendBatch=function(e){r.default.setOptions({beforeSendBatch:e})},exports.flushOfflineCache=async function(){await a.default.flushOfflineCache()},exports.traceCustomEvent=function(r){a.default.send({...t.default(),type:e.EventType.Custom,status:e.Status.OK,name:r.name,message:r.message,extra:r.extra})},exports.traceError=function(r){s.handleError({...t.default(),type:e.EventType.Error,status:e.Status.Error,extra:r})},exports.tracePageView=function(r={}){a.default.send({...t.default(),type:e.EventType.PV,name:r.name??"ManualPageView",message:r.message??location.href,status:e.Status.OK,extra:r.extra??{url:location.href,referrer:document.referrer}})},exports.tracePerformance=function(r){a.default.send({...t.default(),type:e.EventType.Performance,status:e.Status.OK,...r})};
@@ -1,5 +1,26 @@
1
- import { IReportPayload } from '../types/common.js';
2
- import { AfterSendDataHook, ReportBatchHook, ReportDataHook } from '../types/options.js';
1
+ import { AfterSendHook, BeforeSendHook, BeforeSendBatchHook } from '../types/options.js';
2
+
3
+ /**
4
+ * Copyright (c) 2026 hangtiancheng
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
3
24
 
4
25
  declare function traceError(error: unknown): void;
5
26
  declare function tracePerformance(input: {
@@ -17,11 +38,9 @@ declare function tracePageView(input?: {
17
38
  readonly message?: string;
18
39
  readonly extra?: unknown;
19
40
  }): void;
20
- declare function getUserId(): string;
21
- declare function getBaseInfo(): IReportPayload;
22
- declare function beforeSendData(hook: ReportDataHook): void;
23
- declare function beforePushEventList(hook: ReportBatchHook): void;
24
- declare function afterSendData(hook: AfterSendDataHook): void;
25
- declare function sendLocal(): Promise<void>;
41
+ declare function beforeSend(hook: BeforeSendHook): void;
42
+ declare function beforeSendBatch(hook: BeforeSendBatchHook): void;
43
+ declare function afterSend(hook: AfterSendHook): void;
44
+ declare function flushOfflineCache(): Promise<void>;
26
45
 
27
- export { afterSendData, beforePushEventList, beforeSendData, getBaseInfo, getUserId, sendLocal, traceCustomEvent, traceError, tracePageView, tracePerformance };
46
+ export { afterSend, beforeSend, beforeSendBatch, flushOfflineCache, traceCustomEvent, traceError, tracePageView, tracePerformance };
package/dist/core/api.js CHANGED
@@ -1 +1 @@
1
- import{Status as e,EventType as t}from"../types/enums.js";import"../constants/index.js";import r from"../utils/get-base-data.js";import n from"../utils/sentry.js";import"../utils/is-type.js";import{handleError as s}from"./handle-error.js";import"./breadcrumb.js";import o from"../reporter/index.js";function a(n){s({...r(),type:t.Error,status:e.Error,extra:n})}function i(n){o.send({...r(),type:t.Performance,status:e.OK,...n})}function u(n){o.send({...r(),type:t.Custom,status:e.OK,name:n.name,message:n.message,extra:n.extra})}function f(n={}){o.send({...r(),type:t.PV,name:n.name??"ManualPageView",message:n.message??location.href,status:e.OK,extra:n.extra??{url:location.href,referrer:document.referrer}})}function m(){return n.options.userId}function p(){return r()}function c(e){n.setOptions({onBeforeReportData:e})}function d(e){n.setOptions({beforePushEventList:e})}function l(e){n.setOptions({afterSendData:e})}async function j(){await o.flushOfflineCache()}export{l as afterSendData,d as beforePushEventList,c as beforeSendData,p as getBaseInfo,m as getUserId,j as sendLocal,u as traceCustomEvent,a as traceError,f as tracePageView,i as tracePerformance};
1
+ import{Status as e,EventType as t}from"../types/enums.js";import"../constants/index.js";import r from"../utils/get-base-data.js";import s from"../utils/sentry.js";import"../utils/is-type.js";import"../utils/logger.js";import{handleError as n}from"./handle-error.js";import o from"../reporter/index.js";function a(s){n({...r(),type:t.Error,status:e.Error,extra:s})}function i(s){o.send({...r(),type:t.Performance,status:e.OK,...s})}function m(s){o.send({...r(),type:t.Custom,status:e.OK,name:s.name,message:s.message,extra:s.extra})}function f(s={}){o.send({...r(),type:t.PV,name:s.name??"ManualPageView",message:s.message??location.href,status:e.OK,extra:s.extra??{url:location.href,referrer:document.referrer}})}function u(e){s.setOptions({beforeSend:e})}function p(e){s.setOptions({beforeSendBatch:e})}function c(e){s.setOptions({afterSend:e})}async function l(){await o.flushOfflineCache()}export{c as afterSend,u as beforeSend,p as beforeSendBatch,l as flushOfflineCache,m as traceCustomEvent,a as traceError,f as tracePageView,i as tracePerformance};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../utils/data-structures.cjs");require("../types/enums.cjs");var s=require("../utils/sentry.cjs");require("../utils/is-type.cjs");class t extends e.MinHeap{static#e;static get instance(){return t.#e||(t.#e=new t),t.#e}push(e){const{onBeforePushBreadcrumb:t}=s.default.options;return t&&(e=t(e)),super.push(e)}}const r=t.instance;exports.Breadcrumb=t,exports.default=r;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../utils/data-structures.cjs");require("../types/enums.cjs");var s=require("../utils/sentry.cjs");require("../utils/is-type.cjs"),require("../utils/logger.cjs");class r extends e.BoundedList{push(e){const{beforeBreadcrumb:r}=s.default.options;super.push(r?r(e):e)}}const t=new r;exports.default=t;
@@ -1 +1 @@
1
- import{MinHeap as s}from"../utils/data-structures.js";import"../types/enums.js";import t from"../utils/sentry.js";import"../utils/is-type.js";class e extends s{static#s;static get instance(){return e.#s||(e.#s=new e),e.#s}push(s){const{onBeforePushBreadcrumb:e}=t.options;return e&&(s=e(s)),super.push(s)}}const n=e.instance;export{e as Breadcrumb,n as default};
1
+ import{BoundedList as s}from"../utils/data-structures.js";import"../types/enums.js";import t from"../utils/sentry.js";import"../utils/is-type.js";import"../utils/logger.js";const r=new class extends s{push(s){const{beforeBreadcrumb:r}=t.options;super.push(r?r(s):s)}};export{r as default};
@@ -1 +1 @@
1
- "use strict";var e=require("../types/enums.cjs");require("../constants/index.cjs");var t=require("../utils/decorate-prop.cjs"),s=require("../utils/get-base-data.cjs"),r=require("../utils/is-excluded-api.cjs"),n=require("../utils/sentry.cjs");require("../utils/is-type.cjs");var i=require("../utils/server-timing.cjs"),a=require("./bus.cjs");function o(t,s){return t.toUpperCase()===e.HttpMethod.Post&&s===n.default.options.dsn||r.default(s)}exports.pubFetch=function(){return t.default(globalThis,"fetch",t=>async function(r,n){const u=n?.method?.toUpperCase()??e.HttpMethod.Get,p={...s.default(),type:e.EventType.Fetch,method:u,requestData:{body:n?.body},name:"Fetch",api:r.toString(),elapsedTime:0,statusCode:e.HttpStatusCode.OK};return t.call(globalThis,r,n).then(t=>{const s=t.clone();return p.elapsedTime=Date.now()-p.timestamp,p.statusCode=s.status,p.serverTiming=i.getServerTimingFromHeaders(s.headers),s.text().then(t=>{o(u,r.toString())||(p.responseData=t,a.pub(e.EventType.Fetch,p))}).catch(()=>{o(u,r.toString())||a.pub(e.EventType.Fetch,p)}),t}).catch(t=>{throw o(u,r.toString())||(p.elapsedTime=Date.now()-p.timestamp,p.statusCode=0,p.message=t instanceof Error?t.message:"Network error",a.pub(e.EventType.Fetch,p)),t})})},exports.pubXhr=function(){const r=XMLHttpRequest.prototype,n=t.default(r,"open",t=>function(r,n,i,...a){return this.__sentry__={...s.default(),name:"XMLHttpRequest",type:e.EventType.Xhr,method:r.toUpperCase(),api:n,elapsedTime:0,statusCode:e.HttpStatusCode.OK},t.call(this,r,n,i,...a)}),u=t.default(r,"send",t=>function(s){if(!this.__sentry__)return t.call(this,s);const{method:r,api:n}=this.__sentry__;return this.addEventListener("loadend",()=>{o(r,n)||(this.__sentry__.statusCode=this.status,this.__sentry__.requestData={body:s},this.__sentry__.responseData={responseType:this.responseType,response:this.response},this.__sentry__.serverTiming=i.parseServerTiming(this.getResponseHeader("server-timing")),this.__sentry__.elapsedTime=Date.now()-this.__sentry__.timestamp,a.pub(e.EventType.Xhr,this.__sentry__))}),t.call(this,s)});return()=>{u(),n()}};
1
+ "use strict";var e=require("../types/enums.cjs");require("../constants/index.cjs");var t=require("../utils/decorate-prop.cjs"),s=require("../utils/get-base-data.cjs"),r=require("../utils/is-excluded-api.cjs"),n=require("../utils/sentry.cjs");require("../utils/is-type.cjs");var i=require("../utils/server-timing.cjs");require("../utils/logger.cjs");var a=require("./bus.cjs");function o(e){return e.length>8192?e.slice(0,8192):e}function u(e){return 0===e||e>=400}function p(e,t){return"POST"===e.toUpperCase()&&t===n.default.options.dsn||r.default(t)}exports.pubFetch=function(){return t.default(globalThis,"fetch",t=>function(r,n){const c=function(e){return"string"==typeof e?e:e instanceof URL?e.href:e.url}(r),h=function(e,t){return t?.method?t.method.toUpperCase():"undefined"!=typeof Request&&e instanceof Request?e.method.toUpperCase():"GET"}(r,n);if(p(h,c))return t.call(globalThis,r,n);const d={...s.default(),type:e.EventType.Fetch,method:h,name:"Fetch",api:c,elapsedTime:0,statusCode:200},l=d.timestamp;return t.call(globalThis,r,n).then(t=>(d.elapsedTime=Date.now()-l,d.statusCode=t.status,d.serverTiming=i.getServerTimingFromHeaders(t.headers),u(t.status)?(d.requestData={body:n?.body},t.clone().text().then(e=>{d.responseData=o(e)}).catch(()=>{}).finally(()=>{a.pub(e.EventType.Fetch,d)})):a.pub(e.EventType.Fetch,d),t)).catch(t=>{throw d.elapsedTime=Date.now()-l,d.statusCode=0,d.requestData={body:n?.body},d.message=t instanceof Error?t.message:"Network error",a.pub(e.EventType.Fetch,d),t})})},exports.pubXhr=function(){const r=XMLHttpRequest.prototype,n=t.default(r,"open",t=>function(r,n,i,...a){return this.__sentry__={...s.default(),name:"XMLHttpRequest",type:e.EventType.Xhr,method:r.toUpperCase(),api:String(n),elapsedTime:0,statusCode:200},t.call(this,r,n,i,...a)}),c=t.default(r,"send",t=>function(s){if(!this.__sentry__)return t.call(this,s);const{method:r,api:n}=this.__sentry__,c=Date.now();return this.__sentry__.timestamp=c,this.__sentry__.time=new Date(c).toISOString(),this.addEventListener("loadend",()=>{p(r,n)||(this.__sentry__.statusCode=this.status,u(this.status)&&(this.__sentry__.requestData={body:s},this.__sentry__.responseData={responseType:this.responseType,response:"string"==typeof this.response?o(this.response):this.response}),this.__sentry__.serverTiming=i.parseServerTiming(this.getResponseHeader("server-timing")),this.__sentry__.elapsedTime=Date.now()-c,a.pub(e.EventType.Xhr,this.__sentry__))},{once:!0}),t.call(this,s)});return()=>{c(),n()}};
@@ -1 +1 @@
1
- import{EventType as t,HttpStatusCode as e,HttpMethod as s}from"../types/enums.js";import"../constants/index.js";import r from"../utils/decorate-prop.js";import o from"../utils/get-base-data.js";import i from"../utils/is-excluded-api.js";import n from"../utils/sentry.js";import"../utils/is-type.js";import{parseServerTiming as a,getServerTimingFromHeaders as p}from"../utils/server-timing.js";import{pub as m}from"./bus.js";function _(){const s=XMLHttpRequest.prototype,i=r(s,"open",s=>function(r,i,n,...a){return this.__sentry__={...o(),name:"XMLHttpRequest",type:t.Xhr,method:r.toUpperCase(),api:i,elapsedTime:0,statusCode:e.OK},s.call(this,r,i,n,...a)}),n=r(s,"send",e=>function(s){if(!this.__sentry__)return e.call(this,s);const{method:r,api:o}=this.__sentry__;return this.addEventListener("loadend",()=>{u(r,o)||(this.__sentry__.statusCode=this.status,this.__sentry__.requestData={body:s},this.__sentry__.responseData={responseType:this.responseType,response:this.response},this.__sentry__.serverTiming=a(this.getResponseHeader("server-timing")),this.__sentry__.elapsedTime=Date.now()-this.__sentry__.timestamp,m(t.Xhr,this.__sentry__))}),e.call(this,s)});return()=>{n(),i()}}function h(){return r(globalThis,"fetch",r=>async function(i,n){const a=n?.method?.toUpperCase()??s.Get,_={...o(),type:t.Fetch,method:a,requestData:{body:n?.body},name:"Fetch",api:i.toString(),elapsedTime:0,statusCode:e.OK};return r.call(globalThis,i,n).then(e=>{const s=e.clone();return _.elapsedTime=Date.now()-_.timestamp,_.statusCode=s.status,_.serverTiming=p(s.headers),s.text().then(e=>{u(a,i.toString())||(_.responseData=e,m(t.Fetch,_))}).catch(()=>{u(a,i.toString())||m(t.Fetch,_)}),e}).catch(e=>{throw u(a,i.toString())||(_.elapsedTime=Date.now()-_.timestamp,_.statusCode=0,_.message=e instanceof Error?e.message:"Network error",m(t.Fetch,_)),e})})}function u(t,e){return t.toUpperCase()===s.Post&&e===n.options.dsn||i(e)}export{h as pubFetch,_ as pubXhr};
1
+ import{EventType as t}from"../types/enums.js";import"../constants/index.js";import e from"../utils/decorate-prop.js";import s from"../utils/get-base-data.js";import r from"../utils/is-excluded-api.js";import n from"../utils/sentry.js";import"../utils/is-type.js";import{parseServerTiming as o,getServerTimingFromHeaders as i}from"../utils/server-timing.js";import"../utils/logger.js";import{pub as a}from"./bus.js";function p(t){return t.length>8192?t.slice(0,8192):t}function u(t){return 0===t||t>=400}function h(){const r=XMLHttpRequest.prototype,n=e(r,"open",e=>function(r,n,o,...i){return this.__sentry__={...s(),name:"XMLHttpRequest",type:t.Xhr,method:r.toUpperCase(),api:String(n),elapsedTime:0,statusCode:200},e.call(this,r,n,o,...i)}),i=e(r,"send",e=>function(s){if(!this.__sentry__)return e.call(this,s);const{method:r,api:n}=this.__sentry__,i=Date.now();return this.__sentry__.timestamp=i,this.__sentry__.time=new Date(i).toISOString(),this.addEventListener("loadend",()=>{m(r,n)||(this.__sentry__.statusCode=this.status,u(this.status)&&(this.__sentry__.requestData={body:s},this.__sentry__.responseData={responseType:this.responseType,response:"string"==typeof this.response?p(this.response):this.response}),this.__sentry__.serverTiming=o(this.getResponseHeader("server-timing")),this.__sentry__.elapsedTime=Date.now()-i,a(t.Xhr,this.__sentry__))},{once:!0}),e.call(this,s)});return()=>{i(),n()}}function _(){return e(globalThis,"fetch",e=>function(r,n){const o=function(t){return"string"==typeof t?t:t instanceof URL?t.href:t.url}(r),h=function(t,e){return e?.method?e.method.toUpperCase():"undefined"!=typeof Request&&t instanceof Request?t.method.toUpperCase():"GET"}(r,n);if(m(h,o))return e.call(globalThis,r,n);const _={...s(),type:t.Fetch,method:h,name:"Fetch",api:o,elapsedTime:0,statusCode:200},c=_.timestamp;return e.call(globalThis,r,n).then(e=>(_.elapsedTime=Date.now()-c,_.statusCode=e.status,_.serverTiming=i(e.headers),u(e.status)?(_.requestData={body:n?.body},e.clone().text().then(t=>{_.responseData=p(t)}).catch(()=>{}).finally(()=>{a(t.Fetch,_)})):a(t.Fetch,_),e)).catch(e=>{throw _.elapsedTime=Date.now()-c,_.statusCode=0,_.requestData={body:n?.body},_.message=e instanceof Error?e.message:"Network error",a(t.Fetch,_),e})})}function m(t,e){return"POST"===t.toUpperCase()&&e===n.options.dsn||r(e)}export{_ as pubFetch,h as pubXhr};