diff --git a/.changeset/curvy-pets-report.md b/.changeset/curvy-pets-report.md new file mode 100644 index 0000000..f40b39f --- /dev/null +++ b/.changeset/curvy-pets-report.md @@ -0,0 +1,5 @@ +--- +"@livechat/agent-app-sdk": minor +--- + +[DPS-4294] extend `page_data` event for Fullscreen apps diff --git a/packages/agent-app-sdk/README.md b/packages/agent-app-sdk/README.md index 818f103..9b74568 100644 --- a/packages/agent-app-sdk/README.md +++ b/packages/agent-app-sdk/README.md @@ -239,7 +239,15 @@ Gets the customer profile recorded most recently. Returns the `ICustomerProfile` ### Events -This widget currently does not support any events. +#### `page_data` + +Emitted when widget in initialized. The handler will get the main window page data object as an argument: + +```ts +interface IPageData { + queryParams: object; +} +``` ### Methods @@ -255,6 +263,10 @@ Navigates LiveChat Agent App to given pathname. Updates "Reports" section filters to given `filters` object. +#### `getPageData(): IPageData | null` + +Gets the main window page data recorded most recently. Returns the `IPageData` object, which is identical to the one emitted by the `page_data` event or `null` (if no data were registered). + ## Settings widget (`ISettingsWidget`) ### Events diff --git a/packages/agent-app-sdk/src/widgets/fullscreen/fullscreen-widget.spec.ts b/packages/agent-app-sdk/src/widgets/fullscreen/fullscreen-widget.spec.ts index 40c532c..2d9b5d5 100644 --- a/packages/agent-app-sdk/src/widgets/fullscreen/fullscreen-widget.spec.ts +++ b/packages/agent-app-sdk/src/widgets/fullscreen/fullscreen-widget.spec.ts @@ -18,6 +18,15 @@ jest.mock('@livechat/widget-core-sdk', () => { }; }); +jest.mock('../shared/page-data', () => { + return { + withPageData: jest.fn().mockImplementation(widget => ({ + ...widget, + getPageData: jest.fn() + })) + }; +}); + describe('FullscreenWidget', () => { it('has a `setNotificationBadge` method', () => { const connection = createMockConnection(); @@ -108,12 +117,13 @@ describe('createFullscreenWidget', () => { }); it('returns the correct object with correct properties', async () => { - expect.assertions(4); + expect.assertions(5); const widget = await createFullscreenWidget(); expect(widget).toHaveProperty('setNotificationBadge'); expect(widget).toHaveProperty('on'); expect(widget).toHaveProperty('off'); expect(widget).toHaveProperty('sendMessage'); + expect(widget).toHaveProperty('getPageData'); }); }); diff --git a/packages/agent-app-sdk/src/widgets/fullscreen/fullscreen-widget.ts b/packages/agent-app-sdk/src/widgets/fullscreen/fullscreen-widget.ts index 93c7aae..3e2dbe4 100644 --- a/packages/agent-app-sdk/src/widgets/fullscreen/fullscreen-widget.ts +++ b/packages/agent-app-sdk/src/widgets/fullscreen/fullscreen-widget.ts @@ -9,6 +9,7 @@ import { IFullscreenWidgetEvents, ReportsFilters } from './interfaces'; +import { withPageData } from '../shared/page-data'; export { ReportsFilters } from './interfaces'; @@ -35,13 +36,17 @@ export function FullscreenWidget( } } ); - return withAmplitude(base); + return withAmplitude(withPageData(base)); } export type IFullscreenWidget = ReturnType; export default function createFullscreenWidget(): Promise { - return createConnection().then(connection => - FullscreenWidget(connection) - ); + let widget: IFullscreenWidget; + return createConnection() + .then(connection => { + widget = FullscreenWidget(connection); + return connection.sendMessage('plugin_inited'); + }) + .then(() => widget); }