# JS Evy API Client

An extended JS/TS client for [Evy API](https://evy.readme.io/reference/introduction).

Works in browsers and node.

## Add the dependency to your project

```sh
npm i @getevy/api-client
```

## Initialization

```typescript
import EvyApi from '@getevy/api-client';
const apiClient = new EvyApi({ apiKey: 'your_api_key' });
```

**Configuration object**

| Key          | **Required** | **Description**                                                             |
| ------------ | ------------ | --------------------------------------------------------------------------- |
| **apiKey**   | **yes**      | your API key                                                                |
| **apiURL**   | no           | the URL of the API to target                                                |
| **language** | no           | the prefered language of the user, only `en` and `fr` are supported for now |

## Usage

### Get offers

**Usage**

```typescript
const offers = await apiClient.offers.get('product_id', 1000, 'en');
```

**Interface**

```typescript
apiClient.offers.get(product_id: string, price: number, language?: string) => Promise<IOffersData>
```

**Parameters (from left to right)**

| Name           | **Required** | **Description**                                  |
| -------------- | ------------ | ------------------------------------------------ |
| **product_id** | **yes**      | The product for which we want insurance offers   |
| **price**      | **yes**      | The current price of the product                 |
| **language**   | no           | The locale (overrides the initial configuration) |

**Result: IOffersData**

| Key         | Description                                           |
| ----------- | ----------------------------------------------------- |
| **offers**  | The offers attachable on the product                  |
| **locales** | The translations of the wording to use with the offer |

See the [types](src/types/offer.ts) or the [API documentation](https://evy.readme.io/reference/retrieve-offers) for further descriptions.

## License

The MIT License (MIT). Please see the [License File](./LICENSE) for more information.
