# Fans United JavaScript SDK

Welcome to the Fans United JavaScript SDK. This SDK works for client-side, server-side and React Native implementations.
The SDK has complete coverage of the Fans United APIs and is split into different namespaces depending on what you want
to achieve.

Operations supported by the SDK:

- [Activity Operations](https://docs.fansunitedmedia.com/docs/activity-operations)
- [Bracket Game Operations](https://docs.fansunitedmedia.com/docs/bracket-game-operations)
- [Challenges Operations](https://docs.fansunitedmedia.com/docs/challenges-operations)
- [Discussions Operations](https://docs.fansunitedmedia.com/docs/discussions-operations)
- [Fantasy Operations](https://docs.fansunitedmedia.com/docs/fantasy-operations)
- [Football Operations](https://docs.fansunitedmedia.com/docs/football-operations)
- [Helpers Operations](https://docs.fansunitedmedia.com/docs/helpers-operations)
- [Id Mapping Operations](https://docs.fansunitedmedia.com/docs/id-mapping-operations)
- [Loyalty Operations](https://docs.fansunitedmedia.com/docs/loyalty-operations)
- [Match Quiz Operations](https://docs.fansunitedmedia.com/docs/match-quiz-operations)
- [Mini Games Operations](https://docs.fansunitedmedia.com/docs/mini-games-operations)
- [Predictor Operations](https://docs.fansunitedmedia.com/docs/predictor-operations)
- [Private Leagues Operations](https://docs.fansunitedmedia.com/docs/private-leagues-operations)
- [Profile Operations](https://docs.fansunitedmedia.com/docs/profile-operations)
- [Progress Operations](https://docs.fansunitedmedia.com/docs/progress-operations)
- [Top X Operations](https://docs.fansunitedmedia.com/docs/top-x-operations)
- [Voting Operations](https://docs.fansunitedmedia.com/docs/voting-operations)

## Install the SDK

The JavaScript SDK is distributed as NPM package. You can install it by running the following command:

```bash
npm i fansunited-sdk-esm
yarn add fansunited-sdk-esm
```

## Use the SDK in your app

The SDK works with JWTs provided from OAuth2 provider. The default provider is Firebase Authentication, but if the
client has their own provider, it can be integrated into the platform.

The SDK comes with a configuration and an interface. The client needs to implement this interface and pass the implementation
in the config.

### Initiate the SDK

This is what the SDK config requires:

```javascript
import {FansUnitedSDK} from "fansunited-sdk-esm";
// If you want too use map file for better debugging.
import {FansUnitedSDK} from "fansunited-sdk-esm/index";

const fansUnitedSdk = FansUnitedSDK({
    "apiKey": "your-api-key-here",
    "environment": "dev|prod|staging", // default: prod
    "clientId": "your-client-id-here",
    "lang": "bg|en|ro|el|sk|pt|sr|hu|sv|es|fr|nl|de|it|ar", // default: en
    "idSchema": "native|enetpulse|sportradar|sportal365|api_football", // default: native
    "errorHandlingMode": "default|standard", // default: default
    "authProvider": new myTokenProvider()
});
```

The interface being exported by the Fans United SDK:

```javascript
interface FansUnitedAuthInterface() {
    getIdToken = () => {},
    logout = () => {}
}
```

A client supplied class that implements the interface is provided:

```javascript
class myTokenProvider implements FansUnitedAuthInterface() {
    getIdToken = () => {
        // custom logic ...
        return tokenString;
    };

    logout = () => {
        // custom logic to delete token...
    };
}
```

The token is being stored in memory for security purposes.
The Fans United SDK is monitoring for the validity/expiration of the token and issues a new token before expiry.