File tree 7 files changed +61
-6
lines changed
7 files changed +61
-6
lines changed Original file line number Diff line number Diff line change 1
1
// 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' ;
3
3
import {
4
4
addTracingExtensionsShim ,
5
5
browserTracingIntegrationShim ,
@@ -12,5 +12,6 @@ export {
12
12
addTracingExtensionsShim as addTracingExtensions ,
13
13
replayIntegrationShim as replayIntegration ,
14
14
feedbackIntegration ,
15
+ getFeedback ,
15
16
} ;
16
17
// 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' ;
2
2
import { replayIntegration } from '@sentry-internal/replay' ;
3
3
import {
4
4
browserTracingIntegration ,
@@ -27,6 +27,7 @@ export {
27
27
addTracingExtensions ,
28
28
startBrowserTracingNavigationSpan ,
29
29
startBrowserTracingPageLoadSpan ,
30
+ getFeedback ,
30
31
} ;
31
32
32
33
export * 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';
49
49
50
50
export {
51
51
feedbackIntegration ,
52
+ getFeedback ,
52
53
sendFeedback ,
53
54
} from '@sentry-internal/feedback' ;
54
55
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' ;
2
2
import type { Integration , IntegrationFn } from '@sentry/types' ;
3
3
import { isBrowser , logger } from '@sentry/utils' ;
4
4
import {
@@ -45,7 +45,10 @@ interface PublicFeedbackIntegration {
45
45
}
46
46
export type IFeedbackIntegration = Integration & PublicFeedbackIntegration ;
47
47
48
- export const _feedbackIntegration = ( ( {
48
+ /**
49
+ * Allow users to capture user feedback and send it to Sentry.
50
+ */
51
+ export const feedbackIntegration = ( ( {
49
52
// FeedbackGeneralConfiguration
50
53
id = 'sentry-feedback' ,
51
54
showBranding = true ,
@@ -279,5 +282,3 @@ export const _feedbackIntegration = (({
279
282
} ,
280
283
} ;
281
284
} ) satisfies IntegrationFn ;
282
-
283
- export const feedbackIntegration = defineIntegration ( _feedbackIntegration ) ;
Original file line number Diff line number Diff line change 1
1
export { sendFeedback } from './core/sendFeedback' ;
2
2
export { feedbackIntegration } from './core/integration' ;
3
3
export { feedbackModalIntegration } from './modal/integration' ;
4
+ export { getFeedback } from './core/getFeedback' ;
4
5
export { feedbackScreenshotIntegration } from './screenshot/integration' ;
5
6
6
7
export type { OptionalFeedbackConfiguration } from './types' ;
You can’t perform that action at this time.
0 commit comments