File tree Expand file tree Collapse file tree 7 files changed +61
-6
lines changed Expand file tree Collapse file tree 7 files changed +61
-6
lines changed Original file line number Diff line number Diff line change 11// This is exported so the loader does not fail when switching off Replay/Tracing
2- import { feedbackIntegration } from '@sentry-internal/feedback' ;
2+ import { feedbackIntegration , getFeedback } from '@sentry-internal/feedback' ;
33import {
44 addTracingExtensionsShim ,
55 browserTracingIntegrationShim ,
@@ -12,5 +12,6 @@ export {
1212 addTracingExtensionsShim as addTracingExtensions ,
1313 replayIntegrationShim as replayIntegration ,
1414 feedbackIntegration ,
15+ getFeedback ,
1516} ;
1617// Note: We do not export a shim for `Span` here, as that is quite complex and would blow up the bundle
Original file line number Diff line number Diff line change 1- import { feedbackIntegration } from '@sentry-internal/feedback' ;
1+ import { feedbackIntegration , getFeedback } from '@sentry-internal/feedback' ;
22import { replayIntegration } from '@sentry-internal/replay' ;
33import {
44 browserTracingIntegration ,
@@ -27,6 +27,7 @@ export {
2727 addTracingExtensions ,
2828 startBrowserTracingNavigationSpan ,
2929 startBrowserTracingPageLoadSpan ,
30+ getFeedback ,
3031} ;
3132
3233export * from './index.bundle.base' ;
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ export { replayCanvasIntegration } from '@sentry-internal/replay-canvas';
4949
5050export {
5151 feedbackIntegration ,
52+ getFeedback ,
5253 sendFeedback ,
5354} from '@sentry-internal/feedback' ;
5455
Original file line number Diff line number Diff line change 1+ import { getCurrentScope } from '@sentry/core' ;
2+ import { getFeedback } from './getFeedback' ;
3+ import { feedbackIntegration } from './integration' ;
4+ import { mockSdk } from './mockSdk' ;
5+
6+ describe ( 'getFeedback' , ( ) => {
7+ beforeEach ( ( ) => {
8+ getCurrentScope ( ) . setClient ( undefined ) ;
9+ } ) ;
10+
11+ it ( 'works without a client' , ( ) => {
12+ const actual = getFeedback ( ) ;
13+ expect ( actual ) . toBeUndefined ( ) ;
14+ } ) ;
15+
16+ it ( 'works with a client without Feedback' , ( ) => {
17+ mockSdk ( {
18+ sentryOptions : {
19+ integrations : [ ] ,
20+ } ,
21+ } ) ;
22+
23+ const actual = getFeedback ( ) ;
24+ expect ( actual ) . toBeUndefined ( ) ;
25+ } ) ;
26+
27+ it ( 'works with a client with Feedback' , ( ) => {
28+ const feedback = feedbackIntegration ( ) ;
29+
30+ mockSdk ( {
31+ sentryOptions : {
32+ integrations : [ feedback ] ,
33+ } ,
34+ } ) ;
35+
36+ const actual = getFeedback ( ) ;
37+ expect ( actual ) . toBeDefined ( ) ;
38+ expect ( actual === feedback ) . toBe ( true ) ;
39+ } ) ;
40+ } ) ;
Original file line number Diff line number Diff line change 1+ import { getClient } from '@sentry/core' ;
2+ import type { feedbackIntegration } from './integration' ;
3+
4+ /**
5+ * This is a small utility to get a type-safe instance of the Feedback integration.
6+ */
7+ export function getFeedback ( ) : ReturnType < typeof feedbackIntegration > | undefined {
8+ const client = getClient ( ) ;
9+ return client && client . getIntegrationByName < ReturnType < typeof feedbackIntegration > > ( 'Feedback' ) ;
10+ }
Original file line number Diff line number Diff line change 1- import { defineIntegration , getClient } from '@sentry/core' ;
1+ import { getClient } from '@sentry/core' ;
22import type { Integration , IntegrationFn } from '@sentry/types' ;
33import { isBrowser , logger } from '@sentry/utils' ;
44import {
@@ -45,7 +45,10 @@ interface PublicFeedbackIntegration {
4545}
4646export type IFeedbackIntegration = Integration & PublicFeedbackIntegration ;
4747
48- export const _feedbackIntegration = ( ( {
48+ /**
49+ * Allow users to capture user feedback and send it to Sentry.
50+ */
51+ export const feedbackIntegration = ( ( {
4952 // FeedbackGeneralConfiguration
5053 id = 'sentry-feedback' ,
5154 showBranding = true ,
@@ -279,5 +282,3 @@ export const _feedbackIntegration = (({
279282 } ,
280283 } ;
281284} ) satisfies IntegrationFn ;
282-
283- export const feedbackIntegration = defineIntegration ( _feedbackIntegration ) ;
Original file line number Diff line number Diff line change 11export { sendFeedback } from './core/sendFeedback' ;
22export { feedbackIntegration } from './core/integration' ;
33export { feedbackModalIntegration } from './modal/integration' ;
4+ export { getFeedback } from './core/getFeedback' ;
45export { feedbackScreenshotIntegration } from './screenshot/integration' ;
56
67export type { OptionalFeedbackConfiguration } from './types' ;
You can’t perform that action at this time.
0 commit comments