Skip to content

Async adapter to save & deliver front-end events to some back-end

License

Notifications You must be signed in to change notification settings

qiwi/event-transmitter

Repository files navigation

@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