# @whiterabbitjs/client

> Simple frontend library to integrate WhiteRabbit on your streaming website.

Latest version **4.1.1** (published 2023-08-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @whiterabbitjs/client
pnpm add @whiterabbitjs/client
yarn add @whiterabbitjs/client
bun add @whiterabbitjs/client
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.1 |
| Published | 2023-08-01 |
| First published | 2020-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 135.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | WhiteRabbit |
| Maintainers | vlad17451, troggy, whiterabbit-cd |

## Links

- npm: https://www.npmjs.com/package/@whiterabbitjs/client
- Repository: https://github.com/WhiteRabbitTheWorldIsYours/mad-hatter
- Homepage: https://github.com/WhiteRabbitTheWorldIsYours/mad-hatter#readme
- Issues: https://github.com/WhiteRabbitTheWorldIsYours/mad-hatter/issues
- npm.io page: https://npm.io/package/@whiterabbitjs/client

## Recent versions

- 4.1.1 (latest) — 2023-08-01
- 4.1.0 — 2023-08-01
- 4.0.1 — 2023-08-01
- 4.0.0 — 2023-08-01
- 3.5.0 — 2022-11-28
- 3.4.0 — 2022-10-31
- 3.3.4 — 2022-10-28
- 3.3.1 — 2022-10-10
- 3.3.0 — 2022-09-26
- 3.1.0 — 2022-09-05
- 3.0.7 — 2022-06-24
- 3.0.6 — 2022-06-24
- 3.0.5 — 2022-06-24
- 3.0.2 — 2022-06-10
- 3.0.0 — 2022-06-09
- … 97 more at https://npm.io/package/@whiterabbitjs/client/versions

## README

# WhiteRabbit client

Simple frontend library to integrate WhiteRabbit on your streaming website.

## Usage

### Option 1. Install from npm
Install `@whiterabbitjs/client` package

```sh
npm install --save @whiterabbitjs/client
```

Then use it on your webpage

```js
import { WhiteRabbitClient } from '@whiterabbitjs/client';

const client = new WhiteRabbitClient({ apiKey: '....your API key' });

client.requestPayment('tt8367814');
```

### Option 2. Use as module

```js
import { WhiteRabbitClient } from 'https://unpkg.com/@whiterabbitjs/client@2.40.1/dist/index.min.mjs';
const client = new WhiteRabbitClient({ apiKey: '....your API key' });

client.requestPayment('tt8367814');
```

## API

### `new WhiteRabbitClient(whiterabbitConfig)`

Create a new client instance.

Arguments:

* `whiteRabbitConfig` — config object with attributes:

  * `apiKey` — API key of the partner. Could test or production one

### `client.requestPayment(imdbId, [pssAddress], [medium])`

Request a payment by movie's imdb ID. Example: `tt8367814`. Returns a Promise which resolves with the status of the payment.

Arguments:
* `imdbId` - imdb ID for the movie.

Response:
* `movieId` — Number. Movie id as encoded by `utils.imdbToToken` function.
* `paymentId` - String. Unique ID for the payment
* `status` - Boolean. Result of the payment. `true` means the payment was successful, `false` — the payment was either declined by user or failure happened

Response example: 

```json
{
  movieId: "423557889"
  paymentId: "0x3202b4ef03ef29d87d81357e4c50105206be0396c5e5c4624d498b8cb7e2a083"
  status: true
}
```

## Utils API

```js
import { utils } from '@whiterabbitjs/client';
```

### `utils.imdbToToken(imdbId)`

Convert given `imdbId` to WhiteRabbit token.

Arguments:

* `imdbId` — imdbID for the Movie.

### `utils.tokenToImdb(tokenId)`

Convert given WhiteRabbit `tokenId` to imdbId.

Arguments:

* `tokenId` — tokenId for the MovieToken.

### `utils.getRegionByCode(regionCode)`

Given a [three digit M49 region code](https://en.wikipedia.org/wiki/UN_M49) returns a [two-letter ISO 3166-1 alpha-2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)

Arguments:

* `regionCode` — M49 region code. Three digits, zero-padded (e.g. 008).

---
_Source: https://npm.io/package/@whiterabbitjs/client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
