Skip to content

Commit

Permalink
fix PR
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Apr 9, 2024
1 parent 955048f commit abf402e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
34 changes: 14 additions & 20 deletions packages/core/src/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface FeedbackParams {
attachments?: Attachment[];
url?: string;
source?: string;
relatedEventId?: string;
associatedEventId?: string;
}

/**
Expand All @@ -19,7 +19,7 @@ export function captureFeedback(
feedbackParams: FeedbackParams,
hint?: EventHint & { includeReplay?: boolean },
): string {
const { message, name, email, url, source, attachments } = feedbackParams;
const { message, name, email, url, source, attachments, associatedEventId } = feedbackParams;

const client = getClient();
const transport = client && client.getTransport();
Expand All @@ -37,14 +37,13 @@ export function captureFeedback(
message,
url,
source,
associated_event_id: associatedEventId,
},
},
type: 'feedback',
level: 'info',
};

// TODO: What to do with `relatedEventId` ?

if (client) {
client.emit('beforeSendFeedback', feedbackEvent, hint);
}
Expand All @@ -55,22 +54,17 @@ export function captureFeedback(
// Because we do not support attachments in the feedback envelope
// Once the Sentry API properly supports this, we can get rid of this and send it through the event envelope
if (client && attachments && attachments.length) {
const transport = client.getTransport();
const dsn = client.getDsn();

if (dsn && transport) {
// TODO: https://docs.sentry.io/platforms/javascript/enriching-events/attachments/
// eslint-disable-next-line @typescript-eslint/no-floating-promises
void transport.send(
createAttachmentEnvelope(
feedbackEvent,
attachments,
dsn,
client.getOptions()._metadata,
client.getOptions().tunnel,
),
);
}
// TODO: https://docs.sentry.io/platforms/javascript/enriching-events/attachments/
// eslint-disable-next-line @typescript-eslint/no-floating-promises
void transport.send(
createAttachmentEnvelope(
feedbackEvent,
attachments,
dsn,
client.getOptions()._metadata,
client.getOptions().tunnel,
),
);
}

return eventId;
Expand Down
13 changes: 7 additions & 6 deletions packages/feedback/src/core/sendFeedback.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { createAttachmentEnvelope, createEventEnvelope, getClient, withScope } from '@sentry/core';
import type { FeedbackEvent, SendFeedback, SendFeedbackParams } from '@sentry/types';
import { captureFeedback } from '@sentry/core';
import { getClient } from '@sentry/core';
import type { SendFeedback, SendFeedbackParams, TransportMakeRequestResponse } from '@sentry/types';
import type { Event } from '@sentry/types';
import { getLocationHref } from '@sentry/utils';
import { FEEDBACK_API_SOURCE, FEEDBACK_WIDGET_SOURCE } from '../constants';
import { prepareFeedbackEvent } from '../util/prepareFeedbackEvent';
import { FEEDBACK_API_SOURCE } from '../constants';

/**
* Public API to send a Feedback item to Sentry
*/
export const sendFeedback: SendFeedback = (
{ name, email, message, attachments, source = FEEDBACK_API_SOURCE, url = getLocationHref() }: SendFeedbackParams,
{ includeReplay = true } = {},
): Promise<void> {
): Promise<void> => {
if (!message) {
throw new Error('Unable to submit feedback with empty message');
}
Expand All @@ -22,7 +23,7 @@ export const sendFeedback: SendFeedback = (
throw new Error('No client setup, cannot send feedback.');
}

const eventId = captureFeedback({ name, email, message, attachments, source, url }, hint);
const eventId = captureFeedback({ name, email, message, attachments, source, url }, { includeReplay });

// We want to wait for the feedback to be sent (or not)
return new Promise<void>((resolve, reject) => {
Expand Down
7 changes: 2 additions & 5 deletions packages/types/src/feedback/sendFeedback.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Attachment } from '../attachment';
import type { Event } from '../event';
import type { TransportMakeRequestResponse } from '../transport';
import type { User } from '../user';

/**
Expand All @@ -19,6 +18,7 @@ interface FeedbackContext extends Record<string, unknown> {
name?: string;
replay_id?: string;
url?: string;
associated_event_id?: string;
}

/**
Expand Down Expand Up @@ -48,7 +48,4 @@ interface SendFeedbackOptions {
includeReplay?: boolean;
}

export type SendFeedback = (
params: SendFeedbackParams,
options?: SendFeedbackOptions,
) => Promise<TransportMakeRequestResponse>;
export type SendFeedback = (params: SendFeedbackParams, options?: SendFeedbackOptions) => Promise<void>;

0 comments on commit abf402e

Please sign in to comment.