Skip to content

Commit

Permalink
feat: provide pipeline to createFrontLogProxyTransmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
pismenskiy authored Apr 7, 2023
1 parent a84638a commit 3a308db
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/main/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IClientEventDto, LogLevel } from '@qiwi/substrate'
import { nanoid } from 'nanoid'

import { IPipeOutput } from './interfaces'
import { IPipeOutput, TPipeline } from './interfaces'
import { createFlpPipeline, eventifyPipe } from './pipes/flp'
import { createTransmittable, createTransmitter } from './transmitter'
import { getCookie, setCookie } from './utils/cookie'
Expand Down Expand Up @@ -33,9 +33,11 @@ type IClientEventDtoFlp = Omit<
const createFrontLogProxyTransmitter = ({
appName,
url,
pipeline,
}: {
appName: string
url?: string
pipeline?: TPipeline
}) => {
const appContextId = nanoid()
const clientId = getClientId(appName)
Expand All @@ -44,10 +46,12 @@ const createFrontLogProxyTransmitter = ({
}

const transmitter = createTransmitter({
pipeline: createFlpPipeline({
url,
method: 'POST' as any,
}),
pipeline:
pipeline ||
createFlpPipeline({
url,
method: 'POST' as any,
}),
})

return [
Expand All @@ -66,12 +70,12 @@ const createFrontLogProxyTransmitter = ({
data === undefined ||
data instanceof Error
) {
return transmitter.push(({
return transmitter.push({
message: data,
details: { appContextId, clientId },
meta: { appName },
level,
}))
})
}

return transmitter.push({
Expand Down
9 changes: 4 additions & 5 deletions src/main/ts/pipes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import once from 'lodash.once'
import { IPipeOutput, ITransmittable, TPipeline } from '../interfaces'

export const getPipelineId = (pipeline: TPipeline): string =>
pipeline.reduce((acc, pipe, index) =>
(
pipeline.reduce(
(acc, pipe, index) =>
acc +
(Array.isArray(pipe)
? `{${index}-[${getPipelineId(pipe)}]}`
: `{${index}-${pipe.type}}`)
),
''
: `{${index}-${pipe.type}}`),
'',
)

export const execute = async (
Expand Down
4 changes: 3 additions & 1 deletion src/test/ts/pipes/browserLocationHref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ test('browserLocationHref is returned by factory', async () => {
const browserLocationHrefPipe = createBrowserLocationHrefPipe()
const res = await browserLocationHrefPipe.execute(
{ data: {}, err: null, meta: { history: [] } },
() => { /* noop */ },
() => {
/* noop */
},
)
assert.equal(res, [
null,
Expand Down

0 comments on commit 3a308db

Please sign in to comment.