fansunited-sdk-esm
v1.83.0
Published
Javascript SDK implemented as a standart module system
Downloads
1,077
Readme
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:
- Profile Operations
- Football Operations
- Predictor Operations
- Top X Operations
- Match Quiz Operations
- Loyalty Operations
- Activity Operations
Install the SDK
The JavaScript SDK is distributed as NPM package. You can install it by running the following command:
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:
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", // 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:
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.