Javascript SDK implemented as a standard module system
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
- Bracket Game Operations
- Challenges Operations
- Discussions Operations
- Fantasy Operations
- Football Operations
- Helpers Operations
- Id Mapping Operations
- Loyalty Operations
- Match Quiz Operations
- Mini Games Operations
- Predictor Operations
- Private Leagues Operations
- Profile Operations
- Progress Operations
- Top X Operations
- Voting Operations
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
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.
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.