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:
- Profile Operations
- Football Operations
- Predictor Operations
- Top X Operations
- Match Quiz Operations
- Loyalty Operations
- Activity Operations
The JavaScript SDK is distributed as NPM package. You can install it by running the following command:
npm i fansunited-sdk-umd
yarn add fansunited-sdk-umd
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:
<script src="path-to-node_modules/fansunited-sdk-umd/index.js"></script>
// If you want too use map file for better debugging.
<script src="path-to-node_modules/fansunited-sdk-umd/index.js.map"></script>
<script>
const sdk = FansUnitedSDK.FansUnitedSDK({
apiKey: "your-api-key-here",
clientId: "your-client-id-here",
idSchema: "native|enetpulse|sportradar|sportal365|api_football", // default: native
environment: "dev|prod|staging", // default: prod
lang: "bg|en|ro|el|sk|pt|sr|hu|sv|es|fr|nl|de|it", // default: en
errorHandlingMode: "default|standard", // default: default
authProvider: new myTokenProvider()
});
</script>
The interface being exported by the Fans United SDK:
interface FansUnitedAuthInterface() {
getIdToken = () => {},
logout = () => {}
}
A client supplied class that implements the interface is provided:
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.