diff --git a/src/main/ts/index.ts b/src/main/ts/index.ts index d8a5525..89f649a 100644 --- a/src/main/ts/index.ts +++ b/src/main/ts/index.ts @@ -10,6 +10,7 @@ export { createHttpPipeFallback } from './pipes/httpFallback' export { createMaskerPipe, panMaskerPipe } from './pipes/masker' export { createHttpBatchPipe } from './pipes/httpBatch' export { createDeviceInfoPipe } from './pipes/deviceInfo' +export { createBrowserLocationHrefPipe } from './pipes/browserLocationHref' export * from './interfaces' export * from './pipes/index' @@ -80,6 +81,4 @@ export { createFrontLogProxyTransmitter, } -export type { - IClientEventDtoFlp -} +export type { IClientEventDtoFlp } diff --git a/src/main/ts/pipes/browserLocationHref.ts b/src/main/ts/pipes/browserLocationHref.ts new file mode 100644 index 0000000..0bf1210 --- /dev/null +++ b/src/main/ts/pipes/browserLocationHref.ts @@ -0,0 +1,14 @@ +import { IPromise } from '@qiwi/substrate' + +import { IPipe, IPipeOutput, ITransmittable } from '../interfaces' +import { clone, set } from '../utils/index' + +export const type = 'browser-location-href' + +export const createBrowserLocationHrefPipe = (): IPipe => ({ + type, + execute({ data }: ITransmittable): IPromise { + const output = set(clone(data), 'meta.location', window.location.href) + return Promise.resolve([null, output]) + }, +}) diff --git a/src/main/ts/pipes/flp.ts b/src/main/ts/pipes/flp.ts index 5cc1921..ac88b63 100644 --- a/src/main/ts/pipes/flp.ts +++ b/src/main/ts/pipes/flp.ts @@ -2,6 +2,7 @@ import { IClientEventDto, LogLevel } from '@qiwi/substrate' import { IPipe, ITransmittable, TPipeline } from '../interfaces' import { identity } from '../utils/index' +import { createBrowserLocationHrefPipe } from './browserLocationHref' import { createDeviceInfoPipe } from './deviceInfo' import { createHttpBatchPipe, IHttpBatchPipeOpts } from './httpBatch' import { panMaskerPipe } from './masker' @@ -82,5 +83,6 @@ export const createFlpPipeline = ({ panMaskerPipe, eventifyPipe, createDeviceInfoPipe(), + createBrowserLocationHrefPipe(), createHttpBatchPipe({ url, batchUrl, headers, method }), ] diff --git a/src/test/ts/createFrontLogProxyTransmitter.ts b/src/test/ts/createFrontLogProxyTransmitter.ts index d3d7699..ba32b2d 100644 --- a/src/test/ts/createFrontLogProxyTransmitter.ts +++ b/src/test/ts/createFrontLogProxyTransmitter.ts @@ -13,6 +13,10 @@ global.window = { navigator: { userAgent: '', }, + // @ts-ignore + location: { + href: 'https://github.com/qiwi/event-transmitter', + }, } // @ts-ignore @@ -35,7 +39,6 @@ test('createFrontLogProxyTransmitter correctly call fetch with data', async () = code: '211', tags: ['frontend', 'qiwi'], }) - res.details.appContextId = '' res.details.clientId = '' diff --git a/src/test/ts/pipes/browserLocationHref.ts b/src/test/ts/pipes/browserLocationHref.ts new file mode 100644 index 0000000..6d9a7b6 --- /dev/null +++ b/src/test/ts/pipes/browserLocationHref.ts @@ -0,0 +1,18 @@ +import { test } from 'uvu' +import * as assert from 'uvu/assert' + +import { createBrowserLocationHrefPipe } from '../../../main/ts/index' + +test('browserLocationHref is returned by factory', async () => { + const browserLocationHrefPipe = createBrowserLocationHrefPipe() + const res = await browserLocationHrefPipe.execute( + { data: {}, err: null, meta: { history: [] } }, + () => { /* noop */ }, + ) + assert.equal(res, [ + null, + { meta: { location: 'https://github.com/qiwi/event-transmitter' } }, + ]) +}) + +test.run()