1.7.4 • Published 5 months ago

@dabafinance/shared-backend v1.7.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Installation

This is a simple installation guide.

Run the following command to install the package:

npm install @dabafinance/shared-backend

or if you are using Yarn:

yarn add @dabafinance/shared-backend

Quick Start

This package exports a set of resuable classes and functions that can be used across our microservices. The following is a list of the exported classes and functions:

Kafka

  • Producer: A class that can be extended to make custom classes for producing to various kafka topics.
  • Consumer: A class that can be extended to make custom classes for consuming from various kafka topics.
  • Kafka: A class that can be extended to make custom classes for interacting with kafka.

Currency-Conversion

Currency Converter

This package is a simple tool that allows you to convert currencies in real-time, check rates between two currencies, and also pass a manual rate for conversion purposes.

Usage

To use the package, you need to create an instance of the CurrencyConverter class, passing your API key as a parameter. The class has several methods that allow you to interact with the API.

Methods

getApi(): AxiosInstance

Returns the AxiosInstance used by the CurrencyConverter instance.

getCurrencyRate(pair: IPair): Promise<IRateResponse | IError>

Returns the exchange rate between two currencies.

  • pair: An object with two properties: from and to.

getAvailableCurrencies(): Promise<ICurrencyResponse | IError>

Returns a list of available currencies.

convertCurrencyWithAdjustedRates(input: IConvertWithRate): Promise<IRateResponse | IError>

Converts an amount from one currency to another using a manual rate.

  • input: An object with three properties: from, to, amount, and rate.

convertCurrencyWithMarketRates(payload: IConvert): Promise<ICurrencyResponse | IError>

Converts an amount from one currency to another using the current market rate.

  • payload: An object with three properties: from, to, and amount.

Example

import CurrencyConverter from 'currency-converter'

const apiKey = 'YOUR_API_KEY'
const currencyConverter = new CurrencyConverter(apiKey)

// Get the exchange rate between USD and EUR
const rate = await currencyConverter.getCurrencyRate({ from: 'USD', to: 'EUR' })
console.log(rate)

// Get a list of available currencies
const currencies = await currencyConverter.getAvailableCurrencies()
console.log(currencies)

// Convert 10 USD to EUR using a manual rate
const result = await currencyConverter.convertCurrencyWithAdjustedRates({
  from: 'USD',
  to: 'EUR',
  amount: 10,
  rate: 0.85
})
console.log(result)

// Convert 10 USD to EUR using the current market rate
const response = await currencyConverter.convertCurrencyWithMarketRates({
  from: 'USD',
  to: 'EUR',
  amount: 10
})
console.log(response)

Auth

  • authDirective: A function that checks that the token is available in request headers, decodeds the token and returns the payload.
  • roleDirective: A function that checks that the token is available in request headers, decodeds the token and extracts the role from the payload and checks if the user has the necessary role to perform the action.

Errors

  • ErrorService: A class that exposes a bunch of static methods for creating errors. The errors are returned as a GraphQLError object.

Base Repository

  • BaseRepository: A class that can be extended to make custom classes for interacting with a database.
1.7.4

5 months ago

1.7.3

5 months ago

1.7.2

5 months ago

1.7.1

5 months ago

1.7.0

9 months ago

1.6.0

10 months ago

1.5.3

12 months ago

1.5.2

12 months ago

1.5.1

12 months ago

1.5.0

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.9

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.25

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago