From 52716cb8779277fe9f82a8320dd702e7b2b7e659 Mon Sep 17 00:00:00 2001 From: HazA Date: Tue, 11 Sep 2018 15:07:04 +0200 Subject: [PATCH 1/2] fix: Expose and repair report dialog --- packages/browser/src/index.ts | 2 +- packages/browser/src/sdk.ts | 43 ++++++++++++++++++++++++++++++ packages/core/src/api.ts | 1 + packages/core/test/lib/api.test.ts | 14 +++++++--- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index 247372470017..f7a32f9a18f6 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -19,7 +19,7 @@ export { getHubFromCarrier, getCurrentHub, Hub, Scope } from '@sentry/hub'; export { BrowserBackend, BrowserOptions } from './backend'; export { BrowserClient } from './client'; -export { defaultIntegrations, init } from './sdk'; +export { defaultIntegrations, init, lastEventId, showReportDialog } from './sdk'; export { SDK_NAME, SDK_VERSION } from './version'; import * as Integrations from './integrations'; diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index d006799c83c8..871ee5eb34ff 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -1,4 +1,6 @@ import { initAndBind } from '@sentry/core'; +import { getCurrentHub } from '@sentry/hub'; +import { DsnLike } from '@sentry/types'; import { BrowserOptions } from './backend'; import { BrowserClient } from './client'; import { @@ -69,3 +71,44 @@ export const defaultIntegrations = [ export function init(options: BrowserOptions): void { initAndBind(BrowserClient, options, defaultIntegrations); } + +/** + * Present the user with a report dialog. + * + * @param options Everything is optional, we try to fetch all info need from the global scope. + */ +export function showReportDialog(options: { + [key: string]: any; + eventId?: string; + dsn?: DsnLike; + user?: { + email?: string; + name?: string; + }; + lang?: string; + title?: string; + subtitle?: string; + subtitle2?: string; + labelName?: string; + labelEmail?: string; + labelComments?: string; + labelClose?: string; + labelSubmit?: string; + errorGeneric?: string; + errorFormEntry?: string; + successMessage?: string; +}): void { + if (!options.eventId) { + options.eventId = getCurrentHub().lastEventId(); + } + (getCurrentHub().getClient() as BrowserClient).showReportDialog(options); +} + +/** + * This is the getter for lastEventId. + * + * @returns The last event id of a captured event. + */ +export function lastEventId(): string | undefined { + return getCurrentHub().lastEventId(); +} diff --git a/packages/core/src/api.ts b/packages/core/src/api.ts index 6bc2cc334f67..619a1241fc88 100644 --- a/packages/core/src/api.ts +++ b/packages/core/src/api.ts @@ -73,6 +73,7 @@ export class API { const endpoint = `${this.getBaseUrl()}${dsn.path ? `/${dsn.path}` : ''}/api/embed/error-page/`; const encodedOptions = []; + encodedOptions.push(`dsn=${dsn.toString()}`); for (const key in dialogOptions) { if (key === 'user') { if (!dialogOptions.user) { diff --git a/packages/core/test/lib/api.test.ts b/packages/core/test/lib/api.test.ts index 9fe2007c365a..ac6d66383c80 100644 --- a/packages/core/test/lib/api.test.ts +++ b/packages/core/test/lib/api.test.ts @@ -21,14 +21,16 @@ describe('API', () => { }); test('getReportDialogEndpoint', () => { expect(new API(dsnPublic).getReportDialogEndpoint({})).toEqual( - 'https://sentry.io:1234/subpath/api/embed/error-page/', + 'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123', ); expect( new API(dsnPublic).getReportDialogEndpoint({ eventId: 'abc', testy: '2', }), - ).toEqual('https://sentry.io:1234/subpath/api/embed/error-page/?eventId=abc&testy=2'); + ).toEqual( + 'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&eventId=abc&testy=2', + ); expect( new API(dsnPublic).getReportDialogEndpoint({ @@ -38,14 +40,18 @@ describe('API', () => { name: 'yo', }, }), - ).toEqual('https://sentry.io:1234/subpath/api/embed/error-page/?eventId=abc&name=yo&email=email'); + ).toEqual( + 'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&eventId=abc&name=yo&email=email', + ); expect( new API(dsnPublic).getReportDialogEndpoint({ eventId: 'abc', user: undefined, }), - ).toEqual('https://sentry.io:1234/subpath/api/embed/error-page/?eventId=abc'); + ).toEqual( + 'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&eventId=abc', + ); }); test('getDsn', () => { expect(new API(dsnPublic).getDsn()).toEqual(new Dsn(dsnPublic)); From 0072d035b00cca22191239d0cf932ff7a924a6f6 Mon Sep 17 00:00:00 2001 From: HazA Date: Tue, 11 Sep 2018 15:42:51 +0200 Subject: [PATCH 2/2] fix: Add default empty object for report dialog --- packages/browser/src/sdk.ts | 44 +++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index 871ee5eb34ff..66e69ca8ca1d 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -77,27 +77,29 @@ export function init(options: BrowserOptions): void { * * @param options Everything is optional, we try to fetch all info need from the global scope. */ -export function showReportDialog(options: { - [key: string]: any; - eventId?: string; - dsn?: DsnLike; - user?: { - email?: string; - name?: string; - }; - lang?: string; - title?: string; - subtitle?: string; - subtitle2?: string; - labelName?: string; - labelEmail?: string; - labelComments?: string; - labelClose?: string; - labelSubmit?: string; - errorGeneric?: string; - errorFormEntry?: string; - successMessage?: string; -}): void { +export function showReportDialog( + options: { + [key: string]: any; + eventId?: string; + dsn?: DsnLike; + user?: { + email?: string; + name?: string; + }; + lang?: string; + title?: string; + subtitle?: string; + subtitle2?: string; + labelName?: string; + labelEmail?: string; + labelComments?: string; + labelClose?: string; + labelSubmit?: string; + errorGeneric?: string; + errorFormEntry?: string; + successMessage?: string; + } = {}, +): void { if (!options.eventId) { options.eventId = getCurrentHub().lastEventId(); }