Skip to content

Latest commit

 

History

History
83 lines (65 loc) · 2.09 KB

README.md

File metadata and controls

83 lines (65 loc) · 2.09 KB

@qiwi/event-transmitter

Async adapter to save & deliver reasonable events to some endpoint

CI Maintainability Test Coverage

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

License

MIT