@qiwi/event-transmitter
v1.19.1
Published
Async adapter to save & deliver reasonable events to some endpoint
Downloads
83
Readme
@qiwi/event-transmitter
Async adapter to save & deliver reasonable events to some endpoint
Install
yarn add @qiwi/event-transmitter
Usage
FLP integration
import { createFrontLogProxyTransmitter } from '@qiwi/event-transmitter'
const transmitter = createFrontLogProxyTransmitter({
appName: 'my-app',
url: 'https://example.qiwi.com/event'
})
// logger-like interface
transmitter.error(new Error('some error'))
transmitter.info('some-event')
transmitter.debug('debug')
transmitter.warn('warn')
transmitter.trace('trace')
FLP integration with React
import { createFrontLogProxyTransmitter } from '@qiwi/event-transmitter'
const transmitter = createFrontLogProxyTransmitter({
appName: 'my=app',
url: 'https://example.qiwi.com/event'
})
class ErrorBoundary extends Component {
public state = {
hasError: false
};
public static getDerivedStateFromError() {
return { hasError: true };
}
public componentDidCatch(error, errorInfo) {
transmitter.error({message: error, details: {errorInfo}})
}
public render() {
if (this.state.hasError) {
return <h1>Sorry.. there was an error</h1>;
}
return this.props.children;
}
}
Custom usage
import {createTransmitter, createHttpPipe, IPipe} from '@qiwi/event-transmitter'
const httpPipe: IPipe = createHttpPipe({
url: 'https://example.qiwi.com/event',
method: 'POST'
})
const transmitter = createTransmitter({
pipeline: [httpPipe]
})
const event: IClientEventDto = {...}
transmitter.push(event)
See also https://github.com/qiwi/flp-njs