Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ClientEmitter

Main class for work with API for Node.js

Library for Node.js default export this class

Hierarchy

Index

Methods

call

  • call(method: string, options?: object): Promise<any>
  • Call backend API method directly (types unsafe)

    Use it if backend API update (add new methods, change request or response fileds), but library is not

    throws

    Error - If there is an error sending request to backend API or parsing response

    Parameters

    • method: string

      Backend API method name

    • options: object = {}

      Backend API options object

    Returns Promise<any>

    Promise, what resolved to backend API response result field value

closeServer

  • closeServer(): Promise<void>
  • Close created handling webhooks server

    throws

    Error - If server not was started or closing error

    Returns Promise<void>

    Promise, what resolved void

createInvoice

createServer

  • Create handling webhooks server

    Important: at the time of publication of version 0.2.0 (Dec 9, 2021), API servers do not accept self-signed certificates

    throws

    Error - If create server error

    Parameters

    • serverOptions: ServerOptions

      Node.js built-in server options

    • secretPath: string = '/'

      Webhooks secret path, processing webhooks takes place only on it

    • listenOptions: ListenOptions = ...

      Node.js built-in server listen options

    Returns Promise<void>

    Promise, what resolved void

getBalance

  • getBalance(currencyCode: string, isReturnInNanos?: boolean, isForce?: boolean): Promise<string>
  • Get API app balance value for passed currency

    Call Client.getBalances method to fetch balances information

    throws

    Error - If there is an error sending request to backend API or parsing response

    Parameters

    • currencyCode: string

      Currency code

    • isReturnInNanos: boolean = false

      If true, return raw balances in nanos, else return converted to coins balances

    • isForce: boolean = false

      If true, return fresh data from backend API, not from cache

    Returns Promise<string>

    Promise, what resolved to API app balance value for passed currency

getBalances

  • getBalances(isReturnInNanos?: boolean, isForce?: boolean): Promise<Balances>
  • Get API app balances infomation

    Use toBalances backend API result convert function

    Call Store.getCurrencies method to fetch exchange rates information

    throws

    Error - If there is an error sending request to backend API or parsing response

    Parameters

    • isReturnInNanos: boolean = false

      If true, return raw balances in nanos, else return converted to coins balances

    • isForce: boolean = false

      If true, return fresh data from backend API, not from cache

    Returns Promise<Balances>

    Promise, what resolved to API app balances infomation object

getCurrencies

  • getCurrencies(isForce?: boolean): Promise<Currencies>
  • Get API supported currencies infomation

    Use toCurrencies backend API result convert function

    throws

    Error - If there is an error sending request to backend API or parsing response

    Parameters

    • Optional isForce: boolean

      If true, return fresh data from backend API, not from cache

    Returns Promise<Currencies>

    Promise, what resolved to API supported currencies infomation object

getCurrency

  • getCurrency(currencyCode: string, isForce?: boolean): Promise<Currency>
  • Get currency with passed code infomation

    Call Store.getCurrencies method to fetch currencies information

    throws

    Error - If there is an error sending request to backend API or parsing response

    Parameters

    • currencyCode: string

      Currency code

    • isForce: boolean = false

      If true, return fresh data from backend API, not from cache

    Returns Promise<Currency>

    Promise, what resolved to currency with passed code infomation object or null, if currency with passed code not exists

getExchangeRate

  • getExchangeRate(source: string, target: string, isForce?: boolean): Promise<number>
  • Get one exchange rate infomation to passed currencies pair

    Call Store.getExchangeRates method to fetch exchange rates information, Store.getCurrencies method to fetch currencies information and use getExchageRate function to get signle exchange rate

    throws

    Error - If there is an error sending request to backend API or parsing response

    Parameters

    • source: string

      Source currency code

    • target: string

      Target currency code

    • isForce: boolean = false

      If true, return fresh data from backend API, not from cache

    Returns Promise<number>

    Promise, what resolved to exchange rate or zero, if currencies pair not exists

getExchangeRates

  • Get API supported currencies exchange rate infomation

    Use toExchangeRates backend API result convert function

    throws

    Error - If there is an error sending request to backend API or parsing response

    Parameters

    • Optional isForce: boolean

      If true, return fresh data from backend API, not from cache

    Returns Promise<ExchangeRates>

    Promise, what resolved to API supported currencies exchange rate infomation object

getInvoices

getInvoicesPaginate

getMe

  • getMe(isForce?: boolean): Promise<Me>
  • Get associated with passed API key app infomation

    Use toMe backend API result convert function

    throws

    Error - If there is an error sending request to backend API or parsing response

    Parameters

    • isForce: boolean = false

      If true, return fresh data from backend API, not from cache

    Returns Promise<Me>

    Promise, what resolved to associated with passed API key app infomation object

getPageSize

  • getPageSize(): number

middleware

off

  • off(event: "paid", listener: (invoice?: Invoice, requestDate?: Date) => any): void
  • Unsubscribes from paid event

    Parameters

    • event: "paid"

      paid event name

    • listener: (invoice?: Invoice, requestDate?: Date) => any

      Event listener with invoice and requestDate callback parameters

        • (invoice?: Invoice, requestDate?: Date): any
        • Parameters

          • Optional invoice: Invoice
          • Optional requestDate: Date

          Returns any

    Returns void

on

  • on(event: "paid", listener: (invoice?: Invoice, requestDate?: Date) => any): void
  • Subscribes to paid event

    See ClientEmitter._emit to more about event listener

    Parameters

    • event: "paid"

      paid event name

    • listener: (invoice?: Invoice, requestDate?: Date) => any

      Event listener with invoice and requestDate callback parameters

        • (invoice?: Invoice, requestDate?: Date): any
        • Parameters

          • Optional invoice: Invoice
          • Optional requestDate: Date

          Returns any

    Returns void

setPageSize

  • setPageSize(pageSizeParam: number): void

Private _emit

  • _emit(event: "paid", invoice: Invoice, requestDate: Date): void
  • Emit event to listeners

    Parameters

    • event: "paid"

      paid event name

    • invoice: Invoice

      Paid invoice information object

    • requestDate: Date

      Date of occurrence of event, need to filter old event. If server is not available, backend API try resend webhooks by timeout, so when server becomes available again, many old events will be sent from backend API.

    Returns void

Private _handleWebhook

  • _handleWebhook(data: any, req: IncomingMessage, res: ServerResponse): void
  • Handling webhook data, send response and emit events

    Parameters

    • data: any

      Parsed request body

    • req: IncomingMessage

      Node.js built-in IncomingMessage object

    • res: ServerResponse

      Node.js built-in ServerResponse object

    Returns void

Constructors

constructor

  • new ClientEmitter(apiKey: string, endpoint?: string): ClientEmitter
  • Create class instance

    Parameters

    • apiKey: string

      Crypto Bot API key, looks like '1234:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'

    • endpoint: string = 'mainnet'

      API endpoint url or 'mainnet' or 'testnet' for hardcoded in library endpoint urls

    Returns ClientEmitter

Properties

Protected _transport

_transport: Transport

Transport class instance

Private _apiKey

_apiKey: string

Api key

Private _events

_events: {} = {}

Event listeners store

Type declaration

  • [key: string]: ((...args: any) => any)[]

Private _server

_server: Server

Handling webhooks created Node.js built-in server